]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-3.0-3.15.10-201408140023.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.15.10-201408140023.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 76b75f7b84..34cd7f7 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,75 @@ else
317 KBUILD_CFLAGS += -O2
318 endif
319
320 +# Tell gcc to never replace conditional load with a non-conditional one
321 +KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)
322 +
323 +ifndef DISABLE_PAX_PLUGINS
324 +ifeq ($(call cc-ifversion, -ge, 0408, y), y)
325 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
326 +else
327 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
328 +endif
329 +ifneq ($(PLUGINCC),)
330 +ifdef CONFIG_PAX_CONSTIFY_PLUGIN
331 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
332 +endif
333 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
334 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
335 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
336 +endif
337 +ifdef CONFIG_KALLOCSTAT_PLUGIN
338 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
339 +endif
340 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
341 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
342 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
343 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
344 +endif
345 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT
346 +RANDSTRUCT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/randomize_layout_plugin.so -DRANDSTRUCT_PLUGIN
347 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT_PERFORMANCE
348 +RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-performance-mode
349 +endif
350 +endif
351 +ifdef CONFIG_CHECKER_PLUGIN
352 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
353 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
354 +endif
355 +endif
356 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
357 +ifdef CONFIG_PAX_SIZE_OVERFLOW
358 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
359 +endif
360 +ifdef CONFIG_PAX_LATENT_ENTROPY
361 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
362 +endif
363 +ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
364 +STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
365 +endif
366 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
367 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
368 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
369 +GCC_PLUGINS_CFLAGS += $(RANDSTRUCT_PLUGIN_CFLAGS)
370 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
371 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN LATENT_ENTROPY_PLUGIN_CFLAGS
372 +ifeq ($(KBUILD_EXTMOD),)
373 +gcc-plugins:
374 + $(Q)$(MAKE) $(build)=tools/gcc
375 +else
376 +gcc-plugins: ;
377 +endif
378 +else
379 +gcc-plugins:
380 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
381 + $(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.))
382 +else
383 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
384 +endif
385 + $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
386 +endif
387 +endif
388 +
389 include $(srctree)/arch/$(SRCARCH)/Makefile
390
391 ifdef CONFIG_READABLE_ASM
392 @@ -818,7 +888,7 @@ export mod_sign_cmd
393
394
395 ifeq ($(KBUILD_EXTMOD),)
396 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
397 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
398
399 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
400 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
401 @@ -867,6 +937,8 @@ endif
402
403 # The actual objects are generated when descending,
404 # make sure no implicit rule kicks in
405 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
406 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
407 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
408
409 # Handle descending into subdirectories listed in $(vmlinux-dirs)
410 @@ -876,7 +948,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
411 # Error messages still appears in the original language
412
413 PHONY += $(vmlinux-dirs)
414 -$(vmlinux-dirs): prepare scripts
415 +$(vmlinux-dirs): gcc-plugins prepare scripts
416 $(Q)$(MAKE) $(build)=$@
417
418 define filechk_kernel.release
419 @@ -919,10 +991,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
420
421 archprepare: archheaders archscripts prepare1 scripts_basic
422
423 +prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
424 +prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
425 prepare0: archprepare FORCE
426 $(Q)$(MAKE) $(build)=.
427
428 # All the preparing..
429 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
430 prepare: prepare0
431
432 # Generate some files
433 @@ -1030,6 +1105,8 @@ all: modules
434 # using awk while concatenating to the final file.
435
436 PHONY += modules
437 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
438 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
439 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
440 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
441 @$(kecho) ' Building modules, stage 2.';
442 @@ -1045,7 +1122,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
443
444 # Target to prepare building external modules
445 PHONY += modules_prepare
446 -modules_prepare: prepare scripts
447 +modules_prepare: gcc-plugins prepare scripts
448
449 # Target to install modules
450 PHONY += modules_install
451 @@ -1111,7 +1188,10 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
452 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
453 signing_key.priv signing_key.x509 x509.genkey \
454 extra_certificates signing_key.x509.keyid \
455 - signing_key.x509.signer include/linux/version.h
456 + signing_key.x509.signer include/linux/version.h \
457 + tools/gcc/size_overflow_plugin/size_overflow_hash_aux.h \
458 + tools/gcc/size_overflow_plugin/size_overflow_hash.h \
459 + tools/gcc/randomize_layout_seed.h
460
461 # clean - Delete most, but leave enough to build external modules
462 #
463 @@ -1150,7 +1230,7 @@ distclean: mrproper
464 @find $(srctree) $(RCS_FIND_IGNORE) \
465 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
466 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
467 - -o -name '.*.rej' -o -name '*%' -o -name 'core' \) \
468 + -o -name '.*.rej' -o -name '*.so' -o -name '*%' -o -name 'core' \) \
469 -type f -print | xargs rm -f
470
471
472 @@ -1311,6 +1391,8 @@ PHONY += $(module-dirs) modules
473 $(module-dirs): crmodverdir $(objtree)/Module.symvers
474 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
475
476 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
477 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
478 modules: $(module-dirs)
479 @$(kecho) ' Building modules, stage 2.';
480 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
481 @@ -1450,17 +1532,21 @@ else
482 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
483 endif
484
485 -%.s: %.c prepare scripts FORCE
486 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
487 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
488 +%.s: %.c gcc-plugins prepare scripts FORCE
489 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
490 %.i: %.c prepare scripts FORCE
491 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
492 -%.o: %.c prepare scripts FORCE
493 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
494 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
495 +%.o: %.c gcc-plugins prepare scripts FORCE
496 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
497 %.lst: %.c prepare scripts FORCE
498 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
499 -%.s: %.S prepare scripts FORCE
500 +%.s: %.S gcc-plugins prepare scripts FORCE
501 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
502 -%.o: %.S prepare scripts FORCE
503 +%.o: %.S gcc-plugins prepare scripts FORCE
504 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
505 %.symtypes: %.c prepare scripts FORCE
506 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
507 @@ -1470,11 +1556,15 @@ endif
508 $(cmd_crmodverdir)
509 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
510 $(build)=$(build-dir)
511 -%/: prepare scripts FORCE
512 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
513 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
514 +%/: gcc-plugins prepare scripts FORCE
515 $(cmd_crmodverdir)
516 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
517 $(build)=$(build-dir)
518 -%.ko: prepare scripts FORCE
519 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
520 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
521 +%.ko: gcc-plugins prepare scripts FORCE
522 $(cmd_crmodverdir)
523 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
524 $(build)=$(build-dir) $(@:.ko=.o)
525 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
526 index 78b03ef..da28a51 100644
527 --- a/arch/alpha/include/asm/atomic.h
528 +++ b/arch/alpha/include/asm/atomic.h
529 @@ -292,6 +292,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
530 #define atomic_dec(v) atomic_sub(1,(v))
531 #define atomic64_dec(v) atomic64_sub(1,(v))
532
533 +#define atomic64_read_unchecked(v) atomic64_read(v)
534 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
535 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
536 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
537 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
538 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
539 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
540 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
541 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
542 +
543 #define smp_mb__before_atomic_dec() smp_mb()
544 #define smp_mb__after_atomic_dec() smp_mb()
545 #define smp_mb__before_atomic_inc() smp_mb()
546 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
547 index ad368a9..fbe0f25 100644
548 --- a/arch/alpha/include/asm/cache.h
549 +++ b/arch/alpha/include/asm/cache.h
550 @@ -4,19 +4,19 @@
551 #ifndef __ARCH_ALPHA_CACHE_H
552 #define __ARCH_ALPHA_CACHE_H
553
554 +#include <linux/const.h>
555
556 /* Bytes per L1 (data) cache line. */
557 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
558 -# define L1_CACHE_BYTES 64
559 # define L1_CACHE_SHIFT 6
560 #else
561 /* Both EV4 and EV5 are write-through, read-allocate,
562 direct-mapped, physical.
563 */
564 -# define L1_CACHE_BYTES 32
565 # define L1_CACHE_SHIFT 5
566 #endif
567
568 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
569 #define SMP_CACHE_BYTES L1_CACHE_BYTES
570
571 #endif
572 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
573 index 968d999..d36b2df 100644
574 --- a/arch/alpha/include/asm/elf.h
575 +++ b/arch/alpha/include/asm/elf.h
576 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
577
578 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
579
580 +#ifdef CONFIG_PAX_ASLR
581 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
582 +
583 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
584 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
585 +#endif
586 +
587 /* $0 is set by ld.so to a pointer to a function which might be
588 registered using atexit. This provides a mean for the dynamic
589 linker to call DT_FINI functions for shared libraries that have
590 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
591 index aab14a0..b4fa3e7 100644
592 --- a/arch/alpha/include/asm/pgalloc.h
593 +++ b/arch/alpha/include/asm/pgalloc.h
594 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
595 pgd_set(pgd, pmd);
596 }
597
598 +static inline void
599 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
600 +{
601 + pgd_populate(mm, pgd, pmd);
602 +}
603 +
604 extern pgd_t *pgd_alloc(struct mm_struct *mm);
605
606 static inline void
607 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
608 index d8f9b7e..f6222fa 100644
609 --- a/arch/alpha/include/asm/pgtable.h
610 +++ b/arch/alpha/include/asm/pgtable.h
611 @@ -102,6 +102,17 @@ struct vm_area_struct;
612 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
613 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
614 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
615 +
616 +#ifdef CONFIG_PAX_PAGEEXEC
617 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
618 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
619 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
620 +#else
621 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
622 +# define PAGE_COPY_NOEXEC PAGE_COPY
623 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
624 +#endif
625 +
626 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
627
628 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
629 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
630 index 2fd00b7..cfd5069 100644
631 --- a/arch/alpha/kernel/module.c
632 +++ b/arch/alpha/kernel/module.c
633 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
634
635 /* The small sections were sorted to the end of the segment.
636 The following should definitely cover them. */
637 - gp = (u64)me->module_core + me->core_size - 0x8000;
638 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
639 got = sechdrs[me->arch.gotsecindex].sh_addr;
640
641 for (i = 0; i < n; i++) {
642 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
643 index 1402fcc..0b1abd2 100644
644 --- a/arch/alpha/kernel/osf_sys.c
645 +++ b/arch/alpha/kernel/osf_sys.c
646 @@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
647 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
648
649 static unsigned long
650 -arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
651 - unsigned long limit)
652 +arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
653 + unsigned long limit, unsigned long flags)
654 {
655 struct vm_unmapped_area_info info;
656 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
657
658 info.flags = 0;
659 info.length = len;
660 @@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
661 info.high_limit = limit;
662 info.align_mask = 0;
663 info.align_offset = 0;
664 + info.threadstack_offset = offset;
665 return vm_unmapped_area(&info);
666 }
667
668 @@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
669 merely specific addresses, but regions of memory -- perhaps
670 this feature should be incorporated into all ports? */
671
672 +#ifdef CONFIG_PAX_RANDMMAP
673 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
674 +#endif
675 +
676 if (addr) {
677 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
678 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
679 if (addr != (unsigned long) -ENOMEM)
680 return addr;
681 }
682
683 /* Next, try allocating at TASK_UNMAPPED_BASE. */
684 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
685 - len, limit);
686 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
687 +
688 if (addr != (unsigned long) -ENOMEM)
689 return addr;
690
691 /* Finally, try allocating in low memory. */
692 - addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
693 + addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
694
695 return addr;
696 }
697 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
698 index 98838a0..b304fb4 100644
699 --- a/arch/alpha/mm/fault.c
700 +++ b/arch/alpha/mm/fault.c
701 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
702 __reload_thread(pcb);
703 }
704
705 +#ifdef CONFIG_PAX_PAGEEXEC
706 +/*
707 + * PaX: decide what to do with offenders (regs->pc = fault address)
708 + *
709 + * returns 1 when task should be killed
710 + * 2 when patched PLT trampoline was detected
711 + * 3 when unpatched PLT trampoline was detected
712 + */
713 +static int pax_handle_fetch_fault(struct pt_regs *regs)
714 +{
715 +
716 +#ifdef CONFIG_PAX_EMUPLT
717 + int err;
718 +
719 + do { /* PaX: patched PLT emulation #1 */
720 + unsigned int ldah, ldq, jmp;
721 +
722 + err = get_user(ldah, (unsigned int *)regs->pc);
723 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
724 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
725 +
726 + if (err)
727 + break;
728 +
729 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
730 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
731 + jmp == 0x6BFB0000U)
732 + {
733 + unsigned long r27, addr;
734 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
735 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
736 +
737 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
738 + err = get_user(r27, (unsigned long *)addr);
739 + if (err)
740 + break;
741 +
742 + regs->r27 = r27;
743 + regs->pc = r27;
744 + return 2;
745 + }
746 + } while (0);
747 +
748 + do { /* PaX: patched PLT emulation #2 */
749 + unsigned int ldah, lda, br;
750 +
751 + err = get_user(ldah, (unsigned int *)regs->pc);
752 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
753 + err |= get_user(br, (unsigned int *)(regs->pc+8));
754 +
755 + if (err)
756 + break;
757 +
758 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
759 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
760 + (br & 0xFFE00000U) == 0xC3E00000U)
761 + {
762 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
763 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
764 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
765 +
766 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
767 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
768 + return 2;
769 + }
770 + } while (0);
771 +
772 + do { /* PaX: unpatched PLT emulation */
773 + unsigned int br;
774 +
775 + err = get_user(br, (unsigned int *)regs->pc);
776 +
777 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
778 + unsigned int br2, ldq, nop, jmp;
779 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
780 +
781 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
782 + err = get_user(br2, (unsigned int *)addr);
783 + err |= get_user(ldq, (unsigned int *)(addr+4));
784 + err |= get_user(nop, (unsigned int *)(addr+8));
785 + err |= get_user(jmp, (unsigned int *)(addr+12));
786 + err |= get_user(resolver, (unsigned long *)(addr+16));
787 +
788 + if (err)
789 + break;
790 +
791 + if (br2 == 0xC3600000U &&
792 + ldq == 0xA77B000CU &&
793 + nop == 0x47FF041FU &&
794 + jmp == 0x6B7B0000U)
795 + {
796 + regs->r28 = regs->pc+4;
797 + regs->r27 = addr+16;
798 + regs->pc = resolver;
799 + return 3;
800 + }
801 + }
802 + } while (0);
803 +#endif
804 +
805 + return 1;
806 +}
807 +
808 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
809 +{
810 + unsigned long i;
811 +
812 + printk(KERN_ERR "PAX: bytes at PC: ");
813 + for (i = 0; i < 5; i++) {
814 + unsigned int c;
815 + if (get_user(c, (unsigned int *)pc+i))
816 + printk(KERN_CONT "???????? ");
817 + else
818 + printk(KERN_CONT "%08x ", c);
819 + }
820 + printk("\n");
821 +}
822 +#endif
823
824 /*
825 * This routine handles page faults. It determines the address,
826 @@ -133,8 +251,29 @@ retry:
827 good_area:
828 si_code = SEGV_ACCERR;
829 if (cause < 0) {
830 - if (!(vma->vm_flags & VM_EXEC))
831 + if (!(vma->vm_flags & VM_EXEC)) {
832 +
833 +#ifdef CONFIG_PAX_PAGEEXEC
834 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
835 + goto bad_area;
836 +
837 + up_read(&mm->mmap_sem);
838 + switch (pax_handle_fetch_fault(regs)) {
839 +
840 +#ifdef CONFIG_PAX_EMUPLT
841 + case 2:
842 + case 3:
843 + return;
844 +#endif
845 +
846 + }
847 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
848 + do_group_exit(SIGKILL);
849 +#else
850 goto bad_area;
851 +#endif
852 +
853 + }
854 } else if (!cause) {
855 /* Allow reads even for write-only mappings */
856 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
857 diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
858 index 34c7a24..592fca9 100644
859 --- a/arch/arm/Kconfig
860 +++ b/arch/arm/Kconfig
861 @@ -1878,7 +1878,7 @@ config ALIGNMENT_TRAP
862
863 config UACCESS_WITH_MEMCPY
864 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
865 - depends on MMU
866 + depends on MMU && !PAX_MEMORY_UDEREF
867 default y if CPU_FEROCEON
868 help
869 Implement faster copy_to_user and clear_user methods for CPU
870 @@ -2142,6 +2142,7 @@ config XIP_PHYS_ADDR
871 config KEXEC
872 bool "Kexec system call (EXPERIMENTAL)"
873 depends on (!SMP || PM_SLEEP_SMP)
874 + depends on !GRKERNSEC_KMEM
875 help
876 kexec is a system call that implements the ability to shutdown your
877 current kernel, and to start another kernel. It is like a reboot
878 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
879 index 9a92fd7..3502a80 100644
880 --- a/arch/arm/include/asm/atomic.h
881 +++ b/arch/arm/include/asm/atomic.h
882 @@ -18,17 +18,35 @@
883 #include <asm/barrier.h>
884 #include <asm/cmpxchg.h>
885
886 +#ifdef CONFIG_GENERIC_ATOMIC64
887 +#include <asm-generic/atomic64.h>
888 +#endif
889 +
890 #define ATOMIC_INIT(i) { (i) }
891
892 #ifdef __KERNEL__
893
894 +#define _ASM_EXTABLE(from, to) \
895 +" .pushsection __ex_table,\"a\"\n"\
896 +" .align 3\n" \
897 +" .long " #from ", " #to"\n" \
898 +" .popsection"
899 +
900 /*
901 * On ARM, ordinary assignment (str instruction) doesn't clear the local
902 * strex/ldrex monitor on some implementations. The reason we can use it for
903 * atomic_set() is the clrex or dummy strex done on every exception return.
904 */
905 #define atomic_read(v) (*(volatile int *)&(v)->counter)
906 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
907 +{
908 + return v->counter;
909 +}
910 #define atomic_set(v,i) (((v)->counter) = (i))
911 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
912 +{
913 + v->counter = i;
914 +}
915
916 #if __LINUX_ARM_ARCH__ >= 6
917
918 @@ -44,6 +62,36 @@ static inline void atomic_add(int i, atomic_t *v)
919
920 prefetchw(&v->counter);
921 __asm__ __volatile__("@ atomic_add\n"
922 +"1: ldrex %1, [%3]\n"
923 +" adds %0, %1, %4\n"
924 +
925 +#ifdef CONFIG_PAX_REFCOUNT
926 +" bvc 3f\n"
927 +"2: bkpt 0xf103\n"
928 +"3:\n"
929 +#endif
930 +
931 +" strex %1, %0, [%3]\n"
932 +" teq %1, #0\n"
933 +" bne 1b"
934 +
935 +#ifdef CONFIG_PAX_REFCOUNT
936 +"\n4:\n"
937 + _ASM_EXTABLE(2b, 4b)
938 +#endif
939 +
940 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
941 + : "r" (&v->counter), "Ir" (i)
942 + : "cc");
943 +}
944 +
945 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
946 +{
947 + unsigned long tmp;
948 + int result;
949 +
950 + prefetchw(&v->counter);
951 + __asm__ __volatile__("@ atomic_add_unchecked\n"
952 "1: ldrex %0, [%3]\n"
953 " add %0, %0, %4\n"
954 " strex %1, %0, [%3]\n"
955 @@ -63,6 +111,43 @@ static inline int atomic_add_return(int i, atomic_t *v)
956 prefetchw(&v->counter);
957
958 __asm__ __volatile__("@ atomic_add_return\n"
959 +"1: ldrex %1, [%3]\n"
960 +" adds %0, %1, %4\n"
961 +
962 +#ifdef CONFIG_PAX_REFCOUNT
963 +" bvc 3f\n"
964 +" mov %0, %1\n"
965 +"2: bkpt 0xf103\n"
966 +"3:\n"
967 +#endif
968 +
969 +" strex %1, %0, [%3]\n"
970 +" teq %1, #0\n"
971 +" bne 1b"
972 +
973 +#ifdef CONFIG_PAX_REFCOUNT
974 +"\n4:\n"
975 + _ASM_EXTABLE(2b, 4b)
976 +#endif
977 +
978 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
979 + : "r" (&v->counter), "Ir" (i)
980 + : "cc");
981 +
982 + smp_mb();
983 +
984 + return result;
985 +}
986 +
987 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
988 +{
989 + unsigned long tmp;
990 + int result;
991 +
992 + smp_mb();
993 + prefetchw(&v->counter);
994 +
995 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
996 "1: ldrex %0, [%3]\n"
997 " add %0, %0, %4\n"
998 " strex %1, %0, [%3]\n"
999 @@ -84,6 +169,36 @@ static inline void atomic_sub(int i, atomic_t *v)
1000
1001 prefetchw(&v->counter);
1002 __asm__ __volatile__("@ atomic_sub\n"
1003 +"1: ldrex %1, [%3]\n"
1004 +" subs %0, %1, %4\n"
1005 +
1006 +#ifdef CONFIG_PAX_REFCOUNT
1007 +" bvc 3f\n"
1008 +"2: bkpt 0xf103\n"
1009 +"3:\n"
1010 +#endif
1011 +
1012 +" strex %1, %0, [%3]\n"
1013 +" teq %1, #0\n"
1014 +" bne 1b"
1015 +
1016 +#ifdef CONFIG_PAX_REFCOUNT
1017 +"\n4:\n"
1018 + _ASM_EXTABLE(2b, 4b)
1019 +#endif
1020 +
1021 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1022 + : "r" (&v->counter), "Ir" (i)
1023 + : "cc");
1024 +}
1025 +
1026 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1027 +{
1028 + unsigned long tmp;
1029 + int result;
1030 +
1031 + prefetchw(&v->counter);
1032 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
1033 "1: ldrex %0, [%3]\n"
1034 " sub %0, %0, %4\n"
1035 " strex %1, %0, [%3]\n"
1036 @@ -103,11 +218,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1037 prefetchw(&v->counter);
1038
1039 __asm__ __volatile__("@ atomic_sub_return\n"
1040 -"1: ldrex %0, [%3]\n"
1041 -" sub %0, %0, %4\n"
1042 +"1: ldrex %1, [%3]\n"
1043 +" subs %0, %1, %4\n"
1044 +
1045 +#ifdef CONFIG_PAX_REFCOUNT
1046 +" bvc 3f\n"
1047 +" mov %0, %1\n"
1048 +"2: bkpt 0xf103\n"
1049 +"3:\n"
1050 +#endif
1051 +
1052 " strex %1, %0, [%3]\n"
1053 " teq %1, #0\n"
1054 " bne 1b"
1055 +
1056 +#ifdef CONFIG_PAX_REFCOUNT
1057 +"\n4:\n"
1058 + _ASM_EXTABLE(2b, 4b)
1059 +#endif
1060 +
1061 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1062 : "r" (&v->counter), "Ir" (i)
1063 : "cc");
1064 @@ -152,12 +281,24 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1065 __asm__ __volatile__ ("@ atomic_add_unless\n"
1066 "1: ldrex %0, [%4]\n"
1067 " teq %0, %5\n"
1068 -" beq 2f\n"
1069 -" add %1, %0, %6\n"
1070 +" beq 4f\n"
1071 +" adds %1, %0, %6\n"
1072 +
1073 +#ifdef CONFIG_PAX_REFCOUNT
1074 +" bvc 3f\n"
1075 +"2: bkpt 0xf103\n"
1076 +"3:\n"
1077 +#endif
1078 +
1079 " strex %2, %1, [%4]\n"
1080 " teq %2, #0\n"
1081 " bne 1b\n"
1082 -"2:"
1083 +"4:"
1084 +
1085 +#ifdef CONFIG_PAX_REFCOUNT
1086 + _ASM_EXTABLE(2b, 4b)
1087 +#endif
1088 +
1089 : "=&r" (oldval), "=&r" (newval), "=&r" (tmp), "+Qo" (v->counter)
1090 : "r" (&v->counter), "r" (u), "r" (a)
1091 : "cc");
1092 @@ -168,6 +309,28 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1093 return oldval;
1094 }
1095
1096 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1097 +{
1098 + unsigned long oldval, res;
1099 +
1100 + smp_mb();
1101 +
1102 + do {
1103 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1104 + "ldrex %1, [%3]\n"
1105 + "mov %0, #0\n"
1106 + "teq %1, %4\n"
1107 + "strexeq %0, %5, [%3]\n"
1108 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1109 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
1110 + : "cc");
1111 + } while (res);
1112 +
1113 + smp_mb();
1114 +
1115 + return oldval;
1116 +}
1117 +
1118 #else /* ARM_ARCH_6 */
1119
1120 #ifdef CONFIG_SMP
1121 @@ -186,7 +349,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1122
1123 return val;
1124 }
1125 +
1126 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1127 +{
1128 + return atomic_add_return(i, v);
1129 +}
1130 +
1131 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1132 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1133 +{
1134 + (void) atomic_add_return(i, v);
1135 +}
1136
1137 static inline int atomic_sub_return(int i, atomic_t *v)
1138 {
1139 @@ -201,6 +374,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1140 return val;
1141 }
1142 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1143 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1144 +{
1145 + (void) atomic_sub_return(i, v);
1146 +}
1147
1148 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1149 {
1150 @@ -216,6 +393,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1151 return ret;
1152 }
1153
1154 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1155 +{
1156 + return atomic_cmpxchg(v, old, new);
1157 +}
1158 +
1159 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1160 {
1161 int c, old;
1162 @@ -229,13 +411,33 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1163 #endif /* __LINUX_ARM_ARCH__ */
1164
1165 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1166 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1167 +{
1168 + return xchg(&v->counter, new);
1169 +}
1170
1171 #define atomic_inc(v) atomic_add(1, v)
1172 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1173 +{
1174 + atomic_add_unchecked(1, v);
1175 +}
1176 #define atomic_dec(v) atomic_sub(1, v)
1177 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1178 +{
1179 + atomic_sub_unchecked(1, v);
1180 +}
1181
1182 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1183 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1184 +{
1185 + return atomic_add_return_unchecked(1, v) == 0;
1186 +}
1187 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1188 #define atomic_inc_return(v) (atomic_add_return(1, v))
1189 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1190 +{
1191 + return atomic_add_return_unchecked(1, v);
1192 +}
1193 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1194 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1195
1196 @@ -251,6 +453,14 @@ typedef struct {
1197 long long counter;
1198 } atomic64_t;
1199
1200 +#ifdef CONFIG_PAX_REFCOUNT
1201 +typedef struct {
1202 + long long counter;
1203 +} atomic64_unchecked_t;
1204 +#else
1205 +typedef atomic64_t atomic64_unchecked_t;
1206 +#endif
1207 +
1208 #define ATOMIC64_INIT(i) { (i) }
1209
1210 #ifdef CONFIG_ARM_LPAE
1211 @@ -267,6 +477,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1212 return result;
1213 }
1214
1215 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1216 +{
1217 + long long result;
1218 +
1219 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1220 +" ldrd %0, %H0, [%1]"
1221 + : "=&r" (result)
1222 + : "r" (&v->counter), "Qo" (v->counter)
1223 + );
1224 +
1225 + return result;
1226 +}
1227 +
1228 static inline void atomic64_set(atomic64_t *v, long long i)
1229 {
1230 __asm__ __volatile__("@ atomic64_set\n"
1231 @@ -275,6 +498,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1232 : "r" (&v->counter), "r" (i)
1233 );
1234 }
1235 +
1236 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1237 +{
1238 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1239 +" strd %2, %H2, [%1]"
1240 + : "=Qo" (v->counter)
1241 + : "r" (&v->counter), "r" (i)
1242 + );
1243 +}
1244 #else
1245 static inline long long atomic64_read(const atomic64_t *v)
1246 {
1247 @@ -289,6 +521,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1248 return result;
1249 }
1250
1251 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1252 +{
1253 + long long result;
1254 +
1255 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1256 +" ldrexd %0, %H0, [%1]"
1257 + : "=&r" (result)
1258 + : "r" (&v->counter), "Qo" (v->counter)
1259 + );
1260 +
1261 + return result;
1262 +}
1263 +
1264 static inline void atomic64_set(atomic64_t *v, long long i)
1265 {
1266 long long tmp;
1267 @@ -303,6 +548,21 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1268 : "r" (&v->counter), "r" (i)
1269 : "cc");
1270 }
1271 +
1272 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1273 +{
1274 + long long tmp;
1275 +
1276 + prefetchw(&v->counter);
1277 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1278 +"1: ldrexd %0, %H0, [%2]\n"
1279 +" strexd %0, %3, %H3, [%2]\n"
1280 +" teq %0, #0\n"
1281 +" bne 1b"
1282 + : "=&r" (tmp), "=Qo" (v->counter)
1283 + : "r" (&v->counter), "r" (i)
1284 + : "cc");
1285 +}
1286 #endif
1287
1288 static inline void atomic64_add(long long i, atomic64_t *v)
1289 @@ -314,6 +574,37 @@ static inline void atomic64_add(long long i, atomic64_t *v)
1290 __asm__ __volatile__("@ atomic64_add\n"
1291 "1: ldrexd %0, %H0, [%3]\n"
1292 " adds %Q0, %Q0, %Q4\n"
1293 +" adcs %R0, %R0, %R4\n"
1294 +
1295 +#ifdef CONFIG_PAX_REFCOUNT
1296 +" bvc 3f\n"
1297 +"2: bkpt 0xf103\n"
1298 +"3:\n"
1299 +#endif
1300 +
1301 +" strexd %1, %0, %H0, [%3]\n"
1302 +" teq %1, #0\n"
1303 +" bne 1b"
1304 +
1305 +#ifdef CONFIG_PAX_REFCOUNT
1306 +"\n4:\n"
1307 + _ASM_EXTABLE(2b, 4b)
1308 +#endif
1309 +
1310 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1311 + : "r" (&v->counter), "r" (i)
1312 + : "cc");
1313 +}
1314 +
1315 +static inline void atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
1316 +{
1317 + long long result;
1318 + unsigned long tmp;
1319 +
1320 + prefetchw(&v->counter);
1321 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1322 +"1: ldrexd %0, %H0, [%3]\n"
1323 +" adds %Q0, %Q0, %Q4\n"
1324 " adc %R0, %R0, %R4\n"
1325 " strexd %1, %0, %H0, [%3]\n"
1326 " teq %1, #0\n"
1327 @@ -334,6 +625,44 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
1328 __asm__ __volatile__("@ atomic64_add_return\n"
1329 "1: ldrexd %0, %H0, [%3]\n"
1330 " adds %Q0, %Q0, %Q4\n"
1331 +" adcs %R0, %R0, %R4\n"
1332 +
1333 +#ifdef CONFIG_PAX_REFCOUNT
1334 +" bvc 3f\n"
1335 +" mov %0, %1\n"
1336 +" mov %H0, %H1\n"
1337 +"2: bkpt 0xf103\n"
1338 +"3:\n"
1339 +#endif
1340 +
1341 +" strexd %1, %0, %H0, [%3]\n"
1342 +" teq %1, #0\n"
1343 +" bne 1b"
1344 +
1345 +#ifdef CONFIG_PAX_REFCOUNT
1346 +"\n4:\n"
1347 + _ASM_EXTABLE(2b, 4b)
1348 +#endif
1349 +
1350 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1351 + : "r" (&v->counter), "r" (i)
1352 + : "cc");
1353 +
1354 + smp_mb();
1355 +
1356 + return result;
1357 +}
1358 +
1359 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
1360 +{
1361 + long long result;
1362 + unsigned long tmp;
1363 +
1364 + smp_mb();
1365 +
1366 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1367 +"1: ldrexd %0, %H0, [%3]\n"
1368 +" adds %Q0, %Q0, %Q4\n"
1369 " adc %R0, %R0, %R4\n"
1370 " strexd %1, %0, %H0, [%3]\n"
1371 " teq %1, #0\n"
1372 @@ -356,6 +685,37 @@ static inline void atomic64_sub(long long i, atomic64_t *v)
1373 __asm__ __volatile__("@ atomic64_sub\n"
1374 "1: ldrexd %0, %H0, [%3]\n"
1375 " subs %Q0, %Q0, %Q4\n"
1376 +" sbcs %R0, %R0, %R4\n"
1377 +
1378 +#ifdef CONFIG_PAX_REFCOUNT
1379 +" bvc 3f\n"
1380 +"2: bkpt 0xf103\n"
1381 +"3:\n"
1382 +#endif
1383 +
1384 +" strexd %1, %0, %H0, [%3]\n"
1385 +" teq %1, #0\n"
1386 +" bne 1b"
1387 +
1388 +#ifdef CONFIG_PAX_REFCOUNT
1389 +"\n4:\n"
1390 + _ASM_EXTABLE(2b, 4b)
1391 +#endif
1392 +
1393 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1394 + : "r" (&v->counter), "r" (i)
1395 + : "cc");
1396 +}
1397 +
1398 +static inline void atomic64_sub_unchecked(long long i, atomic64_unchecked_t *v)
1399 +{
1400 + long long result;
1401 + unsigned long tmp;
1402 +
1403 + prefetchw(&v->counter);
1404 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1405 +"1: ldrexd %0, %H0, [%3]\n"
1406 +" subs %Q0, %Q0, %Q4\n"
1407 " sbc %R0, %R0, %R4\n"
1408 " strexd %1, %0, %H0, [%3]\n"
1409 " teq %1, #0\n"
1410 @@ -376,16 +736,29 @@ static inline long long atomic64_sub_return(long long i, atomic64_t *v)
1411 __asm__ __volatile__("@ atomic64_sub_return\n"
1412 "1: ldrexd %0, %H0, [%3]\n"
1413 " subs %Q0, %Q0, %Q4\n"
1414 -" sbc %R0, %R0, %R4\n"
1415 +" sbcs %R0, %R0, %R4\n"
1416 +
1417 +#ifdef CONFIG_PAX_REFCOUNT
1418 +" bvc 3f\n"
1419 +" mov %0, %1\n"
1420 +" mov %H0, %H1\n"
1421 +"2: bkpt 0xf103\n"
1422 +"3:\n"
1423 +#endif
1424 +
1425 " strexd %1, %0, %H0, [%3]\n"
1426 " teq %1, #0\n"
1427 " bne 1b"
1428 +
1429 +#ifdef CONFIG_PAX_REFCOUNT
1430 +"\n4:\n"
1431 + _ASM_EXTABLE(2b, 4b)
1432 +#endif
1433 +
1434 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1435 : "r" (&v->counter), "r" (i)
1436 : "cc");
1437
1438 - smp_mb();
1439 -
1440 return result;
1441 }
1442
1443 @@ -415,6 +788,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1444 return oldval;
1445 }
1446
1447 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1448 + long long new)
1449 +{
1450 + long long oldval;
1451 + unsigned long res;
1452 +
1453 + smp_mb();
1454 +
1455 + do {
1456 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1457 + "ldrexd %1, %H1, [%3]\n"
1458 + "mov %0, #0\n"
1459 + "teq %1, %4\n"
1460 + "teqeq %H1, %H4\n"
1461 + "strexdeq %0, %5, %H5, [%3]"
1462 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1463 + : "r" (&ptr->counter), "r" (old), "r" (new)
1464 + : "cc");
1465 + } while (res);
1466 +
1467 + smp_mb();
1468 +
1469 + return oldval;
1470 +}
1471 +
1472 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1473 {
1474 long long result;
1475 @@ -440,21 +838,35 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1476 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1477 {
1478 long long result;
1479 - unsigned long tmp;
1480 + u64 tmp;
1481
1482 smp_mb();
1483 prefetchw(&v->counter);
1484
1485 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1486 -"1: ldrexd %0, %H0, [%3]\n"
1487 -" subs %Q0, %Q0, #1\n"
1488 -" sbc %R0, %R0, #0\n"
1489 +"1: ldrexd %1, %H1, [%3]\n"
1490 +" subs %Q0, %Q1, #1\n"
1491 +" sbcs %R0, %R1, #0\n"
1492 +
1493 +#ifdef CONFIG_PAX_REFCOUNT
1494 +" bvc 3f\n"
1495 +" mov %Q0, %Q1\n"
1496 +" mov %R0, %R1\n"
1497 +"2: bkpt 0xf103\n"
1498 +"3:\n"
1499 +#endif
1500 +
1501 " teq %R0, #0\n"
1502 -" bmi 2f\n"
1503 +" bmi 4f\n"
1504 " strexd %1, %0, %H0, [%3]\n"
1505 " teq %1, #0\n"
1506 " bne 1b\n"
1507 -"2:"
1508 +"4:\n"
1509 +
1510 +#ifdef CONFIG_PAX_REFCOUNT
1511 + _ASM_EXTABLE(2b, 4b)
1512 +#endif
1513 +
1514 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1515 : "r" (&v->counter)
1516 : "cc");
1517 @@ -478,13 +890,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1518 " teq %0, %5\n"
1519 " teqeq %H0, %H5\n"
1520 " moveq %1, #0\n"
1521 -" beq 2f\n"
1522 +" beq 4f\n"
1523 " adds %Q0, %Q0, %Q6\n"
1524 -" adc %R0, %R0, %R6\n"
1525 +" adcs %R0, %R0, %R6\n"
1526 +
1527 +#ifdef CONFIG_PAX_REFCOUNT
1528 +" bvc 3f\n"
1529 +"2: bkpt 0xf103\n"
1530 +"3:\n"
1531 +#endif
1532 +
1533 " strexd %2, %0, %H0, [%4]\n"
1534 " teq %2, #0\n"
1535 " bne 1b\n"
1536 -"2:"
1537 +"4:\n"
1538 +
1539 +#ifdef CONFIG_PAX_REFCOUNT
1540 + _ASM_EXTABLE(2b, 4b)
1541 +#endif
1542 +
1543 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1544 : "r" (&v->counter), "r" (u), "r" (a)
1545 : "cc");
1546 @@ -497,10 +921,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1547
1548 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1549 #define atomic64_inc(v) atomic64_add(1LL, (v))
1550 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1551 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1552 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1553 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1554 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1555 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1556 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1557 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1558 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1559 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1560 diff --git a/arch/arm/include/asm/barrier.h b/arch/arm/include/asm/barrier.h
1561 index 2f59f74..1594659 100644
1562 --- a/arch/arm/include/asm/barrier.h
1563 +++ b/arch/arm/include/asm/barrier.h
1564 @@ -63,7 +63,7 @@
1565 do { \
1566 compiletime_assert_atomic_type(*p); \
1567 smp_mb(); \
1568 - ACCESS_ONCE(*p) = (v); \
1569 + ACCESS_ONCE_RW(*p) = (v); \
1570 } while (0)
1571
1572 #define smp_load_acquire(p) \
1573 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1574 index 75fe66b..ba3dee4 100644
1575 --- a/arch/arm/include/asm/cache.h
1576 +++ b/arch/arm/include/asm/cache.h
1577 @@ -4,8 +4,10 @@
1578 #ifndef __ASMARM_CACHE_H
1579 #define __ASMARM_CACHE_H
1580
1581 +#include <linux/const.h>
1582 +
1583 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1584 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1585 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1586
1587 /*
1588 * Memory returned by kmalloc() may be used for DMA, so we must make
1589 @@ -24,5 +26,6 @@
1590 #endif
1591
1592 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1593 +#define __read_only __attribute__ ((__section__(".data..read_only")))
1594
1595 #endif
1596 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1597 index 8b8b616..d973d24 100644
1598 --- a/arch/arm/include/asm/cacheflush.h
1599 +++ b/arch/arm/include/asm/cacheflush.h
1600 @@ -116,7 +116,7 @@ struct cpu_cache_fns {
1601 void (*dma_unmap_area)(const void *, size_t, int);
1602
1603 void (*dma_flush_range)(const void *, const void *);
1604 -};
1605 +} __no_const;
1606
1607 /*
1608 * Select the calling method
1609 diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1610 index 5233151..87a71fa 100644
1611 --- a/arch/arm/include/asm/checksum.h
1612 +++ b/arch/arm/include/asm/checksum.h
1613 @@ -37,7 +37,19 @@ __wsum
1614 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1615
1616 __wsum
1617 -csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1618 +__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1619 +
1620 +static inline __wsum
1621 +csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1622 +{
1623 + __wsum ret;
1624 + pax_open_userland();
1625 + ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1626 + pax_close_userland();
1627 + return ret;
1628 +}
1629 +
1630 +
1631
1632 /*
1633 * Fold a partial checksum without adding pseudo headers
1634 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1635 index abb2c37..96db950 100644
1636 --- a/arch/arm/include/asm/cmpxchg.h
1637 +++ b/arch/arm/include/asm/cmpxchg.h
1638 @@ -104,6 +104,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1639
1640 #define xchg(ptr,x) \
1641 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1642 +#define xchg_unchecked(ptr,x) \
1643 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1644
1645 #include <asm-generic/cmpxchg-local.h>
1646
1647 diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1648 index 6ddbe44..b5e38b1 100644
1649 --- a/arch/arm/include/asm/domain.h
1650 +++ b/arch/arm/include/asm/domain.h
1651 @@ -48,18 +48,37 @@
1652 * Domain types
1653 */
1654 #define DOMAIN_NOACCESS 0
1655 -#define DOMAIN_CLIENT 1
1656 #ifdef CONFIG_CPU_USE_DOMAINS
1657 +#define DOMAIN_USERCLIENT 1
1658 +#define DOMAIN_KERNELCLIENT 1
1659 #define DOMAIN_MANAGER 3
1660 +#define DOMAIN_VECTORS DOMAIN_USER
1661 #else
1662 +
1663 +#ifdef CONFIG_PAX_KERNEXEC
1664 #define DOMAIN_MANAGER 1
1665 +#define DOMAIN_KERNEXEC 3
1666 +#else
1667 +#define DOMAIN_MANAGER 1
1668 +#endif
1669 +
1670 +#ifdef CONFIG_PAX_MEMORY_UDEREF
1671 +#define DOMAIN_USERCLIENT 0
1672 +#define DOMAIN_UDEREF 1
1673 +#define DOMAIN_VECTORS DOMAIN_KERNEL
1674 +#else
1675 +#define DOMAIN_USERCLIENT 1
1676 +#define DOMAIN_VECTORS DOMAIN_USER
1677 +#endif
1678 +#define DOMAIN_KERNELCLIENT 1
1679 +
1680 #endif
1681
1682 #define domain_val(dom,type) ((type) << (2*(dom)))
1683
1684 #ifndef __ASSEMBLY__
1685
1686 -#ifdef CONFIG_CPU_USE_DOMAINS
1687 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1688 static inline void set_domain(unsigned val)
1689 {
1690 asm volatile(
1691 @@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1692 isb();
1693 }
1694
1695 -#define modify_domain(dom,type) \
1696 - do { \
1697 - struct thread_info *thread = current_thread_info(); \
1698 - unsigned int domain = thread->cpu_domain; \
1699 - domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1700 - thread->cpu_domain = domain | domain_val(dom, type); \
1701 - set_domain(thread->cpu_domain); \
1702 - } while (0)
1703 -
1704 +extern void modify_domain(unsigned int dom, unsigned int type);
1705 #else
1706 static inline void set_domain(unsigned val) { }
1707 static inline void modify_domain(unsigned dom, unsigned type) { }
1708 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1709 index f4b46d3..abc9b2b 100644
1710 --- a/arch/arm/include/asm/elf.h
1711 +++ b/arch/arm/include/asm/elf.h
1712 @@ -114,7 +114,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1713 the loader. We need to make sure that it is out of the way of the program
1714 that it will "exec", and that there is sufficient room for the brk. */
1715
1716 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1717 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1718 +
1719 +#ifdef CONFIG_PAX_ASLR
1720 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1721 +
1722 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1723 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1724 +#endif
1725
1726 /* When the program starts, a1 contains a pointer to a function to be
1727 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1728 @@ -124,10 +131,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1729 extern void elf_set_personality(const struct elf32_hdr *);
1730 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1731
1732 -struct mm_struct;
1733 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1734 -#define arch_randomize_brk arch_randomize_brk
1735 -
1736 #ifdef CONFIG_MMU
1737 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1738 struct linux_binprm;
1739 diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1740 index de53547..52b9a28 100644
1741 --- a/arch/arm/include/asm/fncpy.h
1742 +++ b/arch/arm/include/asm/fncpy.h
1743 @@ -81,7 +81,9 @@
1744 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1745 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1746 \
1747 + pax_open_kernel(); \
1748 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1749 + pax_close_kernel(); \
1750 flush_icache_range((unsigned long)(dest_buf), \
1751 (unsigned long)(dest_buf) + (size)); \
1752 \
1753 diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1754 index 53e69da..3fdc896 100644
1755 --- a/arch/arm/include/asm/futex.h
1756 +++ b/arch/arm/include/asm/futex.h
1757 @@ -46,6 +46,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1758 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1759 return -EFAULT;
1760
1761 + pax_open_userland();
1762 +
1763 smp_mb();
1764 /* Prefetching cannot fault */
1765 prefetchw(uaddr);
1766 @@ -63,6 +65,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1767 : "cc", "memory");
1768 smp_mb();
1769
1770 + pax_close_userland();
1771 +
1772 *uval = val;
1773 return ret;
1774 }
1775 @@ -93,6 +97,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1776 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1777 return -EFAULT;
1778
1779 + pax_open_userland();
1780 +
1781 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1782 "1: " TUSER(ldr) " %1, [%4]\n"
1783 " teq %1, %2\n"
1784 @@ -103,6 +109,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1785 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1786 : "cc", "memory");
1787
1788 + pax_close_userland();
1789 +
1790 *uval = val;
1791 return ret;
1792 }
1793 @@ -125,6 +133,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1794 return -EFAULT;
1795
1796 pagefault_disable(); /* implies preempt_disable() */
1797 + pax_open_userland();
1798
1799 switch (op) {
1800 case FUTEX_OP_SET:
1801 @@ -146,6 +155,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1802 ret = -ENOSYS;
1803 }
1804
1805 + pax_close_userland();
1806 pagefault_enable(); /* subsumes preempt_enable() */
1807
1808 if (!ret) {
1809 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1810 index 83eb2f7..ed77159 100644
1811 --- a/arch/arm/include/asm/kmap_types.h
1812 +++ b/arch/arm/include/asm/kmap_types.h
1813 @@ -4,6 +4,6 @@
1814 /*
1815 * This is the "bare minimum". AIO seems to require this.
1816 */
1817 -#define KM_TYPE_NR 16
1818 +#define KM_TYPE_NR 17
1819
1820 #endif
1821 diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1822 index 9e614a1..3302cca 100644
1823 --- a/arch/arm/include/asm/mach/dma.h
1824 +++ b/arch/arm/include/asm/mach/dma.h
1825 @@ -22,7 +22,7 @@ struct dma_ops {
1826 int (*residue)(unsigned int, dma_t *); /* optional */
1827 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1828 const char *type;
1829 -};
1830 +} __do_const;
1831
1832 struct dma_struct {
1833 void *addr; /* single DMA address */
1834 diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1835 index f98c7f3..e5c626d 100644
1836 --- a/arch/arm/include/asm/mach/map.h
1837 +++ b/arch/arm/include/asm/mach/map.h
1838 @@ -23,17 +23,19 @@ struct map_desc {
1839
1840 /* types 0-3 are defined in asm/io.h */
1841 enum {
1842 - MT_UNCACHED = 4,
1843 - MT_CACHECLEAN,
1844 - MT_MINICLEAN,
1845 + MT_UNCACHED_RW = 4,
1846 + MT_CACHECLEAN_RO,
1847 + MT_MINICLEAN_RO,
1848 MT_LOW_VECTORS,
1849 MT_HIGH_VECTORS,
1850 - MT_MEMORY_RWX,
1851 + __MT_MEMORY_RWX,
1852 MT_MEMORY_RW,
1853 - MT_ROM,
1854 - MT_MEMORY_RWX_NONCACHED,
1855 + MT_MEMORY_RX,
1856 + MT_ROM_RX,
1857 + MT_MEMORY_RW_NONCACHED,
1858 + MT_MEMORY_RX_NONCACHED,
1859 MT_MEMORY_RW_DTCM,
1860 - MT_MEMORY_RWX_ITCM,
1861 + MT_MEMORY_RX_ITCM,
1862 MT_MEMORY_RW_SO,
1863 MT_MEMORY_DMA_READY,
1864 };
1865 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1866 index f94784f..9a09a4a 100644
1867 --- a/arch/arm/include/asm/outercache.h
1868 +++ b/arch/arm/include/asm/outercache.h
1869 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1870 #endif
1871 void (*set_debug)(unsigned long);
1872 void (*resume)(void);
1873 -};
1874 +} __no_const;
1875
1876 extern struct outer_cache_fns outer_cache;
1877
1878 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1879 index 4355f0e..cd9168e 100644
1880 --- a/arch/arm/include/asm/page.h
1881 +++ b/arch/arm/include/asm/page.h
1882 @@ -23,6 +23,7 @@
1883
1884 #else
1885
1886 +#include <linux/compiler.h>
1887 #include <asm/glue.h>
1888
1889 /*
1890 @@ -114,7 +115,7 @@ struct cpu_user_fns {
1891 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1892 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1893 unsigned long vaddr, struct vm_area_struct *vma);
1894 -};
1895 +} __no_const;
1896
1897 #ifdef MULTI_USER
1898 extern struct cpu_user_fns cpu_user;
1899 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1900 index 78a7793..e3dc06c 100644
1901 --- a/arch/arm/include/asm/pgalloc.h
1902 +++ b/arch/arm/include/asm/pgalloc.h
1903 @@ -17,6 +17,7 @@
1904 #include <asm/processor.h>
1905 #include <asm/cacheflush.h>
1906 #include <asm/tlbflush.h>
1907 +#include <asm/system_info.h>
1908
1909 #define check_pgt_cache() do { } while (0)
1910
1911 @@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1912 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1913 }
1914
1915 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1916 +{
1917 + pud_populate(mm, pud, pmd);
1918 +}
1919 +
1920 #else /* !CONFIG_ARM_LPAE */
1921
1922 /*
1923 @@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1924 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1925 #define pmd_free(mm, pmd) do { } while (0)
1926 #define pud_populate(mm,pmd,pte) BUG()
1927 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1928
1929 #endif /* CONFIG_ARM_LPAE */
1930
1931 @@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1932 __free_page(pte);
1933 }
1934
1935 +static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1936 +{
1937 +#ifdef CONFIG_ARM_LPAE
1938 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1939 +#else
1940 + if (addr & SECTION_SIZE)
1941 + pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1942 + else
1943 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1944 +#endif
1945 + flush_pmd_entry(pmdp);
1946 +}
1947 +
1948 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1949 pmdval_t prot)
1950 {
1951 @@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1952 static inline void
1953 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1954 {
1955 - __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1956 + __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1957 }
1958 #define pmd_pgtable(pmd) pmd_page(pmd)
1959
1960 diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1961 index 5cfba15..f415e1a 100644
1962 --- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1963 +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1964 @@ -20,12 +20,15 @@
1965 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1966 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1967 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1968 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1969 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1970 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1971 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1972 +
1973 /*
1974 * - section
1975 */
1976 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1977 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1978 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1979 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1980 @@ -37,6 +40,7 @@
1981 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1982 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1983 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1984 +#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1985
1986 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1987 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1988 @@ -66,6 +70,7 @@
1989 * - extended small page/tiny page
1990 */
1991 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1992 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1993 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1994 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1995 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1996 diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1997 index 219ac88..73ec32a 100644
1998 --- a/arch/arm/include/asm/pgtable-2level.h
1999 +++ b/arch/arm/include/asm/pgtable-2level.h
2000 @@ -126,6 +126,9 @@
2001 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
2002 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
2003
2004 +/* Two-level page tables only have PXN in the PGD, not in the PTE. */
2005 +#define L_PTE_PXN (_AT(pteval_t, 0))
2006 +
2007 /*
2008 * These are the memory types, defined to be compatible with
2009 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
2010 diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
2011 index 626989f..9d67a33 100644
2012 --- a/arch/arm/include/asm/pgtable-3level-hwdef.h
2013 +++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
2014 @@ -75,6 +75,7 @@
2015 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
2016 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
2017 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
2018 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2019 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
2020
2021 /*
2022 diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
2023 index 85c60ad..b0bbd7e 100644
2024 --- a/arch/arm/include/asm/pgtable-3level.h
2025 +++ b/arch/arm/include/asm/pgtable-3level.h
2026 @@ -82,6 +82,7 @@
2027 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
2028 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
2029 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
2030 +#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2031 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
2032 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
2033 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
2034 @@ -95,6 +96,7 @@
2035 /*
2036 * To be used in assembly code with the upper page attributes.
2037 */
2038 +#define L_PTE_PXN_HIGH (1 << (53 - 32))
2039 #define L_PTE_XN_HIGH (1 << (54 - 32))
2040 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
2041
2042 diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
2043 index 5478e5d..f5b5cb3 100644
2044 --- a/arch/arm/include/asm/pgtable.h
2045 +++ b/arch/arm/include/asm/pgtable.h
2046 @@ -33,6 +33,9 @@
2047 #include <asm/pgtable-2level.h>
2048 #endif
2049
2050 +#define ktla_ktva(addr) (addr)
2051 +#define ktva_ktla(addr) (addr)
2052 +
2053 /*
2054 * Just any arbitrary offset to the start of the vmalloc VM area: the
2055 * current 8MB value just means that there will be a 8MB "hole" after the
2056 @@ -48,6 +51,9 @@
2057 #define LIBRARY_TEXT_START 0x0c000000
2058
2059 #ifndef __ASSEMBLY__
2060 +extern pteval_t __supported_pte_mask;
2061 +extern pmdval_t __supported_pmd_mask;
2062 +
2063 extern void __pte_error(const char *file, int line, pte_t);
2064 extern void __pmd_error(const char *file, int line, pmd_t);
2065 extern void __pgd_error(const char *file, int line, pgd_t);
2066 @@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2067 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2068 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2069
2070 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
2071 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2072 +
2073 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2074 +#include <asm/domain.h>
2075 +#include <linux/thread_info.h>
2076 +#include <linux/preempt.h>
2077 +
2078 +static inline int test_domain(int domain, int domaintype)
2079 +{
2080 + return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2081 +}
2082 +#endif
2083 +
2084 +#ifdef CONFIG_PAX_KERNEXEC
2085 +static inline unsigned long pax_open_kernel(void) {
2086 +#ifdef CONFIG_ARM_LPAE
2087 + /* TODO */
2088 +#else
2089 + preempt_disable();
2090 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2091 + modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2092 +#endif
2093 + return 0;
2094 +}
2095 +
2096 +static inline unsigned long pax_close_kernel(void) {
2097 +#ifdef CONFIG_ARM_LPAE
2098 + /* TODO */
2099 +#else
2100 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2101 + /* DOMAIN_MANAGER = "client" under KERNEXEC */
2102 + modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2103 + preempt_enable_no_resched();
2104 +#endif
2105 + return 0;
2106 +}
2107 +#else
2108 +static inline unsigned long pax_open_kernel(void) { return 0; }
2109 +static inline unsigned long pax_close_kernel(void) { return 0; }
2110 +#endif
2111 +
2112 /*
2113 * This is the lowest virtual address we can permit any user space
2114 * mapping to be mapped at. This is particularly important for
2115 @@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2116 /*
2117 * The pgprot_* and protection_map entries will be fixed up in runtime
2118 * to include the cachable and bufferable bits based on memory policy,
2119 - * as well as any architecture dependent bits like global/ASID and SMP
2120 - * shared mapping bits.
2121 + * as well as any architecture dependent bits like global/ASID, PXN,
2122 + * and SMP shared mapping bits.
2123 */
2124 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2125
2126 @@ -265,7 +313,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2127 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2128 {
2129 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2130 - L_PTE_NONE | L_PTE_VALID;
2131 + L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2132 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2133 return pte;
2134 }
2135 diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2136 index c4ae171..ea0c0c2 100644
2137 --- a/arch/arm/include/asm/psci.h
2138 +++ b/arch/arm/include/asm/psci.h
2139 @@ -29,7 +29,7 @@ struct psci_operations {
2140 int (*cpu_off)(struct psci_power_state state);
2141 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2142 int (*migrate)(unsigned long cpuid);
2143 -};
2144 +} __no_const;
2145
2146 extern struct psci_operations psci_ops;
2147 extern struct smp_operations psci_smp_ops;
2148 diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2149 index 2ec765c..beb1fe16 100644
2150 --- a/arch/arm/include/asm/smp.h
2151 +++ b/arch/arm/include/asm/smp.h
2152 @@ -113,7 +113,7 @@ struct smp_operations {
2153 int (*cpu_disable)(unsigned int cpu);
2154 #endif
2155 #endif
2156 -};
2157 +} __no_const;
2158
2159 struct of_cpu_method {
2160 const char *method;
2161 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2162 index f989d7c..e8aa7f0 100644
2163 --- a/arch/arm/include/asm/thread_info.h
2164 +++ b/arch/arm/include/asm/thread_info.h
2165 @@ -88,9 +88,9 @@ struct thread_info {
2166 .flags = 0, \
2167 .preempt_count = INIT_PREEMPT_COUNT, \
2168 .addr_limit = KERNEL_DS, \
2169 - .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2170 - domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2171 - domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2172 + .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2173 + domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2174 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2175 .restart_block = { \
2176 .fn = do_no_restart_syscall, \
2177 }, \
2178 @@ -158,7 +158,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2179 #define TIF_SYSCALL_AUDIT 9
2180 #define TIF_SYSCALL_TRACEPOINT 10
2181 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2182 -#define TIF_NOHZ 12 /* in adaptive nohz mode */
2183 +/* within 8 bits of TIF_SYSCALL_TRACE
2184 + * to meet flexible second operand requirements
2185 + */
2186 +#define TIF_GRSEC_SETXID 12
2187 +#define TIF_NOHZ 13 /* in adaptive nohz mode */
2188 #define TIF_USING_IWMMXT 17
2189 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2190 #define TIF_RESTORE_SIGMASK 20
2191 @@ -172,10 +176,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2192 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2193 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2194 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2195 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2196
2197 /* Checks for any syscall work in entry-common.S */
2198 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2199 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2200 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2201
2202 /*
2203 * Change these and you break ASM code in entry-common.S
2204 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2205 index 75d9579..b5b40e4 100644
2206 --- a/arch/arm/include/asm/uaccess.h
2207 +++ b/arch/arm/include/asm/uaccess.h
2208 @@ -18,6 +18,7 @@
2209 #include <asm/domain.h>
2210 #include <asm/unified.h>
2211 #include <asm/compiler.h>
2212 +#include <asm/pgtable.h>
2213
2214 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2215 #include <asm-generic/uaccess-unaligned.h>
2216 @@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2217 static inline void set_fs(mm_segment_t fs)
2218 {
2219 current_thread_info()->addr_limit = fs;
2220 - modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2221 + modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2222 }
2223
2224 #define segment_eq(a,b) ((a) == (b))
2225
2226 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
2227 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2228 +
2229 +static inline void pax_open_userland(void)
2230 +{
2231 +
2232 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2233 + if (segment_eq(get_fs(), USER_DS)) {
2234 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2235 + modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2236 + }
2237 +#endif
2238 +
2239 +}
2240 +
2241 +static inline void pax_close_userland(void)
2242 +{
2243 +
2244 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2245 + if (segment_eq(get_fs(), USER_DS)) {
2246 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2247 + modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2248 + }
2249 +#endif
2250 +
2251 +}
2252 +
2253 #define __addr_ok(addr) ({ \
2254 unsigned long flag; \
2255 __asm__("cmp %2, %0; movlo %0, #0" \
2256 @@ -150,8 +178,12 @@ extern int __get_user_4(void *);
2257
2258 #define get_user(x,p) \
2259 ({ \
2260 + int __e; \
2261 might_fault(); \
2262 - __get_user_check(x,p); \
2263 + pax_open_userland(); \
2264 + __e = __get_user_check(x,p); \
2265 + pax_close_userland(); \
2266 + __e; \
2267 })
2268
2269 extern int __put_user_1(void *, unsigned int);
2270 @@ -196,8 +228,12 @@ extern int __put_user_8(void *, unsigned long long);
2271
2272 #define put_user(x,p) \
2273 ({ \
2274 + int __e; \
2275 might_fault(); \
2276 - __put_user_check(x,p); \
2277 + pax_open_userland(); \
2278 + __e = __put_user_check(x,p); \
2279 + pax_close_userland(); \
2280 + __e; \
2281 })
2282
2283 #else /* CONFIG_MMU */
2284 @@ -221,6 +257,7 @@ static inline void set_fs(mm_segment_t fs)
2285
2286 #endif /* CONFIG_MMU */
2287
2288 +#define access_ok_noprefault(type,addr,size) access_ok((type),(addr),(size))
2289 #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
2290
2291 #define user_addr_max() \
2292 @@ -238,13 +275,17 @@ static inline void set_fs(mm_segment_t fs)
2293 #define __get_user(x,ptr) \
2294 ({ \
2295 long __gu_err = 0; \
2296 + pax_open_userland(); \
2297 __get_user_err((x),(ptr),__gu_err); \
2298 + pax_close_userland(); \
2299 __gu_err; \
2300 })
2301
2302 #define __get_user_error(x,ptr,err) \
2303 ({ \
2304 + pax_open_userland(); \
2305 __get_user_err((x),(ptr),err); \
2306 + pax_close_userland(); \
2307 (void) 0; \
2308 })
2309
2310 @@ -320,13 +361,17 @@ do { \
2311 #define __put_user(x,ptr) \
2312 ({ \
2313 long __pu_err = 0; \
2314 + pax_open_userland(); \
2315 __put_user_err((x),(ptr),__pu_err); \
2316 + pax_close_userland(); \
2317 __pu_err; \
2318 })
2319
2320 #define __put_user_error(x,ptr,err) \
2321 ({ \
2322 + pax_open_userland(); \
2323 __put_user_err((x),(ptr),err); \
2324 + pax_close_userland(); \
2325 (void) 0; \
2326 })
2327
2328 @@ -426,11 +471,44 @@ do { \
2329
2330
2331 #ifdef CONFIG_MMU
2332 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2333 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2334 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2335 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2336 +
2337 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2338 +{
2339 + unsigned long ret;
2340 +
2341 + check_object_size(to, n, false);
2342 + pax_open_userland();
2343 + ret = ___copy_from_user(to, from, n);
2344 + pax_close_userland();
2345 + return ret;
2346 +}
2347 +
2348 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2349 +{
2350 + unsigned long ret;
2351 +
2352 + check_object_size(from, n, true);
2353 + pax_open_userland();
2354 + ret = ___copy_to_user(to, from, n);
2355 + pax_close_userland();
2356 + return ret;
2357 +}
2358 +
2359 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2360 -extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2361 +extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2362 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2363 +
2364 +static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2365 +{
2366 + unsigned long ret;
2367 + pax_open_userland();
2368 + ret = ___clear_user(addr, n);
2369 + pax_close_userland();
2370 + return ret;
2371 +}
2372 +
2373 #else
2374 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2375 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2376 @@ -439,6 +517,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2377
2378 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2379 {
2380 + if ((long)n < 0)
2381 + return n;
2382 +
2383 if (access_ok(VERIFY_READ, from, n))
2384 n = __copy_from_user(to, from, n);
2385 else /* security hole - plug it */
2386 @@ -448,6 +529,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2387
2388 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2389 {
2390 + if ((long)n < 0)
2391 + return n;
2392 +
2393 if (access_ok(VERIFY_WRITE, to, n))
2394 n = __copy_to_user(to, from, n);
2395 return n;
2396 diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2397 index 5af0ed1..cea83883 100644
2398 --- a/arch/arm/include/uapi/asm/ptrace.h
2399 +++ b/arch/arm/include/uapi/asm/ptrace.h
2400 @@ -92,7 +92,7 @@
2401 * ARMv7 groups of PSR bits
2402 */
2403 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2404 -#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2405 +#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2406 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2407 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2408
2409 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2410 index f7b450f..f5364c5 100644
2411 --- a/arch/arm/kernel/armksyms.c
2412 +++ b/arch/arm/kernel/armksyms.c
2413 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2414
2415 /* networking */
2416 EXPORT_SYMBOL(csum_partial);
2417 -EXPORT_SYMBOL(csum_partial_copy_from_user);
2418 +EXPORT_SYMBOL(__csum_partial_copy_from_user);
2419 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2420 EXPORT_SYMBOL(__csum_ipv6_magic);
2421
2422 @@ -91,9 +91,9 @@ EXPORT_SYMBOL(__memzero);
2423 #ifdef CONFIG_MMU
2424 EXPORT_SYMBOL(copy_page);
2425
2426 -EXPORT_SYMBOL(__copy_from_user);
2427 -EXPORT_SYMBOL(__copy_to_user);
2428 -EXPORT_SYMBOL(__clear_user);
2429 +EXPORT_SYMBOL(___copy_from_user);
2430 +EXPORT_SYMBOL(___copy_to_user);
2431 +EXPORT_SYMBOL(___clear_user);
2432
2433 EXPORT_SYMBOL(__get_user_1);
2434 EXPORT_SYMBOL(__get_user_2);
2435 diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2436 index 1879e8d..5602dd4 100644
2437 --- a/arch/arm/kernel/entry-armv.S
2438 +++ b/arch/arm/kernel/entry-armv.S
2439 @@ -47,6 +47,87 @@
2440 9997:
2441 .endm
2442
2443 + .macro pax_enter_kernel
2444 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2445 + @ make aligned space for saved DACR
2446 + sub sp, sp, #8
2447 + @ save regs
2448 + stmdb sp!, {r1, r2}
2449 + @ read DACR from cpu_domain into r1
2450 + mov r2, sp
2451 + @ assume 8K pages, since we have to split the immediate in two
2452 + bic r2, r2, #(0x1fc0)
2453 + bic r2, r2, #(0x3f)
2454 + ldr r1, [r2, #TI_CPU_DOMAIN]
2455 + @ store old DACR on stack
2456 + str r1, [sp, #8]
2457 +#ifdef CONFIG_PAX_KERNEXEC
2458 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2459 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2460 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2461 +#endif
2462 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2463 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2464 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2465 +#endif
2466 + @ write r1 to current_thread_info()->cpu_domain
2467 + str r1, [r2, #TI_CPU_DOMAIN]
2468 + @ write r1 to DACR
2469 + mcr p15, 0, r1, c3, c0, 0
2470 + @ instruction sync
2471 + instr_sync
2472 + @ restore regs
2473 + ldmia sp!, {r1, r2}
2474 +#endif
2475 + .endm
2476 +
2477 + .macro pax_open_userland
2478 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2479 + @ save regs
2480 + stmdb sp!, {r0, r1}
2481 + @ read DACR from cpu_domain into r1
2482 + mov r0, sp
2483 + @ assume 8K pages, since we have to split the immediate in two
2484 + bic r0, r0, #(0x1fc0)
2485 + bic r0, r0, #(0x3f)
2486 + ldr r1, [r0, #TI_CPU_DOMAIN]
2487 + @ set current DOMAIN_USER to DOMAIN_CLIENT
2488 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2489 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2490 + @ write r1 to current_thread_info()->cpu_domain
2491 + str r1, [r0, #TI_CPU_DOMAIN]
2492 + @ write r1 to DACR
2493 + mcr p15, 0, r1, c3, c0, 0
2494 + @ instruction sync
2495 + instr_sync
2496 + @ restore regs
2497 + ldmia sp!, {r0, r1}
2498 +#endif
2499 + .endm
2500 +
2501 + .macro pax_close_userland
2502 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2503 + @ save regs
2504 + stmdb sp!, {r0, r1}
2505 + @ read DACR from cpu_domain into r1
2506 + mov r0, sp
2507 + @ assume 8K pages, since we have to split the immediate in two
2508 + bic r0, r0, #(0x1fc0)
2509 + bic r0, r0, #(0x3f)
2510 + ldr r1, [r0, #TI_CPU_DOMAIN]
2511 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2512 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2513 + @ write r1 to current_thread_info()->cpu_domain
2514 + str r1, [r0, #TI_CPU_DOMAIN]
2515 + @ write r1 to DACR
2516 + mcr p15, 0, r1, c3, c0, 0
2517 + @ instruction sync
2518 + instr_sync
2519 + @ restore regs
2520 + ldmia sp!, {r0, r1}
2521 +#endif
2522 + .endm
2523 +
2524 .macro pabt_helper
2525 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2526 #ifdef MULTI_PABORT
2527 @@ -89,11 +170,15 @@
2528 * Invalid mode handlers
2529 */
2530 .macro inv_entry, reason
2531 +
2532 + pax_enter_kernel
2533 +
2534 sub sp, sp, #S_FRAME_SIZE
2535 ARM( stmib sp, {r1 - lr} )
2536 THUMB( stmia sp, {r0 - r12} )
2537 THUMB( str sp, [sp, #S_SP] )
2538 THUMB( str lr, [sp, #S_LR] )
2539 +
2540 mov r1, #\reason
2541 .endm
2542
2543 @@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2544 .macro svc_entry, stack_hole=0
2545 UNWIND(.fnstart )
2546 UNWIND(.save {r0 - pc} )
2547 +
2548 + pax_enter_kernel
2549 +
2550 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2551 +
2552 #ifdef CONFIG_THUMB2_KERNEL
2553 SPFIX( str r0, [sp] ) @ temporarily saved
2554 SPFIX( mov r0, sp )
2555 @@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2556 ldmia r0, {r3 - r5}
2557 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2558 mov r6, #-1 @ "" "" "" ""
2559 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2560 + @ offset sp by 8 as done in pax_enter_kernel
2561 + add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2562 +#else
2563 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2564 +#endif
2565 SPFIX( addeq r2, r2, #4 )
2566 str r3, [sp, #-4]! @ save the "real" r0 copied
2567 @ from the exception stack
2568 @@ -317,6 +411,9 @@ ENDPROC(__pabt_svc)
2569 .macro usr_entry
2570 UNWIND(.fnstart )
2571 UNWIND(.cantunwind ) @ don't unwind the user space
2572 +
2573 + pax_enter_kernel_user
2574 +
2575 sub sp, sp, #S_FRAME_SIZE
2576 ARM( stmib sp, {r1 - r12} )
2577 THUMB( stmia sp, {r0 - r12} )
2578 @@ -416,7 +513,9 @@ __und_usr:
2579 tst r3, #PSR_T_BIT @ Thumb mode?
2580 bne __und_usr_thumb
2581 sub r4, r2, #4 @ ARM instr at LR - 4
2582 + pax_open_userland
2583 1: ldrt r0, [r4]
2584 + pax_close_userland
2585 ARM_BE8(rev r0, r0) @ little endian instruction
2586
2587 @ r0 = 32-bit ARM instruction which caused the exception
2588 @@ -450,11 +549,15 @@ __und_usr_thumb:
2589 */
2590 .arch armv6t2
2591 #endif
2592 + pax_open_userland
2593 2: ldrht r5, [r4]
2594 + pax_close_userland
2595 ARM_BE8(rev16 r5, r5) @ little endian instruction
2596 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2597 blo __und_usr_fault_16 @ 16bit undefined instruction
2598 + pax_open_userland
2599 3: ldrht r0, [r2]
2600 + pax_close_userland
2601 ARM_BE8(rev16 r0, r0) @ little endian instruction
2602 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2603 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2604 @@ -484,7 +587,8 @@ ENDPROC(__und_usr)
2605 */
2606 .pushsection .fixup, "ax"
2607 .align 2
2608 -4: mov pc, r9
2609 +4: pax_close_userland
2610 + mov pc, r9
2611 .popsection
2612 .pushsection __ex_table,"a"
2613 .long 1b, 4b
2614 @@ -694,7 +798,7 @@ ENTRY(__switch_to)
2615 THUMB( str lr, [ip], #4 )
2616 ldr r4, [r2, #TI_TP_VALUE]
2617 ldr r5, [r2, #TI_TP_VALUE + 4]
2618 -#ifdef CONFIG_CPU_USE_DOMAINS
2619 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2620 ldr r6, [r2, #TI_CPU_DOMAIN]
2621 #endif
2622 switch_tls r1, r4, r5, r3, r7
2623 @@ -703,7 +807,7 @@ ENTRY(__switch_to)
2624 ldr r8, =__stack_chk_guard
2625 ldr r7, [r7, #TSK_STACK_CANARY]
2626 #endif
2627 -#ifdef CONFIG_CPU_USE_DOMAINS
2628 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2629 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2630 #endif
2631 mov r5, r0
2632 diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2633 index a2dcafd..1048b5a 100644
2634 --- a/arch/arm/kernel/entry-common.S
2635 +++ b/arch/arm/kernel/entry-common.S
2636 @@ -10,18 +10,46 @@
2637
2638 #include <asm/unistd.h>
2639 #include <asm/ftrace.h>
2640 +#include <asm/domain.h>
2641 #include <asm/unwind.h>
2642
2643 +#include "entry-header.S"
2644 +
2645 #ifdef CONFIG_NEED_RET_TO_USER
2646 #include <mach/entry-macro.S>
2647 #else
2648 .macro arch_ret_to_user, tmp1, tmp2
2649 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2650 + @ save regs
2651 + stmdb sp!, {r1, r2}
2652 + @ read DACR from cpu_domain into r1
2653 + mov r2, sp
2654 + @ assume 8K pages, since we have to split the immediate in two
2655 + bic r2, r2, #(0x1fc0)
2656 + bic r2, r2, #(0x3f)
2657 + ldr r1, [r2, #TI_CPU_DOMAIN]
2658 +#ifdef CONFIG_PAX_KERNEXEC
2659 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2660 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2661 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2662 +#endif
2663 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2664 + @ set current DOMAIN_USER to DOMAIN_UDEREF
2665 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2666 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2667 +#endif
2668 + @ write r1 to current_thread_info()->cpu_domain
2669 + str r1, [r2, #TI_CPU_DOMAIN]
2670 + @ write r1 to DACR
2671 + mcr p15, 0, r1, c3, c0, 0
2672 + @ instruction sync
2673 + instr_sync
2674 + @ restore regs
2675 + ldmia sp!, {r1, r2}
2676 +#endif
2677 .endm
2678 #endif
2679
2680 -#include "entry-header.S"
2681 -
2682 -
2683 .align 5
2684 /*
2685 * This is the fast syscall return path. We do as little as
2686 @@ -411,6 +439,12 @@ ENTRY(vector_swi)
2687 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2688 #endif
2689
2690 + /*
2691 + * do this here to avoid a performance hit of wrapping the code above
2692 + * that directly dereferences userland to parse the SWI instruction
2693 + */
2694 + pax_enter_kernel_user
2695 +
2696 adr tbl, sys_call_table @ load syscall table pointer
2697
2698 #if defined(CONFIG_OABI_COMPAT)
2699 diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2700 index efb208d..d34bd02 100644
2701 --- a/arch/arm/kernel/entry-header.S
2702 +++ b/arch/arm/kernel/entry-header.S
2703 @@ -188,6 +188,60 @@
2704 msr cpsr_c, \rtemp @ switch back to the SVC mode
2705 .endm
2706
2707 + .macro pax_enter_kernel_user
2708 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2709 + @ save regs
2710 + stmdb sp!, {r0, r1}
2711 + @ read DACR from cpu_domain into r1
2712 + mov r0, sp
2713 + @ assume 8K pages, since we have to split the immediate in two
2714 + bic r0, r0, #(0x1fc0)
2715 + bic r0, r0, #(0x3f)
2716 + ldr r1, [r0, #TI_CPU_DOMAIN]
2717 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2718 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2719 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2720 +#endif
2721 +#ifdef CONFIG_PAX_KERNEXEC
2722 + @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2723 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2724 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2725 +#endif
2726 + @ write r1 to current_thread_info()->cpu_domain
2727 + str r1, [r0, #TI_CPU_DOMAIN]
2728 + @ write r1 to DACR
2729 + mcr p15, 0, r1, c3, c0, 0
2730 + @ instruction sync
2731 + instr_sync
2732 + @ restore regs
2733 + ldmia sp!, {r0, r1}
2734 +#endif
2735 + .endm
2736 +
2737 + .macro pax_exit_kernel
2738 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2739 + @ save regs
2740 + stmdb sp!, {r0, r1}
2741 + @ read old DACR from stack into r1
2742 + ldr r1, [sp, #(8 + S_SP)]
2743 + sub r1, r1, #8
2744 + ldr r1, [r1]
2745 +
2746 + @ write r1 to current_thread_info()->cpu_domain
2747 + mov r0, sp
2748 + @ assume 8K pages, since we have to split the immediate in two
2749 + bic r0, r0, #(0x1fc0)
2750 + bic r0, r0, #(0x3f)
2751 + str r1, [r0, #TI_CPU_DOMAIN]
2752 + @ write r1 to DACR
2753 + mcr p15, 0, r1, c3, c0, 0
2754 + @ instruction sync
2755 + instr_sync
2756 + @ restore regs
2757 + ldmia sp!, {r0, r1}
2758 +#endif
2759 + .endm
2760 +
2761 #ifndef CONFIG_THUMB2_KERNEL
2762 .macro svc_exit, rpsr, irq = 0
2763 .if \irq != 0
2764 @@ -207,6 +261,9 @@
2765 blne trace_hardirqs_off
2766 #endif
2767 .endif
2768 +
2769 + pax_exit_kernel
2770 +
2771 msr spsr_cxsf, \rpsr
2772 #if defined(CONFIG_CPU_V6)
2773 ldr r0, [sp]
2774 @@ -265,6 +322,9 @@
2775 blne trace_hardirqs_off
2776 #endif
2777 .endif
2778 +
2779 + pax_exit_kernel
2780 +
2781 ldr lr, [sp, #S_SP] @ top of the stack
2782 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2783 clrex @ clear the exclusive monitor
2784 diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2785 index 918875d..cd5fa27 100644
2786 --- a/arch/arm/kernel/fiq.c
2787 +++ b/arch/arm/kernel/fiq.c
2788 @@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2789 void *base = vectors_page;
2790 unsigned offset = FIQ_OFFSET;
2791
2792 + pax_open_kernel();
2793 memcpy(base + offset, start, length);
2794 + pax_close_kernel();
2795 +
2796 if (!cache_is_vipt_nonaliasing())
2797 flush_icache_range((unsigned long)base + offset, offset +
2798 length);
2799 diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2800 index 591d6e4..8322a26 100644
2801 --- a/arch/arm/kernel/head.S
2802 +++ b/arch/arm/kernel/head.S
2803 @@ -437,7 +437,7 @@ __enable_mmu:
2804 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2805 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2806 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2807 - domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2808 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2809 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2810 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2811 #endif
2812 diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2813 index 45e4781..8eac93d 100644
2814 --- a/arch/arm/kernel/module.c
2815 +++ b/arch/arm/kernel/module.c
2816 @@ -38,12 +38,39 @@
2817 #endif
2818
2819 #ifdef CONFIG_MMU
2820 -void *module_alloc(unsigned long size)
2821 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2822 {
2823 + if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2824 + return NULL;
2825 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2826 - GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
2827 + GFP_KERNEL, prot, NUMA_NO_NODE,
2828 __builtin_return_address(0));
2829 }
2830 +
2831 +void *module_alloc(unsigned long size)
2832 +{
2833 +
2834 +#ifdef CONFIG_PAX_KERNEXEC
2835 + return __module_alloc(size, PAGE_KERNEL);
2836 +#else
2837 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2838 +#endif
2839 +
2840 +}
2841 +
2842 +#ifdef CONFIG_PAX_KERNEXEC
2843 +void module_free_exec(struct module *mod, void *module_region)
2844 +{
2845 + module_free(mod, module_region);
2846 +}
2847 +EXPORT_SYMBOL(module_free_exec);
2848 +
2849 +void *module_alloc_exec(unsigned long size)
2850 +{
2851 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2852 +}
2853 +EXPORT_SYMBOL(module_alloc_exec);
2854 +#endif
2855 #endif
2856
2857 int
2858 diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2859 index 07314af..c46655c 100644
2860 --- a/arch/arm/kernel/patch.c
2861 +++ b/arch/arm/kernel/patch.c
2862 @@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2863 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2864 int size;
2865
2866 + pax_open_kernel();
2867 if (thumb2 && __opcode_is_thumb16(insn)) {
2868 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2869 size = sizeof(u16);
2870 @@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2871 *(u32 *)addr = insn;
2872 size = sizeof(u32);
2873 }
2874 + pax_close_kernel();
2875
2876 flush_icache_range((uintptr_t)(addr),
2877 (uintptr_t)(addr) + size);
2878 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2879 index 81ef686..f4130b8 100644
2880 --- a/arch/arm/kernel/process.c
2881 +++ b/arch/arm/kernel/process.c
2882 @@ -212,6 +212,7 @@ void machine_power_off(void)
2883
2884 if (pm_power_off)
2885 pm_power_off();
2886 + BUG();
2887 }
2888
2889 /*
2890 @@ -225,7 +226,7 @@ void machine_power_off(void)
2891 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2892 * to use. Implementing such co-ordination would be essentially impossible.
2893 */
2894 -void machine_restart(char *cmd)
2895 +__noreturn void machine_restart(char *cmd)
2896 {
2897 local_irq_disable();
2898 smp_send_stop();
2899 @@ -248,8 +249,8 @@ void __show_regs(struct pt_regs *regs)
2900
2901 show_regs_print_info(KERN_DEFAULT);
2902
2903 - print_symbol("PC is at %s\n", instruction_pointer(regs));
2904 - print_symbol("LR is at %s\n", regs->ARM_lr);
2905 + printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2906 + printk("LR is at %pA\n", (void *)regs->ARM_lr);
2907 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2908 "sp : %08lx ip : %08lx fp : %08lx\n",
2909 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2910 @@ -425,12 +426,6 @@ unsigned long get_wchan(struct task_struct *p)
2911 return 0;
2912 }
2913
2914 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2915 -{
2916 - unsigned long range_end = mm->brk + 0x02000000;
2917 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2918 -}
2919 -
2920 #ifdef CONFIG_MMU
2921 #ifdef CONFIG_KUSER_HELPERS
2922 /*
2923 @@ -446,7 +441,7 @@ static struct vm_area_struct gate_vma = {
2924
2925 static int __init gate_vma_init(void)
2926 {
2927 - gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2928 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2929 return 0;
2930 }
2931 arch_initcall(gate_vma_init);
2932 @@ -472,41 +467,16 @@ int in_gate_area_no_mm(unsigned long addr)
2933
2934 const char *arch_vma_name(struct vm_area_struct *vma)
2935 {
2936 - return is_gate_vma(vma) ? "[vectors]" :
2937 - (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
2938 - "[sigpage]" : NULL;
2939 + return is_gate_vma(vma) ? "[vectors]" : NULL;
2940 }
2941
2942 -static struct page *signal_page;
2943 -extern struct page *get_signal_page(void);
2944 -
2945 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2946 {
2947 struct mm_struct *mm = current->mm;
2948 - unsigned long addr;
2949 - int ret;
2950 -
2951 - if (!signal_page)
2952 - signal_page = get_signal_page();
2953 - if (!signal_page)
2954 - return -ENOMEM;
2955
2956 down_write(&mm->mmap_sem);
2957 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
2958 - if (IS_ERR_VALUE(addr)) {
2959 - ret = addr;
2960 - goto up_fail;
2961 - }
2962 -
2963 - ret = install_special_mapping(mm, addr, PAGE_SIZE,
2964 - VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2965 - &signal_page);
2966 -
2967 - if (ret == 0)
2968 - mm->context.sigpage = addr;
2969 -
2970 - up_fail:
2971 + mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2972 up_write(&mm->mmap_sem);
2973 - return ret;
2974 + return 0;
2975 }
2976 #endif
2977 diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2978 index 4693188..4596c5e 100644
2979 --- a/arch/arm/kernel/psci.c
2980 +++ b/arch/arm/kernel/psci.c
2981 @@ -24,7 +24,7 @@
2982 #include <asm/opcodes-virt.h>
2983 #include <asm/psci.h>
2984
2985 -struct psci_operations psci_ops;
2986 +struct psci_operations psci_ops __read_only;
2987
2988 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2989
2990 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2991 index 0dd3b79..b67388e 100644
2992 --- a/arch/arm/kernel/ptrace.c
2993 +++ b/arch/arm/kernel/ptrace.c
2994 @@ -908,7 +908,7 @@ enum ptrace_syscall_dir {
2995 PTRACE_SYSCALL_EXIT,
2996 };
2997
2998 -static int tracehook_report_syscall(struct pt_regs *regs,
2999 +static void tracehook_report_syscall(struct pt_regs *regs,
3000 enum ptrace_syscall_dir dir)
3001 {
3002 unsigned long ip;
3003 @@ -926,19 +926,29 @@ static int tracehook_report_syscall(struct pt_regs *regs,
3004 current_thread_info()->syscall = -1;
3005
3006 regs->ARM_ip = ip;
3007 - return current_thread_info()->syscall;
3008 }
3009
3010 +#ifdef CONFIG_GRKERNSEC_SETXID
3011 +extern void gr_delayed_cred_worker(void);
3012 +#endif
3013 +
3014 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
3015 {
3016 current_thread_info()->syscall = scno;
3017
3018 +#ifdef CONFIG_GRKERNSEC_SETXID
3019 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3020 + gr_delayed_cred_worker();
3021 +#endif
3022 +
3023 /* Do the secure computing check first; failures should be fast. */
3024 if (secure_computing(scno) == -1)
3025 return -1;
3026
3027 if (test_thread_flag(TIF_SYSCALL_TRACE))
3028 - scno = tracehook_report_syscall(regs, PTRACE_SYSCALL_ENTER);
3029 + tracehook_report_syscall(regs, PTRACE_SYSCALL_ENTER);
3030 +
3031 + scno = current_thread_info()->syscall;
3032
3033 if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
3034 trace_sys_enter(regs, scno);
3035 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
3036 index 50e198c..a8b5f49 100644
3037 --- a/arch/arm/kernel/setup.c
3038 +++ b/arch/arm/kernel/setup.c
3039 @@ -103,21 +103,23 @@ EXPORT_SYMBOL(elf_hwcap);
3040 unsigned int elf_hwcap2 __read_mostly;
3041 EXPORT_SYMBOL(elf_hwcap2);
3042
3043 +pteval_t __supported_pte_mask __read_only;
3044 +pmdval_t __supported_pmd_mask __read_only;
3045
3046 #ifdef MULTI_CPU
3047 -struct processor processor __read_mostly;
3048 +struct processor processor __read_only;
3049 #endif
3050 #ifdef MULTI_TLB
3051 -struct cpu_tlb_fns cpu_tlb __read_mostly;
3052 +struct cpu_tlb_fns cpu_tlb __read_only;
3053 #endif
3054 #ifdef MULTI_USER
3055 -struct cpu_user_fns cpu_user __read_mostly;
3056 +struct cpu_user_fns cpu_user __read_only;
3057 #endif
3058 #ifdef MULTI_CACHE
3059 -struct cpu_cache_fns cpu_cache __read_mostly;
3060 +struct cpu_cache_fns cpu_cache __read_only;
3061 #endif
3062 #ifdef CONFIG_OUTER_CACHE
3063 -struct outer_cache_fns outer_cache __read_mostly;
3064 +struct outer_cache_fns outer_cache __read_only;
3065 EXPORT_SYMBOL(outer_cache);
3066 #endif
3067
3068 @@ -250,9 +252,13 @@ static int __get_cpu_architecture(void)
3069 asm("mrc p15, 0, %0, c0, c1, 4"
3070 : "=r" (mmfr0));
3071 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3072 - (mmfr0 & 0x000000f0) >= 0x00000030)
3073 + (mmfr0 & 0x000000f0) >= 0x00000030) {
3074 cpu_arch = CPU_ARCH_ARMv7;
3075 - else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3076 + if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3077 + __supported_pte_mask |= L_PTE_PXN;
3078 + __supported_pmd_mask |= PMD_PXNTABLE;
3079 + }
3080 + } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3081 (mmfr0 & 0x000000f0) == 0x00000020)
3082 cpu_arch = CPU_ARCH_ARMv6;
3083 else
3084 diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3085 index bd19834..e4d8c66 100644
3086 --- a/arch/arm/kernel/signal.c
3087 +++ b/arch/arm/kernel/signal.c
3088 @@ -24,8 +24,6 @@
3089
3090 extern const unsigned long sigreturn_codes[7];
3091
3092 -static unsigned long signal_return_offset;
3093 -
3094 #ifdef CONFIG_CRUNCH
3095 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3096 {
3097 @@ -396,8 +394,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3098 * except when the MPU has protected the vectors
3099 * page from PL0
3100 */
3101 - retcode = mm->context.sigpage + signal_return_offset +
3102 - (idx << 2) + thumb;
3103 + retcode = mm->context.sigpage + (idx << 2) + thumb;
3104 } else
3105 #endif
3106 {
3107 @@ -604,33 +601,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3108 } while (thread_flags & _TIF_WORK_MASK);
3109 return 0;
3110 }
3111 -
3112 -struct page *get_signal_page(void)
3113 -{
3114 - unsigned long ptr;
3115 - unsigned offset;
3116 - struct page *page;
3117 - void *addr;
3118 -
3119 - page = alloc_pages(GFP_KERNEL, 0);
3120 -
3121 - if (!page)
3122 - return NULL;
3123 -
3124 - addr = page_address(page);
3125 -
3126 - /* Give the signal return code some randomness */
3127 - offset = 0x200 + (get_random_int() & 0x7fc);
3128 - signal_return_offset = offset;
3129 -
3130 - /*
3131 - * Copy signal return handlers into the vector page, and
3132 - * set sigreturn to be a pointer to these.
3133 - */
3134 - memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3135 -
3136 - ptr = (unsigned long)addr + offset;
3137 - flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3138 -
3139 - return page;
3140 -}
3141 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3142 index 7c4fada..8581286 100644
3143 --- a/arch/arm/kernel/smp.c
3144 +++ b/arch/arm/kernel/smp.c
3145 @@ -73,7 +73,7 @@ enum ipi_msg_type {
3146
3147 static DECLARE_COMPLETION(cpu_running);
3148
3149 -static struct smp_operations smp_ops;
3150 +static struct smp_operations smp_ops __read_only;
3151
3152 void __init smp_set_ops(struct smp_operations *ops)
3153 {
3154 diff --git a/arch/arm/kernel/tcm.c b/arch/arm/kernel/tcm.c
3155 index 7a3be1d..b00c7de 100644
3156 --- a/arch/arm/kernel/tcm.c
3157 +++ b/arch/arm/kernel/tcm.c
3158 @@ -61,7 +61,7 @@ static struct map_desc itcm_iomap[] __initdata = {
3159 .virtual = ITCM_OFFSET,
3160 .pfn = __phys_to_pfn(ITCM_OFFSET),
3161 .length = 0,
3162 - .type = MT_MEMORY_RWX_ITCM,
3163 + .type = MT_MEMORY_RX_ITCM,
3164 }
3165 };
3166
3167 @@ -267,7 +267,9 @@ no_dtcm:
3168 start = &__sitcm_text;
3169 end = &__eitcm_text;
3170 ram = &__itcm_start;
3171 + pax_open_kernel();
3172 memcpy(start, ram, itcm_code_sz);
3173 + pax_close_kernel();
3174 pr_debug("CPU ITCM: copied code from %p - %p\n",
3175 start, end);
3176 itcm_present = true;
3177 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3178 index abd2fc0..895dbb6 100644
3179 --- a/arch/arm/kernel/traps.c
3180 +++ b/arch/arm/kernel/traps.c
3181 @@ -62,7 +62,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3182 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3183 {
3184 #ifdef CONFIG_KALLSYMS
3185 - printk("[<%08lx>] (%ps) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3186 + printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3187 #else
3188 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3189 #endif
3190 @@ -264,6 +264,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3191 static int die_owner = -1;
3192 static unsigned int die_nest_count;
3193
3194 +extern void gr_handle_kernel_exploit(void);
3195 +
3196 static unsigned long oops_begin(void)
3197 {
3198 int cpu;
3199 @@ -306,6 +308,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3200 panic("Fatal exception in interrupt");
3201 if (panic_on_oops)
3202 panic("Fatal exception");
3203 +
3204 + gr_handle_kernel_exploit();
3205 +
3206 if (signr)
3207 do_exit(signr);
3208 }
3209 @@ -643,7 +648,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3210 * The user helper at 0xffff0fe0 must be used instead.
3211 * (see entry-armv.S for details)
3212 */
3213 + pax_open_kernel();
3214 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3215 + pax_close_kernel();
3216 }
3217 return 0;
3218
3219 @@ -900,7 +907,11 @@ void __init early_trap_init(void *vectors_base)
3220 kuser_init(vectors_base);
3221
3222 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3223 - modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3224 +
3225 +#ifndef CONFIG_PAX_MEMORY_UDEREF
3226 + modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3227 +#endif
3228 +
3229 #else /* ifndef CONFIG_CPU_V7M */
3230 /*
3231 * on V7-M there is no need to copy the vector table to a dedicated
3232 diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3233 index 7bcee5c..e2f3249 100644
3234 --- a/arch/arm/kernel/vmlinux.lds.S
3235 +++ b/arch/arm/kernel/vmlinux.lds.S
3236 @@ -8,7 +8,11 @@
3237 #include <asm/thread_info.h>
3238 #include <asm/memory.h>
3239 #include <asm/page.h>
3240 -
3241 +
3242 +#ifdef CONFIG_PAX_KERNEXEC
3243 +#include <asm/pgtable.h>
3244 +#endif
3245 +
3246 #define PROC_INFO \
3247 . = ALIGN(4); \
3248 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3249 @@ -34,7 +38,7 @@
3250 #endif
3251
3252 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3253 - defined(CONFIG_GENERIC_BUG)
3254 + defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3255 #define ARM_EXIT_KEEP(x) x
3256 #define ARM_EXIT_DISCARD(x)
3257 #else
3258 @@ -90,6 +94,11 @@ SECTIONS
3259 _text = .;
3260 HEAD_TEXT
3261 }
3262 +
3263 +#ifdef CONFIG_PAX_KERNEXEC
3264 + . = ALIGN(1<<SECTION_SHIFT);
3265 +#endif
3266 +
3267 .text : { /* Real text segment */
3268 _stext = .; /* Text and read-only data */
3269 __exception_text_start = .;
3270 @@ -112,6 +121,8 @@ SECTIONS
3271 ARM_CPU_KEEP(PROC_INFO)
3272 }
3273
3274 + _etext = .; /* End of text section */
3275 +
3276 RO_DATA(PAGE_SIZE)
3277
3278 . = ALIGN(4);
3279 @@ -142,7 +153,9 @@ SECTIONS
3280
3281 NOTES
3282
3283 - _etext = .; /* End of text and rodata section */
3284 +#ifdef CONFIG_PAX_KERNEXEC
3285 + . = ALIGN(1<<SECTION_SHIFT);
3286 +#endif
3287
3288 #ifndef CONFIG_XIP_KERNEL
3289 . = ALIGN(PAGE_SIZE);
3290 @@ -220,6 +233,11 @@ SECTIONS
3291 . = PAGE_OFFSET + TEXT_OFFSET;
3292 #else
3293 __init_end = .;
3294 +
3295 +#ifdef CONFIG_PAX_KERNEXEC
3296 + . = ALIGN(1<<SECTION_SHIFT);
3297 +#endif
3298 +
3299 . = ALIGN(THREAD_SIZE);
3300 __data_loc = .;
3301 #endif
3302 diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3303 index f0e50a0..cab3a75 100644
3304 --- a/arch/arm/kvm/arm.c
3305 +++ b/arch/arm/kvm/arm.c
3306 @@ -57,7 +57,7 @@ static unsigned long hyp_default_vectors;
3307 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3308
3309 /* The VMID used in the VTTBR */
3310 -static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3311 +static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3312 static u8 kvm_next_vmid;
3313 static DEFINE_SPINLOCK(kvm_vmid_lock);
3314
3315 @@ -408,7 +408,7 @@ void force_vm_exit(const cpumask_t *mask)
3316 */
3317 static bool need_new_vmid_gen(struct kvm *kvm)
3318 {
3319 - return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3320 + return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3321 }
3322
3323 /**
3324 @@ -441,7 +441,7 @@ static void update_vttbr(struct kvm *kvm)
3325
3326 /* First user of a new VMID generation? */
3327 if (unlikely(kvm_next_vmid == 0)) {
3328 - atomic64_inc(&kvm_vmid_gen);
3329 + atomic64_inc_unchecked(&kvm_vmid_gen);
3330 kvm_next_vmid = 1;
3331
3332 /*
3333 @@ -458,7 +458,7 @@ static void update_vttbr(struct kvm *kvm)
3334 kvm_call_hyp(__kvm_flush_vm_context);
3335 }
3336
3337 - kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3338 + kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3339 kvm->arch.vmid = kvm_next_vmid;
3340 kvm_next_vmid++;
3341
3342 @@ -1033,7 +1033,7 @@ static void check_kvm_target_cpu(void *ret)
3343 /**
3344 * Initialize Hyp-mode and memory mappings on all CPUs.
3345 */
3346 -int kvm_arch_init(void *opaque)
3347 +int kvm_arch_init(const void *opaque)
3348 {
3349 int err;
3350 int ret, cpu;
3351 diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3352 index 14a0d98..7771a7d 100644
3353 --- a/arch/arm/lib/clear_user.S
3354 +++ b/arch/arm/lib/clear_user.S
3355 @@ -12,14 +12,14 @@
3356
3357 .text
3358
3359 -/* Prototype: int __clear_user(void *addr, size_t sz)
3360 +/* Prototype: int ___clear_user(void *addr, size_t sz)
3361 * Purpose : clear some user memory
3362 * Params : addr - user memory address to clear
3363 * : sz - number of bytes to clear
3364 * Returns : number of bytes NOT cleared
3365 */
3366 ENTRY(__clear_user_std)
3367 -WEAK(__clear_user)
3368 +WEAK(___clear_user)
3369 stmfd sp!, {r1, lr}
3370 mov r2, #0
3371 cmp r1, #4
3372 @@ -44,7 +44,7 @@ WEAK(__clear_user)
3373 USER( strnebt r2, [r0])
3374 mov r0, #0
3375 ldmfd sp!, {r1, pc}
3376 -ENDPROC(__clear_user)
3377 +ENDPROC(___clear_user)
3378 ENDPROC(__clear_user_std)
3379
3380 .pushsection .fixup,"ax"
3381 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3382 index 66a477a..bee61d3 100644
3383 --- a/arch/arm/lib/copy_from_user.S
3384 +++ b/arch/arm/lib/copy_from_user.S
3385 @@ -16,7 +16,7 @@
3386 /*
3387 * Prototype:
3388 *
3389 - * size_t __copy_from_user(void *to, const void *from, size_t n)
3390 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
3391 *
3392 * Purpose:
3393 *
3394 @@ -84,11 +84,11 @@
3395
3396 .text
3397
3398 -ENTRY(__copy_from_user)
3399 +ENTRY(___copy_from_user)
3400
3401 #include "copy_template.S"
3402
3403 -ENDPROC(__copy_from_user)
3404 +ENDPROC(___copy_from_user)
3405
3406 .pushsection .fixup,"ax"
3407 .align 0
3408 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3409 index 6ee2f67..d1cce76 100644
3410 --- a/arch/arm/lib/copy_page.S
3411 +++ b/arch/arm/lib/copy_page.S
3412 @@ -10,6 +10,7 @@
3413 * ASM optimised string functions
3414 */
3415 #include <linux/linkage.h>
3416 +#include <linux/const.h>
3417 #include <asm/assembler.h>
3418 #include <asm/asm-offsets.h>
3419 #include <asm/cache.h>
3420 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3421 index d066df6..df28194 100644
3422 --- a/arch/arm/lib/copy_to_user.S
3423 +++ b/arch/arm/lib/copy_to_user.S
3424 @@ -16,7 +16,7 @@
3425 /*
3426 * Prototype:
3427 *
3428 - * size_t __copy_to_user(void *to, const void *from, size_t n)
3429 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
3430 *
3431 * Purpose:
3432 *
3433 @@ -88,11 +88,11 @@
3434 .text
3435
3436 ENTRY(__copy_to_user_std)
3437 -WEAK(__copy_to_user)
3438 +WEAK(___copy_to_user)
3439
3440 #include "copy_template.S"
3441
3442 -ENDPROC(__copy_to_user)
3443 +ENDPROC(___copy_to_user)
3444 ENDPROC(__copy_to_user_std)
3445
3446 .pushsection .fixup,"ax"
3447 diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3448 index 7d08b43..f7ca7ea 100644
3449 --- a/arch/arm/lib/csumpartialcopyuser.S
3450 +++ b/arch/arm/lib/csumpartialcopyuser.S
3451 @@ -57,8 +57,8 @@
3452 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3453 */
3454
3455 -#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3456 -#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3457 +#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3458 +#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3459
3460 #include "csumpartialcopygeneric.S"
3461
3462 diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3463 index 5306de3..aed6d03 100644
3464 --- a/arch/arm/lib/delay.c
3465 +++ b/arch/arm/lib/delay.c
3466 @@ -28,7 +28,7 @@
3467 /*
3468 * Default to the loop-based delay implementation.
3469 */
3470 -struct arm_delay_ops arm_delay_ops = {
3471 +struct arm_delay_ops arm_delay_ops __read_only = {
3472 .delay = __loop_delay,
3473 .const_udelay = __loop_const_udelay,
3474 .udelay = __loop_udelay,
3475 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3476 index 3e58d71..029817c 100644
3477 --- a/arch/arm/lib/uaccess_with_memcpy.c
3478 +++ b/arch/arm/lib/uaccess_with_memcpy.c
3479 @@ -136,7 +136,7 @@ out:
3480 }
3481
3482 unsigned long
3483 -__copy_to_user(void __user *to, const void *from, unsigned long n)
3484 +___copy_to_user(void __user *to, const void *from, unsigned long n)
3485 {
3486 /*
3487 * This test is stubbed out of the main function above to keep
3488 @@ -190,7 +190,7 @@ out:
3489 return n;
3490 }
3491
3492 -unsigned long __clear_user(void __user *addr, unsigned long n)
3493 +unsigned long ___clear_user(void __user *addr, unsigned long n)
3494 {
3495 /* See rational for this in __copy_to_user() above. */
3496 if (n < 64)
3497 diff --git a/arch/arm/mach-at91/setup.c b/arch/arm/mach-at91/setup.c
3498 index f7a07a5..258e1f7 100644
3499 --- a/arch/arm/mach-at91/setup.c
3500 +++ b/arch/arm/mach-at91/setup.c
3501 @@ -81,7 +81,7 @@ void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
3502
3503 desc->pfn = __phys_to_pfn(base);
3504 desc->length = length;
3505 - desc->type = MT_MEMORY_RWX_NONCACHED;
3506 + desc->type = MT_MEMORY_RW_NONCACHED;
3507
3508 pr_info("AT91: sram at 0x%lx of 0x%x mapped at 0x%lx\n",
3509 base, length, desc->virtual);
3510 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3511 index 255f33a..507b157 100644
3512 --- a/arch/arm/mach-kirkwood/common.c
3513 +++ b/arch/arm/mach-kirkwood/common.c
3514 @@ -157,7 +157,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3515 clk_gate_ops.disable(hw);
3516 }
3517
3518 -static struct clk_ops clk_gate_fn_ops;
3519 +static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3520 +{
3521 + return clk_gate_ops.is_enabled(hw);
3522 +}
3523 +
3524 +static struct clk_ops clk_gate_fn_ops = {
3525 + .enable = clk_gate_fn_enable,
3526 + .disable = clk_gate_fn_disable,
3527 + .is_enabled = clk_gate_fn_is_enabled,
3528 +};
3529
3530 static struct clk __init *clk_register_gate_fn(struct device *dev,
3531 const char *name,
3532 @@ -191,14 +200,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3533 gate_fn->fn_en = fn_en;
3534 gate_fn->fn_dis = fn_dis;
3535
3536 - /* ops is the gate ops, but with our enable/disable functions */
3537 - if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3538 - clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3539 - clk_gate_fn_ops = clk_gate_ops;
3540 - clk_gate_fn_ops.enable = clk_gate_fn_enable;
3541 - clk_gate_fn_ops.disable = clk_gate_fn_disable;
3542 - }
3543 -
3544 clk = clk_register(dev, &gate_fn->gate.hw);
3545
3546 if (IS_ERR(clk))
3547 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3548 index aead77a..a2253fa 100644
3549 --- a/arch/arm/mach-omap2/board-n8x0.c
3550 +++ b/arch/arm/mach-omap2/board-n8x0.c
3551 @@ -568,7 +568,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3552 }
3553 #endif
3554
3555 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3556 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3557 .late_init = n8x0_menelaus_late_init,
3558 };
3559
3560 diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3561 index 9fe8c94..c014a4d 100644
3562 --- a/arch/arm/mach-omap2/gpmc.c
3563 +++ b/arch/arm/mach-omap2/gpmc.c
3564 @@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3565 };
3566
3567 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3568 -static struct irq_chip gpmc_irq_chip;
3569 static int gpmc_irq_start;
3570
3571 static struct resource gpmc_mem_root;
3572 @@ -727,6 +726,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3573
3574 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3575
3576 +static struct irq_chip gpmc_irq_chip = {
3577 + .name = "gpmc",
3578 + .irq_startup = gpmc_irq_noop_ret,
3579 + .irq_enable = gpmc_irq_enable,
3580 + .irq_disable = gpmc_irq_disable,
3581 + .irq_shutdown = gpmc_irq_noop,
3582 + .irq_ack = gpmc_irq_noop,
3583 + .irq_mask = gpmc_irq_noop,
3584 + .irq_unmask = gpmc_irq_noop,
3585 +
3586 +};
3587 +
3588 static int gpmc_setup_irq(void)
3589 {
3590 int i;
3591 @@ -741,15 +752,6 @@ static int gpmc_setup_irq(void)
3592 return gpmc_irq_start;
3593 }
3594
3595 - gpmc_irq_chip.name = "gpmc";
3596 - gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3597 - gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3598 - gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3599 - gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3600 - gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3601 - gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3602 - gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3603 -
3604 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3605 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3606
3607 diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3608 index 667915d..2ee1219 100644
3609 --- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3610 +++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3611 @@ -84,7 +84,7 @@ struct cpu_pm_ops {
3612 int (*finish_suspend)(unsigned long cpu_state);
3613 void (*resume)(void);
3614 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3615 -};
3616 +} __no_const;
3617
3618 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3619 static struct powerdomain *mpuss_pd;
3620 @@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3621 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3622 {}
3623
3624 -struct cpu_pm_ops omap_pm_ops = {
3625 +static struct cpu_pm_ops omap_pm_ops __read_only = {
3626 .finish_suspend = default_finish_suspend,
3627 .resume = dummy_cpu_resume,
3628 .scu_prepare = dummy_scu_prepare,
3629 diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3630 index 693fe48..c15ea73 100644
3631 --- a/arch/arm/mach-omap2/omap-wakeupgen.c
3632 +++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3633 @@ -343,7 +343,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3634 return NOTIFY_OK;
3635 }
3636
3637 -static struct notifier_block __refdata irq_hotplug_notifier = {
3638 +static struct notifier_block irq_hotplug_notifier = {
3639 .notifier_call = irq_cpu_hotplug_notify,
3640 };
3641
3642 diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3643 index 01ef59d..32ae28a8 100644
3644 --- a/arch/arm/mach-omap2/omap_device.c
3645 +++ b/arch/arm/mach-omap2/omap_device.c
3646 @@ -510,7 +510,7 @@ void omap_device_delete(struct omap_device *od)
3647 struct platform_device __init *omap_device_build(const char *pdev_name,
3648 int pdev_id,
3649 struct omap_hwmod *oh,
3650 - void *pdata, int pdata_len)
3651 + const void *pdata, int pdata_len)
3652 {
3653 struct omap_hwmod *ohs[] = { oh };
3654
3655 @@ -538,7 +538,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3656 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3657 int pdev_id,
3658 struct omap_hwmod **ohs,
3659 - int oh_cnt, void *pdata,
3660 + int oh_cnt, const void *pdata,
3661 int pdata_len)
3662 {
3663 int ret = -ENOMEM;
3664 diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3665 index 78c02b3..c94109a 100644
3666 --- a/arch/arm/mach-omap2/omap_device.h
3667 +++ b/arch/arm/mach-omap2/omap_device.h
3668 @@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3669 /* Core code interface */
3670
3671 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3672 - struct omap_hwmod *oh, void *pdata,
3673 + struct omap_hwmod *oh, const void *pdata,
3674 int pdata_len);
3675
3676 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3677 struct omap_hwmod **oh, int oh_cnt,
3678 - void *pdata, int pdata_len);
3679 + const void *pdata, int pdata_len);
3680
3681 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3682 struct omap_hwmod **ohs, int oh_cnt);
3683 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3684 index 66c60fe..c78950d 100644
3685 --- a/arch/arm/mach-omap2/omap_hwmod.c
3686 +++ b/arch/arm/mach-omap2/omap_hwmod.c
3687 @@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3688 int (*init_clkdm)(struct omap_hwmod *oh);
3689 void (*update_context_lost)(struct omap_hwmod *oh);
3690 int (*get_context_lost)(struct omap_hwmod *oh);
3691 -};
3692 +} __no_const;
3693
3694 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3695 -static struct omap_hwmod_soc_ops soc_ops;
3696 +static struct omap_hwmod_soc_ops soc_ops __read_only;
3697
3698 /* omap_hwmod_list contains all registered struct omap_hwmods */
3699 static LIST_HEAD(omap_hwmod_list);
3700 diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
3701 index 95fee54..cfa9cf1 100644
3702 --- a/arch/arm/mach-omap2/powerdomains43xx_data.c
3703 +++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
3704 @@ -10,6 +10,7 @@
3705
3706 #include <linux/kernel.h>
3707 #include <linux/init.h>
3708 +#include <asm/pgtable.h>
3709
3710 #include "powerdomain.h"
3711
3712 @@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
3713
3714 void __init am43xx_powerdomains_init(void)
3715 {
3716 - omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3717 + pax_open_kernel();
3718 + *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3719 + pax_close_kernel();
3720 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
3721 pwrdm_register_pwrdms(powerdomains_am43xx);
3722 pwrdm_complete_init();
3723 diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3724 index d15c7bb..b2d1f0c 100644
3725 --- a/arch/arm/mach-omap2/wd_timer.c
3726 +++ b/arch/arm/mach-omap2/wd_timer.c
3727 @@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3728 struct omap_hwmod *oh;
3729 char *oh_name = "wd_timer2";
3730 char *dev_name = "omap_wdt";
3731 - struct omap_wd_timer_platform_data pdata;
3732 + static struct omap_wd_timer_platform_data pdata = {
3733 + .read_reset_sources = prm_read_reset_sources
3734 + };
3735
3736 if (!cpu_class_is_omap2() || of_have_populated_dt())
3737 return 0;
3738 @@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3739 return -EINVAL;
3740 }
3741
3742 - pdata.read_reset_sources = prm_read_reset_sources;
3743 -
3744 pdev = omap_device_build(dev_name, id, oh, &pdata,
3745 sizeof(struct omap_wd_timer_platform_data));
3746 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3747 diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3748 index b82dcae..44ee5b6 100644
3749 --- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3750 +++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3751 @@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3752 bool entered_lp2 = false;
3753
3754 if (tegra_pending_sgi())
3755 - ACCESS_ONCE(abort_flag) = true;
3756 + ACCESS_ONCE_RW(abort_flag) = true;
3757
3758 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3759
3760 diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3761 index 2dea8b5..6499da2 100644
3762 --- a/arch/arm/mach-ux500/setup.h
3763 +++ b/arch/arm/mach-ux500/setup.h
3764 @@ -33,13 +33,6 @@ extern void ux500_timer_init(void);
3765 .type = MT_DEVICE, \
3766 }
3767
3768 -#define __MEM_DEV_DESC(x, sz) { \
3769 - .virtual = IO_ADDRESS(x), \
3770 - .pfn = __phys_to_pfn(x), \
3771 - .length = sz, \
3772 - .type = MT_MEMORY_RWX, \
3773 -}
3774 -
3775 extern struct smp_operations ux500_smp_ops;
3776 extern void ux500_cpu_die(unsigned int cpu);
3777
3778 diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3779 index 5bf7c3c..571e67e 100644
3780 --- a/arch/arm/mm/Kconfig
3781 +++ b/arch/arm/mm/Kconfig
3782 @@ -446,6 +446,7 @@ config CPU_32v5
3783
3784 config CPU_32v6
3785 bool
3786 + select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3787 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3788
3789 config CPU_32v6K
3790 @@ -600,6 +601,7 @@ config CPU_CP15_MPU
3791
3792 config CPU_USE_DOMAINS
3793 bool
3794 + depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3795 help
3796 This option enables or disables the use of domain switching
3797 via the set_fs() function.
3798 @@ -799,6 +801,7 @@ config NEED_KUSER_HELPERS
3799 config KUSER_HELPERS
3800 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3801 default y
3802 + depends on !(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND
3803 help
3804 Warning: disabling this option may break user programs.
3805
3806 @@ -811,7 +814,7 @@ config KUSER_HELPERS
3807 See Documentation/arm/kernel_user_helpers.txt for details.
3808
3809 However, the fixed address nature of these helpers can be used
3810 - by ROP (return orientated programming) authors when creating
3811 + by ROP (Return Oriented Programming) authors when creating
3812 exploits.
3813
3814 If all of the binaries and libraries which run on your platform
3815 diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3816 index 9240364..a2b8cf3 100644
3817 --- a/arch/arm/mm/alignment.c
3818 +++ b/arch/arm/mm/alignment.c
3819 @@ -212,10 +212,12 @@ union offset_union {
3820 #define __get16_unaligned_check(ins,val,addr) \
3821 do { \
3822 unsigned int err = 0, v, a = addr; \
3823 + pax_open_userland(); \
3824 __get8_unaligned_check(ins,v,a,err); \
3825 val = v << ((BE) ? 8 : 0); \
3826 __get8_unaligned_check(ins,v,a,err); \
3827 val |= v << ((BE) ? 0 : 8); \
3828 + pax_close_userland(); \
3829 if (err) \
3830 goto fault; \
3831 } while (0)
3832 @@ -229,6 +231,7 @@ union offset_union {
3833 #define __get32_unaligned_check(ins,val,addr) \
3834 do { \
3835 unsigned int err = 0, v, a = addr; \
3836 + pax_open_userland(); \
3837 __get8_unaligned_check(ins,v,a,err); \
3838 val = v << ((BE) ? 24 : 0); \
3839 __get8_unaligned_check(ins,v,a,err); \
3840 @@ -237,6 +240,7 @@ union offset_union {
3841 val |= v << ((BE) ? 8 : 16); \
3842 __get8_unaligned_check(ins,v,a,err); \
3843 val |= v << ((BE) ? 0 : 24); \
3844 + pax_close_userland(); \
3845 if (err) \
3846 goto fault; \
3847 } while (0)
3848 @@ -250,6 +254,7 @@ union offset_union {
3849 #define __put16_unaligned_check(ins,val,addr) \
3850 do { \
3851 unsigned int err = 0, v = val, a = addr; \
3852 + pax_open_userland(); \
3853 __asm__( FIRST_BYTE_16 \
3854 ARM( "1: "ins" %1, [%2], #1\n" ) \
3855 THUMB( "1: "ins" %1, [%2]\n" ) \
3856 @@ -269,6 +274,7 @@ union offset_union {
3857 " .popsection\n" \
3858 : "=r" (err), "=&r" (v), "=&r" (a) \
3859 : "0" (err), "1" (v), "2" (a)); \
3860 + pax_close_userland(); \
3861 if (err) \
3862 goto fault; \
3863 } while (0)
3864 @@ -282,6 +288,7 @@ union offset_union {
3865 #define __put32_unaligned_check(ins,val,addr) \
3866 do { \
3867 unsigned int err = 0, v = val, a = addr; \
3868 + pax_open_userland(); \
3869 __asm__( FIRST_BYTE_32 \
3870 ARM( "1: "ins" %1, [%2], #1\n" ) \
3871 THUMB( "1: "ins" %1, [%2]\n" ) \
3872 @@ -311,6 +318,7 @@ union offset_union {
3873 " .popsection\n" \
3874 : "=r" (err), "=&r" (v), "=&r" (a) \
3875 : "0" (err), "1" (v), "2" (a)); \
3876 + pax_close_userland(); \
3877 if (err) \
3878 goto fault; \
3879 } while (0)
3880 diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3881 index 7abde2c..9df495f 100644
3882 --- a/arch/arm/mm/cache-l2x0.c
3883 +++ b/arch/arm/mm/cache-l2x0.c
3884 @@ -46,7 +46,7 @@ struct l2x0_of_data {
3885 void (*setup)(const struct device_node *, u32 *, u32 *);
3886 void (*save)(void);
3887 struct outer_cache_fns outer_cache;
3888 -};
3889 +} __do_const;
3890
3891 static bool of_init = false;
3892
3893 diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3894 index 6eb97b3..ac509f6 100644
3895 --- a/arch/arm/mm/context.c
3896 +++ b/arch/arm/mm/context.c
3897 @@ -43,7 +43,7 @@
3898 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3899
3900 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3901 -static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3902 +static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3903 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3904
3905 static DEFINE_PER_CPU(atomic64_t, active_asids);
3906 @@ -182,7 +182,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3907 {
3908 static u32 cur_idx = 1;
3909 u64 asid = atomic64_read(&mm->context.id);
3910 - u64 generation = atomic64_read(&asid_generation);
3911 + u64 generation = atomic64_read_unchecked(&asid_generation);
3912
3913 if (asid != 0 && is_reserved_asid(asid)) {
3914 /*
3915 @@ -203,7 +203,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3916 */
3917 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, cur_idx);
3918 if (asid == NUM_USER_ASIDS) {
3919 - generation = atomic64_add_return(ASID_FIRST_VERSION,
3920 + generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3921 &asid_generation);
3922 flush_context(cpu);
3923 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3924 @@ -234,14 +234,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3925 cpu_set_reserved_ttbr0();
3926
3927 asid = atomic64_read(&mm->context.id);
3928 - if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3929 + if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3930 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3931 goto switch_mm_fastpath;
3932
3933 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3934 /* Check that our ASID belongs to the current generation. */
3935 asid = atomic64_read(&mm->context.id);
3936 - if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3937 + if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3938 asid = new_context(mm, cpu);
3939 atomic64_set(&mm->context.id, asid);
3940 }
3941 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3942 index eb8830a..5360ce7 100644
3943 --- a/arch/arm/mm/fault.c
3944 +++ b/arch/arm/mm/fault.c
3945 @@ -25,6 +25,7 @@
3946 #include <asm/system_misc.h>
3947 #include <asm/system_info.h>
3948 #include <asm/tlbflush.h>
3949 +#include <asm/sections.h>
3950
3951 #include "fault.h"
3952
3953 @@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3954 if (fixup_exception(regs))
3955 return;
3956
3957 +#ifdef CONFIG_PAX_MEMORY_UDEREF
3958 + if (addr < TASK_SIZE) {
3959 + if (current->signal->curr_ip)
3960 + 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),
3961 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3962 + else
3963 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3964 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3965 + }
3966 +#endif
3967 +
3968 +#ifdef CONFIG_PAX_KERNEXEC
3969 + if ((fsr & FSR_WRITE) &&
3970 + (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3971 + (MODULES_VADDR <= addr && addr < MODULES_END)))
3972 + {
3973 + if (current->signal->curr_ip)
3974 + 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),
3975 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3976 + else
3977 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3978 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3979 + }
3980 +#endif
3981 +
3982 /*
3983 * No handler, we'll have to terminate things with extreme prejudice.
3984 */
3985 @@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3986 }
3987 #endif
3988
3989 +#ifdef CONFIG_PAX_PAGEEXEC
3990 + if (fsr & FSR_LNX_PF) {
3991 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3992 + do_group_exit(SIGKILL);
3993 + }
3994 +#endif
3995 +
3996 tsk->thread.address = addr;
3997 tsk->thread.error_code = fsr;
3998 tsk->thread.trap_no = 14;
3999 @@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4000 }
4001 #endif /* CONFIG_MMU */
4002
4003 +#ifdef CONFIG_PAX_PAGEEXEC
4004 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4005 +{
4006 + long i;
4007 +
4008 + printk(KERN_ERR "PAX: bytes at PC: ");
4009 + for (i = 0; i < 20; i++) {
4010 + unsigned char c;
4011 + if (get_user(c, (__force unsigned char __user *)pc+i))
4012 + printk(KERN_CONT "?? ");
4013 + else
4014 + printk(KERN_CONT "%02x ", c);
4015 + }
4016 + printk("\n");
4017 +
4018 + printk(KERN_ERR "PAX: bytes at SP-4: ");
4019 + for (i = -1; i < 20; i++) {
4020 + unsigned long c;
4021 + if (get_user(c, (__force unsigned long __user *)sp+i))
4022 + printk(KERN_CONT "???????? ");
4023 + else
4024 + printk(KERN_CONT "%08lx ", c);
4025 + }
4026 + printk("\n");
4027 +}
4028 +#endif
4029 +
4030 /*
4031 * First Level Translation Fault Handler
4032 *
4033 @@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4034 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
4035 struct siginfo info;
4036
4037 +#ifdef CONFIG_PAX_MEMORY_UDEREF
4038 + if (addr < TASK_SIZE && is_domain_fault(fsr)) {
4039 + if (current->signal->curr_ip)
4040 + 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),
4041 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4042 + else
4043 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
4044 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4045 + goto die;
4046 + }
4047 +#endif
4048 +
4049 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
4050 return;
4051
4052 +die:
4053 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
4054 inf->name, fsr, addr);
4055
4056 @@ -574,15 +647,98 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
4057 ifsr_info[nr].name = name;
4058 }
4059
4060 +asmlinkage int sys_sigreturn(struct pt_regs *regs);
4061 +asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
4062 +
4063 asmlinkage void __exception
4064 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
4065 {
4066 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
4067 struct siginfo info;
4068 + unsigned long pc = instruction_pointer(regs);
4069 +
4070 + if (user_mode(regs)) {
4071 + unsigned long sigpage = current->mm->context.sigpage;
4072 +
4073 + if (sigpage <= pc && pc < sigpage + 7*4) {
4074 + if (pc < sigpage + 3*4)
4075 + sys_sigreturn(regs);
4076 + else
4077 + sys_rt_sigreturn(regs);
4078 + return;
4079 + }
4080 + if (pc == 0xffff0f60UL) {
4081 + /*
4082 + * PaX: __kuser_cmpxchg64 emulation
4083 + */
4084 + // TODO
4085 + //regs->ARM_pc = regs->ARM_lr;
4086 + //return;
4087 + }
4088 + if (pc == 0xffff0fa0UL) {
4089 + /*
4090 + * PaX: __kuser_memory_barrier emulation
4091 + */
4092 + // dmb(); implied by the exception
4093 + regs->ARM_pc = regs->ARM_lr;
4094 + return;
4095 + }
4096 + if (pc == 0xffff0fc0UL) {
4097 + /*
4098 + * PaX: __kuser_cmpxchg emulation
4099 + */
4100 + // TODO
4101 + //long new;
4102 + //int op;
4103 +
4104 + //op = FUTEX_OP_SET << 28;
4105 + //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4106 + //regs->ARM_r0 = old != new;
4107 + //regs->ARM_pc = regs->ARM_lr;
4108 + //return;
4109 + }
4110 + if (pc == 0xffff0fe0UL) {
4111 + /*
4112 + * PaX: __kuser_get_tls emulation
4113 + */
4114 + regs->ARM_r0 = current_thread_info()->tp_value[0];
4115 + regs->ARM_pc = regs->ARM_lr;
4116 + return;
4117 + }
4118 + }
4119 +
4120 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4121 + else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4122 + if (current->signal->curr_ip)
4123 + 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),
4124 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4125 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4126 + else
4127 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4128 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4129 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4130 + goto die;
4131 + }
4132 +#endif
4133 +
4134 +#ifdef CONFIG_PAX_REFCOUNT
4135 + if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4136 + unsigned int bkpt;
4137 +
4138 + if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4139 + current->thread.error_code = ifsr;
4140 + current->thread.trap_no = 0;
4141 + pax_report_refcount_overflow(regs);
4142 + fixup_exception(regs);
4143 + return;
4144 + }
4145 + }
4146 +#endif
4147
4148 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4149 return;
4150
4151 +die:
4152 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4153 inf->name, ifsr, addr);
4154
4155 diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4156 index cf08bdf..772656c 100644
4157 --- a/arch/arm/mm/fault.h
4158 +++ b/arch/arm/mm/fault.h
4159 @@ -3,6 +3,7 @@
4160
4161 /*
4162 * Fault status register encodings. We steal bit 31 for our own purposes.
4163 + * Set when the FSR value is from an instruction fault.
4164 */
4165 #define FSR_LNX_PF (1 << 31)
4166 #define FSR_WRITE (1 << 11)
4167 @@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4168 }
4169 #endif
4170
4171 +/* valid for LPAE and !LPAE */
4172 +static inline int is_xn_fault(unsigned int fsr)
4173 +{
4174 + return ((fsr_fs(fsr) & 0x3c) == 0xc);
4175 +}
4176 +
4177 +static inline int is_domain_fault(unsigned int fsr)
4178 +{
4179 + return ((fsr_fs(fsr) & 0xD) == 0x9);
4180 +}
4181 +
4182 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4183 unsigned long search_exception_table(unsigned long addr);
4184
4185 diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4186 index 2a77ba8..68e6a7a 100644
4187 --- a/arch/arm/mm/init.c
4188 +++ b/arch/arm/mm/init.c
4189 @@ -30,6 +30,8 @@
4190 #include <asm/setup.h>
4191 #include <asm/tlb.h>
4192 #include <asm/fixmap.h>
4193 +#include <asm/system_info.h>
4194 +#include <asm/cp15.h>
4195
4196 #include <asm/mach/arch.h>
4197 #include <asm/mach/map.h>
4198 @@ -627,7 +629,46 @@ void free_initmem(void)
4199 {
4200 #ifdef CONFIG_HAVE_TCM
4201 extern char __tcm_start, __tcm_end;
4202 +#endif
4203
4204 +#ifdef CONFIG_PAX_KERNEXEC
4205 + unsigned long addr;
4206 + pgd_t *pgd;
4207 + pud_t *pud;
4208 + pmd_t *pmd;
4209 + int cpu_arch = cpu_architecture();
4210 + unsigned int cr = get_cr();
4211 +
4212 + if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4213 + /* make pages tables, etc before .text NX */
4214 + for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4215 + pgd = pgd_offset_k(addr);
4216 + pud = pud_offset(pgd, addr);
4217 + pmd = pmd_offset(pud, addr);
4218 + __section_update(pmd, addr, PMD_SECT_XN);
4219 + }
4220 + /* make init NX */
4221 + for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4222 + pgd = pgd_offset_k(addr);
4223 + pud = pud_offset(pgd, addr);
4224 + pmd = pmd_offset(pud, addr);
4225 + __section_update(pmd, addr, PMD_SECT_XN);
4226 + }
4227 + /* make kernel code/rodata RX */
4228 + for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4229 + pgd = pgd_offset_k(addr);
4230 + pud = pud_offset(pgd, addr);
4231 + pmd = pmd_offset(pud, addr);
4232 +#ifdef CONFIG_ARM_LPAE
4233 + __section_update(pmd, addr, PMD_SECT_RDONLY);
4234 +#else
4235 + __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4236 +#endif
4237 + }
4238 + }
4239 +#endif
4240 +
4241 +#ifdef CONFIG_HAVE_TCM
4242 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4243 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4244 #endif
4245 diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4246 index f9c32ba..8540068 100644
4247 --- a/arch/arm/mm/ioremap.c
4248 +++ b/arch/arm/mm/ioremap.c
4249 @@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4250 unsigned int mtype;
4251
4252 if (cached)
4253 - mtype = MT_MEMORY_RWX;
4254 + mtype = MT_MEMORY_RX;
4255 else
4256 - mtype = MT_MEMORY_RWX_NONCACHED;
4257 + mtype = MT_MEMORY_RX_NONCACHED;
4258
4259 return __arm_ioremap_caller(phys_addr, size, mtype,
4260 __builtin_return_address(0));
4261 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4262 index 5e85ed3..b10a7ed 100644
4263 --- a/arch/arm/mm/mmap.c
4264 +++ b/arch/arm/mm/mmap.c
4265 @@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4266 struct vm_area_struct *vma;
4267 int do_align = 0;
4268 int aliasing = cache_is_vipt_aliasing();
4269 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4270 struct vm_unmapped_area_info info;
4271
4272 /*
4273 @@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4274 if (len > TASK_SIZE)
4275 return -ENOMEM;
4276
4277 +#ifdef CONFIG_PAX_RANDMMAP
4278 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4279 +#endif
4280 +
4281 if (addr) {
4282 if (do_align)
4283 addr = COLOUR_ALIGN(addr, pgoff);
4284 @@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4285 addr = PAGE_ALIGN(addr);
4286
4287 vma = find_vma(mm, addr);
4288 - if (TASK_SIZE - len >= addr &&
4289 - (!vma || addr + len <= vma->vm_start))
4290 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4291 return addr;
4292 }
4293
4294 @@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4295 info.high_limit = TASK_SIZE;
4296 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4297 info.align_offset = pgoff << PAGE_SHIFT;
4298 + info.threadstack_offset = offset;
4299 return vm_unmapped_area(&info);
4300 }
4301
4302 @@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4303 unsigned long addr = addr0;
4304 int do_align = 0;
4305 int aliasing = cache_is_vipt_aliasing();
4306 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4307 struct vm_unmapped_area_info info;
4308
4309 /*
4310 @@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4311 return addr;
4312 }
4313
4314 +#ifdef CONFIG_PAX_RANDMMAP
4315 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4316 +#endif
4317 +
4318 /* requesting a specific address */
4319 if (addr) {
4320 if (do_align)
4321 @@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4322 else
4323 addr = PAGE_ALIGN(addr);
4324 vma = find_vma(mm, addr);
4325 - if (TASK_SIZE - len >= addr &&
4326 - (!vma || addr + len <= vma->vm_start))
4327 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4328 return addr;
4329 }
4330
4331 @@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4332 info.high_limit = mm->mmap_base;
4333 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4334 info.align_offset = pgoff << PAGE_SHIFT;
4335 + info.threadstack_offset = offset;
4336 addr = vm_unmapped_area(&info);
4337
4338 /*
4339 @@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4340 {
4341 unsigned long random_factor = 0UL;
4342
4343 +#ifdef CONFIG_PAX_RANDMMAP
4344 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4345 +#endif
4346 +
4347 /* 8 bits of randomness in 20 address space bits */
4348 if ((current->flags & PF_RANDOMIZE) &&
4349 !(current->personality & ADDR_NO_RANDOMIZE))
4350 @@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4351
4352 if (mmap_is_legacy()) {
4353 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4354 +
4355 +#ifdef CONFIG_PAX_RANDMMAP
4356 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4357 + mm->mmap_base += mm->delta_mmap;
4358 +#endif
4359 +
4360 mm->get_unmapped_area = arch_get_unmapped_area;
4361 } else {
4362 mm->mmap_base = mmap_base(random_factor);
4363 +
4364 +#ifdef CONFIG_PAX_RANDMMAP
4365 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4366 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4367 +#endif
4368 +
4369 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4370 }
4371 }
4372 diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4373 index f15c22e..d830561 100644
4374 --- a/arch/arm/mm/mmu.c
4375 +++ b/arch/arm/mm/mmu.c
4376 @@ -39,6 +39,22 @@
4377 #include "mm.h"
4378 #include "tcm.h"
4379
4380 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4381 +void modify_domain(unsigned int dom, unsigned int type)
4382 +{
4383 + struct thread_info *thread = current_thread_info();
4384 + unsigned int domain = thread->cpu_domain;
4385 + /*
4386 + * DOMAIN_MANAGER might be defined to some other value,
4387 + * use the arch-defined constant
4388 + */
4389 + domain &= ~domain_val(dom, 3);
4390 + thread->cpu_domain = domain | domain_val(dom, type);
4391 + set_domain(thread->cpu_domain);
4392 +}
4393 +EXPORT_SYMBOL(modify_domain);
4394 +#endif
4395 +
4396 /*
4397 * empty_zero_page is a special page that is used for
4398 * zero-initialized data and COW.
4399 @@ -235,7 +251,15 @@ __setup("noalign", noalign_setup);
4400 #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
4401 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4402
4403 -static struct mem_type mem_types[] = {
4404 +#ifdef CONFIG_PAX_KERNEXEC
4405 +#define L_PTE_KERNEXEC L_PTE_RDONLY
4406 +#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4407 +#else
4408 +#define L_PTE_KERNEXEC L_PTE_DIRTY
4409 +#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4410 +#endif
4411 +
4412 +static struct mem_type mem_types[] __read_only = {
4413 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4414 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4415 L_PTE_SHARED,
4416 @@ -264,19 +288,19 @@ static struct mem_type mem_types[] = {
4417 .prot_sect = PROT_SECT_DEVICE,
4418 .domain = DOMAIN_IO,
4419 },
4420 - [MT_UNCACHED] = {
4421 + [MT_UNCACHED_RW] = {
4422 .prot_pte = PROT_PTE_DEVICE,
4423 .prot_l1 = PMD_TYPE_TABLE,
4424 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4425 .domain = DOMAIN_IO,
4426 },
4427 - [MT_CACHECLEAN] = {
4428 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4429 + [MT_CACHECLEAN_RO] = {
4430 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_RDONLY,
4431 .domain = DOMAIN_KERNEL,
4432 },
4433 #ifndef CONFIG_ARM_LPAE
4434 - [MT_MINICLEAN] = {
4435 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4436 + [MT_MINICLEAN_RO] = {
4437 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_XN | PMD_SECT_RDONLY,
4438 .domain = DOMAIN_KERNEL,
4439 },
4440 #endif
4441 @@ -284,15 +308,15 @@ static struct mem_type mem_types[] = {
4442 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4443 L_PTE_RDONLY,
4444 .prot_l1 = PMD_TYPE_TABLE,
4445 - .domain = DOMAIN_USER,
4446 + .domain = DOMAIN_VECTORS,
4447 },
4448 [MT_HIGH_VECTORS] = {
4449 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4450 L_PTE_USER | L_PTE_RDONLY,
4451 .prot_l1 = PMD_TYPE_TABLE,
4452 - .domain = DOMAIN_USER,
4453 + .domain = DOMAIN_VECTORS,
4454 },
4455 - [MT_MEMORY_RWX] = {
4456 + [__MT_MEMORY_RWX] = {
4457 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4458 .prot_l1 = PMD_TYPE_TABLE,
4459 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4460 @@ -305,17 +329,30 @@ static struct mem_type mem_types[] = {
4461 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4462 .domain = DOMAIN_KERNEL,
4463 },
4464 - [MT_ROM] = {
4465 - .prot_sect = PMD_TYPE_SECT,
4466 + [MT_MEMORY_RX] = {
4467 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4468 + .prot_l1 = PMD_TYPE_TABLE,
4469 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4470 + .domain = DOMAIN_KERNEL,
4471 + },
4472 + [MT_ROM_RX] = {
4473 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4474 .domain = DOMAIN_KERNEL,
4475 },
4476 - [MT_MEMORY_RWX_NONCACHED] = {
4477 + [MT_MEMORY_RW_NONCACHED] = {
4478 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4479 L_PTE_MT_BUFFERABLE,
4480 .prot_l1 = PMD_TYPE_TABLE,
4481 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4482 .domain = DOMAIN_KERNEL,
4483 },
4484 + [MT_MEMORY_RX_NONCACHED] = {
4485 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4486 + L_PTE_MT_BUFFERABLE,
4487 + .prot_l1 = PMD_TYPE_TABLE,
4488 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4489 + .domain = DOMAIN_KERNEL,
4490 + },
4491 [MT_MEMORY_RW_DTCM] = {
4492 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4493 L_PTE_XN,
4494 @@ -323,9 +360,10 @@ static struct mem_type mem_types[] = {
4495 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4496 .domain = DOMAIN_KERNEL,
4497 },
4498 - [MT_MEMORY_RWX_ITCM] = {
4499 - .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4500 + [MT_MEMORY_RX_ITCM] = {
4501 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4502 .prot_l1 = PMD_TYPE_TABLE,
4503 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4504 .domain = DOMAIN_KERNEL,
4505 },
4506 [MT_MEMORY_RW_SO] = {
4507 @@ -534,9 +572,14 @@ static void __init build_mem_type_table(void)
4508 * Mark cache clean areas and XIP ROM read only
4509 * from SVC mode and no access from userspace.
4510 */
4511 - mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4512 - mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4513 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4514 + mem_types[MT_ROM_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4515 +#ifdef CONFIG_PAX_KERNEXEC
4516 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4517 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4518 + mem_types[MT_MEMORY_RX_ITCM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4519 +#endif
4520 + mem_types[MT_MINICLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4521 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4522 #endif
4523
4524 if (is_smp()) {
4525 @@ -552,13 +595,17 @@ static void __init build_mem_type_table(void)
4526 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4527 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4528 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4529 - mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4530 - mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4531 + mem_types[__MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4532 + mem_types[__MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4533 mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4534 mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4535 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4536 + mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4537 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4538 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_S;
4539 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_pte |= L_PTE_SHARED;
4540 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_S;
4541 + mem_types[MT_MEMORY_RW_NONCACHED].prot_pte |= L_PTE_SHARED;
4542 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_S;
4543 + mem_types[MT_MEMORY_RX_NONCACHED].prot_pte |= L_PTE_SHARED;
4544 }
4545 }
4546
4547 @@ -569,15 +616,20 @@ static void __init build_mem_type_table(void)
4548 if (cpu_arch >= CPU_ARCH_ARMv6) {
4549 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4550 /* Non-cacheable Normal is XCB = 001 */
4551 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4552 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4553 + PMD_SECT_BUFFERED;
4554 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4555 PMD_SECT_BUFFERED;
4556 } else {
4557 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4558 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4559 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4560 + PMD_SECT_TEX(1);
4561 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4562 PMD_SECT_TEX(1);
4563 }
4564 } else {
4565 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4566 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4567 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4568 }
4569
4570 #ifdef CONFIG_ARM_LPAE
4571 @@ -593,6 +645,8 @@ static void __init build_mem_type_table(void)
4572 vecs_pgprot |= PTE_EXT_AF;
4573 #endif
4574
4575 + user_pgprot |= __supported_pte_mask;
4576 +
4577 for (i = 0; i < 16; i++) {
4578 pteval_t v = pgprot_val(protection_map[i]);
4579 protection_map[i] = __pgprot(v | user_pgprot);
4580 @@ -610,21 +664,24 @@ static void __init build_mem_type_table(void)
4581
4582 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4583 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4584 - mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4585 - mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4586 + mem_types[__MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4587 + mem_types[__MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4588 mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4589 mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4590 + mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4591 + mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4592 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4593 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= ecc_mask;
4594 - mem_types[MT_ROM].prot_sect |= cp->pmd;
4595 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= ecc_mask;
4596 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= ecc_mask;
4597 + mem_types[MT_ROM_RX].prot_sect |= cp->pmd;
4598
4599 switch (cp->pmd) {
4600 case PMD_SECT_WT:
4601 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
4602 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WT;
4603 break;
4604 case PMD_SECT_WB:
4605 case PMD_SECT_WBWA:
4606 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
4607 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WB;
4608 break;
4609 }
4610 pr_info("Memory policy: %sData cache %s\n",
4611 @@ -842,7 +899,7 @@ static void __init create_mapping(struct map_desc *md)
4612 return;
4613 }
4614
4615 - if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
4616 + if ((md->type == MT_DEVICE || md->type == MT_ROM_RX) &&
4617 md->virtual >= PAGE_OFFSET &&
4618 (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
4619 printk(KERN_WARNING "BUG: mapping for 0x%08llx"
4620 @@ -1257,18 +1314,15 @@ void __init arm_mm_memblock_reserve(void)
4621 * called function. This means you can't use any function or debugging
4622 * method which may touch any device, otherwise the kernel _will_ crash.
4623 */
4624 +
4625 +static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4626 +
4627 static void __init devicemaps_init(const struct machine_desc *mdesc)
4628 {
4629 struct map_desc map;
4630 unsigned long addr;
4631 - void *vectors;
4632
4633 - /*
4634 - * Allocate the vector page early.
4635 - */
4636 - vectors = early_alloc(PAGE_SIZE * 2);
4637 -
4638 - early_trap_init(vectors);
4639 + early_trap_init(&vectors);
4640
4641 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4642 pmd_clear(pmd_off_k(addr));
4643 @@ -1281,7 +1335,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4644 map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
4645 map.virtual = MODULES_VADDR;
4646 map.length = ((unsigned long)_etext - map.virtual + ~SECTION_MASK) & SECTION_MASK;
4647 - map.type = MT_ROM;
4648 + map.type = MT_ROM_RX;
4649 create_mapping(&map);
4650 #endif
4651
4652 @@ -1292,14 +1346,14 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4653 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
4654 map.virtual = FLUSH_BASE;
4655 map.length = SZ_1M;
4656 - map.type = MT_CACHECLEAN;
4657 + map.type = MT_CACHECLEAN_RO;
4658 create_mapping(&map);
4659 #endif
4660 #ifdef FLUSH_BASE_MINICACHE
4661 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
4662 map.virtual = FLUSH_BASE_MINICACHE;
4663 map.length = SZ_1M;
4664 - map.type = MT_MINICLEAN;
4665 + map.type = MT_MINICLEAN_RO;
4666 create_mapping(&map);
4667 #endif
4668
4669 @@ -1308,7 +1362,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4670 * location (0xffff0000). If we aren't using high-vectors, also
4671 * create a mapping at the low-vectors virtual address.
4672 */
4673 - map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4674 + map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4675 map.virtual = 0xffff0000;
4676 map.length = PAGE_SIZE;
4677 #ifdef CONFIG_KUSER_HELPERS
4678 @@ -1365,8 +1419,10 @@ static void __init kmap_init(void)
4679 static void __init map_lowmem(void)
4680 {
4681 struct memblock_region *reg;
4682 +#ifndef CONFIG_PAX_KERNEXEC
4683 unsigned long kernel_x_start = round_down(__pa(_stext), SECTION_SIZE);
4684 unsigned long kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE);
4685 +#endif
4686
4687 /* Map all the lowmem memory banks. */
4688 for_each_memblock(memory, reg) {
4689 @@ -1379,11 +1435,48 @@ static void __init map_lowmem(void)
4690 if (start >= end)
4691 break;
4692
4693 +#ifdef CONFIG_PAX_KERNEXEC
4694 + map.pfn = __phys_to_pfn(start);
4695 + map.virtual = __phys_to_virt(start);
4696 + map.length = end - start;
4697 +
4698 + if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4699 + struct map_desc kernel;
4700 + struct map_desc initmap;
4701 +
4702 + /* when freeing initmem we will make this RW */
4703 + initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4704 + initmap.virtual = (unsigned long)__init_begin;
4705 + initmap.length = _sdata - __init_begin;
4706 + initmap.type = __MT_MEMORY_RWX;
4707 + create_mapping(&initmap);
4708 +
4709 + /* when freeing initmem we will make this RX */
4710 + kernel.pfn = __phys_to_pfn(__pa(_stext));
4711 + kernel.virtual = (unsigned long)_stext;
4712 + kernel.length = __init_begin - _stext;
4713 + kernel.type = __MT_MEMORY_RWX;
4714 + create_mapping(&kernel);
4715 +
4716 + if (map.virtual < (unsigned long)_stext) {
4717 + map.length = (unsigned long)_stext - map.virtual;
4718 + map.type = __MT_MEMORY_RWX;
4719 + create_mapping(&map);
4720 + }
4721 +
4722 + map.pfn = __phys_to_pfn(__pa(_sdata));
4723 + map.virtual = (unsigned long)_sdata;
4724 + map.length = end - __pa(_sdata);
4725 + }
4726 +
4727 + map.type = MT_MEMORY_RW;
4728 + create_mapping(&map);
4729 +#else
4730 if (end < kernel_x_start || start >= kernel_x_end) {
4731 map.pfn = __phys_to_pfn(start);
4732 map.virtual = __phys_to_virt(start);
4733 map.length = end - start;
4734 - map.type = MT_MEMORY_RWX;
4735 + map.type = __MT_MEMORY_RWX;
4736
4737 create_mapping(&map);
4738 } else {
4739 @@ -1400,7 +1493,7 @@ static void __init map_lowmem(void)
4740 map.pfn = __phys_to_pfn(kernel_x_start);
4741 map.virtual = __phys_to_virt(kernel_x_start);
4742 map.length = kernel_x_end - kernel_x_start;
4743 - map.type = MT_MEMORY_RWX;
4744 + map.type = __MT_MEMORY_RWX;
4745
4746 create_mapping(&map);
4747
4748 @@ -1413,6 +1506,7 @@ static void __init map_lowmem(void)
4749 create_mapping(&map);
4750 }
4751 }
4752 +#endif
4753 }
4754 }
4755
4756 diff --git a/arch/arm/plat-iop/setup.c b/arch/arm/plat-iop/setup.c
4757 index 5b217f4..c23f40e 100644
4758 --- a/arch/arm/plat-iop/setup.c
4759 +++ b/arch/arm/plat-iop/setup.c
4760 @@ -24,7 +24,7 @@ static struct map_desc iop3xx_std_desc[] __initdata = {
4761 .virtual = IOP3XX_PERIPHERAL_VIRT_BASE,
4762 .pfn = __phys_to_pfn(IOP3XX_PERIPHERAL_PHYS_BASE),
4763 .length = IOP3XX_PERIPHERAL_SIZE,
4764 - .type = MT_UNCACHED,
4765 + .type = MT_UNCACHED_RW,
4766 },
4767 };
4768
4769 diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4770 index a5bc92d..0bb4730 100644
4771 --- a/arch/arm/plat-omap/sram.c
4772 +++ b/arch/arm/plat-omap/sram.c
4773 @@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4774 * Looks like we need to preserve some bootloader code at the
4775 * beginning of SRAM for jumping to flash for reboot to work...
4776 */
4777 + pax_open_kernel();
4778 memset_io(omap_sram_base + omap_sram_skip, 0,
4779 omap_sram_size - omap_sram_skip);
4780 + pax_close_kernel();
4781 }
4782 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4783 index ce6d763..cfea917 100644
4784 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4785 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4786 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
4787 int (*started)(unsigned ch);
4788 int (*flush)(unsigned ch);
4789 int (*stop)(unsigned ch);
4790 -};
4791 +} __no_const;
4792
4793 extern void *samsung_dmadev_get_ops(void);
4794 extern void *s3c_dma_get_ops(void);
4795 diff --git a/arch/arm64/include/asm/barrier.h b/arch/arm64/include/asm/barrier.h
4796 index 66eb764..b529b84 100644
4797 --- a/arch/arm64/include/asm/barrier.h
4798 +++ b/arch/arm64/include/asm/barrier.h
4799 @@ -41,7 +41,7 @@
4800 do { \
4801 compiletime_assert_atomic_type(*p); \
4802 smp_mb(); \
4803 - ACCESS_ONCE(*p) = (v); \
4804 + ACCESS_ONCE_RW(*p) = (v); \
4805 } while (0)
4806
4807 #define smp_load_acquire(p) \
4808 diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
4809 index 3bf8f4e..5dd5491 100644
4810 --- a/arch/arm64/include/asm/uaccess.h
4811 +++ b/arch/arm64/include/asm/uaccess.h
4812 @@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
4813 flag; \
4814 })
4815
4816 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
4817 #define access_ok(type, addr, size) __range_ok(addr, size)
4818 #define user_addr_max get_fs
4819
4820 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4821 index c3a58a1..78fbf54 100644
4822 --- a/arch/avr32/include/asm/cache.h
4823 +++ b/arch/avr32/include/asm/cache.h
4824 @@ -1,8 +1,10 @@
4825 #ifndef __ASM_AVR32_CACHE_H
4826 #define __ASM_AVR32_CACHE_H
4827
4828 +#include <linux/const.h>
4829 +
4830 #define L1_CACHE_SHIFT 5
4831 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4832 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4833
4834 /*
4835 * Memory returned by kmalloc() may be used for DMA, so we must make
4836 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4837 index d232888..87c8df1 100644
4838 --- a/arch/avr32/include/asm/elf.h
4839 +++ b/arch/avr32/include/asm/elf.h
4840 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4841 the loader. We need to make sure that it is out of the way of the program
4842 that it will "exec", and that there is sufficient room for the brk. */
4843
4844 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4845 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4846
4847 +#ifdef CONFIG_PAX_ASLR
4848 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4849 +
4850 +#define PAX_DELTA_MMAP_LEN 15
4851 +#define PAX_DELTA_STACK_LEN 15
4852 +#endif
4853
4854 /* This yields a mask that user programs can use to figure out what
4855 instruction set this CPU supports. This could be done in user space,
4856 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4857 index 479330b..53717a8 100644
4858 --- a/arch/avr32/include/asm/kmap_types.h
4859 +++ b/arch/avr32/include/asm/kmap_types.h
4860 @@ -2,9 +2,9 @@
4861 #define __ASM_AVR32_KMAP_TYPES_H
4862
4863 #ifdef CONFIG_DEBUG_HIGHMEM
4864 -# define KM_TYPE_NR 29
4865 +# define KM_TYPE_NR 30
4866 #else
4867 -# define KM_TYPE_NR 14
4868 +# define KM_TYPE_NR 15
4869 #endif
4870
4871 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4872 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4873 index 0eca933..eb78c7b 100644
4874 --- a/arch/avr32/mm/fault.c
4875 +++ b/arch/avr32/mm/fault.c
4876 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4877
4878 int exception_trace = 1;
4879
4880 +#ifdef CONFIG_PAX_PAGEEXEC
4881 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4882 +{
4883 + unsigned long i;
4884 +
4885 + printk(KERN_ERR "PAX: bytes at PC: ");
4886 + for (i = 0; i < 20; i++) {
4887 + unsigned char c;
4888 + if (get_user(c, (unsigned char *)pc+i))
4889 + printk(KERN_CONT "???????? ");
4890 + else
4891 + printk(KERN_CONT "%02x ", c);
4892 + }
4893 + printk("\n");
4894 +}
4895 +#endif
4896 +
4897 /*
4898 * This routine handles page faults. It determines the address and the
4899 * problem, and then passes it off to one of the appropriate routines.
4900 @@ -176,6 +193,16 @@ bad_area:
4901 up_read(&mm->mmap_sem);
4902
4903 if (user_mode(regs)) {
4904 +
4905 +#ifdef CONFIG_PAX_PAGEEXEC
4906 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4907 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4908 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4909 + do_group_exit(SIGKILL);
4910 + }
4911 + }
4912 +#endif
4913 +
4914 if (exception_trace && printk_ratelimit())
4915 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4916 "sp %08lx ecr %lu\n",
4917 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4918 index 568885a..f8008df 100644
4919 --- a/arch/blackfin/include/asm/cache.h
4920 +++ b/arch/blackfin/include/asm/cache.h
4921 @@ -7,6 +7,7 @@
4922 #ifndef __ARCH_BLACKFIN_CACHE_H
4923 #define __ARCH_BLACKFIN_CACHE_H
4924
4925 +#include <linux/const.h>
4926 #include <linux/linkage.h> /* for asmlinkage */
4927
4928 /*
4929 @@ -14,7 +15,7 @@
4930 * Blackfin loads 32 bytes for cache
4931 */
4932 #define L1_CACHE_SHIFT 5
4933 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4934 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4935 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4936
4937 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4938 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4939 index aea2718..3639a60 100644
4940 --- a/arch/cris/include/arch-v10/arch/cache.h
4941 +++ b/arch/cris/include/arch-v10/arch/cache.h
4942 @@ -1,8 +1,9 @@
4943 #ifndef _ASM_ARCH_CACHE_H
4944 #define _ASM_ARCH_CACHE_H
4945
4946 +#include <linux/const.h>
4947 /* Etrax 100LX have 32-byte cache-lines. */
4948 -#define L1_CACHE_BYTES 32
4949 #define L1_CACHE_SHIFT 5
4950 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4951
4952 #endif /* _ASM_ARCH_CACHE_H */
4953 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4954 index 7caf25d..ee65ac5 100644
4955 --- a/arch/cris/include/arch-v32/arch/cache.h
4956 +++ b/arch/cris/include/arch-v32/arch/cache.h
4957 @@ -1,11 +1,12 @@
4958 #ifndef _ASM_CRIS_ARCH_CACHE_H
4959 #define _ASM_CRIS_ARCH_CACHE_H
4960
4961 +#include <linux/const.h>
4962 #include <arch/hwregs/dma.h>
4963
4964 /* A cache-line is 32 bytes. */
4965 -#define L1_CACHE_BYTES 32
4966 #define L1_CACHE_SHIFT 5
4967 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4968
4969 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4970
4971 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4972 index b86329d..6709906 100644
4973 --- a/arch/frv/include/asm/atomic.h
4974 +++ b/arch/frv/include/asm/atomic.h
4975 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4976 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4977 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4978
4979 +#define atomic64_read_unchecked(v) atomic64_read(v)
4980 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4981 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4982 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4983 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4984 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4985 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4986 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4987 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4988 +
4989 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4990 {
4991 int c, old;
4992 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4993 index 2797163..c2a401d 100644
4994 --- a/arch/frv/include/asm/cache.h
4995 +++ b/arch/frv/include/asm/cache.h
4996 @@ -12,10 +12,11 @@
4997 #ifndef __ASM_CACHE_H
4998 #define __ASM_CACHE_H
4999
5000 +#include <linux/const.h>
5001
5002 /* bytes per L1 cache line */
5003 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
5004 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5005 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5006
5007 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5008 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5009 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
5010 index 43901f2..0d8b865 100644
5011 --- a/arch/frv/include/asm/kmap_types.h
5012 +++ b/arch/frv/include/asm/kmap_types.h
5013 @@ -2,6 +2,6 @@
5014 #ifndef _ASM_KMAP_TYPES_H
5015 #define _ASM_KMAP_TYPES_H
5016
5017 -#define KM_TYPE_NR 17
5018 +#define KM_TYPE_NR 18
5019
5020 #endif
5021 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
5022 index 836f147..4cf23f5 100644
5023 --- a/arch/frv/mm/elf-fdpic.c
5024 +++ b/arch/frv/mm/elf-fdpic.c
5025 @@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5026 {
5027 struct vm_area_struct *vma;
5028 struct vm_unmapped_area_info info;
5029 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5030
5031 if (len > TASK_SIZE)
5032 return -ENOMEM;
5033 @@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5034 if (addr) {
5035 addr = PAGE_ALIGN(addr);
5036 vma = find_vma(current->mm, addr);
5037 - if (TASK_SIZE - len >= addr &&
5038 - (!vma || addr + len <= vma->vm_start))
5039 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
5040 goto success;
5041 }
5042
5043 @@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5044 info.high_limit = (current->mm->start_stack - 0x00200000);
5045 info.align_mask = 0;
5046 info.align_offset = 0;
5047 + info.threadstack_offset = offset;
5048 addr = vm_unmapped_area(&info);
5049 if (!(addr & ~PAGE_MASK))
5050 goto success;
5051 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
5052 index f4ca594..adc72fd6 100644
5053 --- a/arch/hexagon/include/asm/cache.h
5054 +++ b/arch/hexagon/include/asm/cache.h
5055 @@ -21,9 +21,11 @@
5056 #ifndef __ASM_CACHE_H
5057 #define __ASM_CACHE_H
5058
5059 +#include <linux/const.h>
5060 +
5061 /* Bytes per L1 cache line */
5062 -#define L1_CACHE_SHIFT (5)
5063 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5064 +#define L1_CACHE_SHIFT 5
5065 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5066
5067 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
5068 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
5069 diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
5070 index 12c3afe..b1abab2 100644
5071 --- a/arch/ia64/Kconfig
5072 +++ b/arch/ia64/Kconfig
5073 @@ -546,6 +546,7 @@ source "drivers/sn/Kconfig"
5074 config KEXEC
5075 bool "kexec system call"
5076 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
5077 + depends on !GRKERNSEC_KMEM
5078 help
5079 kexec is a system call that implements the ability to shutdown your
5080 current kernel, and to start another kernel. It is like a reboot
5081 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
5082 index 6e6fe18..a6ae668 100644
5083 --- a/arch/ia64/include/asm/atomic.h
5084 +++ b/arch/ia64/include/asm/atomic.h
5085 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
5086 #define atomic64_inc(v) atomic64_add(1, (v))
5087 #define atomic64_dec(v) atomic64_sub(1, (v))
5088
5089 +#define atomic64_read_unchecked(v) atomic64_read(v)
5090 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5091 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5092 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5093 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5094 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5095 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5096 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5097 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5098 +
5099 /* Atomic operations are already serializing */
5100 #define smp_mb__before_atomic_dec() barrier()
5101 #define smp_mb__after_atomic_dec() barrier()
5102 diff --git a/arch/ia64/include/asm/barrier.h b/arch/ia64/include/asm/barrier.h
5103 index d0a69aa..142f878 100644
5104 --- a/arch/ia64/include/asm/barrier.h
5105 +++ b/arch/ia64/include/asm/barrier.h
5106 @@ -64,7 +64,7 @@
5107 do { \
5108 compiletime_assert_atomic_type(*p); \
5109 barrier(); \
5110 - ACCESS_ONCE(*p) = (v); \
5111 + ACCESS_ONCE_RW(*p) = (v); \
5112 } while (0)
5113
5114 #define smp_load_acquire(p) \
5115 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
5116 index 988254a..e1ee885 100644
5117 --- a/arch/ia64/include/asm/cache.h
5118 +++ b/arch/ia64/include/asm/cache.h
5119 @@ -1,6 +1,7 @@
5120 #ifndef _ASM_IA64_CACHE_H
5121 #define _ASM_IA64_CACHE_H
5122
5123 +#include <linux/const.h>
5124
5125 /*
5126 * Copyright (C) 1998-2000 Hewlett-Packard Co
5127 @@ -9,7 +10,7 @@
5128
5129 /* Bytes per L1 (data) cache line. */
5130 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
5131 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5132 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5133
5134 #ifdef CONFIG_SMP
5135 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5136 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
5137 index 5a83c5c..4d7f553 100644
5138 --- a/arch/ia64/include/asm/elf.h
5139 +++ b/arch/ia64/include/asm/elf.h
5140 @@ -42,6 +42,13 @@
5141 */
5142 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
5143
5144 +#ifdef CONFIG_PAX_ASLR
5145 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
5146 +
5147 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5148 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5149 +#endif
5150 +
5151 #define PT_IA_64_UNWIND 0x70000001
5152
5153 /* IA-64 relocations: */
5154 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
5155 index 5767cdf..7462574 100644
5156 --- a/arch/ia64/include/asm/pgalloc.h
5157 +++ b/arch/ia64/include/asm/pgalloc.h
5158 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5159 pgd_val(*pgd_entry) = __pa(pud);
5160 }
5161
5162 +static inline void
5163 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5164 +{
5165 + pgd_populate(mm, pgd_entry, pud);
5166 +}
5167 +
5168 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
5169 {
5170 return quicklist_alloc(0, GFP_KERNEL, NULL);
5171 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5172 pud_val(*pud_entry) = __pa(pmd);
5173 }
5174
5175 +static inline void
5176 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5177 +{
5178 + pud_populate(mm, pud_entry, pmd);
5179 +}
5180 +
5181 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5182 {
5183 return quicklist_alloc(0, GFP_KERNEL, NULL);
5184 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5185 index 7935115..c0eca6a 100644
5186 --- a/arch/ia64/include/asm/pgtable.h
5187 +++ b/arch/ia64/include/asm/pgtable.h
5188 @@ -12,7 +12,7 @@
5189 * David Mosberger-Tang <davidm@hpl.hp.com>
5190 */
5191
5192 -
5193 +#include <linux/const.h>
5194 #include <asm/mman.h>
5195 #include <asm/page.h>
5196 #include <asm/processor.h>
5197 @@ -142,6 +142,17 @@
5198 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5199 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5200 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5201 +
5202 +#ifdef CONFIG_PAX_PAGEEXEC
5203 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5204 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5205 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5206 +#else
5207 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
5208 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
5209 +# define PAGE_COPY_NOEXEC PAGE_COPY
5210 +#endif
5211 +
5212 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5213 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5214 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5215 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5216 index 45698cd..e8e2dbc 100644
5217 --- a/arch/ia64/include/asm/spinlock.h
5218 +++ b/arch/ia64/include/asm/spinlock.h
5219 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5220 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5221
5222 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5223 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5224 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5225 }
5226
5227 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5228 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5229 index 449c8c0..3d4b1e9 100644
5230 --- a/arch/ia64/include/asm/uaccess.h
5231 +++ b/arch/ia64/include/asm/uaccess.h
5232 @@ -70,6 +70,7 @@
5233 && ((segment).seg == KERNEL_DS.seg \
5234 || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
5235 })
5236 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5237 #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
5238
5239 /*
5240 @@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5241 static inline unsigned long
5242 __copy_to_user (void __user *to, const void *from, unsigned long count)
5243 {
5244 + if (count > INT_MAX)
5245 + return count;
5246 +
5247 + if (!__builtin_constant_p(count))
5248 + check_object_size(from, count, true);
5249 +
5250 return __copy_user(to, (__force void __user *) from, count);
5251 }
5252
5253 static inline unsigned long
5254 __copy_from_user (void *to, const void __user *from, unsigned long count)
5255 {
5256 + if (count > INT_MAX)
5257 + return count;
5258 +
5259 + if (!__builtin_constant_p(count))
5260 + check_object_size(to, count, false);
5261 +
5262 return __copy_user((__force void __user *) to, from, count);
5263 }
5264
5265 @@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5266 ({ \
5267 void __user *__cu_to = (to); \
5268 const void *__cu_from = (from); \
5269 - long __cu_len = (n); \
5270 + unsigned long __cu_len = (n); \
5271 \
5272 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
5273 + if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5274 + if (!__builtin_constant_p(n)) \
5275 + check_object_size(__cu_from, __cu_len, true); \
5276 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5277 + } \
5278 __cu_len; \
5279 })
5280
5281 @@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5282 ({ \
5283 void *__cu_to = (to); \
5284 const void __user *__cu_from = (from); \
5285 - long __cu_len = (n); \
5286 + unsigned long __cu_len = (n); \
5287 \
5288 __chk_user_ptr(__cu_from); \
5289 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
5290 + if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5291 + if (!__builtin_constant_p(n)) \
5292 + check_object_size(__cu_to, __cu_len, false); \
5293 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5294 + } \
5295 __cu_len; \
5296 })
5297
5298 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5299 index 24603be..948052d 100644
5300 --- a/arch/ia64/kernel/module.c
5301 +++ b/arch/ia64/kernel/module.c
5302 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5303 void
5304 module_free (struct module *mod, void *module_region)
5305 {
5306 - if (mod && mod->arch.init_unw_table &&
5307 - module_region == mod->module_init) {
5308 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5309 unw_remove_unwind_table(mod->arch.init_unw_table);
5310 mod->arch.init_unw_table = NULL;
5311 }
5312 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5313 }
5314
5315 static inline int
5316 +in_init_rx (const struct module *mod, uint64_t addr)
5317 +{
5318 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5319 +}
5320 +
5321 +static inline int
5322 +in_init_rw (const struct module *mod, uint64_t addr)
5323 +{
5324 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5325 +}
5326 +
5327 +static inline int
5328 in_init (const struct module *mod, uint64_t addr)
5329 {
5330 - return addr - (uint64_t) mod->module_init < mod->init_size;
5331 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5332 +}
5333 +
5334 +static inline int
5335 +in_core_rx (const struct module *mod, uint64_t addr)
5336 +{
5337 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5338 +}
5339 +
5340 +static inline int
5341 +in_core_rw (const struct module *mod, uint64_t addr)
5342 +{
5343 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5344 }
5345
5346 static inline int
5347 in_core (const struct module *mod, uint64_t addr)
5348 {
5349 - return addr - (uint64_t) mod->module_core < mod->core_size;
5350 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5351 }
5352
5353 static inline int
5354 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5355 break;
5356
5357 case RV_BDREL:
5358 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5359 + if (in_init_rx(mod, val))
5360 + val -= (uint64_t) mod->module_init_rx;
5361 + else if (in_init_rw(mod, val))
5362 + val -= (uint64_t) mod->module_init_rw;
5363 + else if (in_core_rx(mod, val))
5364 + val -= (uint64_t) mod->module_core_rx;
5365 + else if (in_core_rw(mod, val))
5366 + val -= (uint64_t) mod->module_core_rw;
5367 break;
5368
5369 case RV_LTV:
5370 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5371 * addresses have been selected...
5372 */
5373 uint64_t gp;
5374 - if (mod->core_size > MAX_LTOFF)
5375 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5376 /*
5377 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5378 * at the end of the module.
5379 */
5380 - gp = mod->core_size - MAX_LTOFF / 2;
5381 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5382 else
5383 - gp = mod->core_size / 2;
5384 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5385 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5386 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5387 mod->arch.gp = gp;
5388 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5389 }
5390 diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5391 index c39c3cd..3c77738 100644
5392 --- a/arch/ia64/kernel/palinfo.c
5393 +++ b/arch/ia64/kernel/palinfo.c
5394 @@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5395 return NOTIFY_OK;
5396 }
5397
5398 -static struct notifier_block __refdata palinfo_cpu_notifier =
5399 +static struct notifier_block palinfo_cpu_notifier =
5400 {
5401 .notifier_call = palinfo_cpu_callback,
5402 .priority = 0,
5403 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5404 index 41e33f8..65180b2a 100644
5405 --- a/arch/ia64/kernel/sys_ia64.c
5406 +++ b/arch/ia64/kernel/sys_ia64.c
5407 @@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5408 unsigned long align_mask = 0;
5409 struct mm_struct *mm = current->mm;
5410 struct vm_unmapped_area_info info;
5411 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5412
5413 if (len > RGN_MAP_LIMIT)
5414 return -ENOMEM;
5415 @@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5416 if (REGION_NUMBER(addr) == RGN_HPAGE)
5417 addr = 0;
5418 #endif
5419 +
5420 +#ifdef CONFIG_PAX_RANDMMAP
5421 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5422 + addr = mm->free_area_cache;
5423 + else
5424 +#endif
5425 +
5426 if (!addr)
5427 addr = TASK_UNMAPPED_BASE;
5428
5429 @@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5430 info.high_limit = TASK_SIZE;
5431 info.align_mask = align_mask;
5432 info.align_offset = 0;
5433 + info.threadstack_offset = offset;
5434 return vm_unmapped_area(&info);
5435 }
5436
5437 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5438 index 84f8a52..7c76178 100644
5439 --- a/arch/ia64/kernel/vmlinux.lds.S
5440 +++ b/arch/ia64/kernel/vmlinux.lds.S
5441 @@ -192,7 +192,7 @@ SECTIONS {
5442 /* Per-cpu data: */
5443 . = ALIGN(PERCPU_PAGE_SIZE);
5444 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5445 - __phys_per_cpu_start = __per_cpu_load;
5446 + __phys_per_cpu_start = per_cpu_load;
5447 /*
5448 * ensure percpu data fits
5449 * into percpu page size
5450 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5451 index 7225dad..2a7c8256 100644
5452 --- a/arch/ia64/mm/fault.c
5453 +++ b/arch/ia64/mm/fault.c
5454 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5455 return pte_present(pte);
5456 }
5457
5458 +#ifdef CONFIG_PAX_PAGEEXEC
5459 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5460 +{
5461 + unsigned long i;
5462 +
5463 + printk(KERN_ERR "PAX: bytes at PC: ");
5464 + for (i = 0; i < 8; i++) {
5465 + unsigned int c;
5466 + if (get_user(c, (unsigned int *)pc+i))
5467 + printk(KERN_CONT "???????? ");
5468 + else
5469 + printk(KERN_CONT "%08x ", c);
5470 + }
5471 + printk("\n");
5472 +}
5473 +#endif
5474 +
5475 # define VM_READ_BIT 0
5476 # define VM_WRITE_BIT 1
5477 # define VM_EXEC_BIT 2
5478 @@ -151,8 +168,21 @@ retry:
5479 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5480 goto bad_area;
5481
5482 - if ((vma->vm_flags & mask) != mask)
5483 + if ((vma->vm_flags & mask) != mask) {
5484 +
5485 +#ifdef CONFIG_PAX_PAGEEXEC
5486 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5487 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5488 + goto bad_area;
5489 +
5490 + up_read(&mm->mmap_sem);
5491 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5492 + do_group_exit(SIGKILL);
5493 + }
5494 +#endif
5495 +
5496 goto bad_area;
5497 + }
5498
5499 /*
5500 * If for any reason at all we couldn't handle the fault, make
5501 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5502 index 76069c1..c2aa816 100644
5503 --- a/arch/ia64/mm/hugetlbpage.c
5504 +++ b/arch/ia64/mm/hugetlbpage.c
5505 @@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5506 unsigned long pgoff, unsigned long flags)
5507 {
5508 struct vm_unmapped_area_info info;
5509 + unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5510
5511 if (len > RGN_MAP_LIMIT)
5512 return -ENOMEM;
5513 @@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5514 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5515 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5516 info.align_offset = 0;
5517 + info.threadstack_offset = offset;
5518 return vm_unmapped_area(&info);
5519 }
5520
5521 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5522 index 25c3502..560dae7 100644
5523 --- a/arch/ia64/mm/init.c
5524 +++ b/arch/ia64/mm/init.c
5525 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5526 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5527 vma->vm_end = vma->vm_start + PAGE_SIZE;
5528 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5529 +
5530 +#ifdef CONFIG_PAX_PAGEEXEC
5531 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5532 + vma->vm_flags &= ~VM_EXEC;
5533 +
5534 +#ifdef CONFIG_PAX_MPROTECT
5535 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
5536 + vma->vm_flags &= ~VM_MAYEXEC;
5537 +#endif
5538 +
5539 + }
5540 +#endif
5541 +
5542 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5543 down_write(&current->mm->mmap_sem);
5544 if (insert_vm_struct(current->mm, vma)) {
5545 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5546 index 40b3ee9..8c2c112 100644
5547 --- a/arch/m32r/include/asm/cache.h
5548 +++ b/arch/m32r/include/asm/cache.h
5549 @@ -1,8 +1,10 @@
5550 #ifndef _ASM_M32R_CACHE_H
5551 #define _ASM_M32R_CACHE_H
5552
5553 +#include <linux/const.h>
5554 +
5555 /* L1 cache line size */
5556 #define L1_CACHE_SHIFT 4
5557 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5558 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5559
5560 #endif /* _ASM_M32R_CACHE_H */
5561 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5562 index 82abd15..d95ae5d 100644
5563 --- a/arch/m32r/lib/usercopy.c
5564 +++ b/arch/m32r/lib/usercopy.c
5565 @@ -14,6 +14,9 @@
5566 unsigned long
5567 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5568 {
5569 + if ((long)n < 0)
5570 + return n;
5571 +
5572 prefetch(from);
5573 if (access_ok(VERIFY_WRITE, to, n))
5574 __copy_user(to,from,n);
5575 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5576 unsigned long
5577 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5578 {
5579 + if ((long)n < 0)
5580 + return n;
5581 +
5582 prefetchw(to);
5583 if (access_ok(VERIFY_READ, from, n))
5584 __copy_user_zeroing(to,from,n);
5585 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5586 index 0395c51..5f26031 100644
5587 --- a/arch/m68k/include/asm/cache.h
5588 +++ b/arch/m68k/include/asm/cache.h
5589 @@ -4,9 +4,11 @@
5590 #ifndef __ARCH_M68K_CACHE_H
5591 #define __ARCH_M68K_CACHE_H
5592
5593 +#include <linux/const.h>
5594 +
5595 /* bytes per L1 cache line */
5596 #define L1_CACHE_SHIFT 4
5597 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5598 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5599
5600 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5601
5602 diff --git a/arch/metag/include/asm/barrier.h b/arch/metag/include/asm/barrier.h
5603 index 2d6f0de..de5f5ac 100644
5604 --- a/arch/metag/include/asm/barrier.h
5605 +++ b/arch/metag/include/asm/barrier.h
5606 @@ -89,7 +89,7 @@ static inline void fence(void)
5607 do { \
5608 compiletime_assert_atomic_type(*p); \
5609 smp_mb(); \
5610 - ACCESS_ONCE(*p) = (v); \
5611 + ACCESS_ONCE_RW(*p) = (v); \
5612 } while (0)
5613
5614 #define smp_load_acquire(p) \
5615 diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5616 index 3c52fa6..11b2ad8 100644
5617 --- a/arch/metag/mm/hugetlbpage.c
5618 +++ b/arch/metag/mm/hugetlbpage.c
5619 @@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5620 info.high_limit = TASK_SIZE;
5621 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5622 info.align_offset = 0;
5623 + info.threadstack_offset = 0;
5624 return vm_unmapped_area(&info);
5625 }
5626
5627 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5628 index 4efe96a..60e8699 100644
5629 --- a/arch/microblaze/include/asm/cache.h
5630 +++ b/arch/microblaze/include/asm/cache.h
5631 @@ -13,11 +13,12 @@
5632 #ifndef _ASM_MICROBLAZE_CACHE_H
5633 #define _ASM_MICROBLAZE_CACHE_H
5634
5635 +#include <linux/const.h>
5636 #include <asm/registers.h>
5637
5638 #define L1_CACHE_SHIFT 5
5639 /* word-granular cache in microblaze */
5640 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5641 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5642
5643 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5644
5645 diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5646 index 5cd695f..9a24ad0 100644
5647 --- a/arch/mips/Kconfig
5648 +++ b/arch/mips/Kconfig
5649 @@ -2395,6 +2395,7 @@ source "kernel/Kconfig.preempt"
5650
5651 config KEXEC
5652 bool "Kexec system call"
5653 + depends on !GRKERNSEC_KMEM
5654 help
5655 kexec is a system call that implements the ability to shutdown your
5656 current kernel, and to start another kernel. It is like a reboot
5657 diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
5658 index 02f2444..506969c 100644
5659 --- a/arch/mips/cavium-octeon/dma-octeon.c
5660 +++ b/arch/mips/cavium-octeon/dma-octeon.c
5661 @@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
5662 if (dma_release_from_coherent(dev, order, vaddr))
5663 return;
5664
5665 - swiotlb_free_coherent(dev, size, vaddr, dma_handle);
5666 + swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
5667 }
5668
5669 static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
5670 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5671 index e8eb3d5..2e665d1 100644
5672 --- a/arch/mips/include/asm/atomic.h
5673 +++ b/arch/mips/include/asm/atomic.h
5674 @@ -21,15 +21,39 @@
5675 #include <asm/cmpxchg.h>
5676 #include <asm/war.h>
5677
5678 +#ifdef CONFIG_GENERIC_ATOMIC64
5679 +#include <asm-generic/atomic64.h>
5680 +#endif
5681 +
5682 #define ATOMIC_INIT(i) { (i) }
5683
5684 +#ifdef CONFIG_64BIT
5685 +#define _ASM_EXTABLE(from, to) \
5686 +" .section __ex_table,\"a\"\n" \
5687 +" .dword " #from ", " #to"\n" \
5688 +" .previous\n"
5689 +#else
5690 +#define _ASM_EXTABLE(from, to) \
5691 +" .section __ex_table,\"a\"\n" \
5692 +" .word " #from ", " #to"\n" \
5693 +" .previous\n"
5694 +#endif
5695 +
5696 /*
5697 * atomic_read - read atomic variable
5698 * @v: pointer of type atomic_t
5699 *
5700 * Atomically reads the value of @v.
5701 */
5702 -#define atomic_read(v) (*(volatile int *)&(v)->counter)
5703 +static inline int atomic_read(const atomic_t *v)
5704 +{
5705 + return (*(volatile const int *) &v->counter);
5706 +}
5707 +
5708 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5709 +{
5710 + return (*(volatile const int *) &v->counter);
5711 +}
5712
5713 /*
5714 * atomic_set - set atomic variable
5715 @@ -38,7 +62,15 @@
5716 *
5717 * Atomically sets the value of @v to @i.
5718 */
5719 -#define atomic_set(v, i) ((v)->counter = (i))
5720 +static inline void atomic_set(atomic_t *v, int i)
5721 +{
5722 + v->counter = i;
5723 +}
5724 +
5725 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5726 +{
5727 + v->counter = i;
5728 +}
5729
5730 /*
5731 * atomic_add - add integer to atomic variable
5732 @@ -47,7 +79,67 @@
5733 *
5734 * Atomically adds @i to @v.
5735 */
5736 -static __inline__ void atomic_add(int i, atomic_t * v)
5737 +static __inline__ void atomic_add(int i, atomic_t *v)
5738 +{
5739 + int temp;
5740 +
5741 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5742 + __asm__ __volatile__(
5743 + " .set mips3 \n"
5744 + "1: ll %0, %1 # atomic_add \n"
5745 +#ifdef CONFIG_PAX_REFCOUNT
5746 + /* Exception on overflow. */
5747 + "2: add %0, %2 \n"
5748 +#else
5749 + " addu %0, %2 \n"
5750 +#endif
5751 + " sc %0, %1 \n"
5752 + " beqzl %0, 1b \n"
5753 +#ifdef CONFIG_PAX_REFCOUNT
5754 + "3: \n"
5755 + _ASM_EXTABLE(2b, 3b)
5756 +#endif
5757 + " .set mips0 \n"
5758 + : "=&r" (temp), "+m" (v->counter)
5759 + : "Ir" (i));
5760 + } else if (kernel_uses_llsc) {
5761 + __asm__ __volatile__(
5762 + " .set mips3 \n"
5763 + "1: ll %0, %1 # atomic_add \n"
5764 +#ifdef CONFIG_PAX_REFCOUNT
5765 + /* Exception on overflow. */
5766 + "2: add %0, %2 \n"
5767 +#else
5768 + " addu %0, %2 \n"
5769 +#endif
5770 + " sc %0, %1 \n"
5771 + " beqz %0, 1b \n"
5772 +#ifdef CONFIG_PAX_REFCOUNT
5773 + "3: \n"
5774 + _ASM_EXTABLE(2b, 3b)
5775 +#endif
5776 + " .set mips0 \n"
5777 + : "=&r" (temp), "+m" (v->counter)
5778 + : "Ir" (i));
5779 + } else {
5780 + unsigned long flags;
5781 +
5782 + raw_local_irq_save(flags);
5783 + __asm__ __volatile__(
5784 +#ifdef CONFIG_PAX_REFCOUNT
5785 + /* Exception on overflow. */
5786 + "1: add %0, %1 \n"
5787 + "2: \n"
5788 + _ASM_EXTABLE(1b, 2b)
5789 +#else
5790 + " addu %0, %1 \n"
5791 +#endif
5792 + : "+r" (v->counter) : "Ir" (i));
5793 + raw_local_irq_restore(flags);
5794 + }
5795 +}
5796 +
5797 +static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5798 {
5799 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5800 int temp;
5801 @@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5802 *
5803 * Atomically subtracts @i from @v.
5804 */
5805 -static __inline__ void atomic_sub(int i, atomic_t * v)
5806 +static __inline__ void atomic_sub(int i, atomic_t *v)
5807 +{
5808 + int temp;
5809 +
5810 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5811 + __asm__ __volatile__(
5812 + " .set mips3 \n"
5813 + "1: ll %0, %1 # atomic64_sub \n"
5814 +#ifdef CONFIG_PAX_REFCOUNT
5815 + /* Exception on overflow. */
5816 + "2: sub %0, %2 \n"
5817 +#else
5818 + " subu %0, %2 \n"
5819 +#endif
5820 + " sc %0, %1 \n"
5821 + " beqzl %0, 1b \n"
5822 +#ifdef CONFIG_PAX_REFCOUNT
5823 + "3: \n"
5824 + _ASM_EXTABLE(2b, 3b)
5825 +#endif
5826 + " .set mips0 \n"
5827 + : "=&r" (temp), "+m" (v->counter)
5828 + : "Ir" (i));
5829 + } else if (kernel_uses_llsc) {
5830 + __asm__ __volatile__(
5831 + " .set mips3 \n"
5832 + "1: ll %0, %1 # atomic64_sub \n"
5833 +#ifdef CONFIG_PAX_REFCOUNT
5834 + /* Exception on overflow. */
5835 + "2: sub %0, %2 \n"
5836 +#else
5837 + " subu %0, %2 \n"
5838 +#endif
5839 + " sc %0, %1 \n"
5840 + " beqz %0, 1b \n"
5841 +#ifdef CONFIG_PAX_REFCOUNT
5842 + "3: \n"
5843 + _ASM_EXTABLE(2b, 3b)
5844 +#endif
5845 + " .set mips0 \n"
5846 + : "=&r" (temp), "+m" (v->counter)
5847 + : "Ir" (i));
5848 + } else {
5849 + unsigned long flags;
5850 +
5851 + raw_local_irq_save(flags);
5852 + __asm__ __volatile__(
5853 +#ifdef CONFIG_PAX_REFCOUNT
5854 + /* Exception on overflow. */
5855 + "1: sub %0, %1 \n"
5856 + "2: \n"
5857 + _ASM_EXTABLE(1b, 2b)
5858 +#else
5859 + " subu %0, %1 \n"
5860 +#endif
5861 + : "+r" (v->counter) : "Ir" (i));
5862 + raw_local_irq_restore(flags);
5863 + }
5864 +}
5865 +
5866 +static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5867 {
5868 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5869 int temp;
5870 @@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5871 /*
5872 * Same as above, but return the result value
5873 */
5874 -static __inline__ int atomic_add_return(int i, atomic_t * v)
5875 +static __inline__ int atomic_add_return(int i, atomic_t *v)
5876 +{
5877 + int result;
5878 + int temp;
5879 +
5880 + smp_mb__before_llsc();
5881 +
5882 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5883 + __asm__ __volatile__(
5884 + " .set mips3 \n"
5885 + "1: ll %1, %2 # atomic_add_return \n"
5886 +#ifdef CONFIG_PAX_REFCOUNT
5887 + "2: add %0, %1, %3 \n"
5888 +#else
5889 + " addu %0, %1, %3 \n"
5890 +#endif
5891 + " sc %0, %2 \n"
5892 + " beqzl %0, 1b \n"
5893 +#ifdef CONFIG_PAX_REFCOUNT
5894 + " b 4f \n"
5895 + " .set noreorder \n"
5896 + "3: b 5f \n"
5897 + " move %0, %1 \n"
5898 + " .set reorder \n"
5899 + _ASM_EXTABLE(2b, 3b)
5900 +#endif
5901 + "4: addu %0, %1, %3 \n"
5902 +#ifdef CONFIG_PAX_REFCOUNT
5903 + "5: \n"
5904 +#endif
5905 + " .set mips0 \n"
5906 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5907 + : "Ir" (i));
5908 + } else if (kernel_uses_llsc) {
5909 + __asm__ __volatile__(
5910 + " .set mips3 \n"
5911 + "1: ll %1, %2 # atomic_add_return \n"
5912 +#ifdef CONFIG_PAX_REFCOUNT
5913 + "2: add %0, %1, %3 \n"
5914 +#else
5915 + " addu %0, %1, %3 \n"
5916 +#endif
5917 + " sc %0, %2 \n"
5918 + " bnez %0, 4f \n"
5919 + " b 1b \n"
5920 +#ifdef CONFIG_PAX_REFCOUNT
5921 + " .set noreorder \n"
5922 + "3: b 5f \n"
5923 + " move %0, %1 \n"
5924 + " .set reorder \n"
5925 + _ASM_EXTABLE(2b, 3b)
5926 +#endif
5927 + "4: addu %0, %1, %3 \n"
5928 +#ifdef CONFIG_PAX_REFCOUNT
5929 + "5: \n"
5930 +#endif
5931 + " .set mips0 \n"
5932 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5933 + : "Ir" (i));
5934 + } else {
5935 + unsigned long flags;
5936 +
5937 + raw_local_irq_save(flags);
5938 + __asm__ __volatile__(
5939 + " lw %0, %1 \n"
5940 +#ifdef CONFIG_PAX_REFCOUNT
5941 + /* Exception on overflow. */
5942 + "1: add %0, %2 \n"
5943 +#else
5944 + " addu %0, %2 \n"
5945 +#endif
5946 + " sw %0, %1 \n"
5947 +#ifdef CONFIG_PAX_REFCOUNT
5948 + /* Note: Dest reg is not modified on overflow */
5949 + "2: \n"
5950 + _ASM_EXTABLE(1b, 2b)
5951 +#endif
5952 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5953 + raw_local_irq_restore(flags);
5954 + }
5955 +
5956 + smp_llsc_mb();
5957 +
5958 + return result;
5959 +}
5960 +
5961 +static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5962 {
5963 int result;
5964
5965 @@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5966 return result;
5967 }
5968
5969 -static __inline__ int atomic_sub_return(int i, atomic_t * v)
5970 +static __inline__ int atomic_sub_return(int i, atomic_t *v)
5971 +{
5972 + int result;
5973 + int temp;
5974 +
5975 + smp_mb__before_llsc();
5976 +
5977 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5978 + __asm__ __volatile__(
5979 + " .set mips3 \n"
5980 + "1: ll %1, %2 # atomic_sub_return \n"
5981 +#ifdef CONFIG_PAX_REFCOUNT
5982 + "2: sub %0, %1, %3 \n"
5983 +#else
5984 + " subu %0, %1, %3 \n"
5985 +#endif
5986 + " sc %0, %2 \n"
5987 + " beqzl %0, 1b \n"
5988 +#ifdef CONFIG_PAX_REFCOUNT
5989 + " b 4f \n"
5990 + " .set noreorder \n"
5991 + "3: b 5f \n"
5992 + " move %0, %1 \n"
5993 + " .set reorder \n"
5994 + _ASM_EXTABLE(2b, 3b)
5995 +#endif
5996 + "4: subu %0, %1, %3 \n"
5997 +#ifdef CONFIG_PAX_REFCOUNT
5998 + "5: \n"
5999 +#endif
6000 + " .set mips0 \n"
6001 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6002 + : "Ir" (i), "m" (v->counter)
6003 + : "memory");
6004 + } else if (kernel_uses_llsc) {
6005 + __asm__ __volatile__(
6006 + " .set mips3 \n"
6007 + "1: ll %1, %2 # atomic_sub_return \n"
6008 +#ifdef CONFIG_PAX_REFCOUNT
6009 + "2: sub %0, %1, %3 \n"
6010 +#else
6011 + " subu %0, %1, %3 \n"
6012 +#endif
6013 + " sc %0, %2 \n"
6014 + " bnez %0, 4f \n"
6015 + " b 1b \n"
6016 +#ifdef CONFIG_PAX_REFCOUNT
6017 + " .set noreorder \n"
6018 + "3: b 5f \n"
6019 + " move %0, %1 \n"
6020 + " .set reorder \n"
6021 + _ASM_EXTABLE(2b, 3b)
6022 +#endif
6023 + "4: subu %0, %1, %3 \n"
6024 +#ifdef CONFIG_PAX_REFCOUNT
6025 + "5: \n"
6026 +#endif
6027 + " .set mips0 \n"
6028 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6029 + : "Ir" (i));
6030 + } else {
6031 + unsigned long flags;
6032 +
6033 + raw_local_irq_save(flags);
6034 + __asm__ __volatile__(
6035 + " lw %0, %1 \n"
6036 +#ifdef CONFIG_PAX_REFCOUNT
6037 + /* Exception on overflow. */
6038 + "1: sub %0, %2 \n"
6039 +#else
6040 + " subu %0, %2 \n"
6041 +#endif
6042 + " sw %0, %1 \n"
6043 +#ifdef CONFIG_PAX_REFCOUNT
6044 + /* Note: Dest reg is not modified on overflow */
6045 + "2: \n"
6046 + _ASM_EXTABLE(1b, 2b)
6047 +#endif
6048 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6049 + raw_local_irq_restore(flags);
6050 + }
6051 +
6052 + smp_llsc_mb();
6053 +
6054 + return result;
6055 +}
6056 +static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
6057 {
6058 int result;
6059
6060 @@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
6061 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6062 * The function returns the old value of @v minus @i.
6063 */
6064 -static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6065 +static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
6066 {
6067 int result;
6068
6069 @@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6070 return result;
6071 }
6072
6073 -#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
6074 -#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
6075 +static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
6076 +{
6077 + return cmpxchg(&v->counter, old, new);
6078 +}
6079 +
6080 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
6081 + int new)
6082 +{
6083 + return cmpxchg(&(v->counter), old, new);
6084 +}
6085 +
6086 +static inline int atomic_xchg(atomic_t *v, int new)
6087 +{
6088 + return xchg(&v->counter, new);
6089 +}
6090 +
6091 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
6092 +{
6093 + return xchg(&(v->counter), new);
6094 +}
6095
6096 /**
6097 * __atomic_add_unless - add unless the number is a given value
6098 @@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6099
6100 #define atomic_dec_return(v) atomic_sub_return(1, (v))
6101 #define atomic_inc_return(v) atomic_add_return(1, (v))
6102 +static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
6103 +{
6104 + return atomic_add_return_unchecked(1, v);
6105 +}
6106
6107 /*
6108 * atomic_sub_and_test - subtract value from variable and test result
6109 @@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6110 * other cases.
6111 */
6112 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
6113 +static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
6114 +{
6115 + return atomic_add_return_unchecked(1, v) == 0;
6116 +}
6117
6118 /*
6119 * atomic_dec_and_test - decrement by 1 and test
6120 @@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6121 * Atomically increments @v by 1.
6122 */
6123 #define atomic_inc(v) atomic_add(1, (v))
6124 +static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
6125 +{
6126 + atomic_add_unchecked(1, v);
6127 +}
6128
6129 /*
6130 * atomic_dec - decrement and test
6131 @@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6132 * Atomically decrements @v by 1.
6133 */
6134 #define atomic_dec(v) atomic_sub(1, (v))
6135 +static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
6136 +{
6137 + atomic_sub_unchecked(1, v);
6138 +}
6139
6140 /*
6141 * atomic_add_negative - add and test if negative
6142 @@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6143 * @v: pointer of type atomic64_t
6144 *
6145 */
6146 -#define atomic64_read(v) (*(volatile long *)&(v)->counter)
6147 +static inline long atomic64_read(const atomic64_t *v)
6148 +{
6149 + return (*(volatile const long *) &v->counter);
6150 +}
6151 +
6152 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6153 +{
6154 + return (*(volatile const long *) &v->counter);
6155 +}
6156
6157 /*
6158 * atomic64_set - set atomic variable
6159 * @v: pointer of type atomic64_t
6160 * @i: required value
6161 */
6162 -#define atomic64_set(v, i) ((v)->counter = (i))
6163 +static inline void atomic64_set(atomic64_t *v, long i)
6164 +{
6165 + v->counter = i;
6166 +}
6167 +
6168 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6169 +{
6170 + v->counter = i;
6171 +}
6172
6173 /*
6174 * atomic64_add - add integer to atomic variable
6175 @@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6176 *
6177 * Atomically adds @i to @v.
6178 */
6179 -static __inline__ void atomic64_add(long i, atomic64_t * v)
6180 +static __inline__ void atomic64_add(long i, atomic64_t *v)
6181 +{
6182 + long temp;
6183 +
6184 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6185 + __asm__ __volatile__(
6186 + " .set mips3 \n"
6187 + "1: lld %0, %1 # atomic64_add \n"
6188 +#ifdef CONFIG_PAX_REFCOUNT
6189 + /* Exception on overflow. */
6190 + "2: dadd %0, %2 \n"
6191 +#else
6192 + " daddu %0, %2 \n"
6193 +#endif
6194 + " scd %0, %1 \n"
6195 + " beqzl %0, 1b \n"
6196 +#ifdef CONFIG_PAX_REFCOUNT
6197 + "3: \n"
6198 + _ASM_EXTABLE(2b, 3b)
6199 +#endif
6200 + " .set mips0 \n"
6201 + : "=&r" (temp), "+m" (v->counter)
6202 + : "Ir" (i));
6203 + } else if (kernel_uses_llsc) {
6204 + __asm__ __volatile__(
6205 + " .set mips3 \n"
6206 + "1: lld %0, %1 # atomic64_add \n"
6207 +#ifdef CONFIG_PAX_REFCOUNT
6208 + /* Exception on overflow. */
6209 + "2: dadd %0, %2 \n"
6210 +#else
6211 + " daddu %0, %2 \n"
6212 +#endif
6213 + " scd %0, %1 \n"
6214 + " beqz %0, 1b \n"
6215 +#ifdef CONFIG_PAX_REFCOUNT
6216 + "3: \n"
6217 + _ASM_EXTABLE(2b, 3b)
6218 +#endif
6219 + " .set mips0 \n"
6220 + : "=&r" (temp), "+m" (v->counter)
6221 + : "Ir" (i));
6222 + } else {
6223 + unsigned long flags;
6224 +
6225 + raw_local_irq_save(flags);
6226 + __asm__ __volatile__(
6227 +#ifdef CONFIG_PAX_REFCOUNT
6228 + /* Exception on overflow. */
6229 + "1: dadd %0, %1 \n"
6230 + "2: \n"
6231 + _ASM_EXTABLE(1b, 2b)
6232 +#else
6233 + " daddu %0, %1 \n"
6234 +#endif
6235 + : "+r" (v->counter) : "Ir" (i));
6236 + raw_local_irq_restore(flags);
6237 + }
6238 +}
6239 +static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6240 {
6241 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6242 long temp;
6243 @@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
6244 *
6245 * Atomically subtracts @i from @v.
6246 */
6247 -static __inline__ void atomic64_sub(long i, atomic64_t * v)
6248 +static __inline__ void atomic64_sub(long i, atomic64_t *v)
6249 +{
6250 + long temp;
6251 +
6252 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6253 + __asm__ __volatile__(
6254 + " .set mips3 \n"
6255 + "1: lld %0, %1 # atomic64_sub \n"
6256 +#ifdef CONFIG_PAX_REFCOUNT
6257 + /* Exception on overflow. */
6258 + "2: dsub %0, %2 \n"
6259 +#else
6260 + " dsubu %0, %2 \n"
6261 +#endif
6262 + " scd %0, %1 \n"
6263 + " beqzl %0, 1b \n"
6264 +#ifdef CONFIG_PAX_REFCOUNT
6265 + "3: \n"
6266 + _ASM_EXTABLE(2b, 3b)
6267 +#endif
6268 + " .set mips0 \n"
6269 + : "=&r" (temp), "+m" (v->counter)
6270 + : "Ir" (i));
6271 + } else if (kernel_uses_llsc) {
6272 + __asm__ __volatile__(
6273 + " .set mips3 \n"
6274 + "1: lld %0, %1 # atomic64_sub \n"
6275 +#ifdef CONFIG_PAX_REFCOUNT
6276 + /* Exception on overflow. */
6277 + "2: dsub %0, %2 \n"
6278 +#else
6279 + " dsubu %0, %2 \n"
6280 +#endif
6281 + " scd %0, %1 \n"
6282 + " beqz %0, 1b \n"
6283 +#ifdef CONFIG_PAX_REFCOUNT
6284 + "3: \n"
6285 + _ASM_EXTABLE(2b, 3b)
6286 +#endif
6287 + " .set mips0 \n"
6288 + : "=&r" (temp), "+m" (v->counter)
6289 + : "Ir" (i));
6290 + } else {
6291 + unsigned long flags;
6292 +
6293 + raw_local_irq_save(flags);
6294 + __asm__ __volatile__(
6295 +#ifdef CONFIG_PAX_REFCOUNT
6296 + /* Exception on overflow. */
6297 + "1: dsub %0, %1 \n"
6298 + "2: \n"
6299 + _ASM_EXTABLE(1b, 2b)
6300 +#else
6301 + " dsubu %0, %1 \n"
6302 +#endif
6303 + : "+r" (v->counter) : "Ir" (i));
6304 + raw_local_irq_restore(flags);
6305 + }
6306 +}
6307 +
6308 +static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6309 {
6310 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6311 long temp;
6312 @@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6313 /*
6314 * Same as above, but return the result value
6315 */
6316 -static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6317 +static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6318 +{
6319 + long result;
6320 + long temp;
6321 +
6322 + smp_mb__before_llsc();
6323 +
6324 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6325 + __asm__ __volatile__(
6326 + " .set mips3 \n"
6327 + "1: lld %1, %2 # atomic64_add_return \n"
6328 +#ifdef CONFIG_PAX_REFCOUNT
6329 + "2: dadd %0, %1, %3 \n"
6330 +#else
6331 + " daddu %0, %1, %3 \n"
6332 +#endif
6333 + " scd %0, %2 \n"
6334 + " beqzl %0, 1b \n"
6335 +#ifdef CONFIG_PAX_REFCOUNT
6336 + " b 4f \n"
6337 + " .set noreorder \n"
6338 + "3: b 5f \n"
6339 + " move %0, %1 \n"
6340 + " .set reorder \n"
6341 + _ASM_EXTABLE(2b, 3b)
6342 +#endif
6343 + "4: daddu %0, %1, %3 \n"
6344 +#ifdef CONFIG_PAX_REFCOUNT
6345 + "5: \n"
6346 +#endif
6347 + " .set mips0 \n"
6348 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6349 + : "Ir" (i));
6350 + } else if (kernel_uses_llsc) {
6351 + __asm__ __volatile__(
6352 + " .set mips3 \n"
6353 + "1: lld %1, %2 # atomic64_add_return \n"
6354 +#ifdef CONFIG_PAX_REFCOUNT
6355 + "2: dadd %0, %1, %3 \n"
6356 +#else
6357 + " daddu %0, %1, %3 \n"
6358 +#endif
6359 + " scd %0, %2 \n"
6360 + " bnez %0, 4f \n"
6361 + " b 1b \n"
6362 +#ifdef CONFIG_PAX_REFCOUNT
6363 + " .set noreorder \n"
6364 + "3: b 5f \n"
6365 + " move %0, %1 \n"
6366 + " .set reorder \n"
6367 + _ASM_EXTABLE(2b, 3b)
6368 +#endif
6369 + "4: daddu %0, %1, %3 \n"
6370 +#ifdef CONFIG_PAX_REFCOUNT
6371 + "5: \n"
6372 +#endif
6373 + " .set mips0 \n"
6374 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6375 + : "Ir" (i), "m" (v->counter)
6376 + : "memory");
6377 + } else {
6378 + unsigned long flags;
6379 +
6380 + raw_local_irq_save(flags);
6381 + __asm__ __volatile__(
6382 + " ld %0, %1 \n"
6383 +#ifdef CONFIG_PAX_REFCOUNT
6384 + /* Exception on overflow. */
6385 + "1: dadd %0, %2 \n"
6386 +#else
6387 + " daddu %0, %2 \n"
6388 +#endif
6389 + " sd %0, %1 \n"
6390 +#ifdef CONFIG_PAX_REFCOUNT
6391 + /* Note: Dest reg is not modified on overflow */
6392 + "2: \n"
6393 + _ASM_EXTABLE(1b, 2b)
6394 +#endif
6395 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6396 + raw_local_irq_restore(flags);
6397 + }
6398 +
6399 + smp_llsc_mb();
6400 +
6401 + return result;
6402 +}
6403 +static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6404 {
6405 long result;
6406
6407 @@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6408 return result;
6409 }
6410
6411 -static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6412 +static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6413 +{
6414 + long result;
6415 + long temp;
6416 +
6417 + smp_mb__before_llsc();
6418 +
6419 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6420 + long temp;
6421 +
6422 + __asm__ __volatile__(
6423 + " .set mips3 \n"
6424 + "1: lld %1, %2 # atomic64_sub_return \n"
6425 +#ifdef CONFIG_PAX_REFCOUNT
6426 + "2: dsub %0, %1, %3 \n"
6427 +#else
6428 + " dsubu %0, %1, %3 \n"
6429 +#endif
6430 + " scd %0, %2 \n"
6431 + " beqzl %0, 1b \n"
6432 +#ifdef CONFIG_PAX_REFCOUNT
6433 + " b 4f \n"
6434 + " .set noreorder \n"
6435 + "3: b 5f \n"
6436 + " move %0, %1 \n"
6437 + " .set reorder \n"
6438 + _ASM_EXTABLE(2b, 3b)
6439 +#endif
6440 + "4: dsubu %0, %1, %3 \n"
6441 +#ifdef CONFIG_PAX_REFCOUNT
6442 + "5: \n"
6443 +#endif
6444 + " .set mips0 \n"
6445 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6446 + : "Ir" (i), "m" (v->counter)
6447 + : "memory");
6448 + } else if (kernel_uses_llsc) {
6449 + __asm__ __volatile__(
6450 + " .set mips3 \n"
6451 + "1: lld %1, %2 # atomic64_sub_return \n"
6452 +#ifdef CONFIG_PAX_REFCOUNT
6453 + "2: dsub %0, %1, %3 \n"
6454 +#else
6455 + " dsubu %0, %1, %3 \n"
6456 +#endif
6457 + " scd %0, %2 \n"
6458 + " bnez %0, 4f \n"
6459 + " b 1b \n"
6460 +#ifdef CONFIG_PAX_REFCOUNT
6461 + " .set noreorder \n"
6462 + "3: b 5f \n"
6463 + " move %0, %1 \n"
6464 + " .set reorder \n"
6465 + _ASM_EXTABLE(2b, 3b)
6466 +#endif
6467 + "4: dsubu %0, %1, %3 \n"
6468 +#ifdef CONFIG_PAX_REFCOUNT
6469 + "5: \n"
6470 +#endif
6471 + " .set mips0 \n"
6472 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6473 + : "Ir" (i), "m" (v->counter)
6474 + : "memory");
6475 + } else {
6476 + unsigned long flags;
6477 +
6478 + raw_local_irq_save(flags);
6479 + __asm__ __volatile__(
6480 + " ld %0, %1 \n"
6481 +#ifdef CONFIG_PAX_REFCOUNT
6482 + /* Exception on overflow. */
6483 + "1: dsub %0, %2 \n"
6484 +#else
6485 + " dsubu %0, %2 \n"
6486 +#endif
6487 + " sd %0, %1 \n"
6488 +#ifdef CONFIG_PAX_REFCOUNT
6489 + /* Note: Dest reg is not modified on overflow */
6490 + "2: \n"
6491 + _ASM_EXTABLE(1b, 2b)
6492 +#endif
6493 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6494 + raw_local_irq_restore(flags);
6495 + }
6496 +
6497 + smp_llsc_mb();
6498 +
6499 + return result;
6500 +}
6501 +
6502 +static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6503 {
6504 long result;
6505
6506 @@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6507 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6508 * The function returns the old value of @v minus @i.
6509 */
6510 -static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6511 +static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6512 {
6513 long result;
6514
6515 @@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6516 return result;
6517 }
6518
6519 -#define atomic64_cmpxchg(v, o, n) \
6520 - ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6521 -#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6522 +static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6523 +{
6524 + return cmpxchg(&v->counter, old, new);
6525 +}
6526 +
6527 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6528 + long new)
6529 +{
6530 + return cmpxchg(&(v->counter), old, new);
6531 +}
6532 +
6533 +static inline long atomic64_xchg(atomic64_t *v, long new)
6534 +{
6535 + return xchg(&v->counter, new);
6536 +}
6537 +
6538 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6539 +{
6540 + return xchg(&(v->counter), new);
6541 +}
6542
6543 /**
6544 * atomic64_add_unless - add unless the number is a given value
6545 @@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6546
6547 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6548 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6549 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6550
6551 /*
6552 * atomic64_sub_and_test - subtract value from variable and test result
6553 @@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6554 * other cases.
6555 */
6556 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6557 +#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6558
6559 /*
6560 * atomic64_dec_and_test - decrement by 1 and test
6561 @@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6562 * Atomically increments @v by 1.
6563 */
6564 #define atomic64_inc(v) atomic64_add(1, (v))
6565 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6566
6567 /*
6568 * atomic64_dec - decrement and test
6569 @@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6570 * Atomically decrements @v by 1.
6571 */
6572 #define atomic64_dec(v) atomic64_sub(1, (v))
6573 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6574
6575 /*
6576 * atomic64_add_negative - add and test if negative
6577 diff --git a/arch/mips/include/asm/barrier.h b/arch/mips/include/asm/barrier.h
6578 index e1aa4e4..670b68b 100644
6579 --- a/arch/mips/include/asm/barrier.h
6580 +++ b/arch/mips/include/asm/barrier.h
6581 @@ -184,7 +184,7 @@
6582 do { \
6583 compiletime_assert_atomic_type(*p); \
6584 smp_mb(); \
6585 - ACCESS_ONCE(*p) = (v); \
6586 + ACCESS_ONCE_RW(*p) = (v); \
6587 } while (0)
6588
6589 #define smp_load_acquire(p) \
6590 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6591 index b4db69f..8f3b093 100644
6592 --- a/arch/mips/include/asm/cache.h
6593 +++ b/arch/mips/include/asm/cache.h
6594 @@ -9,10 +9,11 @@
6595 #ifndef _ASM_CACHE_H
6596 #define _ASM_CACHE_H
6597
6598 +#include <linux/const.h>
6599 #include <kmalloc.h>
6600
6601 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6602 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6603 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6604
6605 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6606 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6607 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6608 index d414405..6bb4ba2 100644
6609 --- a/arch/mips/include/asm/elf.h
6610 +++ b/arch/mips/include/asm/elf.h
6611 @@ -398,13 +398,16 @@ extern const char *__elf_platform;
6612 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6613 #endif
6614
6615 +#ifdef CONFIG_PAX_ASLR
6616 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6617 +
6618 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6619 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6620 +#endif
6621 +
6622 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6623 struct linux_binprm;
6624 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6625 int uses_interp);
6626
6627 -struct mm_struct;
6628 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6629 -#define arch_randomize_brk arch_randomize_brk
6630 -
6631 #endif /* _ASM_ELF_H */
6632 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6633 index c1f6afa..38cc6e9 100644
6634 --- a/arch/mips/include/asm/exec.h
6635 +++ b/arch/mips/include/asm/exec.h
6636 @@ -12,6 +12,6 @@
6637 #ifndef _ASM_EXEC_H
6638 #define _ASM_EXEC_H
6639
6640 -extern unsigned long arch_align_stack(unsigned long sp);
6641 +#define arch_align_stack(x) ((x) & ~0xfUL)
6642
6643 #endif /* _ASM_EXEC_H */
6644 diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
6645 index 9e8ef59..1139d6b 100644
6646 --- a/arch/mips/include/asm/hw_irq.h
6647 +++ b/arch/mips/include/asm/hw_irq.h
6648 @@ -10,7 +10,7 @@
6649
6650 #include <linux/atomic.h>
6651
6652 -extern atomic_t irq_err_count;
6653 +extern atomic_unchecked_t irq_err_count;
6654
6655 /*
6656 * interrupt-retrigger: NOP for now. This may not be appropriate for all
6657 diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6658 index 46dfc3c..a16b13a 100644
6659 --- a/arch/mips/include/asm/local.h
6660 +++ b/arch/mips/include/asm/local.h
6661 @@ -12,15 +12,25 @@ typedef struct
6662 atomic_long_t a;
6663 } local_t;
6664
6665 +typedef struct {
6666 + atomic_long_unchecked_t a;
6667 +} local_unchecked_t;
6668 +
6669 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6670
6671 #define local_read(l) atomic_long_read(&(l)->a)
6672 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6673 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6674 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6675
6676 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6677 +#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6678 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6679 +#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6680 #define local_inc(l) atomic_long_inc(&(l)->a)
6681 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6682 #define local_dec(l) atomic_long_dec(&(l)->a)
6683 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6684
6685 /*
6686 * Same as above, but return the result value
6687 @@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6688 return result;
6689 }
6690
6691 +static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6692 +{
6693 + unsigned long result;
6694 +
6695 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6696 + unsigned long temp;
6697 +
6698 + __asm__ __volatile__(
6699 + " .set mips3 \n"
6700 + "1:" __LL "%1, %2 # local_add_return \n"
6701 + " addu %0, %1, %3 \n"
6702 + __SC "%0, %2 \n"
6703 + " beqzl %0, 1b \n"
6704 + " addu %0, %1, %3 \n"
6705 + " .set mips0 \n"
6706 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6707 + : "Ir" (i), "m" (l->a.counter)
6708 + : "memory");
6709 + } else if (kernel_uses_llsc) {
6710 + unsigned long temp;
6711 +
6712 + __asm__ __volatile__(
6713 + " .set mips3 \n"
6714 + "1:" __LL "%1, %2 # local_add_return \n"
6715 + " addu %0, %1, %3 \n"
6716 + __SC "%0, %2 \n"
6717 + " beqz %0, 1b \n"
6718 + " addu %0, %1, %3 \n"
6719 + " .set mips0 \n"
6720 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6721 + : "Ir" (i), "m" (l->a.counter)
6722 + : "memory");
6723 + } else {
6724 + unsigned long flags;
6725 +
6726 + local_irq_save(flags);
6727 + result = l->a.counter;
6728 + result += i;
6729 + l->a.counter = result;
6730 + local_irq_restore(flags);
6731 + }
6732 +
6733 + return result;
6734 +}
6735 +
6736 static __inline__ long local_sub_return(long i, local_t * l)
6737 {
6738 unsigned long result;
6739 @@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6740
6741 #define local_cmpxchg(l, o, n) \
6742 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6743 +#define local_cmpxchg_unchecked(l, o, n) \
6744 + ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6745 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6746
6747 /**
6748 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6749 index 5699ec3..95def83 100644
6750 --- a/arch/mips/include/asm/page.h
6751 +++ b/arch/mips/include/asm/page.h
6752 @@ -120,7 +120,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6753 #ifdef CONFIG_CPU_MIPS32
6754 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6755 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6756 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6757 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6758 #else
6759 typedef struct { unsigned long long pte; } pte_t;
6760 #define pte_val(x) ((x).pte)
6761 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6762 index b336037..5b874cc 100644
6763 --- a/arch/mips/include/asm/pgalloc.h
6764 +++ b/arch/mips/include/asm/pgalloc.h
6765 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6766 {
6767 set_pud(pud, __pud((unsigned long)pmd));
6768 }
6769 +
6770 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6771 +{
6772 + pud_populate(mm, pud, pmd);
6773 +}
6774 #endif
6775
6776 /*
6777 diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
6778 index 008324d..f67c239 100644
6779 --- a/arch/mips/include/asm/pgtable.h
6780 +++ b/arch/mips/include/asm/pgtable.h
6781 @@ -20,6 +20,9 @@
6782 #include <asm/io.h>
6783 #include <asm/pgtable-bits.h>
6784
6785 +#define ktla_ktva(addr) (addr)
6786 +#define ktva_ktla(addr) (addr)
6787 +
6788 struct mm_struct;
6789 struct vm_area_struct;
6790
6791 diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6792 index 25da651..ae2a259 100644
6793 --- a/arch/mips/include/asm/smtc_proc.h
6794 +++ b/arch/mips/include/asm/smtc_proc.h
6795 @@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6796
6797 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6798
6799 -extern atomic_t smtc_fpu_recoveries;
6800 +extern atomic_unchecked_t smtc_fpu_recoveries;
6801
6802 #endif /* __ASM_SMTC_PROC_H */
6803 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6804 index d2d961d..a674df0 100644
6805 --- a/arch/mips/include/asm/thread_info.h
6806 +++ b/arch/mips/include/asm/thread_info.h
6807 @@ -105,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6808 #define TIF_SECCOMP 4 /* secure computing */
6809 #define TIF_NOTIFY_RESUME 5 /* callback before returning to user */
6810 #define TIF_RESTORE_SIGMASK 9 /* restore signal mask in do_signal() */
6811 +/* li takes a 32bit immediate */
6812 +#define TIF_GRSEC_SETXID 10 /* update credentials on syscall entry/exit */
6813 +
6814 #define TIF_USEDFPU 16 /* FPU was used by this task this quantum (SMP) */
6815 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
6816 #define TIF_NOHZ 19 /* in adaptive nohz mode */
6817 @@ -138,14 +141,16 @@ static inline struct thread_info *current_thread_info(void)
6818 #define _TIF_USEDMSA (1<<TIF_USEDMSA)
6819 #define _TIF_MSA_CTX_LIVE (1<<TIF_MSA_CTX_LIVE)
6820 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6821 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6822
6823 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6824 _TIF_SYSCALL_AUDIT | \
6825 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
6826 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \
6827 + _TIF_GRSEC_SETXID)
6828
6829 /* work to do in syscall_trace_leave() */
6830 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6831 - _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6832 + _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6833
6834 /* work to do on interrupt/exception return */
6835 #define _TIF_WORK_MASK \
6836 @@ -153,7 +158,7 @@ static inline struct thread_info *current_thread_info(void)
6837 /* work to do on any return to u-space */
6838 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6839 _TIF_WORK_SYSCALL_EXIT | \
6840 - _TIF_SYSCALL_TRACEPOINT)
6841 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6842
6843 /*
6844 * We stash processor id into a COP0 register to retrieve it fast
6845 diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
6846 index a109510..94ee3f6 100644
6847 --- a/arch/mips/include/asm/uaccess.h
6848 +++ b/arch/mips/include/asm/uaccess.h
6849 @@ -130,6 +130,7 @@ extern u64 __ua_limit;
6850 __ok == 0; \
6851 })
6852
6853 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
6854 #define access_ok(type, addr, size) \
6855 likely(__access_ok((addr), (size), __access_mask))
6856
6857 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6858 index 1188e00..41cf144 100644
6859 --- a/arch/mips/kernel/binfmt_elfn32.c
6860 +++ b/arch/mips/kernel/binfmt_elfn32.c
6861 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6862 #undef ELF_ET_DYN_BASE
6863 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6864
6865 +#ifdef CONFIG_PAX_ASLR
6866 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6867 +
6868 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6869 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6870 +#endif
6871 +
6872 #include <asm/processor.h>
6873 #include <linux/module.h>
6874 #include <linux/elfcore.h>
6875 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6876 index 7faf5f2..f3d3cf4 100644
6877 --- a/arch/mips/kernel/binfmt_elfo32.c
6878 +++ b/arch/mips/kernel/binfmt_elfo32.c
6879 @@ -70,6 +70,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6880 #undef ELF_ET_DYN_BASE
6881 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6882
6883 +#ifdef CONFIG_PAX_ASLR
6884 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6885 +
6886 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6887 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6888 +#endif
6889 +
6890 #include <asm/processor.h>
6891
6892 /*
6893 diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
6894 index 2b91fe8..fe4f6b4 100644
6895 --- a/arch/mips/kernel/i8259.c
6896 +++ b/arch/mips/kernel/i8259.c
6897 @@ -205,7 +205,7 @@ spurious_8259A_irq:
6898 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
6899 spurious_irq_mask |= irqmask;
6900 }
6901 - atomic_inc(&irq_err_count);
6902 + atomic_inc_unchecked(&irq_err_count);
6903 /*
6904 * Theoretically we do not have to handle this IRQ,
6905 * but in Linux this does not cause problems and is
6906 diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
6907 index 44a1f79..2bd6aa3 100644
6908 --- a/arch/mips/kernel/irq-gt641xx.c
6909 +++ b/arch/mips/kernel/irq-gt641xx.c
6910 @@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
6911 }
6912 }
6913
6914 - atomic_inc(&irq_err_count);
6915 + atomic_inc_unchecked(&irq_err_count);
6916 }
6917
6918 void __init gt641xx_irq_init(void)
6919 diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6920 index d1fea7a..2e591b0 100644
6921 --- a/arch/mips/kernel/irq.c
6922 +++ b/arch/mips/kernel/irq.c
6923 @@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6924 printk("unexpected IRQ # %d\n", irq);
6925 }
6926
6927 -atomic_t irq_err_count;
6928 +atomic_unchecked_t irq_err_count;
6929
6930 int arch_show_interrupts(struct seq_file *p, int prec)
6931 {
6932 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6933 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6934 return 0;
6935 }
6936
6937 asmlinkage void spurious_interrupt(void)
6938 {
6939 - atomic_inc(&irq_err_count);
6940 + atomic_inc_unchecked(&irq_err_count);
6941 }
6942
6943 void __init init_IRQ(void)
6944 @@ -110,7 +110,10 @@ void __init init_IRQ(void)
6945 #endif
6946 }
6947
6948 +
6949 #ifdef DEBUG_STACKOVERFLOW
6950 +extern void gr_handle_kernel_exploit(void);
6951 +
6952 static inline void check_stack_overflow(void)
6953 {
6954 unsigned long sp;
6955 @@ -126,6 +129,7 @@ static inline void check_stack_overflow(void)
6956 printk("do_IRQ: stack overflow: %ld\n",
6957 sp - sizeof(struct thread_info));
6958 dump_stack();
6959 + gr_handle_kernel_exploit();
6960 }
6961 }
6962 #else
6963 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6964 index 60e39dc..b4829bf 100644
6965 --- a/arch/mips/kernel/process.c
6966 +++ b/arch/mips/kernel/process.c
6967 @@ -579,15 +579,3 @@ unsigned long get_wchan(struct task_struct *task)
6968 out:
6969 return pc;
6970 }
6971 -
6972 -/*
6973 - * Don't forget that the stack pointer must be aligned on a 8 bytes
6974 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6975 - */
6976 -unsigned long arch_align_stack(unsigned long sp)
6977 -{
6978 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6979 - sp -= get_random_int() & ~PAGE_MASK;
6980 -
6981 - return sp & ALMASK;
6982 -}
6983 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6984 index f639ccd..e4b110d 100644
6985 --- a/arch/mips/kernel/ptrace.c
6986 +++ b/arch/mips/kernel/ptrace.c
6987 @@ -630,6 +630,10 @@ long arch_ptrace(struct task_struct *child, long request,
6988 return ret;
6989 }
6990
6991 +#ifdef CONFIG_GRKERNSEC_SETXID
6992 +extern void gr_delayed_cred_worker(void);
6993 +#endif
6994 +
6995 /*
6996 * Notification of system call entry/exit
6997 * - triggered by current->work.syscall_trace
6998 @@ -646,6 +650,11 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall)
6999 tracehook_report_syscall_entry(regs))
7000 ret = -1;
7001
7002 +#ifdef CONFIG_GRKERNSEC_SETXID
7003 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
7004 + gr_delayed_cred_worker();
7005 +#endif
7006 +
7007 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
7008 trace_sys_enter(regs, regs->regs[2]);
7009
7010 diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
7011 index 07fc524..b9d7f28 100644
7012 --- a/arch/mips/kernel/reset.c
7013 +++ b/arch/mips/kernel/reset.c
7014 @@ -13,6 +13,7 @@
7015 #include <linux/reboot.h>
7016
7017 #include <asm/reboot.h>
7018 +#include <asm/bug.h>
7019
7020 /*
7021 * Urgs ... Too many MIPS machines to handle this in a generic way.
7022 @@ -29,16 +30,19 @@ void machine_restart(char *command)
7023 {
7024 if (_machine_restart)
7025 _machine_restart(command);
7026 + BUG();
7027 }
7028
7029 void machine_halt(void)
7030 {
7031 if (_machine_halt)
7032 _machine_halt();
7033 + BUG();
7034 }
7035
7036 void machine_power_off(void)
7037 {
7038 if (pm_power_off)
7039 pm_power_off();
7040 + BUG();
7041 }
7042 diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
7043 index 38635a9..3fcd5e0 100644
7044 --- a/arch/mips/kernel/smtc-proc.c
7045 +++ b/arch/mips/kernel/smtc-proc.c
7046 @@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
7047
7048 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
7049
7050 -atomic_t smtc_fpu_recoveries;
7051 +atomic_unchecked_t smtc_fpu_recoveries;
7052
7053 static int smtc_proc_show(struct seq_file *m, void *v)
7054 {
7055 @@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
7056 for(i = 0; i < NR_CPUS; i++)
7057 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
7058 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
7059 - atomic_read(&smtc_fpu_recoveries));
7060 + atomic_read_unchecked(&smtc_fpu_recoveries));
7061 return 0;
7062 }
7063
7064 @@ -73,7 +73,7 @@ void init_smtc_stats(void)
7065 smtc_cpu_stats[i].selfipis = 0;
7066 }
7067
7068 - atomic_set(&smtc_fpu_recoveries, 0);
7069 + atomic_set_unchecked(&smtc_fpu_recoveries, 0);
7070
7071 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
7072 }
7073 diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
7074 index c1681d6..9f881d1 100644
7075 --- a/arch/mips/kernel/smtc.c
7076 +++ b/arch/mips/kernel/smtc.c
7077 @@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
7078 }
7079 smtc_ipi_qdump();
7080 printk("%d Recoveries of \"stolen\" FPU\n",
7081 - atomic_read(&smtc_fpu_recoveries));
7082 + atomic_read_unchecked(&smtc_fpu_recoveries));
7083 }
7084
7085
7086 diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
7087 index c24ad5f..9983ab2 100644
7088 --- a/arch/mips/kernel/sync-r4k.c
7089 +++ b/arch/mips/kernel/sync-r4k.c
7090 @@ -20,8 +20,8 @@
7091 #include <asm/mipsregs.h>
7092
7093 static atomic_t count_start_flag = ATOMIC_INIT(0);
7094 -static atomic_t count_count_start = ATOMIC_INIT(0);
7095 -static atomic_t count_count_stop = ATOMIC_INIT(0);
7096 +static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
7097 +static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
7098 static atomic_t count_reference = ATOMIC_INIT(0);
7099
7100 #define COUNTON 100
7101 @@ -68,13 +68,13 @@ void synchronise_count_master(int cpu)
7102
7103 for (i = 0; i < NR_LOOPS; i++) {
7104 /* slaves loop on '!= 2' */
7105 - while (atomic_read(&count_count_start) != 1)
7106 + while (atomic_read_unchecked(&count_count_start) != 1)
7107 mb();
7108 - atomic_set(&count_count_stop, 0);
7109 + atomic_set_unchecked(&count_count_stop, 0);
7110 smp_wmb();
7111
7112 /* this lets the slaves write their count register */
7113 - atomic_inc(&count_count_start);
7114 + atomic_inc_unchecked(&count_count_start);
7115
7116 /*
7117 * Everyone initialises count in the last loop:
7118 @@ -85,11 +85,11 @@ void synchronise_count_master(int cpu)
7119 /*
7120 * Wait for all slaves to leave the synchronization point:
7121 */
7122 - while (atomic_read(&count_count_stop) != 1)
7123 + while (atomic_read_unchecked(&count_count_stop) != 1)
7124 mb();
7125 - atomic_set(&count_count_start, 0);
7126 + atomic_set_unchecked(&count_count_start, 0);
7127 smp_wmb();
7128 - atomic_inc(&count_count_stop);
7129 + atomic_inc_unchecked(&count_count_stop);
7130 }
7131 /* Arrange for an interrupt in a short while */
7132 write_c0_compare(read_c0_count() + COUNTON);
7133 @@ -130,8 +130,8 @@ void synchronise_count_slave(int cpu)
7134 initcount = atomic_read(&count_reference);
7135
7136 for (i = 0; i < NR_LOOPS; i++) {
7137 - atomic_inc(&count_count_start);
7138 - while (atomic_read(&count_count_start) != 2)
7139 + atomic_inc_unchecked(&count_count_start);
7140 + while (atomic_read_unchecked(&count_count_start) != 2)
7141 mb();
7142
7143 /*
7144 @@ -140,8 +140,8 @@ void synchronise_count_slave(int cpu)
7145 if (i == NR_LOOPS-1)
7146 write_c0_count(initcount);
7147
7148 - atomic_inc(&count_count_stop);
7149 - while (atomic_read(&count_count_stop) != 2)
7150 + atomic_inc_unchecked(&count_count_stop);
7151 + while (atomic_read_unchecked(&count_count_stop) != 2)
7152 mb();
7153 }
7154 /* Arrange for an interrupt in a short while */
7155 diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
7156 index 8119ac2..b229939 100644
7157 --- a/arch/mips/kernel/traps.c
7158 +++ b/arch/mips/kernel/traps.c
7159 @@ -695,7 +695,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
7160 siginfo_t info;
7161
7162 prev_state = exception_enter();
7163 - die_if_kernel("Integer overflow", regs);
7164 + if (unlikely(!user_mode(regs))) {
7165 +
7166 +#ifdef CONFIG_PAX_REFCOUNT
7167 + if (fixup_exception(regs)) {
7168 + pax_report_refcount_overflow(regs);
7169 + exception_exit(prev_state);
7170 + return;
7171 + }
7172 +#endif
7173 +
7174 + die("Integer overflow", regs);
7175 + }
7176
7177 info.si_code = FPE_INTOVF;
7178 info.si_signo = SIGFPE;
7179 diff --git a/arch/mips/kvm/kvm_mips.c b/arch/mips/kvm/kvm_mips.c
7180 index 3e0ff8d..9eafbf0b 100644
7181 --- a/arch/mips/kvm/kvm_mips.c
7182 +++ b/arch/mips/kvm/kvm_mips.c
7183 @@ -832,7 +832,7 @@ long kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
7184 return r;
7185 }
7186
7187 -int kvm_arch_init(void *opaque)
7188 +int kvm_arch_init(const void *opaque)
7189 {
7190 int ret;
7191
7192 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
7193 index becc42b..9e43d4b 100644
7194 --- a/arch/mips/mm/fault.c
7195 +++ b/arch/mips/mm/fault.c
7196 @@ -28,6 +28,23 @@
7197 #include <asm/highmem.h> /* For VMALLOC_END */
7198 #include <linux/kdebug.h>
7199
7200 +#ifdef CONFIG_PAX_PAGEEXEC
7201 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7202 +{
7203 + unsigned long i;
7204 +
7205 + printk(KERN_ERR "PAX: bytes at PC: ");
7206 + for (i = 0; i < 5; i++) {
7207 + unsigned int c;
7208 + if (get_user(c, (unsigned int *)pc+i))
7209 + printk(KERN_CONT "???????? ");
7210 + else
7211 + printk(KERN_CONT "%08x ", c);
7212 + }
7213 + printk("\n");
7214 +}
7215 +#endif
7216 +
7217 /*
7218 * This routine handles page faults. It determines the address,
7219 * and the problem, and then passes it off to one of the appropriate
7220 @@ -199,6 +216,14 @@ bad_area:
7221 bad_area_nosemaphore:
7222 /* User mode accesses just cause a SIGSEGV */
7223 if (user_mode(regs)) {
7224 +
7225 +#ifdef CONFIG_PAX_PAGEEXEC
7226 + if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
7227 + pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
7228 + do_group_exit(SIGKILL);
7229 + }
7230 +#endif
7231 +
7232 tsk->thread.cp0_badvaddr = address;
7233 tsk->thread.error_code = write;
7234 #if 0
7235 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
7236 index f1baadd..5472dca 100644
7237 --- a/arch/mips/mm/mmap.c
7238 +++ b/arch/mips/mm/mmap.c
7239 @@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7240 struct vm_area_struct *vma;
7241 unsigned long addr = addr0;
7242 int do_color_align;
7243 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7244 struct vm_unmapped_area_info info;
7245
7246 if (unlikely(len > TASK_SIZE))
7247 @@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7248 do_color_align = 1;
7249
7250 /* requesting a specific address */
7251 +
7252 +#ifdef CONFIG_PAX_RANDMMAP
7253 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7254 +#endif
7255 +
7256 if (addr) {
7257 if (do_color_align)
7258 addr = COLOUR_ALIGN(addr, pgoff);
7259 @@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7260 addr = PAGE_ALIGN(addr);
7261
7262 vma = find_vma(mm, addr);
7263 - if (TASK_SIZE - len >= addr &&
7264 - (!vma || addr + len <= vma->vm_start))
7265 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7266 return addr;
7267 }
7268
7269 info.length = len;
7270 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
7271 info.align_offset = pgoff << PAGE_SHIFT;
7272 + info.threadstack_offset = offset;
7273
7274 if (dir == DOWN) {
7275 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
7276 @@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7277 {
7278 unsigned long random_factor = 0UL;
7279
7280 +#ifdef CONFIG_PAX_RANDMMAP
7281 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7282 +#endif
7283 +
7284 if (current->flags & PF_RANDOMIZE) {
7285 random_factor = get_random_int();
7286 random_factor = random_factor << PAGE_SHIFT;
7287 @@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7288
7289 if (mmap_is_legacy()) {
7290 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7291 +
7292 +#ifdef CONFIG_PAX_RANDMMAP
7293 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7294 + mm->mmap_base += mm->delta_mmap;
7295 +#endif
7296 +
7297 mm->get_unmapped_area = arch_get_unmapped_area;
7298 } else {
7299 mm->mmap_base = mmap_base(random_factor);
7300 +
7301 +#ifdef CONFIG_PAX_RANDMMAP
7302 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7303 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7304 +#endif
7305 +
7306 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7307 }
7308 }
7309
7310 -static inline unsigned long brk_rnd(void)
7311 -{
7312 - unsigned long rnd = get_random_int();
7313 -
7314 - rnd = rnd << PAGE_SHIFT;
7315 - /* 8MB for 32bit, 256MB for 64bit */
7316 - if (TASK_IS_32BIT_ADDR)
7317 - rnd = rnd & 0x7ffffful;
7318 - else
7319 - rnd = rnd & 0xffffffful;
7320 -
7321 - return rnd;
7322 -}
7323 -
7324 -unsigned long arch_randomize_brk(struct mm_struct *mm)
7325 -{
7326 - unsigned long base = mm->brk;
7327 - unsigned long ret;
7328 -
7329 - ret = PAGE_ALIGN(base + brk_rnd());
7330 -
7331 - if (ret < mm->brk)
7332 - return mm->brk;
7333 -
7334 - return ret;
7335 -}
7336 -
7337 int __virt_addr_valid(const volatile void *kaddr)
7338 {
7339 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
7340 diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
7341 index 59cccd9..f39ac2f 100644
7342 --- a/arch/mips/pci/pci-octeon.c
7343 +++ b/arch/mips/pci/pci-octeon.c
7344 @@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7345
7346
7347 static struct pci_ops octeon_pci_ops = {
7348 - octeon_read_config,
7349 - octeon_write_config,
7350 + .read = octeon_read_config,
7351 + .write = octeon_write_config,
7352 };
7353
7354 static struct resource octeon_pci_mem_resource = {
7355 diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7356 index 5e36c33..eb4a17b 100644
7357 --- a/arch/mips/pci/pcie-octeon.c
7358 +++ b/arch/mips/pci/pcie-octeon.c
7359 @@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7360 }
7361
7362 static struct pci_ops octeon_pcie0_ops = {
7363 - octeon_pcie0_read_config,
7364 - octeon_pcie0_write_config,
7365 + .read = octeon_pcie0_read_config,
7366 + .write = octeon_pcie0_write_config,
7367 };
7368
7369 static struct resource octeon_pcie0_mem_resource = {
7370 @@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7371 };
7372
7373 static struct pci_ops octeon_pcie1_ops = {
7374 - octeon_pcie1_read_config,
7375 - octeon_pcie1_write_config,
7376 + .read = octeon_pcie1_read_config,
7377 + .write = octeon_pcie1_write_config,
7378 };
7379
7380 static struct resource octeon_pcie1_mem_resource = {
7381 @@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7382 };
7383
7384 static struct pci_ops octeon_dummy_ops = {
7385 - octeon_dummy_read_config,
7386 - octeon_dummy_write_config,
7387 + .read = octeon_dummy_read_config,
7388 + .write = octeon_dummy_write_config,
7389 };
7390
7391 static struct resource octeon_dummy_mem_resource = {
7392 diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7393 index a2358b4..7cead4f 100644
7394 --- a/arch/mips/sgi-ip27/ip27-nmi.c
7395 +++ b/arch/mips/sgi-ip27/ip27-nmi.c
7396 @@ -187,9 +187,9 @@ void
7397 cont_nmi_dump(void)
7398 {
7399 #ifndef REAL_NMI_SIGNAL
7400 - static atomic_t nmied_cpus = ATOMIC_INIT(0);
7401 + static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7402
7403 - atomic_inc(&nmied_cpus);
7404 + atomic_inc_unchecked(&nmied_cpus);
7405 #endif
7406 /*
7407 * Only allow 1 cpu to proceed
7408 @@ -233,7 +233,7 @@ cont_nmi_dump(void)
7409 udelay(10000);
7410 }
7411 #else
7412 - while (atomic_read(&nmied_cpus) != num_online_cpus());
7413 + while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7414 #endif
7415
7416 /*
7417 diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7418 index a046b30..6799527 100644
7419 --- a/arch/mips/sni/rm200.c
7420 +++ b/arch/mips/sni/rm200.c
7421 @@ -270,7 +270,7 @@ spurious_8259A_irq:
7422 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7423 spurious_irq_mask |= irqmask;
7424 }
7425 - atomic_inc(&irq_err_count);
7426 + atomic_inc_unchecked(&irq_err_count);
7427 /*
7428 * Theoretically we do not have to handle this IRQ,
7429 * but in Linux this does not cause problems and is
7430 diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7431 index 41e873b..34d33a7 100644
7432 --- a/arch/mips/vr41xx/common/icu.c
7433 +++ b/arch/mips/vr41xx/common/icu.c
7434 @@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7435
7436 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7437
7438 - atomic_inc(&irq_err_count);
7439 + atomic_inc_unchecked(&irq_err_count);
7440
7441 return -1;
7442 }
7443 diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7444 index ae0e4ee..e8f0692 100644
7445 --- a/arch/mips/vr41xx/common/irq.c
7446 +++ b/arch/mips/vr41xx/common/irq.c
7447 @@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7448 irq_cascade_t *cascade;
7449
7450 if (irq >= NR_IRQS) {
7451 - atomic_inc(&irq_err_count);
7452 + atomic_inc_unchecked(&irq_err_count);
7453 return;
7454 }
7455
7456 @@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7457 ret = cascade->get_irq(irq);
7458 irq = ret;
7459 if (ret < 0)
7460 - atomic_inc(&irq_err_count);
7461 + atomic_inc_unchecked(&irq_err_count);
7462 else
7463 irq_dispatch(irq);
7464 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7465 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7466 index 967d144..db12197 100644
7467 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7468 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7469 @@ -11,12 +11,14 @@
7470 #ifndef _ASM_PROC_CACHE_H
7471 #define _ASM_PROC_CACHE_H
7472
7473 +#include <linux/const.h>
7474 +
7475 /* L1 cache */
7476
7477 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7478 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7479 -#define L1_CACHE_BYTES 16 /* bytes per entry */
7480 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7481 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7482 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7483
7484 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7485 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7486 index bcb5df2..84fabd2 100644
7487 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7488 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7489 @@ -16,13 +16,15 @@
7490 #ifndef _ASM_PROC_CACHE_H
7491 #define _ASM_PROC_CACHE_H
7492
7493 +#include <linux/const.h>
7494 +
7495 /*
7496 * L1 cache
7497 */
7498 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7499 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7500 -#define L1_CACHE_BYTES 32 /* bytes per entry */
7501 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7502 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7503 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7504
7505 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7506 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7507 index 4ce7a01..449202a 100644
7508 --- a/arch/openrisc/include/asm/cache.h
7509 +++ b/arch/openrisc/include/asm/cache.h
7510 @@ -19,11 +19,13 @@
7511 #ifndef __ASM_OPENRISC_CACHE_H
7512 #define __ASM_OPENRISC_CACHE_H
7513
7514 +#include <linux/const.h>
7515 +
7516 /* FIXME: How can we replace these with values from the CPU...
7517 * they shouldn't be hard-coded!
7518 */
7519
7520 -#define L1_CACHE_BYTES 16
7521 #define L1_CACHE_SHIFT 4
7522 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7523
7524 #endif /* __ASM_OPENRISC_CACHE_H */
7525 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7526 index 472886c..00e7df9 100644
7527 --- a/arch/parisc/include/asm/atomic.h
7528 +++ b/arch/parisc/include/asm/atomic.h
7529 @@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7530 return dec;
7531 }
7532
7533 +#define atomic64_read_unchecked(v) atomic64_read(v)
7534 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7535 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7536 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7537 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7538 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7539 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7540 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7541 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7542 +
7543 #endif /* !CONFIG_64BIT */
7544
7545
7546 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7547 index 47f11c7..3420df2 100644
7548 --- a/arch/parisc/include/asm/cache.h
7549 +++ b/arch/parisc/include/asm/cache.h
7550 @@ -5,6 +5,7 @@
7551 #ifndef __ARCH_PARISC_CACHE_H
7552 #define __ARCH_PARISC_CACHE_H
7553
7554 +#include <linux/const.h>
7555
7556 /*
7557 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7558 @@ -15,13 +16,13 @@
7559 * just ruin performance.
7560 */
7561 #ifdef CONFIG_PA20
7562 -#define L1_CACHE_BYTES 64
7563 #define L1_CACHE_SHIFT 6
7564 #else
7565 -#define L1_CACHE_BYTES 32
7566 #define L1_CACHE_SHIFT 5
7567 #endif
7568
7569 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7570 +
7571 #ifndef __ASSEMBLY__
7572
7573 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7574 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7575 index 3391d06..c23a2cc 100644
7576 --- a/arch/parisc/include/asm/elf.h
7577 +++ b/arch/parisc/include/asm/elf.h
7578 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7579
7580 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7581
7582 +#ifdef CONFIG_PAX_ASLR
7583 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
7584 +
7585 +#define PAX_DELTA_MMAP_LEN 16
7586 +#define PAX_DELTA_STACK_LEN 16
7587 +#endif
7588 +
7589 /* This yields a mask that user programs can use to figure out what
7590 instruction set this CPU supports. This could be done in user space,
7591 but it's not easy, and we've already done it here. */
7592 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7593 index f213f5b..0af3e8e 100644
7594 --- a/arch/parisc/include/asm/pgalloc.h
7595 +++ b/arch/parisc/include/asm/pgalloc.h
7596 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7597 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7598 }
7599
7600 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7601 +{
7602 + pgd_populate(mm, pgd, pmd);
7603 +}
7604 +
7605 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7606 {
7607 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7608 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7609 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7610 #define pmd_free(mm, x) do { } while (0)
7611 #define pgd_populate(mm, pmd, pte) BUG()
7612 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
7613
7614 #endif
7615
7616 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7617 index 22b89d1..ce34230 100644
7618 --- a/arch/parisc/include/asm/pgtable.h
7619 +++ b/arch/parisc/include/asm/pgtable.h
7620 @@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7621 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7622 #define PAGE_COPY PAGE_EXECREAD
7623 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7624 +
7625 +#ifdef CONFIG_PAX_PAGEEXEC
7626 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7627 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7628 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7629 +#else
7630 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
7631 +# define PAGE_COPY_NOEXEC PAGE_COPY
7632 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
7633 +#endif
7634 +
7635 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7636 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7637 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7638 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7639 index 4006964..fcb3cc2 100644
7640 --- a/arch/parisc/include/asm/uaccess.h
7641 +++ b/arch/parisc/include/asm/uaccess.h
7642 @@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7643 const void __user *from,
7644 unsigned long n)
7645 {
7646 - int sz = __compiletime_object_size(to);
7647 + size_t sz = __compiletime_object_size(to);
7648 int ret = -EFAULT;
7649
7650 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7651 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7652 ret = __copy_from_user(to, from, n);
7653 else
7654 copy_from_user_overflow();
7655 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7656 index 50dfafc..b9fc230 100644
7657 --- a/arch/parisc/kernel/module.c
7658 +++ b/arch/parisc/kernel/module.c
7659 @@ -98,16 +98,38 @@
7660
7661 /* three functions to determine where in the module core
7662 * or init pieces the location is */
7663 +static inline int in_init_rx(struct module *me, void *loc)
7664 +{
7665 + return (loc >= me->module_init_rx &&
7666 + loc < (me->module_init_rx + me->init_size_rx));
7667 +}
7668 +
7669 +static inline int in_init_rw(struct module *me, void *loc)
7670 +{
7671 + return (loc >= me->module_init_rw &&
7672 + loc < (me->module_init_rw + me->init_size_rw));
7673 +}
7674 +
7675 static inline int in_init(struct module *me, void *loc)
7676 {
7677 - return (loc >= me->module_init &&
7678 - loc <= (me->module_init + me->init_size));
7679 + return in_init_rx(me, loc) || in_init_rw(me, loc);
7680 +}
7681 +
7682 +static inline int in_core_rx(struct module *me, void *loc)
7683 +{
7684 + return (loc >= me->module_core_rx &&
7685 + loc < (me->module_core_rx + me->core_size_rx));
7686 +}
7687 +
7688 +static inline int in_core_rw(struct module *me, void *loc)
7689 +{
7690 + return (loc >= me->module_core_rw &&
7691 + loc < (me->module_core_rw + me->core_size_rw));
7692 }
7693
7694 static inline int in_core(struct module *me, void *loc)
7695 {
7696 - return (loc >= me->module_core &&
7697 - loc <= (me->module_core + me->core_size));
7698 + return in_core_rx(me, loc) || in_core_rw(me, loc);
7699 }
7700
7701 static inline int in_local(struct module *me, void *loc)
7702 @@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7703 }
7704
7705 /* align things a bit */
7706 - me->core_size = ALIGN(me->core_size, 16);
7707 - me->arch.got_offset = me->core_size;
7708 - me->core_size += gots * sizeof(struct got_entry);
7709 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7710 + me->arch.got_offset = me->core_size_rw;
7711 + me->core_size_rw += gots * sizeof(struct got_entry);
7712
7713 - me->core_size = ALIGN(me->core_size, 16);
7714 - me->arch.fdesc_offset = me->core_size;
7715 - me->core_size += fdescs * sizeof(Elf_Fdesc);
7716 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7717 + me->arch.fdesc_offset = me->core_size_rw;
7718 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7719
7720 me->arch.got_max = gots;
7721 me->arch.fdesc_max = fdescs;
7722 @@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7723
7724 BUG_ON(value == 0);
7725
7726 - got = me->module_core + me->arch.got_offset;
7727 + got = me->module_core_rw + me->arch.got_offset;
7728 for (i = 0; got[i].addr; i++)
7729 if (got[i].addr == value)
7730 goto out;
7731 @@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7732 #ifdef CONFIG_64BIT
7733 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7734 {
7735 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7736 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7737
7738 if (!value) {
7739 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7740 @@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7741
7742 /* Create new one */
7743 fdesc->addr = value;
7744 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7745 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7746 return (Elf_Addr)fdesc;
7747 }
7748 #endif /* CONFIG_64BIT */
7749 @@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7750
7751 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7752 end = table + sechdrs[me->arch.unwind_section].sh_size;
7753 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7754 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7755
7756 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7757 me->arch.unwind_section, table, end, gp);
7758 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7759 index e1ffea2..46ed66e 100644
7760 --- a/arch/parisc/kernel/sys_parisc.c
7761 +++ b/arch/parisc/kernel/sys_parisc.c
7762 @@ -89,6 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7763 unsigned long task_size = TASK_SIZE;
7764 int do_color_align, last_mmap;
7765 struct vm_unmapped_area_info info;
7766 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7767
7768 if (len > task_size)
7769 return -ENOMEM;
7770 @@ -106,6 +107,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7771 goto found_addr;
7772 }
7773
7774 +#ifdef CONFIG_PAX_RANDMMAP
7775 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7776 +#endif
7777 +
7778 if (addr) {
7779 if (do_color_align && last_mmap)
7780 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7781 @@ -124,6 +129,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7782 info.high_limit = mmap_upper_limit();
7783 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7784 info.align_offset = shared_align_offset(last_mmap, pgoff);
7785 + info.threadstack_offset = offset;
7786 addr = vm_unmapped_area(&info);
7787
7788 found_addr:
7789 @@ -143,6 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7790 unsigned long addr = addr0;
7791 int do_color_align, last_mmap;
7792 struct vm_unmapped_area_info info;
7793 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7794
7795 #ifdef CONFIG_64BIT
7796 /* This should only ever run for 32-bit processes. */
7797 @@ -167,6 +174,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7798 }
7799
7800 /* requesting a specific address */
7801 +#ifdef CONFIG_PAX_RANDMMAP
7802 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7803 +#endif
7804 +
7805 if (addr) {
7806 if (do_color_align && last_mmap)
7807 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7808 @@ -184,6 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7809 info.high_limit = mm->mmap_base;
7810 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7811 info.align_offset = shared_align_offset(last_mmap, pgoff);
7812 + info.threadstack_offset = offset;
7813 addr = vm_unmapped_area(&info);
7814 if (!(addr & ~PAGE_MASK))
7815 goto found_addr;
7816 @@ -249,6 +261,13 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7817 mm->mmap_legacy_base = mmap_legacy_base();
7818 mm->mmap_base = mmap_upper_limit();
7819
7820 +#ifdef CONFIG_PAX_RANDMMAP
7821 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
7822 + mm->mmap_legacy_base += mm->delta_mmap;
7823 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7824 + }
7825 +#endif
7826 +
7827 if (mmap_is_legacy()) {
7828 mm->mmap_base = mm->mmap_legacy_base;
7829 mm->get_unmapped_area = arch_get_unmapped_area;
7830 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7831 index 47ee620..1107387 100644
7832 --- a/arch/parisc/kernel/traps.c
7833 +++ b/arch/parisc/kernel/traps.c
7834 @@ -726,9 +726,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7835
7836 down_read(&current->mm->mmap_sem);
7837 vma = find_vma(current->mm,regs->iaoq[0]);
7838 - if (vma && (regs->iaoq[0] >= vma->vm_start)
7839 - && (vma->vm_flags & VM_EXEC)) {
7840 -
7841 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7842 fault_address = regs->iaoq[0];
7843 fault_space = regs->iasq[0];
7844
7845 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7846 index 3ca9c11..d163ef7 100644
7847 --- a/arch/parisc/mm/fault.c
7848 +++ b/arch/parisc/mm/fault.c
7849 @@ -15,6 +15,7 @@
7850 #include <linux/sched.h>
7851 #include <linux/interrupt.h>
7852 #include <linux/module.h>
7853 +#include <linux/unistd.h>
7854
7855 #include <asm/uaccess.h>
7856 #include <asm/traps.h>
7857 @@ -50,7 +51,7 @@ int show_unhandled_signals = 1;
7858 static unsigned long
7859 parisc_acctyp(unsigned long code, unsigned int inst)
7860 {
7861 - if (code == 6 || code == 16)
7862 + if (code == 6 || code == 7 || code == 16)
7863 return VM_EXEC;
7864
7865 switch (inst & 0xf0000000) {
7866 @@ -136,6 +137,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7867 }
7868 #endif
7869
7870 +#ifdef CONFIG_PAX_PAGEEXEC
7871 +/*
7872 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7873 + *
7874 + * returns 1 when task should be killed
7875 + * 2 when rt_sigreturn trampoline was detected
7876 + * 3 when unpatched PLT trampoline was detected
7877 + */
7878 +static int pax_handle_fetch_fault(struct pt_regs *regs)
7879 +{
7880 +
7881 +#ifdef CONFIG_PAX_EMUPLT
7882 + int err;
7883 +
7884 + do { /* PaX: unpatched PLT emulation */
7885 + unsigned int bl, depwi;
7886 +
7887 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7888 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7889 +
7890 + if (err)
7891 + break;
7892 +
7893 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7894 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7895 +
7896 + err = get_user(ldw, (unsigned int *)addr);
7897 + err |= get_user(bv, (unsigned int *)(addr+4));
7898 + err |= get_user(ldw2, (unsigned int *)(addr+8));
7899 +
7900 + if (err)
7901 + break;
7902 +
7903 + if (ldw == 0x0E801096U &&
7904 + bv == 0xEAC0C000U &&
7905 + ldw2 == 0x0E881095U)
7906 + {
7907 + unsigned int resolver, map;
7908 +
7909 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7910 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7911 + if (err)
7912 + break;
7913 +
7914 + regs->gr[20] = instruction_pointer(regs)+8;
7915 + regs->gr[21] = map;
7916 + regs->gr[22] = resolver;
7917 + regs->iaoq[0] = resolver | 3UL;
7918 + regs->iaoq[1] = regs->iaoq[0] + 4;
7919 + return 3;
7920 + }
7921 + }
7922 + } while (0);
7923 +#endif
7924 +
7925 +#ifdef CONFIG_PAX_EMUTRAMP
7926 +
7927 +#ifndef CONFIG_PAX_EMUSIGRT
7928 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7929 + return 1;
7930 +#endif
7931 +
7932 + do { /* PaX: rt_sigreturn emulation */
7933 + unsigned int ldi1, ldi2, bel, nop;
7934 +
7935 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7936 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7937 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7938 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7939 +
7940 + if (err)
7941 + break;
7942 +
7943 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7944 + ldi2 == 0x3414015AU &&
7945 + bel == 0xE4008200U &&
7946 + nop == 0x08000240U)
7947 + {
7948 + regs->gr[25] = (ldi1 & 2) >> 1;
7949 + regs->gr[20] = __NR_rt_sigreturn;
7950 + regs->gr[31] = regs->iaoq[1] + 16;
7951 + regs->sr[0] = regs->iasq[1];
7952 + regs->iaoq[0] = 0x100UL;
7953 + regs->iaoq[1] = regs->iaoq[0] + 4;
7954 + regs->iasq[0] = regs->sr[2];
7955 + regs->iasq[1] = regs->sr[2];
7956 + return 2;
7957 + }
7958 + } while (0);
7959 +#endif
7960 +
7961 + return 1;
7962 +}
7963 +
7964 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7965 +{
7966 + unsigned long i;
7967 +
7968 + printk(KERN_ERR "PAX: bytes at PC: ");
7969 + for (i = 0; i < 5; i++) {
7970 + unsigned int c;
7971 + if (get_user(c, (unsigned int *)pc+i))
7972 + printk(KERN_CONT "???????? ");
7973 + else
7974 + printk(KERN_CONT "%08x ", c);
7975 + }
7976 + printk("\n");
7977 +}
7978 +#endif
7979 +
7980 int fixup_exception(struct pt_regs *regs)
7981 {
7982 const struct exception_table_entry *fix;
7983 @@ -234,8 +345,33 @@ retry:
7984
7985 good_area:
7986
7987 - if ((vma->vm_flags & acc_type) != acc_type)
7988 + if ((vma->vm_flags & acc_type) != acc_type) {
7989 +
7990 +#ifdef CONFIG_PAX_PAGEEXEC
7991 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7992 + (address & ~3UL) == instruction_pointer(regs))
7993 + {
7994 + up_read(&mm->mmap_sem);
7995 + switch (pax_handle_fetch_fault(regs)) {
7996 +
7997 +#ifdef CONFIG_PAX_EMUPLT
7998 + case 3:
7999 + return;
8000 +#endif
8001 +
8002 +#ifdef CONFIG_PAX_EMUTRAMP
8003 + case 2:
8004 + return;
8005 +#endif
8006 +
8007 + }
8008 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
8009 + do_group_exit(SIGKILL);
8010 + }
8011 +#endif
8012 +
8013 goto bad_area;
8014 + }
8015
8016 /*
8017 * If for any reason at all we couldn't handle the fault, make
8018 diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
8019 index 004851f..c15e65a 100644
8020 --- a/arch/powerpc/Kconfig
8021 +++ b/arch/powerpc/Kconfig
8022 @@ -398,6 +398,7 @@ config PPC64_SUPPORTS_MEMORY_FAILURE
8023 config KEXEC
8024 bool "kexec system call"
8025 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
8026 + depends on !GRKERNSEC_KMEM
8027 help
8028 kexec is a system call that implements the ability to shutdown your
8029 current kernel, and to start another kernel. It is like a reboot
8030 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
8031 index e3b1d41..8e81edf 100644
8032 --- a/arch/powerpc/include/asm/atomic.h
8033 +++ b/arch/powerpc/include/asm/atomic.h
8034 @@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
8035 return t1;
8036 }
8037
8038 +#define atomic64_read_unchecked(v) atomic64_read(v)
8039 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8040 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8041 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8042 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8043 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
8044 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8045 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
8046 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8047 +
8048 #endif /* __powerpc64__ */
8049
8050 #endif /* __KERNEL__ */
8051 diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
8052 index f89da80..7f5b05a 100644
8053 --- a/arch/powerpc/include/asm/barrier.h
8054 +++ b/arch/powerpc/include/asm/barrier.h
8055 @@ -73,7 +73,7 @@
8056 do { \
8057 compiletime_assert_atomic_type(*p); \
8058 __lwsync(); \
8059 - ACCESS_ONCE(*p) = (v); \
8060 + ACCESS_ONCE_RW(*p) = (v); \
8061 } while (0)
8062
8063 #define smp_load_acquire(p) \
8064 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
8065 index ed0afc1..0332825 100644
8066 --- a/arch/powerpc/include/asm/cache.h
8067 +++ b/arch/powerpc/include/asm/cache.h
8068 @@ -3,6 +3,7 @@
8069
8070 #ifdef __KERNEL__
8071
8072 +#include <linux/const.h>
8073
8074 /* bytes per L1 cache line */
8075 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
8076 @@ -22,7 +23,7 @@
8077 #define L1_CACHE_SHIFT 7
8078 #endif
8079
8080 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8081 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8082
8083 #define SMP_CACHE_BYTES L1_CACHE_BYTES
8084
8085 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
8086 index 935b5e7..7001d2d 100644
8087 --- a/arch/powerpc/include/asm/elf.h
8088 +++ b/arch/powerpc/include/asm/elf.h
8089 @@ -28,8 +28,19 @@
8090 the loader. We need to make sure that it is out of the way of the program
8091 that it will "exec", and that there is sufficient room for the brk. */
8092
8093 -extern unsigned long randomize_et_dyn(unsigned long base);
8094 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
8095 +#define ELF_ET_DYN_BASE (0x20000000)
8096 +
8097 +#ifdef CONFIG_PAX_ASLR
8098 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
8099 +
8100 +#ifdef __powerpc64__
8101 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
8102 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
8103 +#else
8104 +#define PAX_DELTA_MMAP_LEN 15
8105 +#define PAX_DELTA_STACK_LEN 15
8106 +#endif
8107 +#endif
8108
8109 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
8110
8111 @@ -127,10 +138,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
8112 (0x7ff >> (PAGE_SHIFT - 12)) : \
8113 (0x3ffff >> (PAGE_SHIFT - 12)))
8114
8115 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8116 -#define arch_randomize_brk arch_randomize_brk
8117 -
8118 -
8119 #ifdef CONFIG_SPU_BASE
8120 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
8121 #define NT_SPU 1
8122 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
8123 index 8196e9c..d83a9f3 100644
8124 --- a/arch/powerpc/include/asm/exec.h
8125 +++ b/arch/powerpc/include/asm/exec.h
8126 @@ -4,6 +4,6 @@
8127 #ifndef _ASM_POWERPC_EXEC_H
8128 #define _ASM_POWERPC_EXEC_H
8129
8130 -extern unsigned long arch_align_stack(unsigned long sp);
8131 +#define arch_align_stack(x) ((x) & ~0xfUL)
8132
8133 #endif /* _ASM_POWERPC_EXEC_H */
8134 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
8135 index 5acabbd..7ea14fa 100644
8136 --- a/arch/powerpc/include/asm/kmap_types.h
8137 +++ b/arch/powerpc/include/asm/kmap_types.h
8138 @@ -10,7 +10,7 @@
8139 * 2 of the License, or (at your option) any later version.
8140 */
8141
8142 -#define KM_TYPE_NR 16
8143 +#define KM_TYPE_NR 17
8144
8145 #endif /* __KERNEL__ */
8146 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
8147 diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
8148 index b8da913..60b608a 100644
8149 --- a/arch/powerpc/include/asm/local.h
8150 +++ b/arch/powerpc/include/asm/local.h
8151 @@ -9,15 +9,26 @@ typedef struct
8152 atomic_long_t a;
8153 } local_t;
8154
8155 +typedef struct
8156 +{
8157 + atomic_long_unchecked_t a;
8158 +} local_unchecked_t;
8159 +
8160 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
8161
8162 #define local_read(l) atomic_long_read(&(l)->a)
8163 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
8164 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
8165 +#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
8166
8167 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
8168 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
8169 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
8170 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
8171 #define local_inc(l) atomic_long_inc(&(l)->a)
8172 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
8173 #define local_dec(l) atomic_long_dec(&(l)->a)
8174 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
8175
8176 static __inline__ long local_add_return(long a, local_t *l)
8177 {
8178 @@ -35,6 +46,7 @@ static __inline__ long local_add_return(long a, local_t *l)
8179
8180 return t;
8181 }
8182 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
8183
8184 #define local_add_negative(a, l) (local_add_return((a), (l)) < 0)
8185
8186 @@ -54,6 +66,7 @@ static __inline__ long local_sub_return(long a, local_t *l)
8187
8188 return t;
8189 }
8190 +#define local_sub_return_unchecked(i, l) atomic_long_sub_return_unchecked((i), (&(l)->a))
8191
8192 static __inline__ long local_inc_return(local_t *l)
8193 {
8194 @@ -101,6 +114,8 @@ static __inline__ long local_dec_return(local_t *l)
8195
8196 #define local_cmpxchg(l, o, n) \
8197 (cmpxchg_local(&((l)->a.counter), (o), (n)))
8198 +#define local_cmpxchg_unchecked(l, o, n) \
8199 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
8200 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
8201
8202 /**
8203 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
8204 index 8565c25..2865190 100644
8205 --- a/arch/powerpc/include/asm/mman.h
8206 +++ b/arch/powerpc/include/asm/mman.h
8207 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
8208 }
8209 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
8210
8211 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
8212 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8213 {
8214 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
8215 }
8216 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
8217 index 32e4e21..62afb12 100644
8218 --- a/arch/powerpc/include/asm/page.h
8219 +++ b/arch/powerpc/include/asm/page.h
8220 @@ -230,8 +230,9 @@ extern long long virt_phys_offset;
8221 * and needs to be executable. This means the whole heap ends
8222 * up being executable.
8223 */
8224 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8225 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8226 +#define VM_DATA_DEFAULT_FLAGS32 \
8227 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8228 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8229
8230 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8231 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8232 @@ -259,6 +260,9 @@ extern long long virt_phys_offset;
8233 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
8234 #endif
8235
8236 +#define ktla_ktva(addr) (addr)
8237 +#define ktva_ktla(addr) (addr)
8238 +
8239 #ifndef CONFIG_PPC_BOOK3S_64
8240 /*
8241 * Use the top bit of the higher-level page table entries to indicate whether
8242 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
8243 index 88693ce..ac6f9ab 100644
8244 --- a/arch/powerpc/include/asm/page_64.h
8245 +++ b/arch/powerpc/include/asm/page_64.h
8246 @@ -153,15 +153,18 @@ do { \
8247 * stack by default, so in the absence of a PT_GNU_STACK program header
8248 * we turn execute permission off.
8249 */
8250 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8251 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8252 +#define VM_STACK_DEFAULT_FLAGS32 \
8253 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8254 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8255
8256 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8257 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8258
8259 +#ifndef CONFIG_PAX_PAGEEXEC
8260 #define VM_STACK_DEFAULT_FLAGS \
8261 (is_32bit_task() ? \
8262 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
8263 +#endif
8264
8265 #include <asm-generic/getorder.h>
8266
8267 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
8268 index 4b0be20..c15a27d 100644
8269 --- a/arch/powerpc/include/asm/pgalloc-64.h
8270 +++ b/arch/powerpc/include/asm/pgalloc-64.h
8271 @@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8272 #ifndef CONFIG_PPC_64K_PAGES
8273
8274 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
8275 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
8276
8277 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
8278 {
8279 @@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8280 pud_set(pud, (unsigned long)pmd);
8281 }
8282
8283 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8284 +{
8285 + pud_populate(mm, pud, pmd);
8286 +}
8287 +
8288 #define pmd_populate(mm, pmd, pte_page) \
8289 pmd_populate_kernel(mm, pmd, page_address(pte_page))
8290 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
8291 @@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
8292 #endif
8293
8294 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
8295 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8296
8297 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
8298 pte_t *pte)
8299 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
8300 index 3ebb188..e17dddf 100644
8301 --- a/arch/powerpc/include/asm/pgtable.h
8302 +++ b/arch/powerpc/include/asm/pgtable.h
8303 @@ -2,6 +2,7 @@
8304 #define _ASM_POWERPC_PGTABLE_H
8305 #ifdef __KERNEL__
8306
8307 +#include <linux/const.h>
8308 #ifndef __ASSEMBLY__
8309 #include <linux/mmdebug.h>
8310 #include <asm/processor.h> /* For TASK_SIZE */
8311 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
8312 index 4aad413..85d86bf 100644
8313 --- a/arch/powerpc/include/asm/pte-hash32.h
8314 +++ b/arch/powerpc/include/asm/pte-hash32.h
8315 @@ -21,6 +21,7 @@
8316 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
8317 #define _PAGE_USER 0x004 /* usermode access allowed */
8318 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
8319 +#define _PAGE_EXEC _PAGE_GUARDED
8320 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
8321 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
8322 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
8323 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
8324 index e5d2e0b..9ac74b1 100644
8325 --- a/arch/powerpc/include/asm/reg.h
8326 +++ b/arch/powerpc/include/asm/reg.h
8327 @@ -249,6 +249,7 @@
8328 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
8329 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
8330 #define DSISR_NOHPTE 0x40000000 /* no translation found */
8331 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
8332 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
8333 #define DSISR_ISSTORE 0x02000000 /* access was a store */
8334 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
8335 diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
8336 index ff51046..b982dd4 100644
8337 --- a/arch/powerpc/include/asm/smp.h
8338 +++ b/arch/powerpc/include/asm/smp.h
8339 @@ -51,7 +51,7 @@ struct smp_ops_t {
8340 int (*cpu_disable)(void);
8341 void (*cpu_die)(unsigned int nr);
8342 int (*cpu_bootable)(unsigned int nr);
8343 -};
8344 +} __no_const;
8345
8346 extern void smp_send_debugger_break(void);
8347 extern void start_secondary_resume(void);
8348 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
8349 index b034ecd..af7e31f 100644
8350 --- a/arch/powerpc/include/asm/thread_info.h
8351 +++ b/arch/powerpc/include/asm/thread_info.h
8352 @@ -107,6 +107,8 @@ static inline struct thread_info *current_thread_info(void)
8353 #if defined(CONFIG_PPC64)
8354 #define TIF_ELF2ABI 18 /* function descriptors must die! */
8355 #endif
8356 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
8357 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
8358
8359 /* as above, but as bit values */
8360 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8361 @@ -125,9 +127,10 @@ static inline struct thread_info *current_thread_info(void)
8362 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8363 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
8364 #define _TIF_NOHZ (1<<TIF_NOHZ)
8365 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8366 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
8367 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
8368 - _TIF_NOHZ)
8369 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
8370
8371 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
8372 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
8373 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
8374 index 9485b43..3bd3c16 100644
8375 --- a/arch/powerpc/include/asm/uaccess.h
8376 +++ b/arch/powerpc/include/asm/uaccess.h
8377 @@ -58,6 +58,7 @@
8378
8379 #endif
8380
8381 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
8382 #define access_ok(type, addr, size) \
8383 (__chk_user_ptr(addr), \
8384 __access_ok((__force unsigned long)(addr), (size), get_fs()))
8385 @@ -318,52 +319,6 @@ do { \
8386 extern unsigned long __copy_tofrom_user(void __user *to,
8387 const void __user *from, unsigned long size);
8388
8389 -#ifndef __powerpc64__
8390 -
8391 -static inline unsigned long copy_from_user(void *to,
8392 - const void __user *from, unsigned long n)
8393 -{
8394 - unsigned long over;
8395 -
8396 - if (access_ok(VERIFY_READ, from, n))
8397 - return __copy_tofrom_user((__force void __user *)to, from, n);
8398 - if ((unsigned long)from < TASK_SIZE) {
8399 - over = (unsigned long)from + n - TASK_SIZE;
8400 - return __copy_tofrom_user((__force void __user *)to, from,
8401 - n - over) + over;
8402 - }
8403 - return n;
8404 -}
8405 -
8406 -static inline unsigned long copy_to_user(void __user *to,
8407 - const void *from, unsigned long n)
8408 -{
8409 - unsigned long over;
8410 -
8411 - if (access_ok(VERIFY_WRITE, to, n))
8412 - return __copy_tofrom_user(to, (__force void __user *)from, n);
8413 - if ((unsigned long)to < TASK_SIZE) {
8414 - over = (unsigned long)to + n - TASK_SIZE;
8415 - return __copy_tofrom_user(to, (__force void __user *)from,
8416 - n - over) + over;
8417 - }
8418 - return n;
8419 -}
8420 -
8421 -#else /* __powerpc64__ */
8422 -
8423 -#define __copy_in_user(to, from, size) \
8424 - __copy_tofrom_user((to), (from), (size))
8425 -
8426 -extern unsigned long copy_from_user(void *to, const void __user *from,
8427 - unsigned long n);
8428 -extern unsigned long copy_to_user(void __user *to, const void *from,
8429 - unsigned long n);
8430 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
8431 - unsigned long n);
8432 -
8433 -#endif /* __powerpc64__ */
8434 -
8435 static inline unsigned long __copy_from_user_inatomic(void *to,
8436 const void __user *from, unsigned long n)
8437 {
8438 @@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
8439 if (ret == 0)
8440 return 0;
8441 }
8442 +
8443 + if (!__builtin_constant_p(n))
8444 + check_object_size(to, n, false);
8445 +
8446 return __copy_tofrom_user((__force void __user *)to, from, n);
8447 }
8448
8449 @@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
8450 if (ret == 0)
8451 return 0;
8452 }
8453 +
8454 + if (!__builtin_constant_p(n))
8455 + check_object_size(from, n, true);
8456 +
8457 return __copy_tofrom_user(to, (__force const void __user *)from, n);
8458 }
8459
8460 @@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
8461 return __copy_to_user_inatomic(to, from, size);
8462 }
8463
8464 +#ifndef __powerpc64__
8465 +
8466 +static inline unsigned long __must_check copy_from_user(void *to,
8467 + const void __user *from, unsigned long n)
8468 +{
8469 + unsigned long over;
8470 +
8471 + if ((long)n < 0)
8472 + return n;
8473 +
8474 + if (access_ok(VERIFY_READ, from, n)) {
8475 + if (!__builtin_constant_p(n))
8476 + check_object_size(to, n, false);
8477 + return __copy_tofrom_user((__force void __user *)to, from, n);
8478 + }
8479 + if ((unsigned long)from < TASK_SIZE) {
8480 + over = (unsigned long)from + n - TASK_SIZE;
8481 + if (!__builtin_constant_p(n - over))
8482 + check_object_size(to, n - over, false);
8483 + return __copy_tofrom_user((__force void __user *)to, from,
8484 + n - over) + over;
8485 + }
8486 + return n;
8487 +}
8488 +
8489 +static inline unsigned long __must_check copy_to_user(void __user *to,
8490 + const void *from, unsigned long n)
8491 +{
8492 + unsigned long over;
8493 +
8494 + if ((long)n < 0)
8495 + return n;
8496 +
8497 + if (access_ok(VERIFY_WRITE, to, n)) {
8498 + if (!__builtin_constant_p(n))
8499 + check_object_size(from, n, true);
8500 + return __copy_tofrom_user(to, (__force void __user *)from, n);
8501 + }
8502 + if ((unsigned long)to < TASK_SIZE) {
8503 + over = (unsigned long)to + n - TASK_SIZE;
8504 + if (!__builtin_constant_p(n))
8505 + check_object_size(from, n - over, true);
8506 + return __copy_tofrom_user(to, (__force void __user *)from,
8507 + n - over) + over;
8508 + }
8509 + return n;
8510 +}
8511 +
8512 +#else /* __powerpc64__ */
8513 +
8514 +#define __copy_in_user(to, from, size) \
8515 + __copy_tofrom_user((to), (from), (size))
8516 +
8517 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
8518 +{
8519 + if ((long)n < 0 || n > INT_MAX)
8520 + return n;
8521 +
8522 + if (!__builtin_constant_p(n))
8523 + check_object_size(to, n, false);
8524 +
8525 + if (likely(access_ok(VERIFY_READ, from, n)))
8526 + n = __copy_from_user(to, from, n);
8527 + else
8528 + memset(to, 0, n);
8529 + return n;
8530 +}
8531 +
8532 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8533 +{
8534 + if ((long)n < 0 || n > INT_MAX)
8535 + return n;
8536 +
8537 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
8538 + if (!__builtin_constant_p(n))
8539 + check_object_size(from, n, true);
8540 + n = __copy_to_user(to, from, n);
8541 + }
8542 + return n;
8543 +}
8544 +
8545 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
8546 + unsigned long n);
8547 +
8548 +#endif /* __powerpc64__ */
8549 +
8550 extern unsigned long __clear_user(void __user *addr, unsigned long size);
8551
8552 static inline unsigned long clear_user(void __user *addr, unsigned long size)
8553 diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
8554 index fcc9a89..07be2bb 100644
8555 --- a/arch/powerpc/kernel/Makefile
8556 +++ b/arch/powerpc/kernel/Makefile
8557 @@ -26,6 +26,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
8558 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
8559 endif
8560
8561 +CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8562 +
8563 obj-y := cputable.o ptrace.o syscalls.o \
8564 irq.o align.o signal_32.o pmc.o vdso.o \
8565 process.o systbl.o idle.o \
8566 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8567 index c1bee3c..5b42583 100644
8568 --- a/arch/powerpc/kernel/exceptions-64e.S
8569 +++ b/arch/powerpc/kernel/exceptions-64e.S
8570 @@ -1010,6 +1010,7 @@ storage_fault_common:
8571 std r14,_DAR(r1)
8572 std r15,_DSISR(r1)
8573 addi r3,r1,STACK_FRAME_OVERHEAD
8574 + bl .save_nvgprs
8575 mr r4,r14
8576 mr r5,r15
8577 ld r14,PACA_EXGEN+EX_R14(r13)
8578 @@ -1018,8 +1019,7 @@ storage_fault_common:
8579 cmpdi r3,0
8580 bne- 1f
8581 b .ret_from_except_lite
8582 -1: bl .save_nvgprs
8583 - mr r5,r3
8584 +1: mr r5,r3
8585 addi r3,r1,STACK_FRAME_OVERHEAD
8586 ld r4,_DAR(r1)
8587 bl .bad_page_fault
8588 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8589 index 3afd391..18f9e36 100644
8590 --- a/arch/powerpc/kernel/exceptions-64s.S
8591 +++ b/arch/powerpc/kernel/exceptions-64s.S
8592 @@ -1587,10 +1587,10 @@ handle_page_fault:
8593 11: ld r4,_DAR(r1)
8594 ld r5,_DSISR(r1)
8595 addi r3,r1,STACK_FRAME_OVERHEAD
8596 + bl .save_nvgprs
8597 bl .do_page_fault
8598 cmpdi r3,0
8599 beq+ 12f
8600 - bl .save_nvgprs
8601 mr r5,r3
8602 addi r3,r1,STACK_FRAME_OVERHEAD
8603 lwz r4,_DAR(r1)
8604 diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
8605 index ca1cd74..6f0241a 100644
8606 --- a/arch/powerpc/kernel/irq.c
8607 +++ b/arch/powerpc/kernel/irq.c
8608 @@ -447,6 +447,8 @@ void migrate_irqs(void)
8609 }
8610 #endif
8611
8612 +extern void gr_handle_kernel_exploit(void);
8613 +
8614 static inline void check_stack_overflow(void)
8615 {
8616 #ifdef CONFIG_DEBUG_STACKOVERFLOW
8617 @@ -459,6 +461,7 @@ static inline void check_stack_overflow(void)
8618 printk("do_IRQ: stack overflow: %ld\n",
8619 sp - sizeof(struct thread_info));
8620 dump_stack();
8621 + gr_handle_kernel_exploit();
8622 }
8623 #endif
8624 }
8625 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8626 index 6cff040..74ac5d1b 100644
8627 --- a/arch/powerpc/kernel/module_32.c
8628 +++ b/arch/powerpc/kernel/module_32.c
8629 @@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8630 me->arch.core_plt_section = i;
8631 }
8632 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8633 - printk("Module doesn't contain .plt or .init.plt sections.\n");
8634 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
8635 return -ENOEXEC;
8636 }
8637
8638 @@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
8639
8640 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8641 /* Init, or core PLT? */
8642 - if (location >= mod->module_core
8643 - && location < mod->module_core + mod->core_size)
8644 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8645 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8646 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8647 - else
8648 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8649 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8650 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8651 + else {
8652 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8653 + return ~0UL;
8654 + }
8655
8656 /* Find this entry, or if that fails, the next avail. entry */
8657 while (entry->jump[0]) {
8658 @@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8659 }
8660 #ifdef CONFIG_DYNAMIC_FTRACE
8661 module->arch.tramp =
8662 - do_plt_call(module->module_core,
8663 + do_plt_call(module->module_core_rx,
8664 (unsigned long)ftrace_caller,
8665 sechdrs, module);
8666 #endif
8667 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8668 index 31d0215..206af70 100644
8669 --- a/arch/powerpc/kernel/process.c
8670 +++ b/arch/powerpc/kernel/process.c
8671 @@ -1031,8 +1031,8 @@ void show_regs(struct pt_regs * regs)
8672 * Lookup NIP late so we have the best change of getting the
8673 * above info out without failing
8674 */
8675 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8676 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8677 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8678 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8679 #endif
8680 show_stack(current, (unsigned long *) regs->gpr[1]);
8681 if (!user_mode(regs))
8682 @@ -1554,10 +1554,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8683 newsp = stack[0];
8684 ip = stack[STACK_FRAME_LR_SAVE];
8685 if (!firstframe || ip != lr) {
8686 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8687 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8688 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8689 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8690 - printk(" (%pS)",
8691 + printk(" (%pA)",
8692 (void *)current->ret_stack[curr_frame].ret);
8693 curr_frame--;
8694 }
8695 @@ -1577,7 +1577,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8696 struct pt_regs *regs = (struct pt_regs *)
8697 (sp + STACK_FRAME_OVERHEAD);
8698 lr = regs->link;
8699 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
8700 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
8701 regs->trap, (void *)regs->nip, (void *)lr);
8702 firstframe = 1;
8703 }
8704 @@ -1613,58 +1613,3 @@ void notrace __ppc64_runlatch_off(void)
8705 mtspr(SPRN_CTRLT, ctrl);
8706 }
8707 #endif /* CONFIG_PPC64 */
8708 -
8709 -unsigned long arch_align_stack(unsigned long sp)
8710 -{
8711 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8712 - sp -= get_random_int() & ~PAGE_MASK;
8713 - return sp & ~0xf;
8714 -}
8715 -
8716 -static inline unsigned long brk_rnd(void)
8717 -{
8718 - unsigned long rnd = 0;
8719 -
8720 - /* 8MB for 32bit, 1GB for 64bit */
8721 - if (is_32bit_task())
8722 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8723 - else
8724 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8725 -
8726 - return rnd << PAGE_SHIFT;
8727 -}
8728 -
8729 -unsigned long arch_randomize_brk(struct mm_struct *mm)
8730 -{
8731 - unsigned long base = mm->brk;
8732 - unsigned long ret;
8733 -
8734 -#ifdef CONFIG_PPC_STD_MMU_64
8735 - /*
8736 - * If we are using 1TB segments and we are allowed to randomise
8737 - * the heap, we can put it above 1TB so it is backed by a 1TB
8738 - * segment. Otherwise the heap will be in the bottom 1TB
8739 - * which always uses 256MB segments and this may result in a
8740 - * performance penalty.
8741 - */
8742 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8743 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8744 -#endif
8745 -
8746 - ret = PAGE_ALIGN(base + brk_rnd());
8747 -
8748 - if (ret < mm->brk)
8749 - return mm->brk;
8750 -
8751 - return ret;
8752 -}
8753 -
8754 -unsigned long randomize_et_dyn(unsigned long base)
8755 -{
8756 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8757 -
8758 - if (ret < base)
8759 - return base;
8760 -
8761 - return ret;
8762 -}
8763 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8764 index 2e3d2bf..35df241 100644
8765 --- a/arch/powerpc/kernel/ptrace.c
8766 +++ b/arch/powerpc/kernel/ptrace.c
8767 @@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
8768 return ret;
8769 }
8770
8771 +#ifdef CONFIG_GRKERNSEC_SETXID
8772 +extern void gr_delayed_cred_worker(void);
8773 +#endif
8774 +
8775 /*
8776 * We must return the syscall number to actually look up in the table.
8777 * This can be -1L to skip running any syscall at all.
8778 @@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8779
8780 secure_computing_strict(regs->gpr[0]);
8781
8782 +#ifdef CONFIG_GRKERNSEC_SETXID
8783 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8784 + gr_delayed_cred_worker();
8785 +#endif
8786 +
8787 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8788 tracehook_report_syscall_entry(regs))
8789 /*
8790 @@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8791 {
8792 int step;
8793
8794 +#ifdef CONFIG_GRKERNSEC_SETXID
8795 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8796 + gr_delayed_cred_worker();
8797 +#endif
8798 +
8799 audit_syscall_exit(regs);
8800
8801 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8802 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8803 index 4e47db6..6dcc96e 100644
8804 --- a/arch/powerpc/kernel/signal_32.c
8805 +++ b/arch/powerpc/kernel/signal_32.c
8806 @@ -1013,7 +1013,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8807 /* Save user registers on the stack */
8808 frame = &rt_sf->uc.uc_mcontext;
8809 addr = frame;
8810 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8811 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8812 sigret = 0;
8813 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8814 } else {
8815 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8816 index d501dc4..e5a0de0 100644
8817 --- a/arch/powerpc/kernel/signal_64.c
8818 +++ b/arch/powerpc/kernel/signal_64.c
8819 @@ -760,7 +760,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8820 current->thread.fp_state.fpscr = 0;
8821
8822 /* Set up to return from userspace. */
8823 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8824 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8825 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8826 } else {
8827 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8828 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8829 index 1bd7ca2..9b78c2f 100644
8830 --- a/arch/powerpc/kernel/traps.c
8831 +++ b/arch/powerpc/kernel/traps.c
8832 @@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8833 return flags;
8834 }
8835
8836 +extern void gr_handle_kernel_exploit(void);
8837 +
8838 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8839 int signr)
8840 {
8841 @@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8842 panic("Fatal exception in interrupt");
8843 if (panic_on_oops)
8844 panic("Fatal exception");
8845 +
8846 + gr_handle_kernel_exploit();
8847 +
8848 do_exit(signr);
8849 }
8850
8851 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8852 index ce74c33..0803371 100644
8853 --- a/arch/powerpc/kernel/vdso.c
8854 +++ b/arch/powerpc/kernel/vdso.c
8855 @@ -35,6 +35,7 @@
8856 #include <asm/vdso.h>
8857 #include <asm/vdso_datapage.h>
8858 #include <asm/setup.h>
8859 +#include <asm/mman.h>
8860
8861 #undef DEBUG
8862
8863 @@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8864 vdso_base = VDSO32_MBASE;
8865 #endif
8866
8867 - current->mm->context.vdso_base = 0;
8868 + current->mm->context.vdso_base = ~0UL;
8869
8870 /* vDSO has a problem and was disabled, just don't "enable" it for the
8871 * process
8872 @@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8873 vdso_base = get_unmapped_area(NULL, vdso_base,
8874 (vdso_pages << PAGE_SHIFT) +
8875 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8876 - 0, 0);
8877 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
8878 if (IS_ERR_VALUE(vdso_base)) {
8879 rc = vdso_base;
8880 goto fail_mmapsem;
8881 diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
8882 index 3cf541a..ab2d825 100644
8883 --- a/arch/powerpc/kvm/powerpc.c
8884 +++ b/arch/powerpc/kvm/powerpc.c
8885 @@ -1153,7 +1153,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
8886 }
8887 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
8888
8889 -int kvm_arch_init(void *opaque)
8890 +int kvm_arch_init(const void *opaque)
8891 {
8892 return 0;
8893 }
8894 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8895 index 5eea6f3..5d10396 100644
8896 --- a/arch/powerpc/lib/usercopy_64.c
8897 +++ b/arch/powerpc/lib/usercopy_64.c
8898 @@ -9,22 +9,6 @@
8899 #include <linux/module.h>
8900 #include <asm/uaccess.h>
8901
8902 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8903 -{
8904 - if (likely(access_ok(VERIFY_READ, from, n)))
8905 - n = __copy_from_user(to, from, n);
8906 - else
8907 - memset(to, 0, n);
8908 - return n;
8909 -}
8910 -
8911 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8912 -{
8913 - if (likely(access_ok(VERIFY_WRITE, to, n)))
8914 - n = __copy_to_user(to, from, n);
8915 - return n;
8916 -}
8917 -
8918 unsigned long copy_in_user(void __user *to, const void __user *from,
8919 unsigned long n)
8920 {
8921 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8922 return n;
8923 }
8924
8925 -EXPORT_SYMBOL(copy_from_user);
8926 -EXPORT_SYMBOL(copy_to_user);
8927 EXPORT_SYMBOL(copy_in_user);
8928
8929 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8930 index 51ab9e7..7d3c78b 100644
8931 --- a/arch/powerpc/mm/fault.c
8932 +++ b/arch/powerpc/mm/fault.c
8933 @@ -33,6 +33,10 @@
8934 #include <linux/magic.h>
8935 #include <linux/ratelimit.h>
8936 #include <linux/context_tracking.h>
8937 +#include <linux/slab.h>
8938 +#include <linux/pagemap.h>
8939 +#include <linux/compiler.h>
8940 +#include <linux/unistd.h>
8941
8942 #include <asm/firmware.h>
8943 #include <asm/page.h>
8944 @@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8945 }
8946 #endif
8947
8948 +#ifdef CONFIG_PAX_PAGEEXEC
8949 +/*
8950 + * PaX: decide what to do with offenders (regs->nip = fault address)
8951 + *
8952 + * returns 1 when task should be killed
8953 + */
8954 +static int pax_handle_fetch_fault(struct pt_regs *regs)
8955 +{
8956 + return 1;
8957 +}
8958 +
8959 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8960 +{
8961 + unsigned long i;
8962 +
8963 + printk(KERN_ERR "PAX: bytes at PC: ");
8964 + for (i = 0; i < 5; i++) {
8965 + unsigned int c;
8966 + if (get_user(c, (unsigned int __user *)pc+i))
8967 + printk(KERN_CONT "???????? ");
8968 + else
8969 + printk(KERN_CONT "%08x ", c);
8970 + }
8971 + printk("\n");
8972 +}
8973 +#endif
8974 +
8975 /*
8976 * Check whether the instruction at regs->nip is a store using
8977 * an update addressing form which will update r1.
8978 @@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8979 * indicate errors in DSISR but can validly be set in SRR1.
8980 */
8981 if (trap == 0x400)
8982 - error_code &= 0x48200000;
8983 + error_code &= 0x58200000;
8984 else
8985 is_write = error_code & DSISR_ISSTORE;
8986 #else
8987 @@ -378,7 +409,7 @@ good_area:
8988 * "undefined". Of those that can be set, this is the only
8989 * one which seems bad.
8990 */
8991 - if (error_code & 0x10000000)
8992 + if (error_code & DSISR_GUARDED)
8993 /* Guarded storage error. */
8994 goto bad_area;
8995 #endif /* CONFIG_8xx */
8996 @@ -393,7 +424,7 @@ good_area:
8997 * processors use the same I/D cache coherency mechanism
8998 * as embedded.
8999 */
9000 - if (error_code & DSISR_PROTFAULT)
9001 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
9002 goto bad_area;
9003 #endif /* CONFIG_PPC_STD_MMU */
9004
9005 @@ -483,6 +514,23 @@ bad_area:
9006 bad_area_nosemaphore:
9007 /* User mode accesses cause a SIGSEGV */
9008 if (user_mode(regs)) {
9009 +
9010 +#ifdef CONFIG_PAX_PAGEEXEC
9011 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
9012 +#ifdef CONFIG_PPC_STD_MMU
9013 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
9014 +#else
9015 + if (is_exec && regs->nip == address) {
9016 +#endif
9017 + switch (pax_handle_fetch_fault(regs)) {
9018 + }
9019 +
9020 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
9021 + do_group_exit(SIGKILL);
9022 + }
9023 + }
9024 +#endif
9025 +
9026 _exception(SIGSEGV, regs, code, address);
9027 goto bail;
9028 }
9029 diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
9030 index cb8bdbe..cde4bc7 100644
9031 --- a/arch/powerpc/mm/mmap.c
9032 +++ b/arch/powerpc/mm/mmap.c
9033 @@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
9034 return sysctl_legacy_va_layout;
9035 }
9036
9037 -static unsigned long mmap_rnd(void)
9038 +static unsigned long mmap_rnd(struct mm_struct *mm)
9039 {
9040 unsigned long rnd = 0;
9041
9042 +#ifdef CONFIG_PAX_RANDMMAP
9043 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9044 +#endif
9045 +
9046 if (current->flags & PF_RANDOMIZE) {
9047 /* 8MB for 32bit, 1GB for 64bit */
9048 if (is_32bit_task())
9049 @@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
9050 return rnd << PAGE_SHIFT;
9051 }
9052
9053 -static inline unsigned long mmap_base(void)
9054 +static inline unsigned long mmap_base(struct mm_struct *mm)
9055 {
9056 unsigned long gap = rlimit(RLIMIT_STACK);
9057
9058 @@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
9059 else if (gap > MAX_GAP)
9060 gap = MAX_GAP;
9061
9062 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
9063 + return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
9064 }
9065
9066 /*
9067 @@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9068 */
9069 if (mmap_is_legacy()) {
9070 mm->mmap_base = TASK_UNMAPPED_BASE;
9071 +
9072 +#ifdef CONFIG_PAX_RANDMMAP
9073 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9074 + mm->mmap_base += mm->delta_mmap;
9075 +#endif
9076 +
9077 mm->get_unmapped_area = arch_get_unmapped_area;
9078 } else {
9079 - mm->mmap_base = mmap_base();
9080 + mm->mmap_base = mmap_base(mm);
9081 +
9082 +#ifdef CONFIG_PAX_RANDMMAP
9083 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9084 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9085 +#endif
9086 +
9087 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9088 }
9089 }
9090 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
9091 index b0c75cc..ef7fb93 100644
9092 --- a/arch/powerpc/mm/slice.c
9093 +++ b/arch/powerpc/mm/slice.c
9094 @@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
9095 if ((mm->task_size - len) < addr)
9096 return 0;
9097 vma = find_vma(mm, addr);
9098 - return (!vma || (addr + len) <= vma->vm_start);
9099 + return check_heap_stack_gap(vma, addr, len, 0);
9100 }
9101
9102 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
9103 @@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
9104 info.align_offset = 0;
9105
9106 addr = TASK_UNMAPPED_BASE;
9107 +
9108 +#ifdef CONFIG_PAX_RANDMMAP
9109 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9110 + addr += mm->delta_mmap;
9111 +#endif
9112 +
9113 while (addr < TASK_SIZE) {
9114 info.low_limit = addr;
9115 if (!slice_scan_available(addr, available, 1, &addr))
9116 @@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
9117 if (fixed && addr > (mm->task_size - len))
9118 return -ENOMEM;
9119
9120 +#ifdef CONFIG_PAX_RANDMMAP
9121 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
9122 + addr = 0;
9123 +#endif
9124 +
9125 /* If hint, make sure it matches our alignment restrictions */
9126 if (!fixed && addr) {
9127 addr = _ALIGN_UP(addr, 1ul << pshift);
9128 diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9129 index 4278acf..67fd0e6 100644
9130 --- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9131 +++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9132 @@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
9133 }
9134
9135 static struct pci_ops scc_pciex_pci_ops = {
9136 - scc_pciex_read_config,
9137 - scc_pciex_write_config,
9138 + .read = scc_pciex_read_config,
9139 + .write = scc_pciex_write_config,
9140 };
9141
9142 static void pciex_clear_intr_all(unsigned int __iomem *base)
9143 diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
9144 index 9098692..3d54cd1 100644
9145 --- a/arch/powerpc/platforms/cell/spufs/file.c
9146 +++ b/arch/powerpc/platforms/cell/spufs/file.c
9147 @@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9148 return VM_FAULT_NOPAGE;
9149 }
9150
9151 -static int spufs_mem_mmap_access(struct vm_area_struct *vma,
9152 +static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
9153 unsigned long address,
9154 - void *buf, int len, int write)
9155 + void *buf, size_t len, int write)
9156 {
9157 struct spu_context *ctx = vma->vm_file->private_data;
9158 unsigned long offset = address - vma->vm_start;
9159 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
9160 index 1d47061..0714963 100644
9161 --- a/arch/s390/include/asm/atomic.h
9162 +++ b/arch/s390/include/asm/atomic.h
9163 @@ -412,6 +412,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
9164 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
9165 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9166
9167 +#define atomic64_read_unchecked(v) atomic64_read(v)
9168 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9169 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9170 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9171 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9172 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
9173 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9174 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
9175 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9176 +
9177 #define smp_mb__before_atomic_dec() smp_mb()
9178 #define smp_mb__after_atomic_dec() smp_mb()
9179 #define smp_mb__before_atomic_inc() smp_mb()
9180 diff --git a/arch/s390/include/asm/barrier.h b/arch/s390/include/asm/barrier.h
9181 index 578680f..0eb3b11 100644
9182 --- a/arch/s390/include/asm/barrier.h
9183 +++ b/arch/s390/include/asm/barrier.h
9184 @@ -36,7 +36,7 @@
9185 do { \
9186 compiletime_assert_atomic_type(*p); \
9187 barrier(); \
9188 - ACCESS_ONCE(*p) = (v); \
9189 + ACCESS_ONCE_RW(*p) = (v); \
9190 } while (0)
9191
9192 #define smp_load_acquire(p) \
9193 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
9194 index 4d7ccac..d03d0ad 100644
9195 --- a/arch/s390/include/asm/cache.h
9196 +++ b/arch/s390/include/asm/cache.h
9197 @@ -9,8 +9,10 @@
9198 #ifndef __ARCH_S390_CACHE_H
9199 #define __ARCH_S390_CACHE_H
9200
9201 -#define L1_CACHE_BYTES 256
9202 +#include <linux/const.h>
9203 +
9204 #define L1_CACHE_SHIFT 8
9205 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9206 #define NET_SKB_PAD 32
9207
9208 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9209 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
9210 index 78f4f87..598ce39 100644
9211 --- a/arch/s390/include/asm/elf.h
9212 +++ b/arch/s390/include/asm/elf.h
9213 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
9214 the loader. We need to make sure that it is out of the way of the program
9215 that it will "exec", and that there is sufficient room for the brk. */
9216
9217 -extern unsigned long randomize_et_dyn(unsigned long base);
9218 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
9219 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
9220 +
9221 +#ifdef CONFIG_PAX_ASLR
9222 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
9223 +
9224 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9225 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9226 +#endif
9227
9228 /* This yields a mask that user programs can use to figure out what
9229 instruction set this CPU supports. */
9230 @@ -222,9 +228,6 @@ struct linux_binprm;
9231 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
9232 int arch_setup_additional_pages(struct linux_binprm *, int);
9233
9234 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9235 -#define arch_randomize_brk arch_randomize_brk
9236 -
9237 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
9238
9239 #endif
9240 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
9241 index c4a93d6..4d2a9b4 100644
9242 --- a/arch/s390/include/asm/exec.h
9243 +++ b/arch/s390/include/asm/exec.h
9244 @@ -7,6 +7,6 @@
9245 #ifndef __ASM_EXEC_H
9246 #define __ASM_EXEC_H
9247
9248 -extern unsigned long arch_align_stack(unsigned long sp);
9249 +#define arch_align_stack(x) ((x) & ~0xfUL)
9250
9251 #endif /* __ASM_EXEC_H */
9252 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
9253 index 1be64a1..086839d1 100644
9254 --- a/arch/s390/include/asm/uaccess.h
9255 +++ b/arch/s390/include/asm/uaccess.h
9256 @@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
9257 __range_ok((unsigned long)(addr), (size)); \
9258 })
9259
9260 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9261 #define access_ok(type, addr, size) __access_ok(addr, size)
9262
9263 /*
9264 @@ -245,6 +246,10 @@ static inline unsigned long __must_check
9265 copy_to_user(void __user *to, const void *from, unsigned long n)
9266 {
9267 might_fault();
9268 +
9269 + if ((long)n < 0)
9270 + return n;
9271 +
9272 return __copy_to_user(to, from, n);
9273 }
9274
9275 @@ -273,10 +278,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
9276 static inline unsigned long __must_check
9277 copy_from_user(void *to, const void __user *from, unsigned long n)
9278 {
9279 - unsigned int sz = __compiletime_object_size(to);
9280 + size_t sz = __compiletime_object_size(to);
9281
9282 might_fault();
9283 - if (unlikely(sz != -1 && sz < n)) {
9284 +
9285 + if ((long)n < 0)
9286 + return n;
9287 +
9288 + if (unlikely(sz != (size_t)-1 && sz < n)) {
9289 copy_from_user_overflow();
9290 return n;
9291 }
9292 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
9293 index b89b591..fd9609d 100644
9294 --- a/arch/s390/kernel/module.c
9295 +++ b/arch/s390/kernel/module.c
9296 @@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
9297
9298 /* Increase core size by size of got & plt and set start
9299 offsets for got and plt. */
9300 - me->core_size = ALIGN(me->core_size, 4);
9301 - me->arch.got_offset = me->core_size;
9302 - me->core_size += me->arch.got_size;
9303 - me->arch.plt_offset = me->core_size;
9304 - me->core_size += me->arch.plt_size;
9305 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
9306 + me->arch.got_offset = me->core_size_rw;
9307 + me->core_size_rw += me->arch.got_size;
9308 + me->arch.plt_offset = me->core_size_rx;
9309 + me->core_size_rx += me->arch.plt_size;
9310 return 0;
9311 }
9312
9313 @@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9314 if (info->got_initialized == 0) {
9315 Elf_Addr *gotent;
9316
9317 - gotent = me->module_core + me->arch.got_offset +
9318 + gotent = me->module_core_rw + me->arch.got_offset +
9319 info->got_offset;
9320 *gotent = val;
9321 info->got_initialized = 1;
9322 @@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9323 rc = apply_rela_bits(loc, val, 0, 64, 0);
9324 else if (r_type == R_390_GOTENT ||
9325 r_type == R_390_GOTPLTENT) {
9326 - val += (Elf_Addr) me->module_core - loc;
9327 + val += (Elf_Addr) me->module_core_rw - loc;
9328 rc = apply_rela_bits(loc, val, 1, 32, 1);
9329 }
9330 break;
9331 @@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9332 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
9333 if (info->plt_initialized == 0) {
9334 unsigned int *ip;
9335 - ip = me->module_core + me->arch.plt_offset +
9336 + ip = me->module_core_rx + me->arch.plt_offset +
9337 info->plt_offset;
9338 #ifndef CONFIG_64BIT
9339 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
9340 @@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9341 val - loc + 0xffffUL < 0x1ffffeUL) ||
9342 (r_type == R_390_PLT32DBL &&
9343 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
9344 - val = (Elf_Addr) me->module_core +
9345 + val = (Elf_Addr) me->module_core_rx +
9346 me->arch.plt_offset +
9347 info->plt_offset;
9348 val += rela->r_addend - loc;
9349 @@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9350 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
9351 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
9352 val = val + rela->r_addend -
9353 - ((Elf_Addr) me->module_core + me->arch.got_offset);
9354 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
9355 if (r_type == R_390_GOTOFF16)
9356 rc = apply_rela_bits(loc, val, 0, 16, 0);
9357 else if (r_type == R_390_GOTOFF32)
9358 @@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9359 break;
9360 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
9361 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
9362 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
9363 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
9364 rela->r_addend - loc;
9365 if (r_type == R_390_GOTPC)
9366 rc = apply_rela_bits(loc, val, 1, 32, 0);
9367 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
9368 index dd14532..1dfc145 100644
9369 --- a/arch/s390/kernel/process.c
9370 +++ b/arch/s390/kernel/process.c
9371 @@ -242,37 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
9372 }
9373 return 0;
9374 }
9375 -
9376 -unsigned long arch_align_stack(unsigned long sp)
9377 -{
9378 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9379 - sp -= get_random_int() & ~PAGE_MASK;
9380 - return sp & ~0xf;
9381 -}
9382 -
9383 -static inline unsigned long brk_rnd(void)
9384 -{
9385 - /* 8MB for 32bit, 1GB for 64bit */
9386 - if (is_32bit_task())
9387 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
9388 - else
9389 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
9390 -}
9391 -
9392 -unsigned long arch_randomize_brk(struct mm_struct *mm)
9393 -{
9394 - unsigned long ret;
9395 -
9396 - ret = PAGE_ALIGN(mm->brk + brk_rnd());
9397 - return (ret > mm->brk) ? ret : mm->brk;
9398 -}
9399 -
9400 -unsigned long randomize_et_dyn(unsigned long base)
9401 -{
9402 - unsigned long ret;
9403 -
9404 - if (!(current->flags & PF_RANDOMIZE))
9405 - return base;
9406 - ret = PAGE_ALIGN(base + brk_rnd());
9407 - return (ret > base) ? ret : base;
9408 -}
9409 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
9410 index 9b436c2..54fbf0a 100644
9411 --- a/arch/s390/mm/mmap.c
9412 +++ b/arch/s390/mm/mmap.c
9413 @@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9414 */
9415 if (mmap_is_legacy()) {
9416 mm->mmap_base = mmap_base_legacy();
9417 +
9418 +#ifdef CONFIG_PAX_RANDMMAP
9419 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9420 + mm->mmap_base += mm->delta_mmap;
9421 +#endif
9422 +
9423 mm->get_unmapped_area = arch_get_unmapped_area;
9424 } else {
9425 mm->mmap_base = mmap_base();
9426 +
9427 +#ifdef CONFIG_PAX_RANDMMAP
9428 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9429 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9430 +#endif
9431 +
9432 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9433 }
9434 }
9435 @@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9436 */
9437 if (mmap_is_legacy()) {
9438 mm->mmap_base = mmap_base_legacy();
9439 +
9440 +#ifdef CONFIG_PAX_RANDMMAP
9441 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9442 + mm->mmap_base += mm->delta_mmap;
9443 +#endif
9444 +
9445 mm->get_unmapped_area = s390_get_unmapped_area;
9446 } else {
9447 mm->mmap_base = mmap_base();
9448 +
9449 +#ifdef CONFIG_PAX_RANDMMAP
9450 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9451 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9452 +#endif
9453 +
9454 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
9455 }
9456 }
9457 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
9458 index ae3d59f..f65f075 100644
9459 --- a/arch/score/include/asm/cache.h
9460 +++ b/arch/score/include/asm/cache.h
9461 @@ -1,7 +1,9 @@
9462 #ifndef _ASM_SCORE_CACHE_H
9463 #define _ASM_SCORE_CACHE_H
9464
9465 +#include <linux/const.h>
9466 +
9467 #define L1_CACHE_SHIFT 4
9468 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9469 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9470
9471 #endif /* _ASM_SCORE_CACHE_H */
9472 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
9473 index f9f3cd5..58ff438 100644
9474 --- a/arch/score/include/asm/exec.h
9475 +++ b/arch/score/include/asm/exec.h
9476 @@ -1,6 +1,6 @@
9477 #ifndef _ASM_SCORE_EXEC_H
9478 #define _ASM_SCORE_EXEC_H
9479
9480 -extern unsigned long arch_align_stack(unsigned long sp);
9481 +#define arch_align_stack(x) (x)
9482
9483 #endif /* _ASM_SCORE_EXEC_H */
9484 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
9485 index a1519ad3..e8ac1ff 100644
9486 --- a/arch/score/kernel/process.c
9487 +++ b/arch/score/kernel/process.c
9488 @@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
9489
9490 return task_pt_regs(task)->cp0_epc;
9491 }
9492 -
9493 -unsigned long arch_align_stack(unsigned long sp)
9494 -{
9495 - return sp;
9496 -}
9497 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
9498 index ef9e555..331bd29 100644
9499 --- a/arch/sh/include/asm/cache.h
9500 +++ b/arch/sh/include/asm/cache.h
9501 @@ -9,10 +9,11 @@
9502 #define __ASM_SH_CACHE_H
9503 #ifdef __KERNEL__
9504
9505 +#include <linux/const.h>
9506 #include <linux/init.h>
9507 #include <cpu/cache.h>
9508
9509 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9510 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9511
9512 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9513
9514 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
9515 index 6777177..cb5e44f 100644
9516 --- a/arch/sh/mm/mmap.c
9517 +++ b/arch/sh/mm/mmap.c
9518 @@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9519 struct mm_struct *mm = current->mm;
9520 struct vm_area_struct *vma;
9521 int do_colour_align;
9522 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9523 struct vm_unmapped_area_info info;
9524
9525 if (flags & MAP_FIXED) {
9526 @@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9527 if (filp || (flags & MAP_SHARED))
9528 do_colour_align = 1;
9529
9530 +#ifdef CONFIG_PAX_RANDMMAP
9531 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9532 +#endif
9533 +
9534 if (addr) {
9535 if (do_colour_align)
9536 addr = COLOUR_ALIGN(addr, pgoff);
9537 @@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9538 addr = PAGE_ALIGN(addr);
9539
9540 vma = find_vma(mm, addr);
9541 - if (TASK_SIZE - len >= addr &&
9542 - (!vma || addr + len <= vma->vm_start))
9543 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9544 return addr;
9545 }
9546
9547 info.flags = 0;
9548 info.length = len;
9549 - info.low_limit = TASK_UNMAPPED_BASE;
9550 + info.low_limit = mm->mmap_base;
9551 info.high_limit = TASK_SIZE;
9552 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
9553 info.align_offset = pgoff << PAGE_SHIFT;
9554 @@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9555 struct mm_struct *mm = current->mm;
9556 unsigned long addr = addr0;
9557 int do_colour_align;
9558 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9559 struct vm_unmapped_area_info info;
9560
9561 if (flags & MAP_FIXED) {
9562 @@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9563 if (filp || (flags & MAP_SHARED))
9564 do_colour_align = 1;
9565
9566 +#ifdef CONFIG_PAX_RANDMMAP
9567 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9568 +#endif
9569 +
9570 /* requesting a specific address */
9571 if (addr) {
9572 if (do_colour_align)
9573 @@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9574 addr = PAGE_ALIGN(addr);
9575
9576 vma = find_vma(mm, addr);
9577 - if (TASK_SIZE - len >= addr &&
9578 - (!vma || addr + len <= vma->vm_start))
9579 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9580 return addr;
9581 }
9582
9583 @@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9584 VM_BUG_ON(addr != -ENOMEM);
9585 info.flags = 0;
9586 info.low_limit = TASK_UNMAPPED_BASE;
9587 +
9588 +#ifdef CONFIG_PAX_RANDMMAP
9589 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9590 + info.low_limit += mm->delta_mmap;
9591 +#endif
9592 +
9593 info.high_limit = TASK_SIZE;
9594 addr = vm_unmapped_area(&info);
9595 }
9596 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
9597 index be56a24..443328f 100644
9598 --- a/arch/sparc/include/asm/atomic_64.h
9599 +++ b/arch/sparc/include/asm/atomic_64.h
9600 @@ -14,18 +14,40 @@
9601 #define ATOMIC64_INIT(i) { (i) }
9602
9603 #define atomic_read(v) (*(volatile int *)&(v)->counter)
9604 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9605 +{
9606 + return v->counter;
9607 +}
9608 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
9609 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9610 +{
9611 + return v->counter;
9612 +}
9613
9614 #define atomic_set(v, i) (((v)->counter) = i)
9615 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9616 +{
9617 + v->counter = i;
9618 +}
9619 #define atomic64_set(v, i) (((v)->counter) = i)
9620 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9621 +{
9622 + v->counter = i;
9623 +}
9624
9625 extern void atomic_add(int, atomic_t *);
9626 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
9627 extern void atomic64_add(long, atomic64_t *);
9628 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
9629 extern void atomic_sub(int, atomic_t *);
9630 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
9631 extern void atomic64_sub(long, atomic64_t *);
9632 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
9633
9634 extern int atomic_add_ret(int, atomic_t *);
9635 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
9636 extern long atomic64_add_ret(long, atomic64_t *);
9637 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
9638 extern int atomic_sub_ret(int, atomic_t *);
9639 extern long atomic64_sub_ret(long, atomic64_t *);
9640
9641 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9642 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
9643
9644 #define atomic_inc_return(v) atomic_add_ret(1, v)
9645 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9646 +{
9647 + return atomic_add_ret_unchecked(1, v);
9648 +}
9649 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
9650 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9651 +{
9652 + return atomic64_add_ret_unchecked(1, v);
9653 +}
9654
9655 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
9656 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
9657
9658 #define atomic_add_return(i, v) atomic_add_ret(i, v)
9659 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9660 +{
9661 + return atomic_add_ret_unchecked(i, v);
9662 +}
9663 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
9664 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9665 +{
9666 + return atomic64_add_ret_unchecked(i, v);
9667 +}
9668
9669 /*
9670 * atomic_inc_and_test - increment and test
9671 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9672 * other cases.
9673 */
9674 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9675 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9676 +{
9677 + return atomic_inc_return_unchecked(v) == 0;
9678 +}
9679 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9680
9681 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
9682 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9683 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
9684
9685 #define atomic_inc(v) atomic_add(1, v)
9686 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9687 +{
9688 + atomic_add_unchecked(1, v);
9689 +}
9690 #define atomic64_inc(v) atomic64_add(1, v)
9691 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9692 +{
9693 + atomic64_add_unchecked(1, v);
9694 +}
9695
9696 #define atomic_dec(v) atomic_sub(1, v)
9697 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9698 +{
9699 + atomic_sub_unchecked(1, v);
9700 +}
9701 #define atomic64_dec(v) atomic64_sub(1, v)
9702 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9703 +{
9704 + atomic64_sub_unchecked(1, v);
9705 +}
9706
9707 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
9708 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
9709
9710 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
9711 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9712 +{
9713 + return cmpxchg(&v->counter, old, new);
9714 +}
9715 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9716 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9717 +{
9718 + return xchg(&v->counter, new);
9719 +}
9720
9721 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9722 {
9723 - int c, old;
9724 + int c, old, new;
9725 c = atomic_read(v);
9726 for (;;) {
9727 - if (unlikely(c == (u)))
9728 + if (unlikely(c == u))
9729 break;
9730 - old = atomic_cmpxchg((v), c, c + (a));
9731 +
9732 + asm volatile("addcc %2, %0, %0\n"
9733 +
9734 +#ifdef CONFIG_PAX_REFCOUNT
9735 + "tvs %%icc, 6\n"
9736 +#endif
9737 +
9738 + : "=r" (new)
9739 + : "0" (c), "ir" (a)
9740 + : "cc");
9741 +
9742 + old = atomic_cmpxchg(v, c, new);
9743 if (likely(old == c))
9744 break;
9745 c = old;
9746 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9747 #define atomic64_cmpxchg(v, o, n) \
9748 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
9749 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9750 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9751 +{
9752 + return xchg(&v->counter, new);
9753 +}
9754
9755 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9756 {
9757 - long c, old;
9758 + long c, old, new;
9759 c = atomic64_read(v);
9760 for (;;) {
9761 - if (unlikely(c == (u)))
9762 + if (unlikely(c == u))
9763 break;
9764 - old = atomic64_cmpxchg((v), c, c + (a));
9765 +
9766 + asm volatile("addcc %2, %0, %0\n"
9767 +
9768 +#ifdef CONFIG_PAX_REFCOUNT
9769 + "tvs %%xcc, 6\n"
9770 +#endif
9771 +
9772 + : "=r" (new)
9773 + : "0" (c), "ir" (a)
9774 + : "cc");
9775 +
9776 + old = atomic64_cmpxchg(v, c, new);
9777 if (likely(old == c))
9778 break;
9779 c = old;
9780 }
9781 - return c != (u);
9782 + return c != u;
9783 }
9784
9785 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9786 diff --git a/arch/sparc/include/asm/barrier_64.h b/arch/sparc/include/asm/barrier_64.h
9787 index b5aad96..99d7465 100644
9788 --- a/arch/sparc/include/asm/barrier_64.h
9789 +++ b/arch/sparc/include/asm/barrier_64.h
9790 @@ -57,7 +57,7 @@ do { __asm__ __volatile__("ba,pt %%xcc, 1f\n\t" \
9791 do { \
9792 compiletime_assert_atomic_type(*p); \
9793 barrier(); \
9794 - ACCESS_ONCE(*p) = (v); \
9795 + ACCESS_ONCE_RW(*p) = (v); \
9796 } while (0)
9797
9798 #define smp_load_acquire(p) \
9799 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9800 index 5bb6991..5c2132e 100644
9801 --- a/arch/sparc/include/asm/cache.h
9802 +++ b/arch/sparc/include/asm/cache.h
9803 @@ -7,10 +7,12 @@
9804 #ifndef _SPARC_CACHE_H
9805 #define _SPARC_CACHE_H
9806
9807 +#include <linux/const.h>
9808 +
9809 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9810
9811 #define L1_CACHE_SHIFT 5
9812 -#define L1_CACHE_BYTES 32
9813 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9814
9815 #ifdef CONFIG_SPARC32
9816 #define SMP_CACHE_BYTES_SHIFT 5
9817 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9818 index a24e41f..47677ff 100644
9819 --- a/arch/sparc/include/asm/elf_32.h
9820 +++ b/arch/sparc/include/asm/elf_32.h
9821 @@ -114,6 +114,13 @@ typedef struct {
9822
9823 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9824
9825 +#ifdef CONFIG_PAX_ASLR
9826 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
9827 +
9828 +#define PAX_DELTA_MMAP_LEN 16
9829 +#define PAX_DELTA_STACK_LEN 16
9830 +#endif
9831 +
9832 /* This yields a mask that user programs can use to figure out what
9833 instruction set this cpu supports. This can NOT be done in userspace
9834 on Sparc. */
9835 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9836 index 370ca1e..d4f4a98 100644
9837 --- a/arch/sparc/include/asm/elf_64.h
9838 +++ b/arch/sparc/include/asm/elf_64.h
9839 @@ -189,6 +189,13 @@ typedef struct {
9840 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9841 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9842
9843 +#ifdef CONFIG_PAX_ASLR
9844 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9845 +
9846 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9847 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9848 +#endif
9849 +
9850 extern unsigned long sparc64_elf_hwcap;
9851 #define ELF_HWCAP sparc64_elf_hwcap
9852
9853 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9854 index 9b1c36d..209298b 100644
9855 --- a/arch/sparc/include/asm/pgalloc_32.h
9856 +++ b/arch/sparc/include/asm/pgalloc_32.h
9857 @@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9858 }
9859
9860 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9861 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9862
9863 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9864 unsigned long address)
9865 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9866 index bcfe063..b333142 100644
9867 --- a/arch/sparc/include/asm/pgalloc_64.h
9868 +++ b/arch/sparc/include/asm/pgalloc_64.h
9869 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9870 }
9871
9872 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9873 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9874
9875 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9876 {
9877 diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
9878 index 59ba6f6..4518128 100644
9879 --- a/arch/sparc/include/asm/pgtable.h
9880 +++ b/arch/sparc/include/asm/pgtable.h
9881 @@ -5,4 +5,8 @@
9882 #else
9883 #include <asm/pgtable_32.h>
9884 #endif
9885 +
9886 +#define ktla_ktva(addr) (addr)
9887 +#define ktva_ktla(addr) (addr)
9888 +
9889 #endif
9890 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9891 index 502f632..da1917f 100644
9892 --- a/arch/sparc/include/asm/pgtable_32.h
9893 +++ b/arch/sparc/include/asm/pgtable_32.h
9894 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9895 #define PAGE_SHARED SRMMU_PAGE_SHARED
9896 #define PAGE_COPY SRMMU_PAGE_COPY
9897 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9898 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9899 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9900 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9901 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9902
9903 /* Top-level page directory - dummy used by init-mm.
9904 @@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9905
9906 /* xwr */
9907 #define __P000 PAGE_NONE
9908 -#define __P001 PAGE_READONLY
9909 -#define __P010 PAGE_COPY
9910 -#define __P011 PAGE_COPY
9911 +#define __P001 PAGE_READONLY_NOEXEC
9912 +#define __P010 PAGE_COPY_NOEXEC
9913 +#define __P011 PAGE_COPY_NOEXEC
9914 #define __P100 PAGE_READONLY
9915 #define __P101 PAGE_READONLY
9916 #define __P110 PAGE_COPY
9917 #define __P111 PAGE_COPY
9918
9919 #define __S000 PAGE_NONE
9920 -#define __S001 PAGE_READONLY
9921 -#define __S010 PAGE_SHARED
9922 -#define __S011 PAGE_SHARED
9923 +#define __S001 PAGE_READONLY_NOEXEC
9924 +#define __S010 PAGE_SHARED_NOEXEC
9925 +#define __S011 PAGE_SHARED_NOEXEC
9926 #define __S100 PAGE_READONLY
9927 #define __S101 PAGE_READONLY
9928 #define __S110 PAGE_SHARED
9929 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9930 index 79da178..c2eede8 100644
9931 --- a/arch/sparc/include/asm/pgtsrmmu.h
9932 +++ b/arch/sparc/include/asm/pgtsrmmu.h
9933 @@ -115,6 +115,11 @@
9934 SRMMU_EXEC | SRMMU_REF)
9935 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9936 SRMMU_EXEC | SRMMU_REF)
9937 +
9938 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9939 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9940 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9941 +
9942 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9943 SRMMU_DIRTY | SRMMU_REF)
9944
9945 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9946 index 9689176..63c18ea 100644
9947 --- a/arch/sparc/include/asm/spinlock_64.h
9948 +++ b/arch/sparc/include/asm/spinlock_64.h
9949 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9950
9951 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9952
9953 -static void inline arch_read_lock(arch_rwlock_t *lock)
9954 +static inline void arch_read_lock(arch_rwlock_t *lock)
9955 {
9956 unsigned long tmp1, tmp2;
9957
9958 __asm__ __volatile__ (
9959 "1: ldsw [%2], %0\n"
9960 " brlz,pn %0, 2f\n"
9961 -"4: add %0, 1, %1\n"
9962 +"4: addcc %0, 1, %1\n"
9963 +
9964 +#ifdef CONFIG_PAX_REFCOUNT
9965 +" tvs %%icc, 6\n"
9966 +#endif
9967 +
9968 " cas [%2], %0, %1\n"
9969 " cmp %0, %1\n"
9970 " bne,pn %%icc, 1b\n"
9971 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9972 " .previous"
9973 : "=&r" (tmp1), "=&r" (tmp2)
9974 : "r" (lock)
9975 - : "memory");
9976 + : "memory", "cc");
9977 }
9978
9979 -static int inline arch_read_trylock(arch_rwlock_t *lock)
9980 +static inline int arch_read_trylock(arch_rwlock_t *lock)
9981 {
9982 int tmp1, tmp2;
9983
9984 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9985 "1: ldsw [%2], %0\n"
9986 " brlz,a,pn %0, 2f\n"
9987 " mov 0, %0\n"
9988 -" add %0, 1, %1\n"
9989 +" addcc %0, 1, %1\n"
9990 +
9991 +#ifdef CONFIG_PAX_REFCOUNT
9992 +" tvs %%icc, 6\n"
9993 +#endif
9994 +
9995 " cas [%2], %0, %1\n"
9996 " cmp %0, %1\n"
9997 " bne,pn %%icc, 1b\n"
9998 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9999 return tmp1;
10000 }
10001
10002 -static void inline arch_read_unlock(arch_rwlock_t *lock)
10003 +static inline void arch_read_unlock(arch_rwlock_t *lock)
10004 {
10005 unsigned long tmp1, tmp2;
10006
10007 __asm__ __volatile__(
10008 "1: lduw [%2], %0\n"
10009 -" sub %0, 1, %1\n"
10010 +" subcc %0, 1, %1\n"
10011 +
10012 +#ifdef CONFIG_PAX_REFCOUNT
10013 +" tvs %%icc, 6\n"
10014 +#endif
10015 +
10016 " cas [%2], %0, %1\n"
10017 " cmp %0, %1\n"
10018 " bne,pn %%xcc, 1b\n"
10019 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
10020 : "memory");
10021 }
10022
10023 -static void inline arch_write_lock(arch_rwlock_t *lock)
10024 +static inline void arch_write_lock(arch_rwlock_t *lock)
10025 {
10026 unsigned long mask, tmp1, tmp2;
10027
10028 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
10029 : "memory");
10030 }
10031
10032 -static void inline arch_write_unlock(arch_rwlock_t *lock)
10033 +static inline void arch_write_unlock(arch_rwlock_t *lock)
10034 {
10035 __asm__ __volatile__(
10036 " stw %%g0, [%0]"
10037 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
10038 : "memory");
10039 }
10040
10041 -static int inline arch_write_trylock(arch_rwlock_t *lock)
10042 +static inline int arch_write_trylock(arch_rwlock_t *lock)
10043 {
10044 unsigned long mask, tmp1, tmp2, result;
10045
10046 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
10047 index 96efa7a..16858bf 100644
10048 --- a/arch/sparc/include/asm/thread_info_32.h
10049 +++ b/arch/sparc/include/asm/thread_info_32.h
10050 @@ -49,6 +49,8 @@ struct thread_info {
10051 unsigned long w_saved;
10052
10053 struct restart_block restart_block;
10054 +
10055 + unsigned long lowest_stack;
10056 };
10057
10058 /*
10059 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
10060 index a5f01ac..703b554 100644
10061 --- a/arch/sparc/include/asm/thread_info_64.h
10062 +++ b/arch/sparc/include/asm/thread_info_64.h
10063 @@ -63,6 +63,8 @@ struct thread_info {
10064 struct pt_regs *kern_una_regs;
10065 unsigned int kern_una_insn;
10066
10067 + unsigned long lowest_stack;
10068 +
10069 unsigned long fpregs[0] __attribute__ ((aligned(64)));
10070 };
10071
10072 @@ -188,12 +190,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
10073 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
10074 /* flag bit 4 is available */
10075 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
10076 -/* flag bit 6 is available */
10077 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
10078 #define TIF_32BIT 7 /* 32-bit binary */
10079 #define TIF_NOHZ 8 /* in adaptive nohz mode */
10080 #define TIF_SECCOMP 9 /* secure computing */
10081 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
10082 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
10083 +
10084 /* NOTE: Thread flags >= 12 should be ones we have no interest
10085 * in using in assembly, else we can't use the mask as
10086 * an immediate value in instructions such as andcc.
10087 @@ -213,12 +216,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
10088 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
10089 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
10090 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
10091 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
10092
10093 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
10094 _TIF_DO_NOTIFY_RESUME_MASK | \
10095 _TIF_NEED_RESCHED)
10096 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
10097
10098 +#define _TIF_WORK_SYSCALL \
10099 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
10100 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
10101 +
10102 +
10103 /*
10104 * Thread-synchronous status.
10105 *
10106 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
10107 index 0167d26..767bb0c 100644
10108 --- a/arch/sparc/include/asm/uaccess.h
10109 +++ b/arch/sparc/include/asm/uaccess.h
10110 @@ -1,5 +1,6 @@
10111 #ifndef ___ASM_SPARC_UACCESS_H
10112 #define ___ASM_SPARC_UACCESS_H
10113 +
10114 #if defined(__sparc__) && defined(__arch64__)
10115 #include <asm/uaccess_64.h>
10116 #else
10117 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
10118 index 53a28dd..50c38c3 100644
10119 --- a/arch/sparc/include/asm/uaccess_32.h
10120 +++ b/arch/sparc/include/asm/uaccess_32.h
10121 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
10122
10123 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
10124 {
10125 - if (n && __access_ok((unsigned long) to, n))
10126 + if ((long)n < 0)
10127 + return n;
10128 +
10129 + if (n && __access_ok((unsigned long) to, n)) {
10130 + if (!__builtin_constant_p(n))
10131 + check_object_size(from, n, true);
10132 return __copy_user(to, (__force void __user *) from, n);
10133 - else
10134 + } else
10135 return n;
10136 }
10137
10138 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
10139 {
10140 + if ((long)n < 0)
10141 + return n;
10142 +
10143 + if (!__builtin_constant_p(n))
10144 + check_object_size(from, n, true);
10145 +
10146 return __copy_user(to, (__force void __user *) from, n);
10147 }
10148
10149 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
10150 {
10151 - if (n && __access_ok((unsigned long) from, n))
10152 + if ((long)n < 0)
10153 + return n;
10154 +
10155 + if (n && __access_ok((unsigned long) from, n)) {
10156 + if (!__builtin_constant_p(n))
10157 + check_object_size(to, n, false);
10158 return __copy_user((__force void __user *) to, from, n);
10159 - else
10160 + } else
10161 return n;
10162 }
10163
10164 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
10165 {
10166 + if ((long)n < 0)
10167 + return n;
10168 +
10169 return __copy_user((__force void __user *) to, from, n);
10170 }
10171
10172 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
10173 index ad7e178..c9e7423 100644
10174 --- a/arch/sparc/include/asm/uaccess_64.h
10175 +++ b/arch/sparc/include/asm/uaccess_64.h
10176 @@ -10,6 +10,7 @@
10177 #include <linux/compiler.h>
10178 #include <linux/string.h>
10179 #include <linux/thread_info.h>
10180 +#include <linux/kernel.h>
10181 #include <asm/asi.h>
10182 #include <asm/spitfire.h>
10183 #include <asm-generic/uaccess-unaligned.h>
10184 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
10185 static inline unsigned long __must_check
10186 copy_from_user(void *to, const void __user *from, unsigned long size)
10187 {
10188 - unsigned long ret = ___copy_from_user(to, from, size);
10189 + unsigned long ret;
10190
10191 + if ((long)size < 0 || size > INT_MAX)
10192 + return size;
10193 +
10194 + if (!__builtin_constant_p(size))
10195 + check_object_size(to, size, false);
10196 +
10197 + ret = ___copy_from_user(to, from, size);
10198 if (unlikely(ret))
10199 ret = copy_from_user_fixup(to, from, size);
10200
10201 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
10202 static inline unsigned long __must_check
10203 copy_to_user(void __user *to, const void *from, unsigned long size)
10204 {
10205 - unsigned long ret = ___copy_to_user(to, from, size);
10206 + unsigned long ret;
10207
10208 + if ((long)size < 0 || size > INT_MAX)
10209 + return size;
10210 +
10211 + if (!__builtin_constant_p(size))
10212 + check_object_size(from, size, true);
10213 +
10214 + ret = ___copy_to_user(to, from, size);
10215 if (unlikely(ret))
10216 ret = copy_to_user_fixup(to, from, size);
10217 return ret;
10218 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
10219 index d15cc17..d0ae796 100644
10220 --- a/arch/sparc/kernel/Makefile
10221 +++ b/arch/sparc/kernel/Makefile
10222 @@ -4,7 +4,7 @@
10223 #
10224
10225 asflags-y := -ansi
10226 -ccflags-y := -Werror
10227 +#ccflags-y := -Werror
10228
10229 extra-y := head_$(BITS).o
10230
10231 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
10232 index 510baec..9ff2607 100644
10233 --- a/arch/sparc/kernel/process_32.c
10234 +++ b/arch/sparc/kernel/process_32.c
10235 @@ -115,14 +115,14 @@ void show_regs(struct pt_regs *r)
10236
10237 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
10238 r->psr, r->pc, r->npc, r->y, print_tainted());
10239 - printk("PC: <%pS>\n", (void *) r->pc);
10240 + printk("PC: <%pA>\n", (void *) r->pc);
10241 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10242 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
10243 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
10244 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10245 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
10246 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
10247 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
10248 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
10249
10250 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10251 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
10252 @@ -159,7 +159,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10253 rw = (struct reg_window32 *) fp;
10254 pc = rw->ins[7];
10255 printk("[%08lx : ", pc);
10256 - printk("%pS ] ", (void *) pc);
10257 + printk("%pA ] ", (void *) pc);
10258 fp = rw->ins[6];
10259 } while (++count < 16);
10260 printk("\n");
10261 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
10262 index d7b4967..2edf827 100644
10263 --- a/arch/sparc/kernel/process_64.c
10264 +++ b/arch/sparc/kernel/process_64.c
10265 @@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
10266 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
10267 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
10268 if (regs->tstate & TSTATE_PRIV)
10269 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
10270 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
10271 }
10272
10273 void show_regs(struct pt_regs *regs)
10274 @@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
10275
10276 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
10277 regs->tpc, regs->tnpc, regs->y, print_tainted());
10278 - printk("TPC: <%pS>\n", (void *) regs->tpc);
10279 + printk("TPC: <%pA>\n", (void *) regs->tpc);
10280 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
10281 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
10282 regs->u_regs[3]);
10283 @@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
10284 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
10285 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
10286 regs->u_regs[15]);
10287 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
10288 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
10289 show_regwindow(regs);
10290 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
10291 }
10292 @@ -272,7 +272,7 @@ void arch_trigger_all_cpu_backtrace(void)
10293 ((tp && tp->task) ? tp->task->pid : -1));
10294
10295 if (gp->tstate & TSTATE_PRIV) {
10296 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
10297 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
10298 (void *) gp->tpc,
10299 (void *) gp->o7,
10300 (void *) gp->i7,
10301 diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
10302 index 79cc0d1..ec62734 100644
10303 --- a/arch/sparc/kernel/prom_common.c
10304 +++ b/arch/sparc/kernel/prom_common.c
10305 @@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
10306
10307 unsigned int prom_early_allocated __initdata;
10308
10309 -static struct of_pdt_ops prom_sparc_ops __initdata = {
10310 +static struct of_pdt_ops prom_sparc_ops __initconst = {
10311 .nextprop = prom_common_nextprop,
10312 .getproplen = prom_getproplen,
10313 .getproperty = prom_getproperty,
10314 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
10315 index c13c9f2..d572c34 100644
10316 --- a/arch/sparc/kernel/ptrace_64.c
10317 +++ b/arch/sparc/kernel/ptrace_64.c
10318 @@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
10319 return ret;
10320 }
10321
10322 +#ifdef CONFIG_GRKERNSEC_SETXID
10323 +extern void gr_delayed_cred_worker(void);
10324 +#endif
10325 +
10326 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10327 {
10328 int ret = 0;
10329 @@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10330 if (test_thread_flag(TIF_NOHZ))
10331 user_exit();
10332
10333 +#ifdef CONFIG_GRKERNSEC_SETXID
10334 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10335 + gr_delayed_cred_worker();
10336 +#endif
10337 +
10338 if (test_thread_flag(TIF_SYSCALL_TRACE))
10339 ret = tracehook_report_syscall_entry(regs);
10340
10341 @@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
10342 if (test_thread_flag(TIF_NOHZ))
10343 user_exit();
10344
10345 +#ifdef CONFIG_GRKERNSEC_SETXID
10346 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10347 + gr_delayed_cred_worker();
10348 +#endif
10349 +
10350 audit_syscall_exit(regs);
10351
10352 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
10353 diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
10354 index 745a363..b5566b1 100644
10355 --- a/arch/sparc/kernel/smp_64.c
10356 +++ b/arch/sparc/kernel/smp_64.c
10357 @@ -868,8 +868,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
10358 extern unsigned long xcall_flush_dcache_page_spitfire;
10359
10360 #ifdef CONFIG_DEBUG_DCFLUSH
10361 -extern atomic_t dcpage_flushes;
10362 -extern atomic_t dcpage_flushes_xcall;
10363 +extern atomic_unchecked_t dcpage_flushes;
10364 +extern atomic_unchecked_t dcpage_flushes_xcall;
10365 #endif
10366
10367 static inline void __local_flush_dcache_page(struct page *page)
10368 @@ -893,7 +893,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10369 return;
10370
10371 #ifdef CONFIG_DEBUG_DCFLUSH
10372 - atomic_inc(&dcpage_flushes);
10373 + atomic_inc_unchecked(&dcpage_flushes);
10374 #endif
10375
10376 this_cpu = get_cpu();
10377 @@ -917,7 +917,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10378 xcall_deliver(data0, __pa(pg_addr),
10379 (u64) pg_addr, cpumask_of(cpu));
10380 #ifdef CONFIG_DEBUG_DCFLUSH
10381 - atomic_inc(&dcpage_flushes_xcall);
10382 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10383 #endif
10384 }
10385 }
10386 @@ -936,7 +936,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10387 preempt_disable();
10388
10389 #ifdef CONFIG_DEBUG_DCFLUSH
10390 - atomic_inc(&dcpage_flushes);
10391 + atomic_inc_unchecked(&dcpage_flushes);
10392 #endif
10393 data0 = 0;
10394 pg_addr = page_address(page);
10395 @@ -953,7 +953,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10396 xcall_deliver(data0, __pa(pg_addr),
10397 (u64) pg_addr, cpu_online_mask);
10398 #ifdef CONFIG_DEBUG_DCFLUSH
10399 - atomic_inc(&dcpage_flushes_xcall);
10400 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10401 #endif
10402 }
10403 __local_flush_dcache_page(page);
10404 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
10405 index 3a8d184..49498a8 100644
10406 --- a/arch/sparc/kernel/sys_sparc_32.c
10407 +++ b/arch/sparc/kernel/sys_sparc_32.c
10408 @@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10409 if (len > TASK_SIZE - PAGE_SIZE)
10410 return -ENOMEM;
10411 if (!addr)
10412 - addr = TASK_UNMAPPED_BASE;
10413 + addr = current->mm->mmap_base;
10414
10415 info.flags = 0;
10416 info.length = len;
10417 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
10418 index beb0b5a..5a153f7 100644
10419 --- a/arch/sparc/kernel/sys_sparc_64.c
10420 +++ b/arch/sparc/kernel/sys_sparc_64.c
10421 @@ -88,13 +88,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10422 struct vm_area_struct * vma;
10423 unsigned long task_size = TASK_SIZE;
10424 int do_color_align;
10425 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10426 struct vm_unmapped_area_info info;
10427
10428 if (flags & MAP_FIXED) {
10429 /* We do not accept a shared mapping if it would violate
10430 * cache aliasing constraints.
10431 */
10432 - if ((flags & MAP_SHARED) &&
10433 + if ((filp || (flags & MAP_SHARED)) &&
10434 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10435 return -EINVAL;
10436 return addr;
10437 @@ -109,6 +110,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10438 if (filp || (flags & MAP_SHARED))
10439 do_color_align = 1;
10440
10441 +#ifdef CONFIG_PAX_RANDMMAP
10442 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10443 +#endif
10444 +
10445 if (addr) {
10446 if (do_color_align)
10447 addr = COLOR_ALIGN(addr, pgoff);
10448 @@ -116,22 +121,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10449 addr = PAGE_ALIGN(addr);
10450
10451 vma = find_vma(mm, addr);
10452 - if (task_size - len >= addr &&
10453 - (!vma || addr + len <= vma->vm_start))
10454 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10455 return addr;
10456 }
10457
10458 info.flags = 0;
10459 info.length = len;
10460 - info.low_limit = TASK_UNMAPPED_BASE;
10461 + info.low_limit = mm->mmap_base;
10462 info.high_limit = min(task_size, VA_EXCLUDE_START);
10463 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10464 info.align_offset = pgoff << PAGE_SHIFT;
10465 + info.threadstack_offset = offset;
10466 addr = vm_unmapped_area(&info);
10467
10468 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10469 VM_BUG_ON(addr != -ENOMEM);
10470 info.low_limit = VA_EXCLUDE_END;
10471 +
10472 +#ifdef CONFIG_PAX_RANDMMAP
10473 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10474 + info.low_limit += mm->delta_mmap;
10475 +#endif
10476 +
10477 info.high_limit = task_size;
10478 addr = vm_unmapped_area(&info);
10479 }
10480 @@ -149,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10481 unsigned long task_size = STACK_TOP32;
10482 unsigned long addr = addr0;
10483 int do_color_align;
10484 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10485 struct vm_unmapped_area_info info;
10486
10487 /* This should only ever run for 32-bit processes. */
10488 @@ -158,7 +170,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10489 /* We do not accept a shared mapping if it would violate
10490 * cache aliasing constraints.
10491 */
10492 - if ((flags & MAP_SHARED) &&
10493 + if ((filp || (flags & MAP_SHARED)) &&
10494 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10495 return -EINVAL;
10496 return addr;
10497 @@ -171,6 +183,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10498 if (filp || (flags & MAP_SHARED))
10499 do_color_align = 1;
10500
10501 +#ifdef CONFIG_PAX_RANDMMAP
10502 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10503 +#endif
10504 +
10505 /* requesting a specific address */
10506 if (addr) {
10507 if (do_color_align)
10508 @@ -179,8 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10509 addr = PAGE_ALIGN(addr);
10510
10511 vma = find_vma(mm, addr);
10512 - if (task_size - len >= addr &&
10513 - (!vma || addr + len <= vma->vm_start))
10514 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10515 return addr;
10516 }
10517
10518 @@ -190,6 +205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10519 info.high_limit = mm->mmap_base;
10520 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10521 info.align_offset = pgoff << PAGE_SHIFT;
10522 + info.threadstack_offset = offset;
10523 addr = vm_unmapped_area(&info);
10524
10525 /*
10526 @@ -202,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10527 VM_BUG_ON(addr != -ENOMEM);
10528 info.flags = 0;
10529 info.low_limit = TASK_UNMAPPED_BASE;
10530 +
10531 +#ifdef CONFIG_PAX_RANDMMAP
10532 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10533 + info.low_limit += mm->delta_mmap;
10534 +#endif
10535 +
10536 info.high_limit = STACK_TOP32;
10537 addr = vm_unmapped_area(&info);
10538 }
10539 @@ -258,10 +280,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
10540 EXPORT_SYMBOL(get_fb_unmapped_area);
10541
10542 /* Essentially the same as PowerPC. */
10543 -static unsigned long mmap_rnd(void)
10544 +static unsigned long mmap_rnd(struct mm_struct *mm)
10545 {
10546 unsigned long rnd = 0UL;
10547
10548 +#ifdef CONFIG_PAX_RANDMMAP
10549 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10550 +#endif
10551 +
10552 if (current->flags & PF_RANDOMIZE) {
10553 unsigned long val = get_random_int();
10554 if (test_thread_flag(TIF_32BIT))
10555 @@ -274,7 +300,7 @@ static unsigned long mmap_rnd(void)
10556
10557 void arch_pick_mmap_layout(struct mm_struct *mm)
10558 {
10559 - unsigned long random_factor = mmap_rnd();
10560 + unsigned long random_factor = mmap_rnd(mm);
10561 unsigned long gap;
10562
10563 /*
10564 @@ -287,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10565 gap == RLIM_INFINITY ||
10566 sysctl_legacy_va_layout) {
10567 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
10568 +
10569 +#ifdef CONFIG_PAX_RANDMMAP
10570 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10571 + mm->mmap_base += mm->delta_mmap;
10572 +#endif
10573 +
10574 mm->get_unmapped_area = arch_get_unmapped_area;
10575 } else {
10576 /* We know it's 32-bit */
10577 @@ -298,6 +330,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10578 gap = (task_size / 6 * 5);
10579
10580 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
10581 +
10582 +#ifdef CONFIG_PAX_RANDMMAP
10583 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10584 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10585 +#endif
10586 +
10587 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10588 }
10589 }
10590 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
10591 index 33a17e7..d87fb1f 100644
10592 --- a/arch/sparc/kernel/syscalls.S
10593 +++ b/arch/sparc/kernel/syscalls.S
10594 @@ -52,7 +52,7 @@ sys32_rt_sigreturn:
10595 #endif
10596 .align 32
10597 1: ldx [%g6 + TI_FLAGS], %l5
10598 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10599 + andcc %l5, _TIF_WORK_SYSCALL, %g0
10600 be,pt %icc, rtrap
10601 nop
10602 call syscall_trace_leave
10603 @@ -184,7 +184,7 @@ linux_sparc_syscall32:
10604
10605 srl %i3, 0, %o3 ! IEU0
10606 srl %i2, 0, %o2 ! IEU0 Group
10607 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10608 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10609 bne,pn %icc, linux_syscall_trace32 ! CTI
10610 mov %i0, %l5 ! IEU1
10611 5: call %l7 ! CTI Group brk forced
10612 @@ -208,7 +208,7 @@ linux_sparc_syscall:
10613
10614 mov %i3, %o3 ! IEU1
10615 mov %i4, %o4 ! IEU0 Group
10616 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10617 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10618 bne,pn %icc, linux_syscall_trace ! CTI Group
10619 mov %i0, %l5 ! IEU0
10620 2: call %l7 ! CTI Group brk forced
10621 @@ -223,7 +223,7 @@ ret_sys_call:
10622
10623 cmp %o0, -ERESTART_RESTARTBLOCK
10624 bgeu,pn %xcc, 1f
10625 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10626 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10627 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
10628
10629 2:
10630 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
10631 index 6629829..036032d 100644
10632 --- a/arch/sparc/kernel/traps_32.c
10633 +++ b/arch/sparc/kernel/traps_32.c
10634 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
10635 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
10636 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
10637
10638 +extern void gr_handle_kernel_exploit(void);
10639 +
10640 void die_if_kernel(char *str, struct pt_regs *regs)
10641 {
10642 static int die_counter;
10643 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10644 count++ < 30 &&
10645 (((unsigned long) rw) >= PAGE_OFFSET) &&
10646 !(((unsigned long) rw) & 0x7)) {
10647 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
10648 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
10649 (void *) rw->ins[7]);
10650 rw = (struct reg_window32 *)rw->ins[6];
10651 }
10652 }
10653 printk("Instruction DUMP:");
10654 instruction_dump ((unsigned long *) regs->pc);
10655 - if(regs->psr & PSR_PS)
10656 + if(regs->psr & PSR_PS) {
10657 + gr_handle_kernel_exploit();
10658 do_exit(SIGKILL);
10659 + }
10660 do_exit(SIGSEGV);
10661 }
10662
10663 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
10664 index 4ced92f..965eeed 100644
10665 --- a/arch/sparc/kernel/traps_64.c
10666 +++ b/arch/sparc/kernel/traps_64.c
10667 @@ -77,7 +77,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
10668 i + 1,
10669 p->trapstack[i].tstate, p->trapstack[i].tpc,
10670 p->trapstack[i].tnpc, p->trapstack[i].tt);
10671 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
10672 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
10673 }
10674 }
10675
10676 @@ -97,6 +97,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
10677
10678 lvl -= 0x100;
10679 if (regs->tstate & TSTATE_PRIV) {
10680 +
10681 +#ifdef CONFIG_PAX_REFCOUNT
10682 + if (lvl == 6)
10683 + pax_report_refcount_overflow(regs);
10684 +#endif
10685 +
10686 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
10687 die_if_kernel(buffer, regs);
10688 }
10689 @@ -115,11 +121,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
10690 void bad_trap_tl1(struct pt_regs *regs, long lvl)
10691 {
10692 char buffer[32];
10693 -
10694 +
10695 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
10696 0, lvl, SIGTRAP) == NOTIFY_STOP)
10697 return;
10698
10699 +#ifdef CONFIG_PAX_REFCOUNT
10700 + if (lvl == 6)
10701 + pax_report_refcount_overflow(regs);
10702 +#endif
10703 +
10704 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
10705
10706 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
10707 @@ -1149,7 +1160,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
10708 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
10709 printk("%s" "ERROR(%d): ",
10710 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
10711 - printk("TPC<%pS>\n", (void *) regs->tpc);
10712 + printk("TPC<%pA>\n", (void *) regs->tpc);
10713 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
10714 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
10715 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
10716 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10717 smp_processor_id(),
10718 (type & 0x1) ? 'I' : 'D',
10719 regs->tpc);
10720 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
10721 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
10722 panic("Irrecoverable Cheetah+ parity error.");
10723 }
10724
10725 @@ -1764,7 +1775,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10726 smp_processor_id(),
10727 (type & 0x1) ? 'I' : 'D',
10728 regs->tpc);
10729 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
10730 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
10731 }
10732
10733 struct sun4v_error_entry {
10734 @@ -1837,8 +1848,8 @@ struct sun4v_error_entry {
10735 /*0x38*/u64 reserved_5;
10736 };
10737
10738 -static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10739 -static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10740 +static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10741 +static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10742
10743 static const char *sun4v_err_type_to_str(u8 type)
10744 {
10745 @@ -1930,7 +1941,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
10746 }
10747
10748 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10749 - int cpu, const char *pfx, atomic_t *ocnt)
10750 + int cpu, const char *pfx, atomic_unchecked_t *ocnt)
10751 {
10752 u64 *raw_ptr = (u64 *) ent;
10753 u32 attrs;
10754 @@ -1988,8 +1999,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10755
10756 show_regs(regs);
10757
10758 - if ((cnt = atomic_read(ocnt)) != 0) {
10759 - atomic_set(ocnt, 0);
10760 + if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
10761 + atomic_set_unchecked(ocnt, 0);
10762 wmb();
10763 printk("%s: Queue overflowed %d times.\n",
10764 pfx, cnt);
10765 @@ -2046,7 +2057,7 @@ out:
10766 */
10767 void sun4v_resum_overflow(struct pt_regs *regs)
10768 {
10769 - atomic_inc(&sun4v_resum_oflow_cnt);
10770 + atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
10771 }
10772
10773 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
10774 @@ -2099,7 +2110,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
10775 /* XXX Actually even this can make not that much sense. Perhaps
10776 * XXX we should just pull the plug and panic directly from here?
10777 */
10778 - atomic_inc(&sun4v_nonresum_oflow_cnt);
10779 + atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
10780 }
10781
10782 unsigned long sun4v_err_itlb_vaddr;
10783 @@ -2114,9 +2125,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
10784
10785 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10786 regs->tpc, tl);
10787 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10788 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10789 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10790 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10791 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10792 (void *) regs->u_regs[UREG_I7]);
10793 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10794 "pte[%lx] error[%lx]\n",
10795 @@ -2138,9 +2149,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10796
10797 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10798 regs->tpc, tl);
10799 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10800 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10801 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10802 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10803 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10804 (void *) regs->u_regs[UREG_I7]);
10805 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10806 "pte[%lx] error[%lx]\n",
10807 @@ -2359,13 +2370,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10808 fp = (unsigned long)sf->fp + STACK_BIAS;
10809 }
10810
10811 - printk(" [%016lx] %pS\n", pc, (void *) pc);
10812 + printk(" [%016lx] %pA\n", pc, (void *) pc);
10813 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10814 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10815 int index = tsk->curr_ret_stack;
10816 if (tsk->ret_stack && index >= graph) {
10817 pc = tsk->ret_stack[index - graph].ret;
10818 - printk(" [%016lx] %pS\n", pc, (void *) pc);
10819 + printk(" [%016lx] %pA\n", pc, (void *) pc);
10820 graph++;
10821 }
10822 }
10823 @@ -2383,6 +2394,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10824 return (struct reg_window *) (fp + STACK_BIAS);
10825 }
10826
10827 +extern void gr_handle_kernel_exploit(void);
10828 +
10829 void die_if_kernel(char *str, struct pt_regs *regs)
10830 {
10831 static int die_counter;
10832 @@ -2411,7 +2424,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10833 while (rw &&
10834 count++ < 30 &&
10835 kstack_valid(tp, (unsigned long) rw)) {
10836 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
10837 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
10838 (void *) rw->ins[7]);
10839
10840 rw = kernel_stack_up(rw);
10841 @@ -2424,8 +2437,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10842 }
10843 user_instruction_dump ((unsigned int __user *) regs->tpc);
10844 }
10845 - if (regs->tstate & TSTATE_PRIV)
10846 + if (regs->tstate & TSTATE_PRIV) {
10847 + gr_handle_kernel_exploit();
10848 do_exit(SIGKILL);
10849 + }
10850 do_exit(SIGSEGV);
10851 }
10852 EXPORT_SYMBOL(die_if_kernel);
10853 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10854 index 35ab8b6..9046547 100644
10855 --- a/arch/sparc/kernel/unaligned_64.c
10856 +++ b/arch/sparc/kernel/unaligned_64.c
10857 @@ -295,7 +295,7 @@ static void log_unaligned(struct pt_regs *regs)
10858 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10859
10860 if (__ratelimit(&ratelimit)) {
10861 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
10862 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
10863 regs->tpc, (void *) regs->tpc);
10864 }
10865 }
10866 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10867 index dbe119b..089c7c1 100644
10868 --- a/arch/sparc/lib/Makefile
10869 +++ b/arch/sparc/lib/Makefile
10870 @@ -2,7 +2,7 @@
10871 #
10872
10873 asflags-y := -ansi -DST_DIV0=0x02
10874 -ccflags-y := -Werror
10875 +#ccflags-y := -Werror
10876
10877 lib-$(CONFIG_SPARC32) += ashrdi3.o
10878 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10879 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10880 index 85c233d..68500e0 100644
10881 --- a/arch/sparc/lib/atomic_64.S
10882 +++ b/arch/sparc/lib/atomic_64.S
10883 @@ -17,7 +17,12 @@
10884 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10885 BACKOFF_SETUP(%o2)
10886 1: lduw [%o1], %g1
10887 - add %g1, %o0, %g7
10888 + addcc %g1, %o0, %g7
10889 +
10890 +#ifdef CONFIG_PAX_REFCOUNT
10891 + tvs %icc, 6
10892 +#endif
10893 +
10894 cas [%o1], %g1, %g7
10895 cmp %g1, %g7
10896 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10897 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10898 2: BACKOFF_SPIN(%o2, %o3, 1b)
10899 ENDPROC(atomic_add)
10900
10901 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10902 + BACKOFF_SETUP(%o2)
10903 +1: lduw [%o1], %g1
10904 + add %g1, %o0, %g7
10905 + cas [%o1], %g1, %g7
10906 + cmp %g1, %g7
10907 + bne,pn %icc, 2f
10908 + nop
10909 + retl
10910 + nop
10911 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10912 +ENDPROC(atomic_add_unchecked)
10913 +
10914 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10915 BACKOFF_SETUP(%o2)
10916 1: lduw [%o1], %g1
10917 - sub %g1, %o0, %g7
10918 + subcc %g1, %o0, %g7
10919 +
10920 +#ifdef CONFIG_PAX_REFCOUNT
10921 + tvs %icc, 6
10922 +#endif
10923 +
10924 cas [%o1], %g1, %g7
10925 cmp %g1, %g7
10926 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10927 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10928 2: BACKOFF_SPIN(%o2, %o3, 1b)
10929 ENDPROC(atomic_sub)
10930
10931 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10932 + BACKOFF_SETUP(%o2)
10933 +1: lduw [%o1], %g1
10934 + sub %g1, %o0, %g7
10935 + cas [%o1], %g1, %g7
10936 + cmp %g1, %g7
10937 + bne,pn %icc, 2f
10938 + nop
10939 + retl
10940 + nop
10941 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10942 +ENDPROC(atomic_sub_unchecked)
10943 +
10944 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10945 BACKOFF_SETUP(%o2)
10946 1: lduw [%o1], %g1
10947 - add %g1, %o0, %g7
10948 + addcc %g1, %o0, %g7
10949 +
10950 +#ifdef CONFIG_PAX_REFCOUNT
10951 + tvs %icc, 6
10952 +#endif
10953 +
10954 cas [%o1], %g1, %g7
10955 cmp %g1, %g7
10956 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10957 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10958 2: BACKOFF_SPIN(%o2, %o3, 1b)
10959 ENDPROC(atomic_add_ret)
10960
10961 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10962 + BACKOFF_SETUP(%o2)
10963 +1: lduw [%o1], %g1
10964 + addcc %g1, %o0, %g7
10965 + cas [%o1], %g1, %g7
10966 + cmp %g1, %g7
10967 + bne,pn %icc, 2f
10968 + add %g7, %o0, %g7
10969 + sra %g7, 0, %o0
10970 + retl
10971 + nop
10972 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10973 +ENDPROC(atomic_add_ret_unchecked)
10974 +
10975 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10976 BACKOFF_SETUP(%o2)
10977 1: lduw [%o1], %g1
10978 - sub %g1, %o0, %g7
10979 + subcc %g1, %o0, %g7
10980 +
10981 +#ifdef CONFIG_PAX_REFCOUNT
10982 + tvs %icc, 6
10983 +#endif
10984 +
10985 cas [%o1], %g1, %g7
10986 cmp %g1, %g7
10987 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10988 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
10989 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10990 BACKOFF_SETUP(%o2)
10991 1: ldx [%o1], %g1
10992 - add %g1, %o0, %g7
10993 + addcc %g1, %o0, %g7
10994 +
10995 +#ifdef CONFIG_PAX_REFCOUNT
10996 + tvs %xcc, 6
10997 +#endif
10998 +
10999 casx [%o1], %g1, %g7
11000 cmp %g1, %g7
11001 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11002 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
11003 2: BACKOFF_SPIN(%o2, %o3, 1b)
11004 ENDPROC(atomic64_add)
11005
11006 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11007 + BACKOFF_SETUP(%o2)
11008 +1: ldx [%o1], %g1
11009 + addcc %g1, %o0, %g7
11010 + casx [%o1], %g1, %g7
11011 + cmp %g1, %g7
11012 + bne,pn %xcc, 2f
11013 + nop
11014 + retl
11015 + nop
11016 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11017 +ENDPROC(atomic64_add_unchecked)
11018 +
11019 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11020 BACKOFF_SETUP(%o2)
11021 1: ldx [%o1], %g1
11022 - sub %g1, %o0, %g7
11023 + subcc %g1, %o0, %g7
11024 +
11025 +#ifdef CONFIG_PAX_REFCOUNT
11026 + tvs %xcc, 6
11027 +#endif
11028 +
11029 casx [%o1], %g1, %g7
11030 cmp %g1, %g7
11031 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11032 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11033 2: BACKOFF_SPIN(%o2, %o3, 1b)
11034 ENDPROC(atomic64_sub)
11035
11036 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
11037 + BACKOFF_SETUP(%o2)
11038 +1: ldx [%o1], %g1
11039 + subcc %g1, %o0, %g7
11040 + casx [%o1], %g1, %g7
11041 + cmp %g1, %g7
11042 + bne,pn %xcc, 2f
11043 + nop
11044 + retl
11045 + nop
11046 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11047 +ENDPROC(atomic64_sub_unchecked)
11048 +
11049 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11050 BACKOFF_SETUP(%o2)
11051 1: ldx [%o1], %g1
11052 - add %g1, %o0, %g7
11053 + addcc %g1, %o0, %g7
11054 +
11055 +#ifdef CONFIG_PAX_REFCOUNT
11056 + tvs %xcc, 6
11057 +#endif
11058 +
11059 casx [%o1], %g1, %g7
11060 cmp %g1, %g7
11061 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11062 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11063 2: BACKOFF_SPIN(%o2, %o3, 1b)
11064 ENDPROC(atomic64_add_ret)
11065
11066 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11067 + BACKOFF_SETUP(%o2)
11068 +1: ldx [%o1], %g1
11069 + addcc %g1, %o0, %g7
11070 + casx [%o1], %g1, %g7
11071 + cmp %g1, %g7
11072 + bne,pn %xcc, 2f
11073 + add %g7, %o0, %g7
11074 + mov %g7, %o0
11075 + retl
11076 + nop
11077 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11078 +ENDPROC(atomic64_add_ret_unchecked)
11079 +
11080 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
11081 BACKOFF_SETUP(%o2)
11082 1: ldx [%o1], %g1
11083 - sub %g1, %o0, %g7
11084 + subcc %g1, %o0, %g7
11085 +
11086 +#ifdef CONFIG_PAX_REFCOUNT
11087 + tvs %xcc, 6
11088 +#endif
11089 +
11090 casx [%o1], %g1, %g7
11091 cmp %g1, %g7
11092 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11093 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
11094 index 323335b..ed85ea2 100644
11095 --- a/arch/sparc/lib/ksyms.c
11096 +++ b/arch/sparc/lib/ksyms.c
11097 @@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
11098
11099 /* Atomic counter implementation. */
11100 EXPORT_SYMBOL(atomic_add);
11101 +EXPORT_SYMBOL(atomic_add_unchecked);
11102 EXPORT_SYMBOL(atomic_add_ret);
11103 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
11104 EXPORT_SYMBOL(atomic_sub);
11105 +EXPORT_SYMBOL(atomic_sub_unchecked);
11106 EXPORT_SYMBOL(atomic_sub_ret);
11107 EXPORT_SYMBOL(atomic64_add);
11108 +EXPORT_SYMBOL(atomic64_add_unchecked);
11109 EXPORT_SYMBOL(atomic64_add_ret);
11110 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
11111 EXPORT_SYMBOL(atomic64_sub);
11112 +EXPORT_SYMBOL(atomic64_sub_unchecked);
11113 EXPORT_SYMBOL(atomic64_sub_ret);
11114 EXPORT_SYMBOL(atomic64_dec_if_positive);
11115
11116 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
11117 index 30c3ecc..736f015 100644
11118 --- a/arch/sparc/mm/Makefile
11119 +++ b/arch/sparc/mm/Makefile
11120 @@ -2,7 +2,7 @@
11121 #
11122
11123 asflags-y := -ansi
11124 -ccflags-y := -Werror
11125 +#ccflags-y := -Werror
11126
11127 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
11128 obj-y += fault_$(BITS).o
11129 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
11130 index 59dbd46..1dd7f5e 100644
11131 --- a/arch/sparc/mm/fault_32.c
11132 +++ b/arch/sparc/mm/fault_32.c
11133 @@ -21,6 +21,9 @@
11134 #include <linux/perf_event.h>
11135 #include <linux/interrupt.h>
11136 #include <linux/kdebug.h>
11137 +#include <linux/slab.h>
11138 +#include <linux/pagemap.h>
11139 +#include <linux/compiler.h>
11140
11141 #include <asm/page.h>
11142 #include <asm/pgtable.h>
11143 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
11144 return safe_compute_effective_address(regs, insn);
11145 }
11146
11147 +#ifdef CONFIG_PAX_PAGEEXEC
11148 +#ifdef CONFIG_PAX_DLRESOLVE
11149 +static void pax_emuplt_close(struct vm_area_struct *vma)
11150 +{
11151 + vma->vm_mm->call_dl_resolve = 0UL;
11152 +}
11153 +
11154 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11155 +{
11156 + unsigned int *kaddr;
11157 +
11158 + vmf->page = alloc_page(GFP_HIGHUSER);
11159 + if (!vmf->page)
11160 + return VM_FAULT_OOM;
11161 +
11162 + kaddr = kmap(vmf->page);
11163 + memset(kaddr, 0, PAGE_SIZE);
11164 + kaddr[0] = 0x9DE3BFA8U; /* save */
11165 + flush_dcache_page(vmf->page);
11166 + kunmap(vmf->page);
11167 + return VM_FAULT_MAJOR;
11168 +}
11169 +
11170 +static const struct vm_operations_struct pax_vm_ops = {
11171 + .close = pax_emuplt_close,
11172 + .fault = pax_emuplt_fault
11173 +};
11174 +
11175 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11176 +{
11177 + int ret;
11178 +
11179 + INIT_LIST_HEAD(&vma->anon_vma_chain);
11180 + vma->vm_mm = current->mm;
11181 + vma->vm_start = addr;
11182 + vma->vm_end = addr + PAGE_SIZE;
11183 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11184 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11185 + vma->vm_ops = &pax_vm_ops;
11186 +
11187 + ret = insert_vm_struct(current->mm, vma);
11188 + if (ret)
11189 + return ret;
11190 +
11191 + ++current->mm->total_vm;
11192 + return 0;
11193 +}
11194 +#endif
11195 +
11196 +/*
11197 + * PaX: decide what to do with offenders (regs->pc = fault address)
11198 + *
11199 + * returns 1 when task should be killed
11200 + * 2 when patched PLT trampoline was detected
11201 + * 3 when unpatched PLT trampoline was detected
11202 + */
11203 +static int pax_handle_fetch_fault(struct pt_regs *regs)
11204 +{
11205 +
11206 +#ifdef CONFIG_PAX_EMUPLT
11207 + int err;
11208 +
11209 + do { /* PaX: patched PLT emulation #1 */
11210 + unsigned int sethi1, sethi2, jmpl;
11211 +
11212 + err = get_user(sethi1, (unsigned int *)regs->pc);
11213 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
11214 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
11215 +
11216 + if (err)
11217 + break;
11218 +
11219 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11220 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
11221 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
11222 + {
11223 + unsigned int addr;
11224 +
11225 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11226 + addr = regs->u_regs[UREG_G1];
11227 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11228 + regs->pc = addr;
11229 + regs->npc = addr+4;
11230 + return 2;
11231 + }
11232 + } while (0);
11233 +
11234 + do { /* PaX: patched PLT emulation #2 */
11235 + unsigned int ba;
11236 +
11237 + err = get_user(ba, (unsigned int *)regs->pc);
11238 +
11239 + if (err)
11240 + break;
11241 +
11242 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11243 + unsigned int addr;
11244 +
11245 + if ((ba & 0xFFC00000U) == 0x30800000U)
11246 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11247 + else
11248 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11249 + regs->pc = addr;
11250 + regs->npc = addr+4;
11251 + return 2;
11252 + }
11253 + } while (0);
11254 +
11255 + do { /* PaX: patched PLT emulation #3 */
11256 + unsigned int sethi, bajmpl, nop;
11257 +
11258 + err = get_user(sethi, (unsigned int *)regs->pc);
11259 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
11260 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11261 +
11262 + if (err)
11263 + break;
11264 +
11265 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11266 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11267 + nop == 0x01000000U)
11268 + {
11269 + unsigned int addr;
11270 +
11271 + addr = (sethi & 0x003FFFFFU) << 10;
11272 + regs->u_regs[UREG_G1] = addr;
11273 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11274 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11275 + else
11276 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11277 + regs->pc = addr;
11278 + regs->npc = addr+4;
11279 + return 2;
11280 + }
11281 + } while (0);
11282 +
11283 + do { /* PaX: unpatched PLT emulation step 1 */
11284 + unsigned int sethi, ba, nop;
11285 +
11286 + err = get_user(sethi, (unsigned int *)regs->pc);
11287 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
11288 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11289 +
11290 + if (err)
11291 + break;
11292 +
11293 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11294 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11295 + nop == 0x01000000U)
11296 + {
11297 + unsigned int addr, save, call;
11298 +
11299 + if ((ba & 0xFFC00000U) == 0x30800000U)
11300 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11301 + else
11302 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11303 +
11304 + err = get_user(save, (unsigned int *)addr);
11305 + err |= get_user(call, (unsigned int *)(addr+4));
11306 + err |= get_user(nop, (unsigned int *)(addr+8));
11307 + if (err)
11308 + break;
11309 +
11310 +#ifdef CONFIG_PAX_DLRESOLVE
11311 + if (save == 0x9DE3BFA8U &&
11312 + (call & 0xC0000000U) == 0x40000000U &&
11313 + nop == 0x01000000U)
11314 + {
11315 + struct vm_area_struct *vma;
11316 + unsigned long call_dl_resolve;
11317 +
11318 + down_read(&current->mm->mmap_sem);
11319 + call_dl_resolve = current->mm->call_dl_resolve;
11320 + up_read(&current->mm->mmap_sem);
11321 + if (likely(call_dl_resolve))
11322 + goto emulate;
11323 +
11324 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11325 +
11326 + down_write(&current->mm->mmap_sem);
11327 + if (current->mm->call_dl_resolve) {
11328 + call_dl_resolve = current->mm->call_dl_resolve;
11329 + up_write(&current->mm->mmap_sem);
11330 + if (vma)
11331 + kmem_cache_free(vm_area_cachep, vma);
11332 + goto emulate;
11333 + }
11334 +
11335 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11336 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11337 + up_write(&current->mm->mmap_sem);
11338 + if (vma)
11339 + kmem_cache_free(vm_area_cachep, vma);
11340 + return 1;
11341 + }
11342 +
11343 + if (pax_insert_vma(vma, call_dl_resolve)) {
11344 + up_write(&current->mm->mmap_sem);
11345 + kmem_cache_free(vm_area_cachep, vma);
11346 + return 1;
11347 + }
11348 +
11349 + current->mm->call_dl_resolve = call_dl_resolve;
11350 + up_write(&current->mm->mmap_sem);
11351 +
11352 +emulate:
11353 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11354 + regs->pc = call_dl_resolve;
11355 + regs->npc = addr+4;
11356 + return 3;
11357 + }
11358 +#endif
11359 +
11360 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11361 + if ((save & 0xFFC00000U) == 0x05000000U &&
11362 + (call & 0xFFFFE000U) == 0x85C0A000U &&
11363 + nop == 0x01000000U)
11364 + {
11365 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11366 + regs->u_regs[UREG_G2] = addr + 4;
11367 + addr = (save & 0x003FFFFFU) << 10;
11368 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11369 + regs->pc = addr;
11370 + regs->npc = addr+4;
11371 + return 3;
11372 + }
11373 + }
11374 + } while (0);
11375 +
11376 + do { /* PaX: unpatched PLT emulation step 2 */
11377 + unsigned int save, call, nop;
11378 +
11379 + err = get_user(save, (unsigned int *)(regs->pc-4));
11380 + err |= get_user(call, (unsigned int *)regs->pc);
11381 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
11382 + if (err)
11383 + break;
11384 +
11385 + if (save == 0x9DE3BFA8U &&
11386 + (call & 0xC0000000U) == 0x40000000U &&
11387 + nop == 0x01000000U)
11388 + {
11389 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
11390 +
11391 + regs->u_regs[UREG_RETPC] = regs->pc;
11392 + regs->pc = dl_resolve;
11393 + regs->npc = dl_resolve+4;
11394 + return 3;
11395 + }
11396 + } while (0);
11397 +#endif
11398 +
11399 + return 1;
11400 +}
11401 +
11402 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11403 +{
11404 + unsigned long i;
11405 +
11406 + printk(KERN_ERR "PAX: bytes at PC: ");
11407 + for (i = 0; i < 8; i++) {
11408 + unsigned int c;
11409 + if (get_user(c, (unsigned int *)pc+i))
11410 + printk(KERN_CONT "???????? ");
11411 + else
11412 + printk(KERN_CONT "%08x ", c);
11413 + }
11414 + printk("\n");
11415 +}
11416 +#endif
11417 +
11418 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11419 int text_fault)
11420 {
11421 @@ -229,6 +503,24 @@ good_area:
11422 if (!(vma->vm_flags & VM_WRITE))
11423 goto bad_area;
11424 } else {
11425 +
11426 +#ifdef CONFIG_PAX_PAGEEXEC
11427 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
11428 + up_read(&mm->mmap_sem);
11429 + switch (pax_handle_fetch_fault(regs)) {
11430 +
11431 +#ifdef CONFIG_PAX_EMUPLT
11432 + case 2:
11433 + case 3:
11434 + return;
11435 +#endif
11436 +
11437 + }
11438 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
11439 + do_group_exit(SIGKILL);
11440 + }
11441 +#endif
11442 +
11443 /* Allow reads even for write-only mappings */
11444 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
11445 goto bad_area;
11446 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
11447 index 4ced3fc..234f1e4 100644
11448 --- a/arch/sparc/mm/fault_64.c
11449 +++ b/arch/sparc/mm/fault_64.c
11450 @@ -22,6 +22,9 @@
11451 #include <linux/kdebug.h>
11452 #include <linux/percpu.h>
11453 #include <linux/context_tracking.h>
11454 +#include <linux/slab.h>
11455 +#include <linux/pagemap.h>
11456 +#include <linux/compiler.h>
11457
11458 #include <asm/page.h>
11459 #include <asm/pgtable.h>
11460 @@ -75,7 +78,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
11461 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
11462 regs->tpc);
11463 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
11464 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
11465 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
11466 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
11467 dump_stack();
11468 unhandled_fault(regs->tpc, current, regs);
11469 @@ -281,6 +284,466 @@ static void noinline __kprobes bogus_32bit_fault_tpc(struct pt_regs *regs)
11470 show_regs(regs);
11471 }
11472
11473 +#ifdef CONFIG_PAX_PAGEEXEC
11474 +#ifdef CONFIG_PAX_DLRESOLVE
11475 +static void pax_emuplt_close(struct vm_area_struct *vma)
11476 +{
11477 + vma->vm_mm->call_dl_resolve = 0UL;
11478 +}
11479 +
11480 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11481 +{
11482 + unsigned int *kaddr;
11483 +
11484 + vmf->page = alloc_page(GFP_HIGHUSER);
11485 + if (!vmf->page)
11486 + return VM_FAULT_OOM;
11487 +
11488 + kaddr = kmap(vmf->page);
11489 + memset(kaddr, 0, PAGE_SIZE);
11490 + kaddr[0] = 0x9DE3BFA8U; /* save */
11491 + flush_dcache_page(vmf->page);
11492 + kunmap(vmf->page);
11493 + return VM_FAULT_MAJOR;
11494 +}
11495 +
11496 +static const struct vm_operations_struct pax_vm_ops = {
11497 + .close = pax_emuplt_close,
11498 + .fault = pax_emuplt_fault
11499 +};
11500 +
11501 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11502 +{
11503 + int ret;
11504 +
11505 + INIT_LIST_HEAD(&vma->anon_vma_chain);
11506 + vma->vm_mm = current->mm;
11507 + vma->vm_start = addr;
11508 + vma->vm_end = addr + PAGE_SIZE;
11509 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11510 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11511 + vma->vm_ops = &pax_vm_ops;
11512 +
11513 + ret = insert_vm_struct(current->mm, vma);
11514 + if (ret)
11515 + return ret;
11516 +
11517 + ++current->mm->total_vm;
11518 + return 0;
11519 +}
11520 +#endif
11521 +
11522 +/*
11523 + * PaX: decide what to do with offenders (regs->tpc = fault address)
11524 + *
11525 + * returns 1 when task should be killed
11526 + * 2 when patched PLT trampoline was detected
11527 + * 3 when unpatched PLT trampoline was detected
11528 + */
11529 +static int pax_handle_fetch_fault(struct pt_regs *regs)
11530 +{
11531 +
11532 +#ifdef CONFIG_PAX_EMUPLT
11533 + int err;
11534 +
11535 + do { /* PaX: patched PLT emulation #1 */
11536 + unsigned int sethi1, sethi2, jmpl;
11537 +
11538 + err = get_user(sethi1, (unsigned int *)regs->tpc);
11539 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
11540 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
11541 +
11542 + if (err)
11543 + break;
11544 +
11545 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11546 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
11547 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
11548 + {
11549 + unsigned long addr;
11550 +
11551 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11552 + addr = regs->u_regs[UREG_G1];
11553 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
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 #2 */
11565 + unsigned int ba;
11566 +
11567 + err = get_user(ba, (unsigned int *)regs->tpc);
11568 +
11569 + if (err)
11570 + break;
11571 +
11572 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11573 + unsigned long addr;
11574 +
11575 + if ((ba & 0xFFC00000U) == 0x30800000U)
11576 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11577 + else
11578 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11579 +
11580 + if (test_thread_flag(TIF_32BIT))
11581 + addr &= 0xFFFFFFFFUL;
11582 +
11583 + regs->tpc = addr;
11584 + regs->tnpc = addr+4;
11585 + return 2;
11586 + }
11587 + } while (0);
11588 +
11589 + do { /* PaX: patched PLT emulation #3 */
11590 + unsigned int sethi, bajmpl, nop;
11591 +
11592 + err = get_user(sethi, (unsigned int *)regs->tpc);
11593 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
11594 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11595 +
11596 + if (err)
11597 + break;
11598 +
11599 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11600 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11601 + nop == 0x01000000U)
11602 + {
11603 + unsigned long addr;
11604 +
11605 + addr = (sethi & 0x003FFFFFU) << 10;
11606 + regs->u_regs[UREG_G1] = addr;
11607 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11608 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11609 + else
11610 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11611 +
11612 + if (test_thread_flag(TIF_32BIT))
11613 + addr &= 0xFFFFFFFFUL;
11614 +
11615 + regs->tpc = addr;
11616 + regs->tnpc = addr+4;
11617 + return 2;
11618 + }
11619 + } while (0);
11620 +
11621 + do { /* PaX: patched PLT emulation #4 */
11622 + unsigned int sethi, mov1, call, mov2;
11623 +
11624 + err = get_user(sethi, (unsigned int *)regs->tpc);
11625 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
11626 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
11627 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
11628 +
11629 + if (err)
11630 + break;
11631 +
11632 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11633 + mov1 == 0x8210000FU &&
11634 + (call & 0xC0000000U) == 0x40000000U &&
11635 + mov2 == 0x9E100001U)
11636 + {
11637 + unsigned long addr;
11638 +
11639 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
11640 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11641 +
11642 + if (test_thread_flag(TIF_32BIT))
11643 + addr &= 0xFFFFFFFFUL;
11644 +
11645 + regs->tpc = addr;
11646 + regs->tnpc = addr+4;
11647 + return 2;
11648 + }
11649 + } while (0);
11650 +
11651 + do { /* PaX: patched PLT emulation #5 */
11652 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
11653 +
11654 + err = get_user(sethi, (unsigned int *)regs->tpc);
11655 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11656 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11657 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
11658 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
11659 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
11660 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
11661 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
11662 +
11663 + if (err)
11664 + break;
11665 +
11666 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11667 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11668 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11669 + (or1 & 0xFFFFE000U) == 0x82106000U &&
11670 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
11671 + sllx == 0x83287020U &&
11672 + jmpl == 0x81C04005U &&
11673 + nop == 0x01000000U)
11674 + {
11675 + unsigned long addr;
11676 +
11677 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11678 + regs->u_regs[UREG_G1] <<= 32;
11679 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11680 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11681 + regs->tpc = addr;
11682 + regs->tnpc = addr+4;
11683 + return 2;
11684 + }
11685 + } while (0);
11686 +
11687 + do { /* PaX: patched PLT emulation #6 */
11688 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
11689 +
11690 + err = get_user(sethi, (unsigned int *)regs->tpc);
11691 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11692 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11693 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11694 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
11695 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11696 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11697 +
11698 + if (err)
11699 + break;
11700 +
11701 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11702 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11703 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11704 + sllx == 0x83287020U &&
11705 + (or & 0xFFFFE000U) == 0x8A116000U &&
11706 + jmpl == 0x81C04005U &&
11707 + nop == 0x01000000U)
11708 + {
11709 + unsigned long addr;
11710 +
11711 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11712 + regs->u_regs[UREG_G1] <<= 32;
11713 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
11714 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11715 + regs->tpc = addr;
11716 + regs->tnpc = addr+4;
11717 + return 2;
11718 + }
11719 + } while (0);
11720 +
11721 + do { /* PaX: unpatched PLT emulation step 1 */
11722 + unsigned int sethi, ba, nop;
11723 +
11724 + err = get_user(sethi, (unsigned int *)regs->tpc);
11725 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11726 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11727 +
11728 + if (err)
11729 + break;
11730 +
11731 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11732 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11733 + nop == 0x01000000U)
11734 + {
11735 + unsigned long addr;
11736 + unsigned int save, call;
11737 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11738 +
11739 + if ((ba & 0xFFC00000U) == 0x30800000U)
11740 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11741 + else
11742 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11743 +
11744 + if (test_thread_flag(TIF_32BIT))
11745 + addr &= 0xFFFFFFFFUL;
11746 +
11747 + err = get_user(save, (unsigned int *)addr);
11748 + err |= get_user(call, (unsigned int *)(addr+4));
11749 + err |= get_user(nop, (unsigned int *)(addr+8));
11750 + if (err)
11751 + break;
11752 +
11753 +#ifdef CONFIG_PAX_DLRESOLVE
11754 + if (save == 0x9DE3BFA8U &&
11755 + (call & 0xC0000000U) == 0x40000000U &&
11756 + nop == 0x01000000U)
11757 + {
11758 + struct vm_area_struct *vma;
11759 + unsigned long call_dl_resolve;
11760 +
11761 + down_read(&current->mm->mmap_sem);
11762 + call_dl_resolve = current->mm->call_dl_resolve;
11763 + up_read(&current->mm->mmap_sem);
11764 + if (likely(call_dl_resolve))
11765 + goto emulate;
11766 +
11767 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11768 +
11769 + down_write(&current->mm->mmap_sem);
11770 + if (current->mm->call_dl_resolve) {
11771 + call_dl_resolve = current->mm->call_dl_resolve;
11772 + up_write(&current->mm->mmap_sem);
11773 + if (vma)
11774 + kmem_cache_free(vm_area_cachep, vma);
11775 + goto emulate;
11776 + }
11777 +
11778 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11779 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11780 + up_write(&current->mm->mmap_sem);
11781 + if (vma)
11782 + kmem_cache_free(vm_area_cachep, vma);
11783 + return 1;
11784 + }
11785 +
11786 + if (pax_insert_vma(vma, call_dl_resolve)) {
11787 + up_write(&current->mm->mmap_sem);
11788 + kmem_cache_free(vm_area_cachep, vma);
11789 + return 1;
11790 + }
11791 +
11792 + current->mm->call_dl_resolve = call_dl_resolve;
11793 + up_write(&current->mm->mmap_sem);
11794 +
11795 +emulate:
11796 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11797 + regs->tpc = call_dl_resolve;
11798 + regs->tnpc = addr+4;
11799 + return 3;
11800 + }
11801 +#endif
11802 +
11803 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11804 + if ((save & 0xFFC00000U) == 0x05000000U &&
11805 + (call & 0xFFFFE000U) == 0x85C0A000U &&
11806 + nop == 0x01000000U)
11807 + {
11808 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11809 + regs->u_regs[UREG_G2] = addr + 4;
11810 + addr = (save & 0x003FFFFFU) << 10;
11811 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11812 +
11813 + if (test_thread_flag(TIF_32BIT))
11814 + addr &= 0xFFFFFFFFUL;
11815 +
11816 + regs->tpc = addr;
11817 + regs->tnpc = addr+4;
11818 + return 3;
11819 + }
11820 +
11821 + /* PaX: 64-bit PLT stub */
11822 + err = get_user(sethi1, (unsigned int *)addr);
11823 + err |= get_user(sethi2, (unsigned int *)(addr+4));
11824 + err |= get_user(or1, (unsigned int *)(addr+8));
11825 + err |= get_user(or2, (unsigned int *)(addr+12));
11826 + err |= get_user(sllx, (unsigned int *)(addr+16));
11827 + err |= get_user(add, (unsigned int *)(addr+20));
11828 + err |= get_user(jmpl, (unsigned int *)(addr+24));
11829 + err |= get_user(nop, (unsigned int *)(addr+28));
11830 + if (err)
11831 + break;
11832 +
11833 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11834 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11835 + (or1 & 0xFFFFE000U) == 0x88112000U &&
11836 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
11837 + sllx == 0x89293020U &&
11838 + add == 0x8A010005U &&
11839 + jmpl == 0x89C14000U &&
11840 + nop == 0x01000000U)
11841 + {
11842 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11843 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11844 + regs->u_regs[UREG_G4] <<= 32;
11845 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11846 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11847 + regs->u_regs[UREG_G4] = addr + 24;
11848 + addr = regs->u_regs[UREG_G5];
11849 + regs->tpc = addr;
11850 + regs->tnpc = addr+4;
11851 + return 3;
11852 + }
11853 + }
11854 + } while (0);
11855 +
11856 +#ifdef CONFIG_PAX_DLRESOLVE
11857 + do { /* PaX: unpatched PLT emulation step 2 */
11858 + unsigned int save, call, nop;
11859 +
11860 + err = get_user(save, (unsigned int *)(regs->tpc-4));
11861 + err |= get_user(call, (unsigned int *)regs->tpc);
11862 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11863 + if (err)
11864 + break;
11865 +
11866 + if (save == 0x9DE3BFA8U &&
11867 + (call & 0xC0000000U) == 0x40000000U &&
11868 + nop == 0x01000000U)
11869 + {
11870 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11871 +
11872 + if (test_thread_flag(TIF_32BIT))
11873 + dl_resolve &= 0xFFFFFFFFUL;
11874 +
11875 + regs->u_regs[UREG_RETPC] = regs->tpc;
11876 + regs->tpc = dl_resolve;
11877 + regs->tnpc = dl_resolve+4;
11878 + return 3;
11879 + }
11880 + } while (0);
11881 +#endif
11882 +
11883 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
11884 + unsigned int sethi, ba, nop;
11885 +
11886 + err = get_user(sethi, (unsigned int *)regs->tpc);
11887 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11888 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11889 +
11890 + if (err)
11891 + break;
11892 +
11893 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11894 + (ba & 0xFFF00000U) == 0x30600000U &&
11895 + nop == 0x01000000U)
11896 + {
11897 + unsigned long addr;
11898 +
11899 + addr = (sethi & 0x003FFFFFU) << 10;
11900 + regs->u_regs[UREG_G1] = addr;
11901 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11902 +
11903 + if (test_thread_flag(TIF_32BIT))
11904 + addr &= 0xFFFFFFFFUL;
11905 +
11906 + regs->tpc = addr;
11907 + regs->tnpc = addr+4;
11908 + return 2;
11909 + }
11910 + } while (0);
11911 +
11912 +#endif
11913 +
11914 + return 1;
11915 +}
11916 +
11917 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11918 +{
11919 + unsigned long i;
11920 +
11921 + printk(KERN_ERR "PAX: bytes at PC: ");
11922 + for (i = 0; i < 8; i++) {
11923 + unsigned int c;
11924 + if (get_user(c, (unsigned int *)pc+i))
11925 + printk(KERN_CONT "???????? ");
11926 + else
11927 + printk(KERN_CONT "%08x ", c);
11928 + }
11929 + printk("\n");
11930 +}
11931 +#endif
11932 +
11933 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
11934 {
11935 enum ctx_state prev_state = exception_enter();
11936 @@ -352,6 +815,29 @@ retry:
11937 if (!vma)
11938 goto bad_area;
11939
11940 +#ifdef CONFIG_PAX_PAGEEXEC
11941 + /* PaX: detect ITLB misses on non-exec pages */
11942 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
11943 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
11944 + {
11945 + if (address != regs->tpc)
11946 + goto good_area;
11947 +
11948 + up_read(&mm->mmap_sem);
11949 + switch (pax_handle_fetch_fault(regs)) {
11950 +
11951 +#ifdef CONFIG_PAX_EMUPLT
11952 + case 2:
11953 + case 3:
11954 + return;
11955 +#endif
11956 +
11957 + }
11958 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
11959 + do_group_exit(SIGKILL);
11960 + }
11961 +#endif
11962 +
11963 /* Pure DTLB misses do not tell us whether the fault causing
11964 * load/store/atomic was a write or not, it only says that there
11965 * was no match. So in such a case we (carefully) read the
11966 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
11967 index d329537..2c3746a 100644
11968 --- a/arch/sparc/mm/hugetlbpage.c
11969 +++ b/arch/sparc/mm/hugetlbpage.c
11970 @@ -25,8 +25,10 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11971 unsigned long addr,
11972 unsigned long len,
11973 unsigned long pgoff,
11974 - unsigned long flags)
11975 + unsigned long flags,
11976 + unsigned long offset)
11977 {
11978 + struct mm_struct *mm = current->mm;
11979 unsigned long task_size = TASK_SIZE;
11980 struct vm_unmapped_area_info info;
11981
11982 @@ -35,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11983
11984 info.flags = 0;
11985 info.length = len;
11986 - info.low_limit = TASK_UNMAPPED_BASE;
11987 + info.low_limit = mm->mmap_base;
11988 info.high_limit = min(task_size, VA_EXCLUDE_START);
11989 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11990 info.align_offset = 0;
11991 + info.threadstack_offset = offset;
11992 addr = vm_unmapped_area(&info);
11993
11994 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11995 VM_BUG_ON(addr != -ENOMEM);
11996 info.low_limit = VA_EXCLUDE_END;
11997 +
11998 +#ifdef CONFIG_PAX_RANDMMAP
11999 + if (mm->pax_flags & MF_PAX_RANDMMAP)
12000 + info.low_limit += mm->delta_mmap;
12001 +#endif
12002 +
12003 info.high_limit = task_size;
12004 addr = vm_unmapped_area(&info);
12005 }
12006 @@ -55,7 +64,8 @@ static unsigned long
12007 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12008 const unsigned long len,
12009 const unsigned long pgoff,
12010 - const unsigned long flags)
12011 + const unsigned long flags,
12012 + const unsigned long offset)
12013 {
12014 struct mm_struct *mm = current->mm;
12015 unsigned long addr = addr0;
12016 @@ -70,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12017 info.high_limit = mm->mmap_base;
12018 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12019 info.align_offset = 0;
12020 + info.threadstack_offset = offset;
12021 addr = vm_unmapped_area(&info);
12022
12023 /*
12024 @@ -82,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12025 VM_BUG_ON(addr != -ENOMEM);
12026 info.flags = 0;
12027 info.low_limit = TASK_UNMAPPED_BASE;
12028 +
12029 +#ifdef CONFIG_PAX_RANDMMAP
12030 + if (mm->pax_flags & MF_PAX_RANDMMAP)
12031 + info.low_limit += mm->delta_mmap;
12032 +#endif
12033 +
12034 info.high_limit = STACK_TOP32;
12035 addr = vm_unmapped_area(&info);
12036 }
12037 @@ -96,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12038 struct mm_struct *mm = current->mm;
12039 struct vm_area_struct *vma;
12040 unsigned long task_size = TASK_SIZE;
12041 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
12042
12043 if (test_thread_flag(TIF_32BIT))
12044 task_size = STACK_TOP32;
12045 @@ -111,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12046 return addr;
12047 }
12048
12049 +#ifdef CONFIG_PAX_RANDMMAP
12050 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
12051 +#endif
12052 +
12053 if (addr) {
12054 addr = ALIGN(addr, HPAGE_SIZE);
12055 vma = find_vma(mm, addr);
12056 - if (task_size - len >= addr &&
12057 - (!vma || addr + len <= vma->vm_start))
12058 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
12059 return addr;
12060 }
12061 if (mm->get_unmapped_area == arch_get_unmapped_area)
12062 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
12063 - pgoff, flags);
12064 + pgoff, flags, offset);
12065 else
12066 return hugetlb_get_unmapped_area_topdown(file, addr, len,
12067 - pgoff, flags);
12068 + pgoff, flags, offset);
12069 }
12070
12071 pte_t *huge_pte_alloc(struct mm_struct *mm,
12072 diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
12073 index 9686224..dfbdb10 100644
12074 --- a/arch/sparc/mm/init_64.c
12075 +++ b/arch/sparc/mm/init_64.c
12076 @@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
12077 int num_kernel_image_mappings;
12078
12079 #ifdef CONFIG_DEBUG_DCFLUSH
12080 -atomic_t dcpage_flushes = ATOMIC_INIT(0);
12081 +atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
12082 #ifdef CONFIG_SMP
12083 -atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12084 +atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12085 #endif
12086 #endif
12087
12088 @@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
12089 {
12090 BUG_ON(tlb_type == hypervisor);
12091 #ifdef CONFIG_DEBUG_DCFLUSH
12092 - atomic_inc(&dcpage_flushes);
12093 + atomic_inc_unchecked(&dcpage_flushes);
12094 #endif
12095
12096 #ifdef DCACHE_ALIASING_POSSIBLE
12097 @@ -470,10 +470,10 @@ void mmu_info(struct seq_file *m)
12098
12099 #ifdef CONFIG_DEBUG_DCFLUSH
12100 seq_printf(m, "DCPageFlushes\t: %d\n",
12101 - atomic_read(&dcpage_flushes));
12102 + atomic_read_unchecked(&dcpage_flushes));
12103 #ifdef CONFIG_SMP
12104 seq_printf(m, "DCPageFlushesXC\t: %d\n",
12105 - atomic_read(&dcpage_flushes_xcall));
12106 + atomic_read_unchecked(&dcpage_flushes_xcall));
12107 #endif /* CONFIG_SMP */
12108 #endif /* CONFIG_DEBUG_DCFLUSH */
12109 }
12110 diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
12111 index 85258ca..df97c79 100644
12112 --- a/arch/tile/Kconfig
12113 +++ b/arch/tile/Kconfig
12114 @@ -190,6 +190,7 @@ source "kernel/Kconfig.hz"
12115
12116 config KEXEC
12117 bool "kexec system call"
12118 + depends on !GRKERNSEC_KMEM
12119 ---help---
12120 kexec is a system call that implements the ability to shutdown your
12121 current kernel, and to start another kernel. It is like a reboot
12122 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
12123 index ad220ee..2f537b3 100644
12124 --- a/arch/tile/include/asm/atomic_64.h
12125 +++ b/arch/tile/include/asm/atomic_64.h
12126 @@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
12127
12128 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12129
12130 +#define atomic64_read_unchecked(v) atomic64_read(v)
12131 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
12132 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
12133 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
12134 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
12135 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
12136 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
12137 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
12138 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
12139 +
12140 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
12141 #define smp_mb__before_atomic_dec() smp_mb()
12142 #define smp_mb__after_atomic_dec() smp_mb()
12143 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
12144 index 6160761..00cac88 100644
12145 --- a/arch/tile/include/asm/cache.h
12146 +++ b/arch/tile/include/asm/cache.h
12147 @@ -15,11 +15,12 @@
12148 #ifndef _ASM_TILE_CACHE_H
12149 #define _ASM_TILE_CACHE_H
12150
12151 +#include <linux/const.h>
12152 #include <arch/chip.h>
12153
12154 /* bytes per L1 data cache line */
12155 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
12156 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12157 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12158
12159 /* bytes per L2 cache line */
12160 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
12161 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
12162 index b6cde32..c0cb736 100644
12163 --- a/arch/tile/include/asm/uaccess.h
12164 +++ b/arch/tile/include/asm/uaccess.h
12165 @@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
12166 const void __user *from,
12167 unsigned long n)
12168 {
12169 - int sz = __compiletime_object_size(to);
12170 + size_t sz = __compiletime_object_size(to);
12171
12172 - if (likely(sz == -1 || sz >= n))
12173 + if (likely(sz == (size_t)-1 || sz >= n))
12174 n = _copy_from_user(to, from, n);
12175 else
12176 copy_from_user_overflow();
12177 diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
12178 index e514899..f8743c4 100644
12179 --- a/arch/tile/mm/hugetlbpage.c
12180 +++ b/arch/tile/mm/hugetlbpage.c
12181 @@ -207,6 +207,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
12182 info.high_limit = TASK_SIZE;
12183 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12184 info.align_offset = 0;
12185 + info.threadstack_offset = 0;
12186 return vm_unmapped_area(&info);
12187 }
12188
12189 @@ -224,6 +225,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
12190 info.high_limit = current->mm->mmap_base;
12191 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12192 info.align_offset = 0;
12193 + info.threadstack_offset = 0;
12194 addr = vm_unmapped_area(&info);
12195
12196 /*
12197 diff --git a/arch/um/Makefile b/arch/um/Makefile
12198 index 36e658a..71a5c5a 100644
12199 --- a/arch/um/Makefile
12200 +++ b/arch/um/Makefile
12201 @@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
12202 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
12203 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
12204
12205 +ifdef CONSTIFY_PLUGIN
12206 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12207 +endif
12208 +
12209 #This will adjust *FLAGS accordingly to the platform.
12210 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
12211
12212 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
12213 index 19e1bdd..3665b77 100644
12214 --- a/arch/um/include/asm/cache.h
12215 +++ b/arch/um/include/asm/cache.h
12216 @@ -1,6 +1,7 @@
12217 #ifndef __UM_CACHE_H
12218 #define __UM_CACHE_H
12219
12220 +#include <linux/const.h>
12221
12222 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
12223 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12224 @@ -12,6 +13,6 @@
12225 # define L1_CACHE_SHIFT 5
12226 #endif
12227
12228 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12229 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12230
12231 #endif
12232 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
12233 index 2e0a6b1..a64d0f5 100644
12234 --- a/arch/um/include/asm/kmap_types.h
12235 +++ b/arch/um/include/asm/kmap_types.h
12236 @@ -8,6 +8,6 @@
12237
12238 /* No more #include "asm/arch/kmap_types.h" ! */
12239
12240 -#define KM_TYPE_NR 14
12241 +#define KM_TYPE_NR 15
12242
12243 #endif
12244 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
12245 index 5ff53d9..5850cdf 100644
12246 --- a/arch/um/include/asm/page.h
12247 +++ b/arch/um/include/asm/page.h
12248 @@ -14,6 +14,9 @@
12249 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
12250 #define PAGE_MASK (~(PAGE_SIZE-1))
12251
12252 +#define ktla_ktva(addr) (addr)
12253 +#define ktva_ktla(addr) (addr)
12254 +
12255 #ifndef __ASSEMBLY__
12256
12257 struct page;
12258 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
12259 index 0032f92..cd151e0 100644
12260 --- a/arch/um/include/asm/pgtable-3level.h
12261 +++ b/arch/um/include/asm/pgtable-3level.h
12262 @@ -58,6 +58,7 @@
12263 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
12264 #define pud_populate(mm, pud, pmd) \
12265 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
12266 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
12267
12268 #ifdef CONFIG_64BIT
12269 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
12270 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
12271 index f17bca8..48adb87 100644
12272 --- a/arch/um/kernel/process.c
12273 +++ b/arch/um/kernel/process.c
12274 @@ -356,22 +356,6 @@ int singlestepping(void * t)
12275 return 2;
12276 }
12277
12278 -/*
12279 - * Only x86 and x86_64 have an arch_align_stack().
12280 - * All other arches have "#define arch_align_stack(x) (x)"
12281 - * in their asm/exec.h
12282 - * As this is included in UML from asm-um/system-generic.h,
12283 - * we can use it to behave as the subarch does.
12284 - */
12285 -#ifndef arch_align_stack
12286 -unsigned long arch_align_stack(unsigned long sp)
12287 -{
12288 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
12289 - sp -= get_random_int() % 8192;
12290 - return sp & ~0xf;
12291 -}
12292 -#endif
12293 -
12294 unsigned long get_wchan(struct task_struct *p)
12295 {
12296 unsigned long stack_page, sp, ip;
12297 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
12298 index ad8f795..2c7eec6 100644
12299 --- a/arch/unicore32/include/asm/cache.h
12300 +++ b/arch/unicore32/include/asm/cache.h
12301 @@ -12,8 +12,10 @@
12302 #ifndef __UNICORE_CACHE_H__
12303 #define __UNICORE_CACHE_H__
12304
12305 -#define L1_CACHE_SHIFT (5)
12306 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12307 +#include <linux/const.h>
12308 +
12309 +#define L1_CACHE_SHIFT 5
12310 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12311
12312 /*
12313 * Memory returned by kmalloc() may be used for DMA, so we must make
12314 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
12315 index 1dd1408..be4ce12 100644
12316 --- a/arch/x86/Kconfig
12317 +++ b/arch/x86/Kconfig
12318 @@ -127,7 +127,7 @@ config X86
12319 select RTC_LIB
12320 select HAVE_DEBUG_STACKOVERFLOW
12321 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
12322 - select HAVE_CC_STACKPROTECTOR
12323 + select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
12324 select GENERIC_CPU_AUTOPROBE
12325 select HAVE_ARCH_AUDITSYSCALL
12326 select ARCH_SUPPORTS_ATOMIC_RMW
12327 @@ -252,7 +252,7 @@ config X86_HT
12328
12329 config X86_32_LAZY_GS
12330 def_bool y
12331 - depends on X86_32 && !CC_STACKPROTECTOR
12332 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12333
12334 config ARCH_HWEIGHT_CFLAGS
12335 string
12336 @@ -546,6 +546,7 @@ config SCHED_OMIT_FRAME_POINTER
12337
12338 menuconfig HYPERVISOR_GUEST
12339 bool "Linux guest support"
12340 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
12341 ---help---
12342 Say Y here to enable options for running Linux under various hyper-
12343 visors. This option enables basic hypervisor detection and platform
12344 @@ -1072,6 +1073,7 @@ choice
12345
12346 config NOHIGHMEM
12347 bool "off"
12348 + depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12349 ---help---
12350 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12351 However, the address space of 32-bit x86 processors is only 4
12352 @@ -1108,6 +1110,7 @@ config NOHIGHMEM
12353
12354 config HIGHMEM4G
12355 bool "4GB"
12356 + depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12357 ---help---
12358 Select this if you have a 32-bit processor and between 1 and 4
12359 gigabytes of physical RAM.
12360 @@ -1160,7 +1163,7 @@ config PAGE_OFFSET
12361 hex
12362 default 0xB0000000 if VMSPLIT_3G_OPT
12363 default 0x80000000 if VMSPLIT_2G
12364 - default 0x78000000 if VMSPLIT_2G_OPT
12365 + default 0x70000000 if VMSPLIT_2G_OPT
12366 default 0x40000000 if VMSPLIT_1G
12367 default 0xC0000000
12368 depends on X86_32
12369 @@ -1573,6 +1576,7 @@ source kernel/Kconfig.hz
12370
12371 config KEXEC
12372 bool "kexec system call"
12373 + depends on !GRKERNSEC_KMEM
12374 ---help---
12375 kexec is a system call that implements the ability to shutdown your
12376 current kernel, and to start another kernel. It is like a reboot
12377 @@ -1724,7 +1728,9 @@ config X86_NEED_RELOCS
12378
12379 config PHYSICAL_ALIGN
12380 hex "Alignment value to which kernel should be aligned"
12381 - default "0x200000"
12382 + default "0x1000000"
12383 + range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
12384 + range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
12385 range 0x2000 0x1000000 if X86_32
12386 range 0x200000 0x1000000 if X86_64
12387 ---help---
12388 @@ -1807,6 +1813,7 @@ config COMPAT_VDSO
12389 def_bool n
12390 prompt "Disable the 32-bit vDSO (needed for glibc 2.3.3)"
12391 depends on X86_32 || IA32_EMULATION
12392 + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
12393 ---help---
12394 Certain buggy versions of glibc will crash if they are
12395 presented with a 32-bit vDSO that is not mapped at the address
12396 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
12397 index 6983314..54ad7e8 100644
12398 --- a/arch/x86/Kconfig.cpu
12399 +++ b/arch/x86/Kconfig.cpu
12400 @@ -319,7 +319,7 @@ config X86_PPRO_FENCE
12401
12402 config X86_F00F_BUG
12403 def_bool y
12404 - depends on M586MMX || M586TSC || M586 || M486
12405 + depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
12406
12407 config X86_INVD_BUG
12408 def_bool y
12409 @@ -327,7 +327,7 @@ config X86_INVD_BUG
12410
12411 config X86_ALIGNMENT_16
12412 def_bool y
12413 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12414 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12415
12416 config X86_INTEL_USERCOPY
12417 def_bool y
12418 @@ -369,7 +369,7 @@ config X86_CMPXCHG64
12419 # generates cmov.
12420 config X86_CMOV
12421 def_bool y
12422 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12423 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12424
12425 config X86_MINIMUM_CPU_FAMILY
12426 int
12427 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
12428 index 61bd2ad..50b625d 100644
12429 --- a/arch/x86/Kconfig.debug
12430 +++ b/arch/x86/Kconfig.debug
12431 @@ -93,7 +93,7 @@ config EFI_PGT_DUMP
12432 config DEBUG_RODATA
12433 bool "Write protect kernel read-only data structures"
12434 default y
12435 - depends on DEBUG_KERNEL
12436 + depends on DEBUG_KERNEL && BROKEN
12437 ---help---
12438 Mark the kernel read-only data as write-protected in the pagetables,
12439 in order to catch accidental (and incorrect) writes to such const
12440 @@ -111,7 +111,7 @@ config DEBUG_RODATA_TEST
12441
12442 config DEBUG_SET_MODULE_RONX
12443 bool "Set loadable kernel module data as NX and text as RO"
12444 - depends on MODULES
12445 + depends on MODULES && BROKEN
12446 ---help---
12447 This option helps catch unintended modifications to loadable
12448 kernel module's text and read-only data. It also prevents execution
12449 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
12450 index 33f71b0..c2cefa2 100644
12451 --- a/arch/x86/Makefile
12452 +++ b/arch/x86/Makefile
12453 @@ -71,9 +71,6 @@ ifeq ($(CONFIG_X86_32),y)
12454 # CPU-specific tuning. Anything which can be shared with UML should go here.
12455 include $(srctree)/arch/x86/Makefile_32.cpu
12456 KBUILD_CFLAGS += $(cflags-y)
12457 -
12458 - # temporary until string.h is fixed
12459 - KBUILD_CFLAGS += -ffreestanding
12460 else
12461 BITS := 64
12462 UTS_MACHINE := x86_64
12463 @@ -114,6 +111,9 @@ else
12464 KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args)
12465 endif
12466
12467 +# temporary until string.h is fixed
12468 +KBUILD_CFLAGS += -ffreestanding
12469 +
12470 # Make sure compiler does not have buggy stack-protector support.
12471 ifdef CONFIG_CC_STACKPROTECTOR
12472 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
12473 @@ -271,3 +271,12 @@ define archhelp
12474 echo ' FDINITRD=file initrd for the booted kernel'
12475 echo ' kvmconfig - Enable additional options for guest kernel support'
12476 endef
12477 +
12478 +define OLD_LD
12479 +
12480 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
12481 +*** Please upgrade your binutils to 2.18 or newer
12482 +endef
12483 +
12484 +archprepare:
12485 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
12486 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
12487 index dbe8dd2..2f0a98f 100644
12488 --- a/arch/x86/boot/Makefile
12489 +++ b/arch/x86/boot/Makefile
12490 @@ -52,6 +52,9 @@ $(obj)/cpustr.h: $(obj)/mkcpustr FORCE
12491 # ---------------------------------------------------------------------------
12492
12493 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
12494 +ifdef CONSTIFY_PLUGIN
12495 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12496 +endif
12497 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12498 GCOV_PROFILE := n
12499
12500 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
12501 index 878e4b9..20537ab 100644
12502 --- a/arch/x86/boot/bitops.h
12503 +++ b/arch/x86/boot/bitops.h
12504 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12505 u8 v;
12506 const u32 *p = (const u32 *)addr;
12507
12508 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12509 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12510 return v;
12511 }
12512
12513 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12514
12515 static inline void set_bit(int nr, void *addr)
12516 {
12517 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12518 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12519 }
12520
12521 #endif /* BOOT_BITOPS_H */
12522 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
12523 index bd49ec6..94c7f58 100644
12524 --- a/arch/x86/boot/boot.h
12525 +++ b/arch/x86/boot/boot.h
12526 @@ -84,7 +84,7 @@ static inline void io_delay(void)
12527 static inline u16 ds(void)
12528 {
12529 u16 seg;
12530 - asm("movw %%ds,%0" : "=rm" (seg));
12531 + asm volatile("movw %%ds,%0" : "=rm" (seg));
12532 return seg;
12533 }
12534
12535 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
12536 index 0fcd913..3bb5c42 100644
12537 --- a/arch/x86/boot/compressed/Makefile
12538 +++ b/arch/x86/boot/compressed/Makefile
12539 @@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
12540 KBUILD_CFLAGS += -mno-mmx -mno-sse
12541 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
12542 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
12543 +ifdef CONSTIFY_PLUGIN
12544 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12545 +endif
12546
12547 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12548 GCOV_PROFILE := n
12549 diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
12550 index a53440e..c3dbf1e 100644
12551 --- a/arch/x86/boot/compressed/efi_stub_32.S
12552 +++ b/arch/x86/boot/compressed/efi_stub_32.S
12553 @@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
12554 * parameter 2, ..., param n. To make things easy, we save the return
12555 * address of efi_call_phys in a global variable.
12556 */
12557 - popl %ecx
12558 - movl %ecx, saved_return_addr(%edx)
12559 - /* get the function pointer into ECX*/
12560 - popl %ecx
12561 - movl %ecx, efi_rt_function_ptr(%edx)
12562 + popl saved_return_addr(%edx)
12563 + popl efi_rt_function_ptr(%edx)
12564
12565 /*
12566 * 3. Call the physical function.
12567 */
12568 - call *%ecx
12569 + call *efi_rt_function_ptr(%edx)
12570
12571 /*
12572 * 4. Balance the stack. And because EAX contain the return value,
12573 @@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
12574 1: popl %edx
12575 subl $1b, %edx
12576
12577 - movl efi_rt_function_ptr(%edx), %ecx
12578 - pushl %ecx
12579 + pushl efi_rt_function_ptr(%edx)
12580
12581 /*
12582 * 10. Push the saved return address onto the stack and return.
12583 */
12584 - movl saved_return_addr(%edx), %ecx
12585 - pushl %ecx
12586 - ret
12587 + jmpl *saved_return_addr(%edx)
12588 ENDPROC(efi_call_phys)
12589 .previous
12590
12591 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
12592 index cbed140..5f2ca57 100644
12593 --- a/arch/x86/boot/compressed/head_32.S
12594 +++ b/arch/x86/boot/compressed/head_32.S
12595 @@ -140,10 +140,10 @@ preferred_addr:
12596 addl %eax, %ebx
12597 notl %eax
12598 andl %eax, %ebx
12599 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
12600 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12601 jge 1f
12602 #endif
12603 - movl $LOAD_PHYSICAL_ADDR, %ebx
12604 + movl $____LOAD_PHYSICAL_ADDR, %ebx
12605 1:
12606
12607 /* Target address to relocate to for decompression */
12608 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
12609 index 0d558ee..58f257e 100644
12610 --- a/arch/x86/boot/compressed/head_64.S
12611 +++ b/arch/x86/boot/compressed/head_64.S
12612 @@ -94,10 +94,10 @@ ENTRY(startup_32)
12613 addl %eax, %ebx
12614 notl %eax
12615 andl %eax, %ebx
12616 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
12617 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12618 jge 1f
12619 #endif
12620 - movl $LOAD_PHYSICAL_ADDR, %ebx
12621 + movl $____LOAD_PHYSICAL_ADDR, %ebx
12622 1:
12623
12624 /* Target address to relocate to for decompression */
12625 @@ -322,10 +322,10 @@ preferred_addr:
12626 addq %rax, %rbp
12627 notq %rax
12628 andq %rax, %rbp
12629 - cmpq $LOAD_PHYSICAL_ADDR, %rbp
12630 + cmpq $____LOAD_PHYSICAL_ADDR, %rbp
12631 jge 1f
12632 #endif
12633 - movq $LOAD_PHYSICAL_ADDR, %rbp
12634 + movq $____LOAD_PHYSICAL_ADDR, %rbp
12635 1:
12636
12637 /* Target address to relocate to for decompression */
12638 @@ -431,8 +431,8 @@ gdt:
12639 .long gdt
12640 .word 0
12641 .quad 0x0000000000000000 /* NULL descriptor */
12642 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
12643 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
12644 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
12645 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
12646 .quad 0x0080890000000000 /* TS descriptor */
12647 .quad 0x0000000000000000 /* TS continued */
12648 gdt_end:
12649 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
12650 index 57ab74d..7c52182 100644
12651 --- a/arch/x86/boot/compressed/misc.c
12652 +++ b/arch/x86/boot/compressed/misc.c
12653 @@ -242,7 +242,7 @@ static void handle_relocations(void *output, unsigned long output_len)
12654 * Calculate the delta between where vmlinux was linked to load
12655 * and where it was actually loaded.
12656 */
12657 - delta = min_addr - LOAD_PHYSICAL_ADDR;
12658 + delta = min_addr - ____LOAD_PHYSICAL_ADDR;
12659 if (!delta) {
12660 debug_putstr("No relocation needed... ");
12661 return;
12662 @@ -312,7 +312,7 @@ static void parse_elf(void *output)
12663 Elf32_Ehdr ehdr;
12664 Elf32_Phdr *phdrs, *phdr;
12665 #endif
12666 - void *dest;
12667 + void *dest, *prev;
12668 int i;
12669
12670 memcpy(&ehdr, output, sizeof(ehdr));
12671 @@ -339,13 +339,16 @@ static void parse_elf(void *output)
12672 case PT_LOAD:
12673 #ifdef CONFIG_RELOCATABLE
12674 dest = output;
12675 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
12676 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
12677 #else
12678 dest = (void *)(phdr->p_paddr);
12679 #endif
12680 memcpy(dest,
12681 output + phdr->p_offset,
12682 phdr->p_filesz);
12683 + if (i)
12684 + memset(prev, 0xff, dest - prev);
12685 + prev = dest + phdr->p_filesz;
12686 break;
12687 default: /* Ignore other PT_* */ break;
12688 }
12689 @@ -395,7 +398,7 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap,
12690 error("Destination address too large");
12691 #endif
12692 #ifndef CONFIG_RELOCATABLE
12693 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
12694 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
12695 error("Wrong destination address");
12696 #endif
12697
12698 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
12699 index 1fd7d57..0f7d096 100644
12700 --- a/arch/x86/boot/cpucheck.c
12701 +++ b/arch/x86/boot/cpucheck.c
12702 @@ -125,9 +125,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12703 u32 ecx = MSR_K7_HWCR;
12704 u32 eax, edx;
12705
12706 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12707 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12708 eax &= ~(1 << 15);
12709 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12710 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12711
12712 get_cpuflags(); /* Make sure it really did something */
12713 err = check_cpuflags();
12714 @@ -140,9 +140,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12715 u32 ecx = MSR_VIA_FCR;
12716 u32 eax, edx;
12717
12718 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12719 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12720 eax |= (1<<1)|(1<<7);
12721 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12722 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12723
12724 set_bit(X86_FEATURE_CX8, cpu.flags);
12725 err = check_cpuflags();
12726 @@ -153,12 +153,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12727 u32 eax, edx;
12728 u32 level = 1;
12729
12730 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12731 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12732 - asm("cpuid"
12733 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12734 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12735 + asm volatile("cpuid"
12736 : "+a" (level), "=d" (cpu.flags[0])
12737 : : "ecx", "ebx");
12738 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12739 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12740
12741 err = check_cpuflags();
12742 } else if (err == 0x01 &&
12743 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12744 index 7a6d43a..edf6e40 100644
12745 --- a/arch/x86/boot/header.S
12746 +++ b/arch/x86/boot/header.S
12747 @@ -438,10 +438,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12748 # single linked list of
12749 # struct setup_data
12750
12751 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12752 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12753
12754 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12755 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12756 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12757 +#else
12758 #define VO_INIT_SIZE (VO__end - VO__text)
12759 +#endif
12760 #if ZO_INIT_SIZE > VO_INIT_SIZE
12761 #define INIT_SIZE ZO_INIT_SIZE
12762 #else
12763 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12764 index db75d07..8e6d0af 100644
12765 --- a/arch/x86/boot/memory.c
12766 +++ b/arch/x86/boot/memory.c
12767 @@ -19,7 +19,7 @@
12768
12769 static int detect_memory_e820(void)
12770 {
12771 - int count = 0;
12772 + unsigned int count = 0;
12773 struct biosregs ireg, oreg;
12774 struct e820entry *desc = boot_params.e820_map;
12775 static struct e820entry buf; /* static so it is zeroed */
12776 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12777 index ba3e100..6501b8f 100644
12778 --- a/arch/x86/boot/video-vesa.c
12779 +++ b/arch/x86/boot/video-vesa.c
12780 @@ -201,6 +201,7 @@ static void vesa_store_pm_info(void)
12781
12782 boot_params.screen_info.vesapm_seg = oreg.es;
12783 boot_params.screen_info.vesapm_off = oreg.di;
12784 + boot_params.screen_info.vesapm_size = oreg.cx;
12785 }
12786
12787 /*
12788 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12789 index 43eda28..5ab5fdb 100644
12790 --- a/arch/x86/boot/video.c
12791 +++ b/arch/x86/boot/video.c
12792 @@ -96,7 +96,7 @@ static void store_mode_params(void)
12793 static unsigned int get_entry(void)
12794 {
12795 char entry_buf[4];
12796 - int i, len = 0;
12797 + unsigned int i, len = 0;
12798 int key;
12799 unsigned int v;
12800
12801 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12802 index 9105655..41779c1 100644
12803 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
12804 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12805 @@ -8,6 +8,8 @@
12806 * including this sentence is retained in full.
12807 */
12808
12809 +#include <asm/alternative-asm.h>
12810 +
12811 .extern crypto_ft_tab
12812 .extern crypto_it_tab
12813 .extern crypto_fl_tab
12814 @@ -70,6 +72,8 @@
12815 je B192; \
12816 leaq 32(r9),r9;
12817
12818 +#define ret pax_force_retaddr; ret
12819 +
12820 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12821 movq r1,r2; \
12822 movq r3,r4; \
12823 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12824 index 477e9d7..c92c7d8 100644
12825 --- a/arch/x86/crypto/aesni-intel_asm.S
12826 +++ b/arch/x86/crypto/aesni-intel_asm.S
12827 @@ -31,6 +31,7 @@
12828
12829 #include <linux/linkage.h>
12830 #include <asm/inst.h>
12831 +#include <asm/alternative-asm.h>
12832
12833 #ifdef __x86_64__
12834 .data
12835 @@ -205,7 +206,7 @@ enc: .octa 0x2
12836 * num_initial_blocks = b mod 4
12837 * encrypt the initial num_initial_blocks blocks and apply ghash on
12838 * the ciphertext
12839 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12840 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12841 * are clobbered
12842 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12843 */
12844 @@ -214,8 +215,8 @@ enc: .octa 0x2
12845 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12846 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12847 mov arg7, %r10 # %r10 = AAD
12848 - mov arg8, %r12 # %r12 = aadLen
12849 - mov %r12, %r11
12850 + mov arg8, %r15 # %r15 = aadLen
12851 + mov %r15, %r11
12852 pxor %xmm\i, %xmm\i
12853 _get_AAD_loop\num_initial_blocks\operation:
12854 movd (%r10), \TMP1
12855 @@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12856 psrldq $4, %xmm\i
12857 pxor \TMP1, %xmm\i
12858 add $4, %r10
12859 - sub $4, %r12
12860 + sub $4, %r15
12861 jne _get_AAD_loop\num_initial_blocks\operation
12862 cmp $16, %r11
12863 je _get_AAD_loop2_done\num_initial_blocks\operation
12864 - mov $16, %r12
12865 + mov $16, %r15
12866 _get_AAD_loop2\num_initial_blocks\operation:
12867 psrldq $4, %xmm\i
12868 - sub $4, %r12
12869 - cmp %r11, %r12
12870 + sub $4, %r15
12871 + cmp %r11, %r15
12872 jne _get_AAD_loop2\num_initial_blocks\operation
12873 _get_AAD_loop2_done\num_initial_blocks\operation:
12874 movdqa SHUF_MASK(%rip), %xmm14
12875 @@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
12876 * num_initial_blocks = b mod 4
12877 * encrypt the initial num_initial_blocks blocks and apply ghash on
12878 * the ciphertext
12879 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12880 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12881 * are clobbered
12882 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12883 */
12884 @@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
12885 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12886 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12887 mov arg7, %r10 # %r10 = AAD
12888 - mov arg8, %r12 # %r12 = aadLen
12889 - mov %r12, %r11
12890 + mov arg8, %r15 # %r15 = aadLen
12891 + mov %r15, %r11
12892 pxor %xmm\i, %xmm\i
12893 _get_AAD_loop\num_initial_blocks\operation:
12894 movd (%r10), \TMP1
12895 @@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12896 psrldq $4, %xmm\i
12897 pxor \TMP1, %xmm\i
12898 add $4, %r10
12899 - sub $4, %r12
12900 + sub $4, %r15
12901 jne _get_AAD_loop\num_initial_blocks\operation
12902 cmp $16, %r11
12903 je _get_AAD_loop2_done\num_initial_blocks\operation
12904 - mov $16, %r12
12905 + mov $16, %r15
12906 _get_AAD_loop2\num_initial_blocks\operation:
12907 psrldq $4, %xmm\i
12908 - sub $4, %r12
12909 - cmp %r11, %r12
12910 + sub $4, %r15
12911 + cmp %r11, %r15
12912 jne _get_AAD_loop2\num_initial_blocks\operation
12913 _get_AAD_loop2_done\num_initial_blocks\operation:
12914 movdqa SHUF_MASK(%rip), %xmm14
12915 @@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
12916 *
12917 *****************************************************************************/
12918 ENTRY(aesni_gcm_dec)
12919 - push %r12
12920 + push %r15
12921 push %r13
12922 push %r14
12923 mov %rsp, %r14
12924 @@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
12925 */
12926 sub $VARIABLE_OFFSET, %rsp
12927 and $~63, %rsp # align rsp to 64 bytes
12928 - mov %arg6, %r12
12929 - movdqu (%r12), %xmm13 # %xmm13 = HashKey
12930 + mov %arg6, %r15
12931 + movdqu (%r15), %xmm13 # %xmm13 = HashKey
12932 movdqa SHUF_MASK(%rip), %xmm2
12933 PSHUFB_XMM %xmm2, %xmm13
12934
12935 @@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
12936 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
12937 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
12938 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
12939 - mov %r13, %r12
12940 - and $(3<<4), %r12
12941 + mov %r13, %r15
12942 + and $(3<<4), %r15
12943 jz _initial_num_blocks_is_0_decrypt
12944 - cmp $(2<<4), %r12
12945 + cmp $(2<<4), %r15
12946 jb _initial_num_blocks_is_1_decrypt
12947 je _initial_num_blocks_is_2_decrypt
12948 _initial_num_blocks_is_3_decrypt:
12949 @@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
12950 sub $16, %r11
12951 add %r13, %r11
12952 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
12953 - lea SHIFT_MASK+16(%rip), %r12
12954 - sub %r13, %r12
12955 + lea SHIFT_MASK+16(%rip), %r15
12956 + sub %r13, %r15
12957 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
12958 # (%r13 is the number of bytes in plaintext mod 16)
12959 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12960 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12961 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
12962
12963 movdqa %xmm1, %xmm2
12964 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
12965 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12966 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12967 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
12968 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
12969 pand %xmm1, %xmm2
12970 @@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
12971 sub $1, %r13
12972 jne _less_than_8_bytes_left_decrypt
12973 _multiple_of_16_bytes_decrypt:
12974 - mov arg8, %r12 # %r13 = aadLen (number of bytes)
12975 - shl $3, %r12 # convert into number of bits
12976 - movd %r12d, %xmm15 # len(A) in %xmm15
12977 + mov arg8, %r15 # %r13 = aadLen (number of bytes)
12978 + shl $3, %r15 # convert into number of bits
12979 + movd %r15d, %xmm15 # len(A) in %xmm15
12980 shl $3, %arg4 # len(C) in bits (*128)
12981 MOVQ_R64_XMM %arg4, %xmm1
12982 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12983 @@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
12984 mov %r14, %rsp
12985 pop %r14
12986 pop %r13
12987 - pop %r12
12988 + pop %r15
12989 + pax_force_retaddr
12990 ret
12991 ENDPROC(aesni_gcm_dec)
12992
12993 @@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
12994 * poly = x^128 + x^127 + x^126 + x^121 + 1
12995 ***************************************************************************/
12996 ENTRY(aesni_gcm_enc)
12997 - push %r12
12998 + push %r15
12999 push %r13
13000 push %r14
13001 mov %rsp, %r14
13002 @@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
13003 #
13004 sub $VARIABLE_OFFSET, %rsp
13005 and $~63, %rsp
13006 - mov %arg6, %r12
13007 - movdqu (%r12), %xmm13
13008 + mov %arg6, %r15
13009 + movdqu (%r15), %xmm13
13010 movdqa SHUF_MASK(%rip), %xmm2
13011 PSHUFB_XMM %xmm2, %xmm13
13012
13013 @@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
13014 movdqa %xmm13, HashKey(%rsp)
13015 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
13016 and $-16, %r13
13017 - mov %r13, %r12
13018 + mov %r13, %r15
13019
13020 # Encrypt first few blocks
13021
13022 - and $(3<<4), %r12
13023 + and $(3<<4), %r15
13024 jz _initial_num_blocks_is_0_encrypt
13025 - cmp $(2<<4), %r12
13026 + cmp $(2<<4), %r15
13027 jb _initial_num_blocks_is_1_encrypt
13028 je _initial_num_blocks_is_2_encrypt
13029 _initial_num_blocks_is_3_encrypt:
13030 @@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
13031 sub $16, %r11
13032 add %r13, %r11
13033 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
13034 - lea SHIFT_MASK+16(%rip), %r12
13035 - sub %r13, %r12
13036 + lea SHIFT_MASK+16(%rip), %r15
13037 + sub %r13, %r15
13038 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
13039 # (%r13 is the number of bytes in plaintext mod 16)
13040 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13041 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13042 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
13043 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
13044 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13045 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13046 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
13047 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
13048 movdqa SHUF_MASK(%rip), %xmm10
13049 @@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
13050 sub $1, %r13
13051 jne _less_than_8_bytes_left_encrypt
13052 _multiple_of_16_bytes_encrypt:
13053 - mov arg8, %r12 # %r12 = addLen (number of bytes)
13054 - shl $3, %r12
13055 - movd %r12d, %xmm15 # len(A) in %xmm15
13056 + mov arg8, %r15 # %r15 = addLen (number of bytes)
13057 + shl $3, %r15
13058 + movd %r15d, %xmm15 # len(A) in %xmm15
13059 shl $3, %arg4 # len(C) in bits (*128)
13060 MOVQ_R64_XMM %arg4, %xmm1
13061 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13062 @@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
13063 mov %r14, %rsp
13064 pop %r14
13065 pop %r13
13066 - pop %r12
13067 + pop %r15
13068 + pax_force_retaddr
13069 ret
13070 ENDPROC(aesni_gcm_enc)
13071
13072 @@ -1722,6 +1725,7 @@ _key_expansion_256a:
13073 pxor %xmm1, %xmm0
13074 movaps %xmm0, (TKEYP)
13075 add $0x10, TKEYP
13076 + pax_force_retaddr
13077 ret
13078 ENDPROC(_key_expansion_128)
13079 ENDPROC(_key_expansion_256a)
13080 @@ -1748,6 +1752,7 @@ _key_expansion_192a:
13081 shufps $0b01001110, %xmm2, %xmm1
13082 movaps %xmm1, 0x10(TKEYP)
13083 add $0x20, TKEYP
13084 + pax_force_retaddr
13085 ret
13086 ENDPROC(_key_expansion_192a)
13087
13088 @@ -1768,6 +1773,7 @@ _key_expansion_192b:
13089
13090 movaps %xmm0, (TKEYP)
13091 add $0x10, TKEYP
13092 + pax_force_retaddr
13093 ret
13094 ENDPROC(_key_expansion_192b)
13095
13096 @@ -1781,6 +1787,7 @@ _key_expansion_256b:
13097 pxor %xmm1, %xmm2
13098 movaps %xmm2, (TKEYP)
13099 add $0x10, TKEYP
13100 + pax_force_retaddr
13101 ret
13102 ENDPROC(_key_expansion_256b)
13103
13104 @@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
13105 #ifndef __x86_64__
13106 popl KEYP
13107 #endif
13108 + pax_force_retaddr
13109 ret
13110 ENDPROC(aesni_set_key)
13111
13112 @@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
13113 popl KLEN
13114 popl KEYP
13115 #endif
13116 + pax_force_retaddr
13117 ret
13118 ENDPROC(aesni_enc)
13119
13120 @@ -1974,6 +1983,7 @@ _aesni_enc1:
13121 AESENC KEY STATE
13122 movaps 0x70(TKEYP), KEY
13123 AESENCLAST KEY STATE
13124 + pax_force_retaddr
13125 ret
13126 ENDPROC(_aesni_enc1)
13127
13128 @@ -2083,6 +2093,7 @@ _aesni_enc4:
13129 AESENCLAST KEY STATE2
13130 AESENCLAST KEY STATE3
13131 AESENCLAST KEY STATE4
13132 + pax_force_retaddr
13133 ret
13134 ENDPROC(_aesni_enc4)
13135
13136 @@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
13137 popl KLEN
13138 popl KEYP
13139 #endif
13140 + pax_force_retaddr
13141 ret
13142 ENDPROC(aesni_dec)
13143
13144 @@ -2164,6 +2176,7 @@ _aesni_dec1:
13145 AESDEC KEY STATE
13146 movaps 0x70(TKEYP), KEY
13147 AESDECLAST KEY STATE
13148 + pax_force_retaddr
13149 ret
13150 ENDPROC(_aesni_dec1)
13151
13152 @@ -2273,6 +2286,7 @@ _aesni_dec4:
13153 AESDECLAST KEY STATE2
13154 AESDECLAST KEY STATE3
13155 AESDECLAST KEY STATE4
13156 + pax_force_retaddr
13157 ret
13158 ENDPROC(_aesni_dec4)
13159
13160 @@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
13161 popl KEYP
13162 popl LEN
13163 #endif
13164 + pax_force_retaddr
13165 ret
13166 ENDPROC(aesni_ecb_enc)
13167
13168 @@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
13169 popl KEYP
13170 popl LEN
13171 #endif
13172 + pax_force_retaddr
13173 ret
13174 ENDPROC(aesni_ecb_dec)
13175
13176 @@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
13177 popl LEN
13178 popl IVP
13179 #endif
13180 + pax_force_retaddr
13181 ret
13182 ENDPROC(aesni_cbc_enc)
13183
13184 @@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
13185 popl LEN
13186 popl IVP
13187 #endif
13188 + pax_force_retaddr
13189 ret
13190 ENDPROC(aesni_cbc_dec)
13191
13192 @@ -2550,6 +2568,7 @@ _aesni_inc_init:
13193 mov $1, TCTR_LOW
13194 MOVQ_R64_XMM TCTR_LOW INC
13195 MOVQ_R64_XMM CTR TCTR_LOW
13196 + pax_force_retaddr
13197 ret
13198 ENDPROC(_aesni_inc_init)
13199
13200 @@ -2579,6 +2598,7 @@ _aesni_inc:
13201 .Linc_low:
13202 movaps CTR, IV
13203 PSHUFB_XMM BSWAP_MASK IV
13204 + pax_force_retaddr
13205 ret
13206 ENDPROC(_aesni_inc)
13207
13208 @@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
13209 .Lctr_enc_ret:
13210 movups IV, (IVP)
13211 .Lctr_enc_just_ret:
13212 + pax_force_retaddr
13213 ret
13214 ENDPROC(aesni_ctr_enc)
13215
13216 @@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
13217 pxor INC, STATE4
13218 movdqu STATE4, 0x70(OUTP)
13219
13220 + pax_force_retaddr
13221 ret
13222 ENDPROC(aesni_xts_crypt8)
13223
13224 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13225 index 246c670..466e2d6 100644
13226 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13227 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13228 @@ -21,6 +21,7 @@
13229 */
13230
13231 #include <linux/linkage.h>
13232 +#include <asm/alternative-asm.h>
13233
13234 .file "blowfish-x86_64-asm.S"
13235 .text
13236 @@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13237 jnz .L__enc_xor;
13238
13239 write_block();
13240 + pax_force_retaddr
13241 ret;
13242 .L__enc_xor:
13243 xor_block();
13244 + pax_force_retaddr
13245 ret;
13246 ENDPROC(__blowfish_enc_blk)
13247
13248 @@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13249
13250 movq %r11, %rbp;
13251
13252 + pax_force_retaddr
13253 ret;
13254 ENDPROC(blowfish_dec_blk)
13255
13256 @@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13257
13258 popq %rbx;
13259 popq %rbp;
13260 + pax_force_retaddr
13261 ret;
13262
13263 .L__enc_xor4:
13264 @@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13265
13266 popq %rbx;
13267 popq %rbp;
13268 + pax_force_retaddr
13269 ret;
13270 ENDPROC(__blowfish_enc_blk_4way)
13271
13272 @@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13273 popq %rbx;
13274 popq %rbp;
13275
13276 + pax_force_retaddr
13277 ret;
13278 ENDPROC(blowfish_dec_blk_4way)
13279 diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13280 index ce71f92..1dce7ec 100644
13281 --- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13282 +++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13283 @@ -16,6 +16,7 @@
13284 */
13285
13286 #include <linux/linkage.h>
13287 +#include <asm/alternative-asm.h>
13288
13289 #define CAMELLIA_TABLE_BYTE_LEN 272
13290
13291 @@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13292 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13293 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13294 %rcx, (%r9));
13295 + pax_force_retaddr
13296 ret;
13297 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13298
13299 @@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13300 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13301 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13302 %rax, (%r9));
13303 + pax_force_retaddr
13304 ret;
13305 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13306
13307 @@ -780,6 +783,7 @@ __camellia_enc_blk16:
13308 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13309 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13310
13311 + pax_force_retaddr
13312 ret;
13313
13314 .align 8
13315 @@ -865,6 +869,7 @@ __camellia_dec_blk16:
13316 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13317 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13318
13319 + pax_force_retaddr
13320 ret;
13321
13322 .align 8
13323 @@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13324 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13325 %xmm8, %rsi);
13326
13327 + pax_force_retaddr
13328 ret;
13329 ENDPROC(camellia_ecb_enc_16way)
13330
13331 @@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13332 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13333 %xmm8, %rsi);
13334
13335 + pax_force_retaddr
13336 ret;
13337 ENDPROC(camellia_ecb_dec_16way)
13338
13339 @@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13340 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13341 %xmm8, %rsi);
13342
13343 + pax_force_retaddr
13344 ret;
13345 ENDPROC(camellia_cbc_dec_16way)
13346
13347 @@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13348 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13349 %xmm8, %rsi);
13350
13351 + pax_force_retaddr
13352 ret;
13353 ENDPROC(camellia_ctr_16way)
13354
13355 @@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13356 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13357 %xmm8, %rsi);
13358
13359 + pax_force_retaddr
13360 ret;
13361 ENDPROC(camellia_xts_crypt_16way)
13362
13363 diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13364 index 0e0b886..5a3123c 100644
13365 --- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13366 +++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13367 @@ -11,6 +11,7 @@
13368 */
13369
13370 #include <linux/linkage.h>
13371 +#include <asm/alternative-asm.h>
13372
13373 #define CAMELLIA_TABLE_BYTE_LEN 272
13374
13375 @@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13376 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13377 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13378 %rcx, (%r9));
13379 + pax_force_retaddr
13380 ret;
13381 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13382
13383 @@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13384 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13385 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13386 %rax, (%r9));
13387 + pax_force_retaddr
13388 ret;
13389 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13390
13391 @@ -820,6 +823,7 @@ __camellia_enc_blk32:
13392 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13393 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13394
13395 + pax_force_retaddr
13396 ret;
13397
13398 .align 8
13399 @@ -905,6 +909,7 @@ __camellia_dec_blk32:
13400 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13401 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13402
13403 + pax_force_retaddr
13404 ret;
13405
13406 .align 8
13407 @@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13408
13409 vzeroupper;
13410
13411 + pax_force_retaddr
13412 ret;
13413 ENDPROC(camellia_ecb_enc_32way)
13414
13415 @@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13416
13417 vzeroupper;
13418
13419 + pax_force_retaddr
13420 ret;
13421 ENDPROC(camellia_ecb_dec_32way)
13422
13423 @@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13424
13425 vzeroupper;
13426
13427 + pax_force_retaddr
13428 ret;
13429 ENDPROC(camellia_cbc_dec_32way)
13430
13431 @@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13432
13433 vzeroupper;
13434
13435 + pax_force_retaddr
13436 ret;
13437 ENDPROC(camellia_ctr_32way)
13438
13439 @@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13440
13441 vzeroupper;
13442
13443 + pax_force_retaddr
13444 ret;
13445 ENDPROC(camellia_xts_crypt_32way)
13446
13447 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13448 index 310319c..db3d7b5 100644
13449 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13450 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13451 @@ -21,6 +21,7 @@
13452 */
13453
13454 #include <linux/linkage.h>
13455 +#include <asm/alternative-asm.h>
13456
13457 .file "camellia-x86_64-asm_64.S"
13458 .text
13459 @@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13460 enc_outunpack(mov, RT1);
13461
13462 movq RRBP, %rbp;
13463 + pax_force_retaddr
13464 ret;
13465
13466 .L__enc_xor:
13467 enc_outunpack(xor, RT1);
13468
13469 movq RRBP, %rbp;
13470 + pax_force_retaddr
13471 ret;
13472 ENDPROC(__camellia_enc_blk)
13473
13474 @@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13475 dec_outunpack();
13476
13477 movq RRBP, %rbp;
13478 + pax_force_retaddr
13479 ret;
13480 ENDPROC(camellia_dec_blk)
13481
13482 @@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13483
13484 movq RRBP, %rbp;
13485 popq %rbx;
13486 + pax_force_retaddr
13487 ret;
13488
13489 .L__enc2_xor:
13490 @@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13491
13492 movq RRBP, %rbp;
13493 popq %rbx;
13494 + pax_force_retaddr
13495 ret;
13496 ENDPROC(__camellia_enc_blk_2way)
13497
13498 @@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13499
13500 movq RRBP, %rbp;
13501 movq RXOR, %rbx;
13502 + pax_force_retaddr
13503 ret;
13504 ENDPROC(camellia_dec_blk_2way)
13505 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13506 index c35fd5d..2d8c7db 100644
13507 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13508 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13509 @@ -24,6 +24,7 @@
13510 */
13511
13512 #include <linux/linkage.h>
13513 +#include <asm/alternative-asm.h>
13514
13515 .file "cast5-avx-x86_64-asm_64.S"
13516
13517 @@ -281,6 +282,7 @@ __cast5_enc_blk16:
13518 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13519 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13520
13521 + pax_force_retaddr
13522 ret;
13523 ENDPROC(__cast5_enc_blk16)
13524
13525 @@ -352,6 +354,7 @@ __cast5_dec_blk16:
13526 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13527 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13528
13529 + pax_force_retaddr
13530 ret;
13531
13532 .L__skip_dec:
13533 @@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13534 vmovdqu RR4, (6*4*4)(%r11);
13535 vmovdqu RL4, (7*4*4)(%r11);
13536
13537 + pax_force_retaddr
13538 ret;
13539 ENDPROC(cast5_ecb_enc_16way)
13540
13541 @@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13542 vmovdqu RR4, (6*4*4)(%r11);
13543 vmovdqu RL4, (7*4*4)(%r11);
13544
13545 + pax_force_retaddr
13546 ret;
13547 ENDPROC(cast5_ecb_dec_16way)
13548
13549 @@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
13550 * %rdx: src
13551 */
13552
13553 - pushq %r12;
13554 + pushq %r14;
13555
13556 movq %rsi, %r11;
13557 - movq %rdx, %r12;
13558 + movq %rdx, %r14;
13559
13560 vmovdqu (0*16)(%rdx), RL1;
13561 vmovdqu (1*16)(%rdx), RR1;
13562 @@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
13563 call __cast5_dec_blk16;
13564
13565 /* xor with src */
13566 - vmovq (%r12), RX;
13567 + vmovq (%r14), RX;
13568 vpshufd $0x4f, RX, RX;
13569 vpxor RX, RR1, RR1;
13570 - vpxor 0*16+8(%r12), RL1, RL1;
13571 - vpxor 1*16+8(%r12), RR2, RR2;
13572 - vpxor 2*16+8(%r12), RL2, RL2;
13573 - vpxor 3*16+8(%r12), RR3, RR3;
13574 - vpxor 4*16+8(%r12), RL3, RL3;
13575 - vpxor 5*16+8(%r12), RR4, RR4;
13576 - vpxor 6*16+8(%r12), RL4, RL4;
13577 + vpxor 0*16+8(%r14), RL1, RL1;
13578 + vpxor 1*16+8(%r14), RR2, RR2;
13579 + vpxor 2*16+8(%r14), RL2, RL2;
13580 + vpxor 3*16+8(%r14), RR3, RR3;
13581 + vpxor 4*16+8(%r14), RL3, RL3;
13582 + vpxor 5*16+8(%r14), RR4, RR4;
13583 + vpxor 6*16+8(%r14), RL4, RL4;
13584
13585 vmovdqu RR1, (0*16)(%r11);
13586 vmovdqu RL1, (1*16)(%r11);
13587 @@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
13588 vmovdqu RR4, (6*16)(%r11);
13589 vmovdqu RL4, (7*16)(%r11);
13590
13591 - popq %r12;
13592 + popq %r14;
13593
13594 + pax_force_retaddr
13595 ret;
13596 ENDPROC(cast5_cbc_dec_16way)
13597
13598 @@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
13599 * %rcx: iv (big endian, 64bit)
13600 */
13601
13602 - pushq %r12;
13603 + pushq %r14;
13604
13605 movq %rsi, %r11;
13606 - movq %rdx, %r12;
13607 + movq %rdx, %r14;
13608
13609 vpcmpeqd RTMP, RTMP, RTMP;
13610 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
13611 @@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
13612 call __cast5_enc_blk16;
13613
13614 /* dst = src ^ iv */
13615 - vpxor (0*16)(%r12), RR1, RR1;
13616 - vpxor (1*16)(%r12), RL1, RL1;
13617 - vpxor (2*16)(%r12), RR2, RR2;
13618 - vpxor (3*16)(%r12), RL2, RL2;
13619 - vpxor (4*16)(%r12), RR3, RR3;
13620 - vpxor (5*16)(%r12), RL3, RL3;
13621 - vpxor (6*16)(%r12), RR4, RR4;
13622 - vpxor (7*16)(%r12), RL4, RL4;
13623 + vpxor (0*16)(%r14), RR1, RR1;
13624 + vpxor (1*16)(%r14), RL1, RL1;
13625 + vpxor (2*16)(%r14), RR2, RR2;
13626 + vpxor (3*16)(%r14), RL2, RL2;
13627 + vpxor (4*16)(%r14), RR3, RR3;
13628 + vpxor (5*16)(%r14), RL3, RL3;
13629 + vpxor (6*16)(%r14), RR4, RR4;
13630 + vpxor (7*16)(%r14), RL4, RL4;
13631 vmovdqu RR1, (0*16)(%r11);
13632 vmovdqu RL1, (1*16)(%r11);
13633 vmovdqu RR2, (2*16)(%r11);
13634 @@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
13635 vmovdqu RR4, (6*16)(%r11);
13636 vmovdqu RL4, (7*16)(%r11);
13637
13638 - popq %r12;
13639 + popq %r14;
13640
13641 + pax_force_retaddr
13642 ret;
13643 ENDPROC(cast5_ctr_16way)
13644 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13645 index e3531f8..e123f35 100644
13646 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13647 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13648 @@ -24,6 +24,7 @@
13649 */
13650
13651 #include <linux/linkage.h>
13652 +#include <asm/alternative-asm.h>
13653 #include "glue_helper-asm-avx.S"
13654
13655 .file "cast6-avx-x86_64-asm_64.S"
13656 @@ -295,6 +296,7 @@ __cast6_enc_blk8:
13657 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13658 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13659
13660 + pax_force_retaddr
13661 ret;
13662 ENDPROC(__cast6_enc_blk8)
13663
13664 @@ -340,6 +342,7 @@ __cast6_dec_blk8:
13665 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13666 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13667
13668 + pax_force_retaddr
13669 ret;
13670 ENDPROC(__cast6_dec_blk8)
13671
13672 @@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13673
13674 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13675
13676 + pax_force_retaddr
13677 ret;
13678 ENDPROC(cast6_ecb_enc_8way)
13679
13680 @@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13681
13682 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13683
13684 + pax_force_retaddr
13685 ret;
13686 ENDPROC(cast6_ecb_dec_8way)
13687
13688 @@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13689 * %rdx: src
13690 */
13691
13692 - pushq %r12;
13693 + pushq %r14;
13694
13695 movq %rsi, %r11;
13696 - movq %rdx, %r12;
13697 + movq %rdx, %r14;
13698
13699 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13700
13701 call __cast6_dec_blk8;
13702
13703 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13704 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13705
13706 - popq %r12;
13707 + popq %r14;
13708
13709 + pax_force_retaddr
13710 ret;
13711 ENDPROC(cast6_cbc_dec_8way)
13712
13713 @@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13714 * %rcx: iv (little endian, 128bit)
13715 */
13716
13717 - pushq %r12;
13718 + pushq %r14;
13719
13720 movq %rsi, %r11;
13721 - movq %rdx, %r12;
13722 + movq %rdx, %r14;
13723
13724 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13725 RD2, RX, RKR, RKM);
13726
13727 call __cast6_enc_blk8;
13728
13729 - store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13730 + store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13731
13732 - popq %r12;
13733 + popq %r14;
13734
13735 + pax_force_retaddr
13736 ret;
13737 ENDPROC(cast6_ctr_8way)
13738
13739 @@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13740 /* dst <= regs xor IVs(in dst) */
13741 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13742
13743 + pax_force_retaddr
13744 ret;
13745 ENDPROC(cast6_xts_enc_8way)
13746
13747 @@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13748 /* dst <= regs xor IVs(in dst) */
13749 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13750
13751 + pax_force_retaddr
13752 ret;
13753 ENDPROC(cast6_xts_dec_8way)
13754 diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13755 index dbc4339..de6e120 100644
13756 --- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13757 +++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13758 @@ -45,6 +45,7 @@
13759
13760 #include <asm/inst.h>
13761 #include <linux/linkage.h>
13762 +#include <asm/alternative-asm.h>
13763
13764 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
13765
13766 @@ -312,6 +313,7 @@ do_return:
13767 popq %rsi
13768 popq %rdi
13769 popq %rbx
13770 + pax_force_retaddr
13771 ret
13772
13773 ################################################################
13774 diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13775 index 185fad4..ff4cd36 100644
13776 --- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
13777 +++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13778 @@ -18,6 +18,7 @@
13779
13780 #include <linux/linkage.h>
13781 #include <asm/inst.h>
13782 +#include <asm/alternative-asm.h>
13783
13784 .data
13785
13786 @@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
13787 psrlq $1, T2
13788 pxor T2, T1
13789 pxor T1, DATA
13790 + pax_force_retaddr
13791 ret
13792 ENDPROC(__clmul_gf128mul_ble)
13793
13794 @@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
13795 call __clmul_gf128mul_ble
13796 PSHUFB_XMM BSWAP DATA
13797 movups DATA, (%rdi)
13798 + pax_force_retaddr
13799 ret
13800 ENDPROC(clmul_ghash_mul)
13801
13802 @@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
13803 PSHUFB_XMM BSWAP DATA
13804 movups DATA, (%rdi)
13805 .Lupdate_just_ret:
13806 + pax_force_retaddr
13807 ret
13808 ENDPROC(clmul_ghash_update)
13809 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13810 index 9279e0b..c4b3d2c 100644
13811 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
13812 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13813 @@ -1,4 +1,5 @@
13814 #include <linux/linkage.h>
13815 +#include <asm/alternative-asm.h>
13816
13817 # enter salsa20_encrypt_bytes
13818 ENTRY(salsa20_encrypt_bytes)
13819 @@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
13820 add %r11,%rsp
13821 mov %rdi,%rax
13822 mov %rsi,%rdx
13823 + pax_force_retaddr
13824 ret
13825 # bytesatleast65:
13826 ._bytesatleast65:
13827 @@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
13828 add %r11,%rsp
13829 mov %rdi,%rax
13830 mov %rsi,%rdx
13831 + pax_force_retaddr
13832 ret
13833 ENDPROC(salsa20_keysetup)
13834
13835 @@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
13836 add %r11,%rsp
13837 mov %rdi,%rax
13838 mov %rsi,%rdx
13839 + pax_force_retaddr
13840 ret
13841 ENDPROC(salsa20_ivsetup)
13842 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13843 index 2f202f4..d9164d6 100644
13844 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13845 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13846 @@ -24,6 +24,7 @@
13847 */
13848
13849 #include <linux/linkage.h>
13850 +#include <asm/alternative-asm.h>
13851 #include "glue_helper-asm-avx.S"
13852
13853 .file "serpent-avx-x86_64-asm_64.S"
13854 @@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
13855 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13856 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13857
13858 + pax_force_retaddr
13859 ret;
13860 ENDPROC(__serpent_enc_blk8_avx)
13861
13862 @@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
13863 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13864 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13865
13866 + pax_force_retaddr
13867 ret;
13868 ENDPROC(__serpent_dec_blk8_avx)
13869
13870 @@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
13871
13872 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13873
13874 + pax_force_retaddr
13875 ret;
13876 ENDPROC(serpent_ecb_enc_8way_avx)
13877
13878 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
13879
13880 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13881
13882 + pax_force_retaddr
13883 ret;
13884 ENDPROC(serpent_ecb_dec_8way_avx)
13885
13886 @@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
13887
13888 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13889
13890 + pax_force_retaddr
13891 ret;
13892 ENDPROC(serpent_cbc_dec_8way_avx)
13893
13894 @@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
13895
13896 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13897
13898 + pax_force_retaddr
13899 ret;
13900 ENDPROC(serpent_ctr_8way_avx)
13901
13902 @@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
13903 /* dst <= regs xor IVs(in dst) */
13904 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13905
13906 + pax_force_retaddr
13907 ret;
13908 ENDPROC(serpent_xts_enc_8way_avx)
13909
13910 @@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
13911 /* dst <= regs xor IVs(in dst) */
13912 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13913
13914 + pax_force_retaddr
13915 ret;
13916 ENDPROC(serpent_xts_dec_8way_avx)
13917 diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
13918 index b222085..abd483c 100644
13919 --- a/arch/x86/crypto/serpent-avx2-asm_64.S
13920 +++ b/arch/x86/crypto/serpent-avx2-asm_64.S
13921 @@ -15,6 +15,7 @@
13922 */
13923
13924 #include <linux/linkage.h>
13925 +#include <asm/alternative-asm.h>
13926 #include "glue_helper-asm-avx2.S"
13927
13928 .file "serpent-avx2-asm_64.S"
13929 @@ -610,6 +611,7 @@ __serpent_enc_blk16:
13930 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13931 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13932
13933 + pax_force_retaddr
13934 ret;
13935 ENDPROC(__serpent_enc_blk16)
13936
13937 @@ -664,6 +666,7 @@ __serpent_dec_blk16:
13938 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13939 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13940
13941 + pax_force_retaddr
13942 ret;
13943 ENDPROC(__serpent_dec_blk16)
13944
13945 @@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
13946
13947 vzeroupper;
13948
13949 + pax_force_retaddr
13950 ret;
13951 ENDPROC(serpent_ecb_enc_16way)
13952
13953 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
13954
13955 vzeroupper;
13956
13957 + pax_force_retaddr
13958 ret;
13959 ENDPROC(serpent_ecb_dec_16way)
13960
13961 @@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
13962
13963 vzeroupper;
13964
13965 + pax_force_retaddr
13966 ret;
13967 ENDPROC(serpent_cbc_dec_16way)
13968
13969 @@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
13970
13971 vzeroupper;
13972
13973 + pax_force_retaddr
13974 ret;
13975 ENDPROC(serpent_ctr_16way)
13976
13977 @@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
13978
13979 vzeroupper;
13980
13981 + pax_force_retaddr
13982 ret;
13983 ENDPROC(serpent_xts_enc_16way)
13984
13985 @@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
13986
13987 vzeroupper;
13988
13989 + pax_force_retaddr
13990 ret;
13991 ENDPROC(serpent_xts_dec_16way)
13992 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13993 index acc066c..1559cc4 100644
13994 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13995 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13996 @@ -25,6 +25,7 @@
13997 */
13998
13999 #include <linux/linkage.h>
14000 +#include <asm/alternative-asm.h>
14001
14002 .file "serpent-sse2-x86_64-asm_64.S"
14003 .text
14004 @@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
14005 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14006 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14007
14008 + pax_force_retaddr
14009 ret;
14010
14011 .L__enc_xor8:
14012 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14013 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14014
14015 + pax_force_retaddr
14016 ret;
14017 ENDPROC(__serpent_enc_blk_8way)
14018
14019 @@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
14020 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14021 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14022
14023 + pax_force_retaddr
14024 ret;
14025 ENDPROC(serpent_dec_blk_8way)
14026 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
14027 index a410950..9dfe7ad 100644
14028 --- a/arch/x86/crypto/sha1_ssse3_asm.S
14029 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
14030 @@ -29,6 +29,7 @@
14031 */
14032
14033 #include <linux/linkage.h>
14034 +#include <asm/alternative-asm.h>
14035
14036 #define CTX %rdi // arg1
14037 #define BUF %rsi // arg2
14038 @@ -75,9 +76,9 @@
14039
14040 push %rbx
14041 push %rbp
14042 - push %r12
14043 + push %r14
14044
14045 - mov %rsp, %r12
14046 + mov %rsp, %r14
14047 sub $64, %rsp # allocate workspace
14048 and $~15, %rsp # align stack
14049
14050 @@ -99,11 +100,12 @@
14051 xor %rax, %rax
14052 rep stosq
14053
14054 - mov %r12, %rsp # deallocate workspace
14055 + mov %r14, %rsp # deallocate workspace
14056
14057 - pop %r12
14058 + pop %r14
14059 pop %rbp
14060 pop %rbx
14061 + pax_force_retaddr
14062 ret
14063
14064 ENDPROC(\name)
14065 diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
14066 index 642f156..51a513c 100644
14067 --- a/arch/x86/crypto/sha256-avx-asm.S
14068 +++ b/arch/x86/crypto/sha256-avx-asm.S
14069 @@ -49,6 +49,7 @@
14070
14071 #ifdef CONFIG_AS_AVX
14072 #include <linux/linkage.h>
14073 +#include <asm/alternative-asm.h>
14074
14075 ## assume buffers not aligned
14076 #define VMOVDQ vmovdqu
14077 @@ -460,6 +461,7 @@ done_hash:
14078 popq %r13
14079 popq %rbp
14080 popq %rbx
14081 + pax_force_retaddr
14082 ret
14083 ENDPROC(sha256_transform_avx)
14084
14085 diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
14086 index 9e86944..3795e6a 100644
14087 --- a/arch/x86/crypto/sha256-avx2-asm.S
14088 +++ b/arch/x86/crypto/sha256-avx2-asm.S
14089 @@ -50,6 +50,7 @@
14090
14091 #ifdef CONFIG_AS_AVX2
14092 #include <linux/linkage.h>
14093 +#include <asm/alternative-asm.h>
14094
14095 ## assume buffers not aligned
14096 #define VMOVDQ vmovdqu
14097 @@ -720,6 +721,7 @@ done_hash:
14098 popq %r12
14099 popq %rbp
14100 popq %rbx
14101 + pax_force_retaddr
14102 ret
14103 ENDPROC(sha256_transform_rorx)
14104
14105 diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
14106 index f833b74..8c62a9e 100644
14107 --- a/arch/x86/crypto/sha256-ssse3-asm.S
14108 +++ b/arch/x86/crypto/sha256-ssse3-asm.S
14109 @@ -47,6 +47,7 @@
14110 ########################################################################
14111
14112 #include <linux/linkage.h>
14113 +#include <asm/alternative-asm.h>
14114
14115 ## assume buffers not aligned
14116 #define MOVDQ movdqu
14117 @@ -471,6 +472,7 @@ done_hash:
14118 popq %rbp
14119 popq %rbx
14120
14121 + pax_force_retaddr
14122 ret
14123 ENDPROC(sha256_transform_ssse3)
14124
14125 diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
14126 index 974dde9..a823ff9 100644
14127 --- a/arch/x86/crypto/sha512-avx-asm.S
14128 +++ b/arch/x86/crypto/sha512-avx-asm.S
14129 @@ -49,6 +49,7 @@
14130
14131 #ifdef CONFIG_AS_AVX
14132 #include <linux/linkage.h>
14133 +#include <asm/alternative-asm.h>
14134
14135 .text
14136
14137 @@ -364,6 +365,7 @@ updateblock:
14138 mov frame_RSPSAVE(%rsp), %rsp
14139
14140 nowork:
14141 + pax_force_retaddr
14142 ret
14143 ENDPROC(sha512_transform_avx)
14144
14145 diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
14146 index 568b961..ed20c37 100644
14147 --- a/arch/x86/crypto/sha512-avx2-asm.S
14148 +++ b/arch/x86/crypto/sha512-avx2-asm.S
14149 @@ -51,6 +51,7 @@
14150
14151 #ifdef CONFIG_AS_AVX2
14152 #include <linux/linkage.h>
14153 +#include <asm/alternative-asm.h>
14154
14155 .text
14156
14157 @@ -678,6 +679,7 @@ done_hash:
14158
14159 # Restore Stack Pointer
14160 mov frame_RSPSAVE(%rsp), %rsp
14161 + pax_force_retaddr
14162 ret
14163 ENDPROC(sha512_transform_rorx)
14164
14165 diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
14166 index fb56855..6edd768 100644
14167 --- a/arch/x86/crypto/sha512-ssse3-asm.S
14168 +++ b/arch/x86/crypto/sha512-ssse3-asm.S
14169 @@ -48,6 +48,7 @@
14170 ########################################################################
14171
14172 #include <linux/linkage.h>
14173 +#include <asm/alternative-asm.h>
14174
14175 .text
14176
14177 @@ -363,6 +364,7 @@ updateblock:
14178 mov frame_RSPSAVE(%rsp), %rsp
14179
14180 nowork:
14181 + pax_force_retaddr
14182 ret
14183 ENDPROC(sha512_transform_ssse3)
14184
14185 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14186 index 0505813..b067311 100644
14187 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14188 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14189 @@ -24,6 +24,7 @@
14190 */
14191
14192 #include <linux/linkage.h>
14193 +#include <asm/alternative-asm.h>
14194 #include "glue_helper-asm-avx.S"
14195
14196 .file "twofish-avx-x86_64-asm_64.S"
14197 @@ -284,6 +285,7 @@ __twofish_enc_blk8:
14198 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
14199 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
14200
14201 + pax_force_retaddr
14202 ret;
14203 ENDPROC(__twofish_enc_blk8)
14204
14205 @@ -324,6 +326,7 @@ __twofish_dec_blk8:
14206 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
14207 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
14208
14209 + pax_force_retaddr
14210 ret;
14211 ENDPROC(__twofish_dec_blk8)
14212
14213 @@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
14214
14215 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14216
14217 + pax_force_retaddr
14218 ret;
14219 ENDPROC(twofish_ecb_enc_8way)
14220
14221 @@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14222
14223 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14224
14225 + pax_force_retaddr
14226 ret;
14227 ENDPROC(twofish_ecb_dec_8way)
14228
14229 @@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14230 * %rdx: src
14231 */
14232
14233 - pushq %r12;
14234 + pushq %r14;
14235
14236 movq %rsi, %r11;
14237 - movq %rdx, %r12;
14238 + movq %rdx, %r14;
14239
14240 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14241
14242 call __twofish_dec_blk8;
14243
14244 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14245 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14246
14247 - popq %r12;
14248 + popq %r14;
14249
14250 + pax_force_retaddr
14251 ret;
14252 ENDPROC(twofish_cbc_dec_8way)
14253
14254 @@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14255 * %rcx: iv (little endian, 128bit)
14256 */
14257
14258 - pushq %r12;
14259 + pushq %r14;
14260
14261 movq %rsi, %r11;
14262 - movq %rdx, %r12;
14263 + movq %rdx, %r14;
14264
14265 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14266 RD2, RX0, RX1, RY0);
14267
14268 call __twofish_enc_blk8;
14269
14270 - store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14271 + store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14272
14273 - popq %r12;
14274 + popq %r14;
14275
14276 + pax_force_retaddr
14277 ret;
14278 ENDPROC(twofish_ctr_8way)
14279
14280 @@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14281 /* dst <= regs xor IVs(in dst) */
14282 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14283
14284 + pax_force_retaddr
14285 ret;
14286 ENDPROC(twofish_xts_enc_8way)
14287
14288 @@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14289 /* dst <= regs xor IVs(in dst) */
14290 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14291
14292 + pax_force_retaddr
14293 ret;
14294 ENDPROC(twofish_xts_dec_8way)
14295 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14296 index 1c3b7ce..02f578d 100644
14297 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14298 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14299 @@ -21,6 +21,7 @@
14300 */
14301
14302 #include <linux/linkage.h>
14303 +#include <asm/alternative-asm.h>
14304
14305 .file "twofish-x86_64-asm-3way.S"
14306 .text
14307 @@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14308 popq %r13;
14309 popq %r14;
14310 popq %r15;
14311 + pax_force_retaddr
14312 ret;
14313
14314 .L__enc_xor3:
14315 @@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14316 popq %r13;
14317 popq %r14;
14318 popq %r15;
14319 + pax_force_retaddr
14320 ret;
14321 ENDPROC(__twofish_enc_blk_3way)
14322
14323 @@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14324 popq %r13;
14325 popq %r14;
14326 popq %r15;
14327 + pax_force_retaddr
14328 ret;
14329 ENDPROC(twofish_dec_blk_3way)
14330 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14331 index a039d21..524b8b2 100644
14332 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14333 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14334 @@ -22,6 +22,7 @@
14335
14336 #include <linux/linkage.h>
14337 #include <asm/asm-offsets.h>
14338 +#include <asm/alternative-asm.h>
14339
14340 #define a_offset 0
14341 #define b_offset 4
14342 @@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14343
14344 popq R1
14345 movq $1,%rax
14346 + pax_force_retaddr
14347 ret
14348 ENDPROC(twofish_enc_blk)
14349
14350 @@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14351
14352 popq R1
14353 movq $1,%rax
14354 + pax_force_retaddr
14355 ret
14356 ENDPROC(twofish_dec_blk)
14357 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14358 index d21ff89..6da8e6e 100644
14359 --- a/arch/x86/ia32/ia32_aout.c
14360 +++ b/arch/x86/ia32/ia32_aout.c
14361 @@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14362 unsigned long dump_start, dump_size;
14363 struct user32 dump;
14364
14365 + memset(&dump, 0, sizeof(dump));
14366 +
14367 fs = get_fs();
14368 set_fs(KERNEL_DS);
14369 has_dumped = 1;
14370 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14371 index 2206757..85cbcfa 100644
14372 --- a/arch/x86/ia32/ia32_signal.c
14373 +++ b/arch/x86/ia32/ia32_signal.c
14374 @@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14375 if (__get_user(set.sig[0], &frame->sc.oldmask)
14376 || (_COMPAT_NSIG_WORDS > 1
14377 && __copy_from_user((((char *) &set.sig) + 4),
14378 - &frame->extramask,
14379 + frame->extramask,
14380 sizeof(frame->extramask))))
14381 goto badframe;
14382
14383 @@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14384 sp -= frame_size;
14385 /* Align the stack pointer according to the i386 ABI,
14386 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14387 - sp = ((sp + 4) & -16ul) - 4;
14388 + sp = ((sp - 12) & -16ul) - 4;
14389 return (void __user *) sp;
14390 }
14391
14392 @@ -386,7 +386,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14393 restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14394 sigreturn);
14395 else
14396 - restorer = &frame->retcode;
14397 + restorer = frame->retcode;
14398 }
14399
14400 put_user_try {
14401 @@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14402 * These are actually not used anymore, but left because some
14403 * gdb versions depend on them as a marker.
14404 */
14405 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14406 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14407 } put_user_catch(err);
14408
14409 if (err)
14410 @@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14411 0xb8,
14412 __NR_ia32_rt_sigreturn,
14413 0x80cd,
14414 - 0,
14415 + 0
14416 };
14417
14418 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14419 @@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14420
14421 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14422 restorer = ksig->ka.sa.sa_restorer;
14423 + else if (current->mm->context.vdso)
14424 + /* Return stub is in 32bit vsyscall page */
14425 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
14426 else
14427 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14428 - rt_sigreturn);
14429 + restorer = frame->retcode;
14430 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14431
14432 /*
14433 * Not actually used anymore, but left because some gdb
14434 * versions need it.
14435 */
14436 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14437 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14438 } put_user_catch(err);
14439
14440 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14441 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14442 index 4299eb0..fefe70e 100644
14443 --- a/arch/x86/ia32/ia32entry.S
14444 +++ b/arch/x86/ia32/ia32entry.S
14445 @@ -15,8 +15,10 @@
14446 #include <asm/irqflags.h>
14447 #include <asm/asm.h>
14448 #include <asm/smap.h>
14449 +#include <asm/pgtable.h>
14450 #include <linux/linkage.h>
14451 #include <linux/err.h>
14452 +#include <asm/alternative-asm.h>
14453
14454 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14455 #include <linux/elf-em.h>
14456 @@ -62,12 +64,12 @@
14457 */
14458 .macro LOAD_ARGS32 offset, _r9=0
14459 .if \_r9
14460 - movl \offset+16(%rsp),%r9d
14461 + movl \offset+R9(%rsp),%r9d
14462 .endif
14463 - movl \offset+40(%rsp),%ecx
14464 - movl \offset+48(%rsp),%edx
14465 - movl \offset+56(%rsp),%esi
14466 - movl \offset+64(%rsp),%edi
14467 + movl \offset+RCX(%rsp),%ecx
14468 + movl \offset+RDX(%rsp),%edx
14469 + movl \offset+RSI(%rsp),%esi
14470 + movl \offset+RDI(%rsp),%edi
14471 movl %eax,%eax /* zero extension */
14472 .endm
14473
14474 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14475 ENDPROC(native_irq_enable_sysexit)
14476 #endif
14477
14478 + .macro pax_enter_kernel_user
14479 + pax_set_fptr_mask
14480 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14481 + call pax_enter_kernel_user
14482 +#endif
14483 + .endm
14484 +
14485 + .macro pax_exit_kernel_user
14486 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14487 + call pax_exit_kernel_user
14488 +#endif
14489 +#ifdef CONFIG_PAX_RANDKSTACK
14490 + pushq %rax
14491 + pushq %r11
14492 + call pax_randomize_kstack
14493 + popq %r11
14494 + popq %rax
14495 +#endif
14496 + .endm
14497 +
14498 + .macro pax_erase_kstack
14499 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14500 + call pax_erase_kstack
14501 +#endif
14502 + .endm
14503 +
14504 /*
14505 * 32bit SYSENTER instruction entry.
14506 *
14507 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14508 CFI_REGISTER rsp,rbp
14509 SWAPGS_UNSAFE_STACK
14510 movq PER_CPU_VAR(kernel_stack), %rsp
14511 - addq $(KERNEL_STACK_OFFSET),%rsp
14512 - /*
14513 - * No need to follow this irqs on/off section: the syscall
14514 - * disabled irqs, here we enable it straight after entry:
14515 - */
14516 - ENABLE_INTERRUPTS(CLBR_NONE)
14517 movl %ebp,%ebp /* zero extension */
14518 pushq_cfi $__USER32_DS
14519 /*CFI_REL_OFFSET ss,0*/
14520 @@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
14521 CFI_REL_OFFSET rsp,0
14522 pushfq_cfi
14523 /*CFI_REL_OFFSET rflags,0*/
14524 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
14525 - CFI_REGISTER rip,r10
14526 + orl $X86_EFLAGS_IF,(%rsp)
14527 + GET_THREAD_INFO(%r11)
14528 + movl TI_sysenter_return(%r11), %r11d
14529 + CFI_REGISTER rip,r11
14530 pushq_cfi $__USER32_CS
14531 /*CFI_REL_OFFSET cs,0*/
14532 movl %eax, %eax
14533 - pushq_cfi %r10
14534 + pushq_cfi %r11
14535 CFI_REL_OFFSET rip,0
14536 pushq_cfi %rax
14537 cld
14538 SAVE_ARGS 0,1,0
14539 + pax_enter_kernel_user
14540 +
14541 +#ifdef CONFIG_PAX_RANDKSTACK
14542 + pax_erase_kstack
14543 +#endif
14544 +
14545 + /*
14546 + * No need to follow this irqs on/off section: the syscall
14547 + * disabled irqs, here we enable it straight after entry:
14548 + */
14549 + ENABLE_INTERRUPTS(CLBR_NONE)
14550 /* no need to do an access_ok check here because rbp has been
14551 32bit zero extended */
14552 +
14553 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14554 + addq pax_user_shadow_base,%rbp
14555 + ASM_PAX_OPEN_USERLAND
14556 +#endif
14557 +
14558 ASM_STAC
14559 1: movl (%rbp),%ebp
14560 _ASM_EXTABLE(1b,ia32_badarg)
14561 ASM_CLAC
14562 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14563 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14564 +
14565 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14566 + ASM_PAX_CLOSE_USERLAND
14567 +#endif
14568 +
14569 + GET_THREAD_INFO(%r11)
14570 + orl $TS_COMPAT,TI_status(%r11)
14571 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14572 CFI_REMEMBER_STATE
14573 jnz sysenter_tracesys
14574 cmpq $(IA32_NR_syscalls-1),%rax
14575 @@ -162,15 +209,18 @@ sysenter_do_call:
14576 sysenter_dispatch:
14577 call *ia32_sys_call_table(,%rax,8)
14578 movq %rax,RAX-ARGOFFSET(%rsp)
14579 + GET_THREAD_INFO(%r11)
14580 DISABLE_INTERRUPTS(CLBR_NONE)
14581 TRACE_IRQS_OFF
14582 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14583 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14584 jnz sysexit_audit
14585 sysexit_from_sys_call:
14586 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14587 + pax_exit_kernel_user
14588 + pax_erase_kstack
14589 + andl $~TS_COMPAT,TI_status(%r11)
14590 /* clear IF, that popfq doesn't enable interrupts early */
14591 - andl $~0x200,EFLAGS-R11(%rsp)
14592 - movl RIP-R11(%rsp),%edx /* User %eip */
14593 + andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
14594 + movl RIP(%rsp),%edx /* User %eip */
14595 CFI_REGISTER rip,rdx
14596 RESTORE_ARGS 0,24,0,0,0,0
14597 xorq %r8,%r8
14598 @@ -193,6 +243,9 @@ sysexit_from_sys_call:
14599 movl %eax,%esi /* 2nd arg: syscall number */
14600 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
14601 call __audit_syscall_entry
14602 +
14603 + pax_erase_kstack
14604 +
14605 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
14606 cmpq $(IA32_NR_syscalls-1),%rax
14607 ja ia32_badsys
14608 @@ -204,7 +257,7 @@ sysexit_from_sys_call:
14609 .endm
14610
14611 .macro auditsys_exit exit
14612 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14613 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14614 jnz ia32_ret_from_sys_call
14615 TRACE_IRQS_ON
14616 ENABLE_INTERRUPTS(CLBR_NONE)
14617 @@ -215,11 +268,12 @@ sysexit_from_sys_call:
14618 1: setbe %al /* 1 if error, 0 if not */
14619 movzbl %al,%edi /* zero-extend that into %edi */
14620 call __audit_syscall_exit
14621 + GET_THREAD_INFO(%r11)
14622 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
14623 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
14624 DISABLE_INTERRUPTS(CLBR_NONE)
14625 TRACE_IRQS_OFF
14626 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14627 + testl %edi,TI_flags(%r11)
14628 jz \exit
14629 CLEAR_RREGS -ARGOFFSET
14630 jmp int_with_check
14631 @@ -237,7 +291,7 @@ sysexit_audit:
14632
14633 sysenter_tracesys:
14634 #ifdef CONFIG_AUDITSYSCALL
14635 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14636 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14637 jz sysenter_auditsys
14638 #endif
14639 SAVE_REST
14640 @@ -249,6 +303,9 @@ sysenter_tracesys:
14641 RESTORE_REST
14642 cmpq $(IA32_NR_syscalls-1),%rax
14643 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14644 +
14645 + pax_erase_kstack
14646 +
14647 jmp sysenter_do_call
14648 CFI_ENDPROC
14649 ENDPROC(ia32_sysenter_target)
14650 @@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
14651 ENTRY(ia32_cstar_target)
14652 CFI_STARTPROC32 simple
14653 CFI_SIGNAL_FRAME
14654 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14655 + CFI_DEF_CFA rsp,0
14656 CFI_REGISTER rip,rcx
14657 /*CFI_REGISTER rflags,r11*/
14658 SWAPGS_UNSAFE_STACK
14659 movl %esp,%r8d
14660 CFI_REGISTER rsp,r8
14661 movq PER_CPU_VAR(kernel_stack),%rsp
14662 + SAVE_ARGS 8*6,0,0
14663 + pax_enter_kernel_user
14664 +
14665 +#ifdef CONFIG_PAX_RANDKSTACK
14666 + pax_erase_kstack
14667 +#endif
14668 +
14669 /*
14670 * No need to follow this irqs on/off section: the syscall
14671 * disabled irqs and here we enable it straight after entry:
14672 */
14673 ENABLE_INTERRUPTS(CLBR_NONE)
14674 - SAVE_ARGS 8,0,0
14675 movl %eax,%eax /* zero extension */
14676 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14677 movq %rcx,RIP-ARGOFFSET(%rsp)
14678 @@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
14679 /* no need to do an access_ok check here because r8 has been
14680 32bit zero extended */
14681 /* hardware stack frame is complete now */
14682 +
14683 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14684 + ASM_PAX_OPEN_USERLAND
14685 + movq pax_user_shadow_base,%r8
14686 + addq RSP-ARGOFFSET(%rsp),%r8
14687 +#endif
14688 +
14689 ASM_STAC
14690 1: movl (%r8),%r9d
14691 _ASM_EXTABLE(1b,ia32_badarg)
14692 ASM_CLAC
14693 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14694 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14695 +
14696 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14697 + ASM_PAX_CLOSE_USERLAND
14698 +#endif
14699 +
14700 + GET_THREAD_INFO(%r11)
14701 + orl $TS_COMPAT,TI_status(%r11)
14702 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14703 CFI_REMEMBER_STATE
14704 jnz cstar_tracesys
14705 cmpq $IA32_NR_syscalls-1,%rax
14706 @@ -319,13 +395,16 @@ cstar_do_call:
14707 cstar_dispatch:
14708 call *ia32_sys_call_table(,%rax,8)
14709 movq %rax,RAX-ARGOFFSET(%rsp)
14710 + GET_THREAD_INFO(%r11)
14711 DISABLE_INTERRUPTS(CLBR_NONE)
14712 TRACE_IRQS_OFF
14713 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14714 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14715 jnz sysretl_audit
14716 sysretl_from_sys_call:
14717 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14718 - RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14719 + pax_exit_kernel_user
14720 + pax_erase_kstack
14721 + andl $~TS_COMPAT,TI_status(%r11)
14722 + RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14723 movl RIP-ARGOFFSET(%rsp),%ecx
14724 CFI_REGISTER rip,rcx
14725 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14726 @@ -352,7 +431,7 @@ sysretl_audit:
14727
14728 cstar_tracesys:
14729 #ifdef CONFIG_AUDITSYSCALL
14730 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14731 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14732 jz cstar_auditsys
14733 #endif
14734 xchgl %r9d,%ebp
14735 @@ -366,11 +445,19 @@ cstar_tracesys:
14736 xchgl %ebp,%r9d
14737 cmpq $(IA32_NR_syscalls-1),%rax
14738 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14739 +
14740 + pax_erase_kstack
14741 +
14742 jmp cstar_do_call
14743 END(ia32_cstar_target)
14744
14745 ia32_badarg:
14746 ASM_CLAC
14747 +
14748 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14749 + ASM_PAX_CLOSE_USERLAND
14750 +#endif
14751 +
14752 movq $-EFAULT,%rax
14753 jmp ia32_sysret
14754 CFI_ENDPROC
14755 @@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
14756 CFI_REL_OFFSET rip,RIP-RIP
14757 PARAVIRT_ADJUST_EXCEPTION_FRAME
14758 SWAPGS
14759 - /*
14760 - * No need to follow this irqs on/off section: the syscall
14761 - * disabled irqs and here we enable it straight after entry:
14762 - */
14763 - ENABLE_INTERRUPTS(CLBR_NONE)
14764 movl %eax,%eax
14765 pushq_cfi %rax
14766 cld
14767 /* note the registers are not zero extended to the sf.
14768 this could be a problem. */
14769 SAVE_ARGS 0,1,0
14770 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14771 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14772 + pax_enter_kernel_user
14773 +
14774 +#ifdef CONFIG_PAX_RANDKSTACK
14775 + pax_erase_kstack
14776 +#endif
14777 +
14778 + /*
14779 + * No need to follow this irqs on/off section: the syscall
14780 + * disabled irqs and here we enable it straight after entry:
14781 + */
14782 + ENABLE_INTERRUPTS(CLBR_NONE)
14783 + GET_THREAD_INFO(%r11)
14784 + orl $TS_COMPAT,TI_status(%r11)
14785 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14786 jnz ia32_tracesys
14787 cmpq $(IA32_NR_syscalls-1),%rax
14788 ja ia32_badsys
14789 @@ -442,6 +536,9 @@ ia32_tracesys:
14790 RESTORE_REST
14791 cmpq $(IA32_NR_syscalls-1),%rax
14792 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
14793 +
14794 + pax_erase_kstack
14795 +
14796 jmp ia32_do_call
14797 END(ia32_syscall)
14798
14799 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
14800 index 8e0ceec..af13504 100644
14801 --- a/arch/x86/ia32/sys_ia32.c
14802 +++ b/arch/x86/ia32/sys_ia32.c
14803 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
14804 */
14805 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
14806 {
14807 - typeof(ubuf->st_uid) uid = 0;
14808 - typeof(ubuf->st_gid) gid = 0;
14809 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
14810 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
14811 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
14812 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
14813 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
14814 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
14815 index 372231c..51b537d 100644
14816 --- a/arch/x86/include/asm/alternative-asm.h
14817 +++ b/arch/x86/include/asm/alternative-asm.h
14818 @@ -18,6 +18,45 @@
14819 .endm
14820 #endif
14821
14822 +#ifdef KERNEXEC_PLUGIN
14823 + .macro pax_force_retaddr_bts rip=0
14824 + btsq $63,\rip(%rsp)
14825 + .endm
14826 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
14827 + .macro pax_force_retaddr rip=0, reload=0
14828 + btsq $63,\rip(%rsp)
14829 + .endm
14830 + .macro pax_force_fptr ptr
14831 + btsq $63,\ptr
14832 + .endm
14833 + .macro pax_set_fptr_mask
14834 + .endm
14835 +#endif
14836 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
14837 + .macro pax_force_retaddr rip=0, reload=0
14838 + .if \reload
14839 + pax_set_fptr_mask
14840 + .endif
14841 + orq %r12,\rip(%rsp)
14842 + .endm
14843 + .macro pax_force_fptr ptr
14844 + orq %r12,\ptr
14845 + .endm
14846 + .macro pax_set_fptr_mask
14847 + movabs $0x8000000000000000,%r12
14848 + .endm
14849 +#endif
14850 +#else
14851 + .macro pax_force_retaddr rip=0, reload=0
14852 + .endm
14853 + .macro pax_force_fptr ptr
14854 + .endm
14855 + .macro pax_force_retaddr_bts rip=0
14856 + .endm
14857 + .macro pax_set_fptr_mask
14858 + .endm
14859 +#endif
14860 +
14861 .macro altinstruction_entry orig alt feature orig_len alt_len
14862 .long \orig - .
14863 .long \alt - .
14864 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
14865 index 0a3f9c9..c9d081d 100644
14866 --- a/arch/x86/include/asm/alternative.h
14867 +++ b/arch/x86/include/asm/alternative.h
14868 @@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14869 ".pushsection .discard,\"aw\",@progbits\n" \
14870 DISCARD_ENTRY(1) \
14871 ".popsection\n" \
14872 - ".pushsection .altinstr_replacement, \"ax\"\n" \
14873 + ".pushsection .altinstr_replacement, \"a\"\n" \
14874 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
14875 ".popsection"
14876
14877 @@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14878 DISCARD_ENTRY(1) \
14879 DISCARD_ENTRY(2) \
14880 ".popsection\n" \
14881 - ".pushsection .altinstr_replacement, \"ax\"\n" \
14882 + ".pushsection .altinstr_replacement, \"a\"\n" \
14883 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
14884 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
14885 ".popsection"
14886 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
14887 index 19b0eba..12254cd 100644
14888 --- a/arch/x86/include/asm/apic.h
14889 +++ b/arch/x86/include/asm/apic.h
14890 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
14891
14892 #ifdef CONFIG_X86_LOCAL_APIC
14893
14894 -extern unsigned int apic_verbosity;
14895 +extern int apic_verbosity;
14896 extern int local_apic_timer_c2_ok;
14897
14898 extern int disable_apic;
14899 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
14900 index 20370c6..a2eb9b0 100644
14901 --- a/arch/x86/include/asm/apm.h
14902 +++ b/arch/x86/include/asm/apm.h
14903 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
14904 __asm__ __volatile__(APM_DO_ZERO_SEGS
14905 "pushl %%edi\n\t"
14906 "pushl %%ebp\n\t"
14907 - "lcall *%%cs:apm_bios_entry\n\t"
14908 + "lcall *%%ss:apm_bios_entry\n\t"
14909 "setc %%al\n\t"
14910 "popl %%ebp\n\t"
14911 "popl %%edi\n\t"
14912 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
14913 __asm__ __volatile__(APM_DO_ZERO_SEGS
14914 "pushl %%edi\n\t"
14915 "pushl %%ebp\n\t"
14916 - "lcall *%%cs:apm_bios_entry\n\t"
14917 + "lcall *%%ss:apm_bios_entry\n\t"
14918 "setc %%bl\n\t"
14919 "popl %%ebp\n\t"
14920 "popl %%edi\n\t"
14921 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
14922 index b17f4f4..9620151 100644
14923 --- a/arch/x86/include/asm/atomic.h
14924 +++ b/arch/x86/include/asm/atomic.h
14925 @@ -23,7 +23,18 @@
14926 */
14927 static inline int atomic_read(const atomic_t *v)
14928 {
14929 - return (*(volatile int *)&(v)->counter);
14930 + return (*(volatile const int *)&(v)->counter);
14931 +}
14932 +
14933 +/**
14934 + * atomic_read_unchecked - read atomic variable
14935 + * @v: pointer of type atomic_unchecked_t
14936 + *
14937 + * Atomically reads the value of @v.
14938 + */
14939 +static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
14940 +{
14941 + return (*(volatile const int *)&(v)->counter);
14942 }
14943
14944 /**
14945 @@ -39,6 +50,18 @@ static inline void atomic_set(atomic_t *v, int i)
14946 }
14947
14948 /**
14949 + * atomic_set_unchecked - set atomic variable
14950 + * @v: pointer of type atomic_unchecked_t
14951 + * @i: required value
14952 + *
14953 + * Atomically sets the value of @v to @i.
14954 + */
14955 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
14956 +{
14957 + v->counter = i;
14958 +}
14959 +
14960 +/**
14961 * atomic_add - add integer to atomic variable
14962 * @i: integer value to add
14963 * @v: pointer of type atomic_t
14964 @@ -47,7 +70,29 @@ static inline void atomic_set(atomic_t *v, int i)
14965 */
14966 static inline void atomic_add(int i, atomic_t *v)
14967 {
14968 - asm volatile(LOCK_PREFIX "addl %1,%0"
14969 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
14970 +
14971 +#ifdef CONFIG_PAX_REFCOUNT
14972 + "jno 0f\n"
14973 + LOCK_PREFIX "subl %1,%0\n"
14974 + "int $4\n0:\n"
14975 + _ASM_EXTABLE(0b, 0b)
14976 +#endif
14977 +
14978 + : "+m" (v->counter)
14979 + : "ir" (i));
14980 +}
14981 +
14982 +/**
14983 + * atomic_add_unchecked - add integer to atomic variable
14984 + * @i: integer value to add
14985 + * @v: pointer of type atomic_unchecked_t
14986 + *
14987 + * Atomically adds @i to @v.
14988 + */
14989 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
14990 +{
14991 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
14992 : "+m" (v->counter)
14993 : "ir" (i));
14994 }
14995 @@ -61,7 +106,29 @@ static inline void atomic_add(int i, atomic_t *v)
14996 */
14997 static inline void atomic_sub(int i, atomic_t *v)
14998 {
14999 - asm volatile(LOCK_PREFIX "subl %1,%0"
15000 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
15001 +
15002 +#ifdef CONFIG_PAX_REFCOUNT
15003 + "jno 0f\n"
15004 + LOCK_PREFIX "addl %1,%0\n"
15005 + "int $4\n0:\n"
15006 + _ASM_EXTABLE(0b, 0b)
15007 +#endif
15008 +
15009 + : "+m" (v->counter)
15010 + : "ir" (i));
15011 +}
15012 +
15013 +/**
15014 + * atomic_sub_unchecked - subtract integer from atomic variable
15015 + * @i: integer value to subtract
15016 + * @v: pointer of type atomic_unchecked_t
15017 + *
15018 + * Atomically subtracts @i from @v.
15019 + */
15020 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
15021 +{
15022 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
15023 : "+m" (v->counter)
15024 : "ir" (i));
15025 }
15026 @@ -77,7 +144,7 @@ static inline void atomic_sub(int i, atomic_t *v)
15027 */
15028 static inline int atomic_sub_and_test(int i, atomic_t *v)
15029 {
15030 - GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
15031 + GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
15032 }
15033
15034 /**
15035 @@ -88,7 +155,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
15036 */
15037 static inline void atomic_inc(atomic_t *v)
15038 {
15039 - asm volatile(LOCK_PREFIX "incl %0"
15040 + asm volatile(LOCK_PREFIX "incl %0\n"
15041 +
15042 +#ifdef CONFIG_PAX_REFCOUNT
15043 + "jno 0f\n"
15044 + LOCK_PREFIX "decl %0\n"
15045 + "int $4\n0:\n"
15046 + _ASM_EXTABLE(0b, 0b)
15047 +#endif
15048 +
15049 + : "+m" (v->counter));
15050 +}
15051 +
15052 +/**
15053 + * atomic_inc_unchecked - increment atomic variable
15054 + * @v: pointer of type atomic_unchecked_t
15055 + *
15056 + * Atomically increments @v by 1.
15057 + */
15058 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
15059 +{
15060 + asm volatile(LOCK_PREFIX "incl %0\n"
15061 : "+m" (v->counter));
15062 }
15063
15064 @@ -100,7 +187,27 @@ static inline void atomic_inc(atomic_t *v)
15065 */
15066 static inline void atomic_dec(atomic_t *v)
15067 {
15068 - asm volatile(LOCK_PREFIX "decl %0"
15069 + asm volatile(LOCK_PREFIX "decl %0\n"
15070 +
15071 +#ifdef CONFIG_PAX_REFCOUNT
15072 + "jno 0f\n"
15073 + LOCK_PREFIX "incl %0\n"
15074 + "int $4\n0:\n"
15075 + _ASM_EXTABLE(0b, 0b)
15076 +#endif
15077 +
15078 + : "+m" (v->counter));
15079 +}
15080 +
15081 +/**
15082 + * atomic_dec_unchecked - decrement atomic variable
15083 + * @v: pointer of type atomic_unchecked_t
15084 + *
15085 + * Atomically decrements @v by 1.
15086 + */
15087 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
15088 +{
15089 + asm volatile(LOCK_PREFIX "decl %0\n"
15090 : "+m" (v->counter));
15091 }
15092
15093 @@ -114,7 +221,7 @@ static inline void atomic_dec(atomic_t *v)
15094 */
15095 static inline int atomic_dec_and_test(atomic_t *v)
15096 {
15097 - GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
15098 + GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
15099 }
15100
15101 /**
15102 @@ -127,7 +234,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
15103 */
15104 static inline int atomic_inc_and_test(atomic_t *v)
15105 {
15106 - GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
15107 + GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
15108 +}
15109 +
15110 +/**
15111 + * atomic_inc_and_test_unchecked - increment and test
15112 + * @v: pointer of type atomic_unchecked_t
15113 + *
15114 + * Atomically increments @v by 1
15115 + * and returns true if the result is zero, or false for all
15116 + * other cases.
15117 + */
15118 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
15119 +{
15120 + GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
15121 }
15122
15123 /**
15124 @@ -141,7 +261,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
15125 */
15126 static inline int atomic_add_negative(int i, atomic_t *v)
15127 {
15128 - GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
15129 + GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
15130 }
15131
15132 /**
15133 @@ -153,6 +273,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
15134 */
15135 static inline int atomic_add_return(int i, atomic_t *v)
15136 {
15137 + return i + xadd_check_overflow(&v->counter, i);
15138 +}
15139 +
15140 +/**
15141 + * atomic_add_return_unchecked - add integer and return
15142 + * @i: integer value to add
15143 + * @v: pointer of type atomic_unchecked_t
15144 + *
15145 + * Atomically adds @i to @v and returns @i + @v
15146 + */
15147 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
15148 +{
15149 return i + xadd(&v->counter, i);
15150 }
15151
15152 @@ -169,9 +301,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
15153 }
15154
15155 #define atomic_inc_return(v) (atomic_add_return(1, v))
15156 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
15157 +{
15158 + return atomic_add_return_unchecked(1, v);
15159 +}
15160 #define atomic_dec_return(v) (atomic_sub_return(1, v))
15161
15162 -static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
15163 +static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
15164 +{
15165 + return cmpxchg(&v->counter, old, new);
15166 +}
15167 +
15168 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
15169 {
15170 return cmpxchg(&v->counter, old, new);
15171 }
15172 @@ -181,6 +322,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
15173 return xchg(&v->counter, new);
15174 }
15175
15176 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
15177 +{
15178 + return xchg(&v->counter, new);
15179 +}
15180 +
15181 /**
15182 * __atomic_add_unless - add unless the number is already a given value
15183 * @v: pointer of type atomic_t
15184 @@ -190,14 +336,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
15185 * Atomically adds @a to @v, so long as @v was not already @u.
15186 * Returns the old value of @v.
15187 */
15188 -static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15189 +static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
15190 {
15191 - int c, old;
15192 + int c, old, new;
15193 c = atomic_read(v);
15194 for (;;) {
15195 - if (unlikely(c == (u)))
15196 + if (unlikely(c == u))
15197 break;
15198 - old = atomic_cmpxchg((v), c, c + (a));
15199 +
15200 + asm volatile("addl %2,%0\n"
15201 +
15202 +#ifdef CONFIG_PAX_REFCOUNT
15203 + "jno 0f\n"
15204 + "subl %2,%0\n"
15205 + "int $4\n0:\n"
15206 + _ASM_EXTABLE(0b, 0b)
15207 +#endif
15208 +
15209 + : "=r" (new)
15210 + : "0" (c), "ir" (a));
15211 +
15212 + old = atomic_cmpxchg(v, c, new);
15213 if (likely(old == c))
15214 break;
15215 c = old;
15216 @@ -206,6 +365,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15217 }
15218
15219 /**
15220 + * atomic_inc_not_zero_hint - increment if not null
15221 + * @v: pointer of type atomic_t
15222 + * @hint: probable value of the atomic before the increment
15223 + *
15224 + * This version of atomic_inc_not_zero() gives a hint of probable
15225 + * value of the atomic. This helps processor to not read the memory
15226 + * before doing the atomic read/modify/write cycle, lowering
15227 + * number of bus transactions on some arches.
15228 + *
15229 + * Returns: 0 if increment was not done, 1 otherwise.
15230 + */
15231 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15232 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15233 +{
15234 + int val, c = hint, new;
15235 +
15236 + /* sanity test, should be removed by compiler if hint is a constant */
15237 + if (!hint)
15238 + return __atomic_add_unless(v, 1, 0);
15239 +
15240 + do {
15241 + asm volatile("incl %0\n"
15242 +
15243 +#ifdef CONFIG_PAX_REFCOUNT
15244 + "jno 0f\n"
15245 + "decl %0\n"
15246 + "int $4\n0:\n"
15247 + _ASM_EXTABLE(0b, 0b)
15248 +#endif
15249 +
15250 + : "=r" (new)
15251 + : "0" (c));
15252 +
15253 + val = atomic_cmpxchg(v, c, new);
15254 + if (val == c)
15255 + return 1;
15256 + c = val;
15257 + } while (c);
15258 +
15259 + return 0;
15260 +}
15261 +
15262 +/**
15263 * atomic_inc_short - increment of a short integer
15264 * @v: pointer to type int
15265 *
15266 @@ -234,14 +436,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
15267 #endif
15268
15269 /* These are x86-specific, used by some header files */
15270 -#define atomic_clear_mask(mask, addr) \
15271 - asm volatile(LOCK_PREFIX "andl %0,%1" \
15272 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
15273 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15274 +{
15275 + asm volatile(LOCK_PREFIX "andl %1,%0"
15276 + : "+m" (v->counter)
15277 + : "r" (~(mask))
15278 + : "memory");
15279 +}
15280
15281 -#define atomic_set_mask(mask, addr) \
15282 - asm volatile(LOCK_PREFIX "orl %0,%1" \
15283 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15284 - : "memory")
15285 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15286 +{
15287 + asm volatile(LOCK_PREFIX "andl %1,%0"
15288 + : "+m" (v->counter)
15289 + : "r" (~(mask))
15290 + : "memory");
15291 +}
15292 +
15293 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15294 +{
15295 + asm volatile(LOCK_PREFIX "orl %1,%0"
15296 + : "+m" (v->counter)
15297 + : "r" (mask)
15298 + : "memory");
15299 +}
15300 +
15301 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15302 +{
15303 + asm volatile(LOCK_PREFIX "orl %1,%0"
15304 + : "+m" (v->counter)
15305 + : "r" (mask)
15306 + : "memory");
15307 +}
15308
15309 /* Atomic operations are already serializing on x86 */
15310 #define smp_mb__before_atomic_dec() barrier()
15311 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15312 index b154de7..bf18a5a 100644
15313 --- a/arch/x86/include/asm/atomic64_32.h
15314 +++ b/arch/x86/include/asm/atomic64_32.h
15315 @@ -12,6 +12,14 @@ typedef struct {
15316 u64 __aligned(8) counter;
15317 } atomic64_t;
15318
15319 +#ifdef CONFIG_PAX_REFCOUNT
15320 +typedef struct {
15321 + u64 __aligned(8) counter;
15322 +} atomic64_unchecked_t;
15323 +#else
15324 +typedef atomic64_t atomic64_unchecked_t;
15325 +#endif
15326 +
15327 #define ATOMIC64_INIT(val) { (val) }
15328
15329 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15330 @@ -37,21 +45,31 @@ typedef struct {
15331 ATOMIC64_DECL_ONE(sym##_386)
15332
15333 ATOMIC64_DECL_ONE(add_386);
15334 +ATOMIC64_DECL_ONE(add_unchecked_386);
15335 ATOMIC64_DECL_ONE(sub_386);
15336 +ATOMIC64_DECL_ONE(sub_unchecked_386);
15337 ATOMIC64_DECL_ONE(inc_386);
15338 +ATOMIC64_DECL_ONE(inc_unchecked_386);
15339 ATOMIC64_DECL_ONE(dec_386);
15340 +ATOMIC64_DECL_ONE(dec_unchecked_386);
15341 #endif
15342
15343 #define alternative_atomic64(f, out, in...) \
15344 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15345
15346 ATOMIC64_DECL(read);
15347 +ATOMIC64_DECL(read_unchecked);
15348 ATOMIC64_DECL(set);
15349 +ATOMIC64_DECL(set_unchecked);
15350 ATOMIC64_DECL(xchg);
15351 ATOMIC64_DECL(add_return);
15352 +ATOMIC64_DECL(add_return_unchecked);
15353 ATOMIC64_DECL(sub_return);
15354 +ATOMIC64_DECL(sub_return_unchecked);
15355 ATOMIC64_DECL(inc_return);
15356 +ATOMIC64_DECL(inc_return_unchecked);
15357 ATOMIC64_DECL(dec_return);
15358 +ATOMIC64_DECL(dec_return_unchecked);
15359 ATOMIC64_DECL(dec_if_positive);
15360 ATOMIC64_DECL(inc_not_zero);
15361 ATOMIC64_DECL(add_unless);
15362 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15363 }
15364
15365 /**
15366 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15367 + * @p: pointer to type atomic64_unchecked_t
15368 + * @o: expected value
15369 + * @n: new value
15370 + *
15371 + * Atomically sets @v to @n if it was equal to @o and returns
15372 + * the old value.
15373 + */
15374 +
15375 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15376 +{
15377 + return cmpxchg64(&v->counter, o, n);
15378 +}
15379 +
15380 +/**
15381 * atomic64_xchg - xchg atomic64 variable
15382 * @v: pointer to type atomic64_t
15383 * @n: value to assign
15384 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15385 }
15386
15387 /**
15388 + * atomic64_set_unchecked - set atomic64 variable
15389 + * @v: pointer to type atomic64_unchecked_t
15390 + * @n: value to assign
15391 + *
15392 + * Atomically sets the value of @v to @n.
15393 + */
15394 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15395 +{
15396 + unsigned high = (unsigned)(i >> 32);
15397 + unsigned low = (unsigned)i;
15398 + alternative_atomic64(set, /* no output */,
15399 + "S" (v), "b" (low), "c" (high)
15400 + : "eax", "edx", "memory");
15401 +}
15402 +
15403 +/**
15404 * atomic64_read - read atomic64 variable
15405 * @v: pointer to type atomic64_t
15406 *
15407 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15408 }
15409
15410 /**
15411 + * atomic64_read_unchecked - read atomic64 variable
15412 + * @v: pointer to type atomic64_unchecked_t
15413 + *
15414 + * Atomically reads the value of @v and returns it.
15415 + */
15416 +static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15417 +{
15418 + long long r;
15419 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15420 + return r;
15421 + }
15422 +
15423 +/**
15424 * atomic64_add_return - add and return
15425 * @i: integer value to add
15426 * @v: pointer to type atomic64_t
15427 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15428 return i;
15429 }
15430
15431 +/**
15432 + * atomic64_add_return_unchecked - add and return
15433 + * @i: integer value to add
15434 + * @v: pointer to type atomic64_unchecked_t
15435 + *
15436 + * Atomically adds @i to @v and returns @i + *@v
15437 + */
15438 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15439 +{
15440 + alternative_atomic64(add_return_unchecked,
15441 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15442 + ASM_NO_INPUT_CLOBBER("memory"));
15443 + return i;
15444 +}
15445 +
15446 /*
15447 * Other variants with different arithmetic operators:
15448 */
15449 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15450 return a;
15451 }
15452
15453 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15454 +{
15455 + long long a;
15456 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
15457 + "S" (v) : "memory", "ecx");
15458 + return a;
15459 +}
15460 +
15461 static inline long long atomic64_dec_return(atomic64_t *v)
15462 {
15463 long long a;
15464 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15465 }
15466
15467 /**
15468 + * atomic64_add_unchecked - add integer to atomic64 variable
15469 + * @i: integer value to add
15470 + * @v: pointer to type atomic64_unchecked_t
15471 + *
15472 + * Atomically adds @i to @v.
15473 + */
15474 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15475 +{
15476 + __alternative_atomic64(add_unchecked, add_return_unchecked,
15477 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15478 + ASM_NO_INPUT_CLOBBER("memory"));
15479 + return i;
15480 +}
15481 +
15482 +/**
15483 * atomic64_sub - subtract the atomic64 variable
15484 * @i: integer value to subtract
15485 * @v: pointer to type atomic64_t
15486 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15487 index 46e9052..ae45136 100644
15488 --- a/arch/x86/include/asm/atomic64_64.h
15489 +++ b/arch/x86/include/asm/atomic64_64.h
15490 @@ -18,7 +18,19 @@
15491 */
15492 static inline long atomic64_read(const atomic64_t *v)
15493 {
15494 - return (*(volatile long *)&(v)->counter);
15495 + return (*(volatile const long *)&(v)->counter);
15496 +}
15497 +
15498 +/**
15499 + * atomic64_read_unchecked - read atomic64 variable
15500 + * @v: pointer of type atomic64_unchecked_t
15501 + *
15502 + * Atomically reads the value of @v.
15503 + * Doesn't imply a read memory barrier.
15504 + */
15505 +static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15506 +{
15507 + return (*(volatile const long *)&(v)->counter);
15508 }
15509
15510 /**
15511 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15512 }
15513
15514 /**
15515 + * atomic64_set_unchecked - set atomic64 variable
15516 + * @v: pointer to type atomic64_unchecked_t
15517 + * @i: required value
15518 + *
15519 + * Atomically sets the value of @v to @i.
15520 + */
15521 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15522 +{
15523 + v->counter = i;
15524 +}
15525 +
15526 +/**
15527 * atomic64_add - add integer to atomic64 variable
15528 * @i: integer value to add
15529 * @v: pointer to type atomic64_t
15530 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15531 */
15532 static inline void atomic64_add(long i, atomic64_t *v)
15533 {
15534 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
15535 +
15536 +#ifdef CONFIG_PAX_REFCOUNT
15537 + "jno 0f\n"
15538 + LOCK_PREFIX "subq %1,%0\n"
15539 + "int $4\n0:\n"
15540 + _ASM_EXTABLE(0b, 0b)
15541 +#endif
15542 +
15543 + : "=m" (v->counter)
15544 + : "er" (i), "m" (v->counter));
15545 +}
15546 +
15547 +/**
15548 + * atomic64_add_unchecked - add integer to atomic64 variable
15549 + * @i: integer value to add
15550 + * @v: pointer to type atomic64_unchecked_t
15551 + *
15552 + * Atomically adds @i to @v.
15553 + */
15554 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
15555 +{
15556 asm volatile(LOCK_PREFIX "addq %1,%0"
15557 : "=m" (v->counter)
15558 : "er" (i), "m" (v->counter));
15559 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
15560 */
15561 static inline void atomic64_sub(long i, atomic64_t *v)
15562 {
15563 - asm volatile(LOCK_PREFIX "subq %1,%0"
15564 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
15565 +
15566 +#ifdef CONFIG_PAX_REFCOUNT
15567 + "jno 0f\n"
15568 + LOCK_PREFIX "addq %1,%0\n"
15569 + "int $4\n0:\n"
15570 + _ASM_EXTABLE(0b, 0b)
15571 +#endif
15572 +
15573 + : "=m" (v->counter)
15574 + : "er" (i), "m" (v->counter));
15575 +}
15576 +
15577 +/**
15578 + * atomic64_sub_unchecked - subtract the atomic64 variable
15579 + * @i: integer value to subtract
15580 + * @v: pointer to type atomic64_unchecked_t
15581 + *
15582 + * Atomically subtracts @i from @v.
15583 + */
15584 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
15585 +{
15586 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
15587 : "=m" (v->counter)
15588 : "er" (i), "m" (v->counter));
15589 }
15590 @@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
15591 */
15592 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15593 {
15594 - GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
15595 + GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
15596 }
15597
15598 /**
15599 @@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15600 */
15601 static inline void atomic64_inc(atomic64_t *v)
15602 {
15603 + asm volatile(LOCK_PREFIX "incq %0\n"
15604 +
15605 +#ifdef CONFIG_PAX_REFCOUNT
15606 + "jno 0f\n"
15607 + LOCK_PREFIX "decq %0\n"
15608 + "int $4\n0:\n"
15609 + _ASM_EXTABLE(0b, 0b)
15610 +#endif
15611 +
15612 + : "=m" (v->counter)
15613 + : "m" (v->counter));
15614 +}
15615 +
15616 +/**
15617 + * atomic64_inc_unchecked - increment atomic64 variable
15618 + * @v: pointer to type atomic64_unchecked_t
15619 + *
15620 + * Atomically increments @v by 1.
15621 + */
15622 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15623 +{
15624 asm volatile(LOCK_PREFIX "incq %0"
15625 : "=m" (v->counter)
15626 : "m" (v->counter));
15627 @@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
15628 */
15629 static inline void atomic64_dec(atomic64_t *v)
15630 {
15631 - asm volatile(LOCK_PREFIX "decq %0"
15632 + asm volatile(LOCK_PREFIX "decq %0\n"
15633 +
15634 +#ifdef CONFIG_PAX_REFCOUNT
15635 + "jno 0f\n"
15636 + LOCK_PREFIX "incq %0\n"
15637 + "int $4\n0:\n"
15638 + _ASM_EXTABLE(0b, 0b)
15639 +#endif
15640 +
15641 + : "=m" (v->counter)
15642 + : "m" (v->counter));
15643 +}
15644 +
15645 +/**
15646 + * atomic64_dec_unchecked - decrement atomic64 variable
15647 + * @v: pointer to type atomic64_t
15648 + *
15649 + * Atomically decrements @v by 1.
15650 + */
15651 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15652 +{
15653 + asm volatile(LOCK_PREFIX "decq %0\n"
15654 : "=m" (v->counter)
15655 : "m" (v->counter));
15656 }
15657 @@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15658 */
15659 static inline int atomic64_dec_and_test(atomic64_t *v)
15660 {
15661 - GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15662 + GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15663 }
15664
15665 /**
15666 @@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15667 */
15668 static inline int atomic64_inc_and_test(atomic64_t *v)
15669 {
15670 - GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
15671 + GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
15672 }
15673
15674 /**
15675 @@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15676 */
15677 static inline int atomic64_add_negative(long i, atomic64_t *v)
15678 {
15679 - GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
15680 + GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
15681 }
15682
15683 /**
15684 @@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15685 */
15686 static inline long atomic64_add_return(long i, atomic64_t *v)
15687 {
15688 + return i + xadd_check_overflow(&v->counter, i);
15689 +}
15690 +
15691 +/**
15692 + * atomic64_add_return_unchecked - add and return
15693 + * @i: integer value to add
15694 + * @v: pointer to type atomic64_unchecked_t
15695 + *
15696 + * Atomically adds @i to @v and returns @i + @v
15697 + */
15698 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15699 +{
15700 return i + xadd(&v->counter, i);
15701 }
15702
15703 @@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15704 }
15705
15706 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15707 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15708 +{
15709 + return atomic64_add_return_unchecked(1, v);
15710 +}
15711 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15712
15713 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15714 @@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15715 return cmpxchg(&v->counter, old, new);
15716 }
15717
15718 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15719 +{
15720 + return cmpxchg(&v->counter, old, new);
15721 +}
15722 +
15723 static inline long atomic64_xchg(atomic64_t *v, long new)
15724 {
15725 return xchg(&v->counter, new);
15726 @@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15727 */
15728 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15729 {
15730 - long c, old;
15731 + long c, old, new;
15732 c = atomic64_read(v);
15733 for (;;) {
15734 - if (unlikely(c == (u)))
15735 + if (unlikely(c == u))
15736 break;
15737 - old = atomic64_cmpxchg((v), c, c + (a));
15738 +
15739 + asm volatile("add %2,%0\n"
15740 +
15741 +#ifdef CONFIG_PAX_REFCOUNT
15742 + "jno 0f\n"
15743 + "sub %2,%0\n"
15744 + "int $4\n0:\n"
15745 + _ASM_EXTABLE(0b, 0b)
15746 +#endif
15747 +
15748 + : "=r" (new)
15749 + : "0" (c), "ir" (a));
15750 +
15751 + old = atomic64_cmpxchg(v, c, new);
15752 if (likely(old == c))
15753 break;
15754 c = old;
15755 }
15756 - return c != (u);
15757 + return c != u;
15758 }
15759
15760 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
15761 diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h
15762 index 69bbb48..32517fe 100644
15763 --- a/arch/x86/include/asm/barrier.h
15764 +++ b/arch/x86/include/asm/barrier.h
15765 @@ -107,7 +107,7 @@
15766 do { \
15767 compiletime_assert_atomic_type(*p); \
15768 smp_mb(); \
15769 - ACCESS_ONCE(*p) = (v); \
15770 + ACCESS_ONCE_RW(*p) = (v); \
15771 } while (0)
15772
15773 #define smp_load_acquire(p) \
15774 @@ -124,7 +124,7 @@ do { \
15775 do { \
15776 compiletime_assert_atomic_type(*p); \
15777 barrier(); \
15778 - ACCESS_ONCE(*p) = (v); \
15779 + ACCESS_ONCE_RW(*p) = (v); \
15780 } while (0)
15781
15782 #define smp_load_acquire(p) \
15783 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
15784 index 9fc1af7..776d75a 100644
15785 --- a/arch/x86/include/asm/bitops.h
15786 +++ b/arch/x86/include/asm/bitops.h
15787 @@ -49,7 +49,7 @@
15788 * a mask operation on a byte.
15789 */
15790 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
15791 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
15792 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
15793 #define CONST_MASK(nr) (1 << ((nr) & 7))
15794
15795 /**
15796 @@ -205,7 +205,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
15797 */
15798 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
15799 {
15800 - GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15801 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15802 }
15803
15804 /**
15805 @@ -251,7 +251,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
15806 */
15807 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
15808 {
15809 - GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15810 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15811 }
15812
15813 /**
15814 @@ -304,7 +304,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
15815 */
15816 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
15817 {
15818 - GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15819 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15820 }
15821
15822 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
15823 @@ -345,7 +345,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
15824 *
15825 * Undefined if no bit exists, so code should check against 0 first.
15826 */
15827 -static inline unsigned long __ffs(unsigned long word)
15828 +static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
15829 {
15830 asm("rep; bsf %1,%0"
15831 : "=r" (word)
15832 @@ -359,7 +359,7 @@ static inline unsigned long __ffs(unsigned long word)
15833 *
15834 * Undefined if no zero exists, so code should check against ~0UL first.
15835 */
15836 -static inline unsigned long ffz(unsigned long word)
15837 +static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
15838 {
15839 asm("rep; bsf %1,%0"
15840 : "=r" (word)
15841 @@ -373,7 +373,7 @@ static inline unsigned long ffz(unsigned long word)
15842 *
15843 * Undefined if no set bit exists, so code should check against 0 first.
15844 */
15845 -static inline unsigned long __fls(unsigned long word)
15846 +static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
15847 {
15848 asm("bsr %1,%0"
15849 : "=r" (word)
15850 @@ -436,7 +436,7 @@ static inline int ffs(int x)
15851 * set bit if value is nonzero. The last (most significant) bit is
15852 * at position 32.
15853 */
15854 -static inline int fls(int x)
15855 +static inline int __intentional_overflow(-1) fls(int x)
15856 {
15857 int r;
15858
15859 @@ -478,7 +478,7 @@ static inline int fls(int x)
15860 * at position 64.
15861 */
15862 #ifdef CONFIG_X86_64
15863 -static __always_inline int fls64(__u64 x)
15864 +static __always_inline __intentional_overflow(-1) int fls64(__u64 x)
15865 {
15866 int bitpos = -1;
15867 /*
15868 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
15869 index 4fa687a..60f2d39 100644
15870 --- a/arch/x86/include/asm/boot.h
15871 +++ b/arch/x86/include/asm/boot.h
15872 @@ -6,10 +6,15 @@
15873 #include <uapi/asm/boot.h>
15874
15875 /* Physical address where kernel should be loaded. */
15876 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15877 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15878 + (CONFIG_PHYSICAL_ALIGN - 1)) \
15879 & ~(CONFIG_PHYSICAL_ALIGN - 1))
15880
15881 +#ifndef __ASSEMBLY__
15882 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
15883 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
15884 +#endif
15885 +
15886 /* Minimum kernel alignment, as a power of two */
15887 #ifdef CONFIG_X86_64
15888 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
15889 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
15890 index 48f99f1..d78ebf9 100644
15891 --- a/arch/x86/include/asm/cache.h
15892 +++ b/arch/x86/include/asm/cache.h
15893 @@ -5,12 +5,13 @@
15894
15895 /* L1 cache line size */
15896 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
15897 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
15898 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
15899
15900 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
15901 +#define __read_only __attribute__((__section__(".data..read_only")))
15902
15903 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
15904 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
15905 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
15906
15907 #ifdef CONFIG_X86_VSMP
15908 #ifdef CONFIG_SMP
15909 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
15910 index 9863ee3..4a1f8e1 100644
15911 --- a/arch/x86/include/asm/cacheflush.h
15912 +++ b/arch/x86/include/asm/cacheflush.h
15913 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
15914 unsigned long pg_flags = pg->flags & _PGMT_MASK;
15915
15916 if (pg_flags == _PGMT_DEFAULT)
15917 - return -1;
15918 + return ~0UL;
15919 else if (pg_flags == _PGMT_WC)
15920 return _PAGE_CACHE_WC;
15921 else if (pg_flags == _PGMT_UC_MINUS)
15922 diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
15923 index cb4c73b..c473c29 100644
15924 --- a/arch/x86/include/asm/calling.h
15925 +++ b/arch/x86/include/asm/calling.h
15926 @@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
15927 #define RSP 152
15928 #define SS 160
15929
15930 -#define ARGOFFSET R11
15931 -#define SWFRAME ORIG_RAX
15932 +#define ARGOFFSET R15
15933
15934 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
15935 - subq $9*8+\addskip, %rsp
15936 - CFI_ADJUST_CFA_OFFSET 9*8+\addskip
15937 - movq_cfi rdi, 8*8
15938 - movq_cfi rsi, 7*8
15939 - movq_cfi rdx, 6*8
15940 + subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
15941 + CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
15942 + movq_cfi rdi, RDI
15943 + movq_cfi rsi, RSI
15944 + movq_cfi rdx, RDX
15945
15946 .if \save_rcx
15947 - movq_cfi rcx, 5*8
15948 + movq_cfi rcx, RCX
15949 .endif
15950
15951 - movq_cfi rax, 4*8
15952 + movq_cfi rax, RAX
15953
15954 .if \save_r891011
15955 - movq_cfi r8, 3*8
15956 - movq_cfi r9, 2*8
15957 - movq_cfi r10, 1*8
15958 - movq_cfi r11, 0*8
15959 + movq_cfi r8, R8
15960 + movq_cfi r9, R9
15961 + movq_cfi r10, R10
15962 + movq_cfi r11, R11
15963 .endif
15964
15965 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15966 + movq_cfi r12, R12
15967 +#endif
15968 +
15969 .endm
15970
15971 -#define ARG_SKIP (9*8)
15972 +#define ARG_SKIP ORIG_RAX
15973
15974 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
15975 rstor_r8910=1, rstor_rdx=1
15976 +
15977 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15978 + movq_cfi_restore R12, r12
15979 +#endif
15980 +
15981 .if \rstor_r11
15982 - movq_cfi_restore 0*8, r11
15983 + movq_cfi_restore R11, r11
15984 .endif
15985
15986 .if \rstor_r8910
15987 - movq_cfi_restore 1*8, r10
15988 - movq_cfi_restore 2*8, r9
15989 - movq_cfi_restore 3*8, r8
15990 + movq_cfi_restore R10, r10
15991 + movq_cfi_restore R9, r9
15992 + movq_cfi_restore R8, r8
15993 .endif
15994
15995 .if \rstor_rax
15996 - movq_cfi_restore 4*8, rax
15997 + movq_cfi_restore RAX, rax
15998 .endif
15999
16000 .if \rstor_rcx
16001 - movq_cfi_restore 5*8, rcx
16002 + movq_cfi_restore RCX, rcx
16003 .endif
16004
16005 .if \rstor_rdx
16006 - movq_cfi_restore 6*8, rdx
16007 + movq_cfi_restore RDX, rdx
16008 .endif
16009
16010 - movq_cfi_restore 7*8, rsi
16011 - movq_cfi_restore 8*8, rdi
16012 + movq_cfi_restore RSI, rsi
16013 + movq_cfi_restore RDI, rdi
16014
16015 - .if ARG_SKIP+\addskip > 0
16016 - addq $ARG_SKIP+\addskip, %rsp
16017 - CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
16018 + .if ORIG_RAX+\addskip > 0
16019 + addq $ORIG_RAX+\addskip, %rsp
16020 + CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
16021 .endif
16022 .endm
16023
16024 - .macro LOAD_ARGS offset, skiprax=0
16025 - movq \offset(%rsp), %r11
16026 - movq \offset+8(%rsp), %r10
16027 - movq \offset+16(%rsp), %r9
16028 - movq \offset+24(%rsp), %r8
16029 - movq \offset+40(%rsp), %rcx
16030 - movq \offset+48(%rsp), %rdx
16031 - movq \offset+56(%rsp), %rsi
16032 - movq \offset+64(%rsp), %rdi
16033 + .macro LOAD_ARGS skiprax=0
16034 + movq R11(%rsp), %r11
16035 + movq R10(%rsp), %r10
16036 + movq R9(%rsp), %r9
16037 + movq R8(%rsp), %r8
16038 + movq RCX(%rsp), %rcx
16039 + movq RDX(%rsp), %rdx
16040 + movq RSI(%rsp), %rsi
16041 + movq RDI(%rsp), %rdi
16042 .if \skiprax
16043 .else
16044 - movq \offset+72(%rsp), %rax
16045 + movq RAX(%rsp), %rax
16046 .endif
16047 .endm
16048
16049 -#define REST_SKIP (6*8)
16050 -
16051 .macro SAVE_REST
16052 - subq $REST_SKIP, %rsp
16053 - CFI_ADJUST_CFA_OFFSET REST_SKIP
16054 - movq_cfi rbx, 5*8
16055 - movq_cfi rbp, 4*8
16056 - movq_cfi r12, 3*8
16057 - movq_cfi r13, 2*8
16058 - movq_cfi r14, 1*8
16059 - movq_cfi r15, 0*8
16060 + movq_cfi rbx, RBX
16061 + movq_cfi rbp, RBP
16062 +
16063 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16064 + movq_cfi r12, R12
16065 +#endif
16066 +
16067 + movq_cfi r13, R13
16068 + movq_cfi r14, R14
16069 + movq_cfi r15, R15
16070 .endm
16071
16072 .macro RESTORE_REST
16073 - movq_cfi_restore 0*8, r15
16074 - movq_cfi_restore 1*8, r14
16075 - movq_cfi_restore 2*8, r13
16076 - movq_cfi_restore 3*8, r12
16077 - movq_cfi_restore 4*8, rbp
16078 - movq_cfi_restore 5*8, rbx
16079 - addq $REST_SKIP, %rsp
16080 - CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
16081 + movq_cfi_restore R15, r15
16082 + movq_cfi_restore R14, r14
16083 + movq_cfi_restore R13, r13
16084 +
16085 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16086 + movq_cfi_restore R12, r12
16087 +#endif
16088 +
16089 + movq_cfi_restore RBP, rbp
16090 + movq_cfi_restore RBX, rbx
16091 .endm
16092
16093 .macro SAVE_ALL
16094 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
16095 index f50de69..2b0a458 100644
16096 --- a/arch/x86/include/asm/checksum_32.h
16097 +++ b/arch/x86/include/asm/checksum_32.h
16098 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
16099 int len, __wsum sum,
16100 int *src_err_ptr, int *dst_err_ptr);
16101
16102 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
16103 + int len, __wsum sum,
16104 + int *src_err_ptr, int *dst_err_ptr);
16105 +
16106 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
16107 + int len, __wsum sum,
16108 + int *src_err_ptr, int *dst_err_ptr);
16109 +
16110 /*
16111 * Note: when you get a NULL pointer exception here this means someone
16112 * passed in an incorrect kernel address to one of these functions.
16113 @@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
16114
16115 might_sleep();
16116 stac();
16117 - ret = csum_partial_copy_generic((__force void *)src, dst,
16118 + ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
16119 len, sum, err_ptr, NULL);
16120 clac();
16121
16122 @@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
16123 might_sleep();
16124 if (access_ok(VERIFY_WRITE, dst, len)) {
16125 stac();
16126 - ret = csum_partial_copy_generic(src, (__force void *)dst,
16127 + ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
16128 len, sum, NULL, err_ptr);
16129 clac();
16130 return ret;
16131 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
16132 index d47786a..2d8883e 100644
16133 --- a/arch/x86/include/asm/cmpxchg.h
16134 +++ b/arch/x86/include/asm/cmpxchg.h
16135 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
16136 __compiletime_error("Bad argument size for cmpxchg");
16137 extern void __xadd_wrong_size(void)
16138 __compiletime_error("Bad argument size for xadd");
16139 +extern void __xadd_check_overflow_wrong_size(void)
16140 + __compiletime_error("Bad argument size for xadd_check_overflow");
16141 extern void __add_wrong_size(void)
16142 __compiletime_error("Bad argument size for add");
16143 +extern void __add_check_overflow_wrong_size(void)
16144 + __compiletime_error("Bad argument size for add_check_overflow");
16145
16146 /*
16147 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
16148 @@ -67,6 +71,38 @@ extern void __add_wrong_size(void)
16149 __ret; \
16150 })
16151
16152 +#ifdef CONFIG_PAX_REFCOUNT
16153 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
16154 + ({ \
16155 + __typeof__ (*(ptr)) __ret = (arg); \
16156 + switch (sizeof(*(ptr))) { \
16157 + case __X86_CASE_L: \
16158 + asm volatile (lock #op "l %0, %1\n" \
16159 + "jno 0f\n" \
16160 + "mov %0,%1\n" \
16161 + "int $4\n0:\n" \
16162 + _ASM_EXTABLE(0b, 0b) \
16163 + : "+r" (__ret), "+m" (*(ptr)) \
16164 + : : "memory", "cc"); \
16165 + break; \
16166 + case __X86_CASE_Q: \
16167 + asm volatile (lock #op "q %q0, %1\n" \
16168 + "jno 0f\n" \
16169 + "mov %0,%1\n" \
16170 + "int $4\n0:\n" \
16171 + _ASM_EXTABLE(0b, 0b) \
16172 + : "+r" (__ret), "+m" (*(ptr)) \
16173 + : : "memory", "cc"); \
16174 + break; \
16175 + default: \
16176 + __ ## op ## _check_overflow_wrong_size(); \
16177 + } \
16178 + __ret; \
16179 + })
16180 +#else
16181 +#define __xchg_op_check_overflow(ptr, arg, op, lock) __xchg_op(ptr, arg, op, lock)
16182 +#endif
16183 +
16184 /*
16185 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
16186 * Since this is generally used to protect other memory information, we
16187 @@ -167,6 +203,9 @@ extern void __add_wrong_size(void)
16188 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
16189 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
16190
16191 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
16192 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
16193 +
16194 #define __add(ptr, inc, lock) \
16195 ({ \
16196 __typeof__ (*(ptr)) __ret = (inc); \
16197 diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
16198 index 59c6c40..5e0b22c 100644
16199 --- a/arch/x86/include/asm/compat.h
16200 +++ b/arch/x86/include/asm/compat.h
16201 @@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
16202 typedef u32 compat_uint_t;
16203 typedef u32 compat_ulong_t;
16204 typedef u64 __attribute__((aligned(4))) compat_u64;
16205 -typedef u32 compat_uptr_t;
16206 +typedef u32 __user compat_uptr_t;
16207
16208 struct compat_timespec {
16209 compat_time_t tv_sec;
16210 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16211 index e265ff9..72c253b 100644
16212 --- a/arch/x86/include/asm/cpufeature.h
16213 +++ b/arch/x86/include/asm/cpufeature.h
16214 @@ -203,7 +203,7 @@
16215 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
16216 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
16217 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
16218 -
16219 +#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
16220
16221 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
16222 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
16223 @@ -211,7 +211,7 @@
16224 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
16225 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
16226 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
16227 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
16228 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
16229 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
16230 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
16231 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
16232 @@ -359,6 +359,7 @@ extern const char * const x86_power_flags[32];
16233 #undef cpu_has_centaur_mcr
16234 #define cpu_has_centaur_mcr 0
16235
16236 +#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
16237 #endif /* CONFIG_X86_64 */
16238
16239 #if __GNUC__ >= 4
16240 @@ -411,7 +412,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16241
16242 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
16243 t_warn:
16244 - warn_pre_alternatives();
16245 + if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
16246 + warn_pre_alternatives();
16247 return false;
16248 #endif
16249
16250 @@ -431,7 +433,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16251 ".section .discard,\"aw\",@progbits\n"
16252 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16253 ".previous\n"
16254 - ".section .altinstr_replacement,\"ax\"\n"
16255 + ".section .altinstr_replacement,\"a\"\n"
16256 "3: movb $1,%0\n"
16257 "4:\n"
16258 ".previous\n"
16259 @@ -468,7 +470,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16260 " .byte 2b - 1b\n" /* src len */
16261 " .byte 4f - 3f\n" /* repl len */
16262 ".previous\n"
16263 - ".section .altinstr_replacement,\"ax\"\n"
16264 + ".section .altinstr_replacement,\"a\"\n"
16265 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16266 "4:\n"
16267 ".previous\n"
16268 @@ -501,7 +503,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16269 ".section .discard,\"aw\",@progbits\n"
16270 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16271 ".previous\n"
16272 - ".section .altinstr_replacement,\"ax\"\n"
16273 + ".section .altinstr_replacement,\"a\"\n"
16274 "3: movb $0,%0\n"
16275 "4:\n"
16276 ".previous\n"
16277 @@ -515,7 +517,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16278 ".section .discard,\"aw\",@progbits\n"
16279 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16280 ".previous\n"
16281 - ".section .altinstr_replacement,\"ax\"\n"
16282 + ".section .altinstr_replacement,\"a\"\n"
16283 "5: movb $1,%0\n"
16284 "6:\n"
16285 ".previous\n"
16286 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16287 index 50d033a..37deb26 100644
16288 --- a/arch/x86/include/asm/desc.h
16289 +++ b/arch/x86/include/asm/desc.h
16290 @@ -4,6 +4,7 @@
16291 #include <asm/desc_defs.h>
16292 #include <asm/ldt.h>
16293 #include <asm/mmu.h>
16294 +#include <asm/pgtable.h>
16295
16296 #include <linux/smp.h>
16297 #include <linux/percpu.h>
16298 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16299
16300 desc->type = (info->read_exec_only ^ 1) << 1;
16301 desc->type |= info->contents << 2;
16302 + desc->type |= info->seg_not_present ^ 1;
16303
16304 desc->s = 1;
16305 desc->dpl = 0x3;
16306 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16307 }
16308
16309 extern struct desc_ptr idt_descr;
16310 -extern gate_desc idt_table[];
16311 -extern struct desc_ptr debug_idt_descr;
16312 -extern gate_desc debug_idt_table[];
16313 -
16314 -struct gdt_page {
16315 - struct desc_struct gdt[GDT_ENTRIES];
16316 -} __attribute__((aligned(PAGE_SIZE)));
16317 -
16318 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16319 +extern gate_desc idt_table[IDT_ENTRIES];
16320 +extern const struct desc_ptr debug_idt_descr;
16321 +extern gate_desc debug_idt_table[IDT_ENTRIES];
16322
16323 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16324 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16325 {
16326 - return per_cpu(gdt_page, cpu).gdt;
16327 + return cpu_gdt_table[cpu];
16328 }
16329
16330 #ifdef CONFIG_X86_64
16331 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16332 unsigned long base, unsigned dpl, unsigned flags,
16333 unsigned short seg)
16334 {
16335 - gate->a = (seg << 16) | (base & 0xffff);
16336 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16337 + gate->gate.offset_low = base;
16338 + gate->gate.seg = seg;
16339 + gate->gate.reserved = 0;
16340 + gate->gate.type = type;
16341 + gate->gate.s = 0;
16342 + gate->gate.dpl = dpl;
16343 + gate->gate.p = 1;
16344 + gate->gate.offset_high = base >> 16;
16345 }
16346
16347 #endif
16348 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16349
16350 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16351 {
16352 + pax_open_kernel();
16353 memcpy(&idt[entry], gate, sizeof(*gate));
16354 + pax_close_kernel();
16355 }
16356
16357 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16358 {
16359 + pax_open_kernel();
16360 memcpy(&ldt[entry], desc, 8);
16361 + pax_close_kernel();
16362 }
16363
16364 static inline void
16365 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16366 default: size = sizeof(*gdt); break;
16367 }
16368
16369 + pax_open_kernel();
16370 memcpy(&gdt[entry], desc, size);
16371 + pax_close_kernel();
16372 }
16373
16374 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16375 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16376
16377 static inline void native_load_tr_desc(void)
16378 {
16379 + pax_open_kernel();
16380 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16381 + pax_close_kernel();
16382 }
16383
16384 static inline void native_load_gdt(const struct desc_ptr *dtr)
16385 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16386 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16387 unsigned int i;
16388
16389 + pax_open_kernel();
16390 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16391 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16392 + pax_close_kernel();
16393 }
16394
16395 #define _LDT_empty(info) \
16396 @@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
16397 preempt_enable();
16398 }
16399
16400 -static inline unsigned long get_desc_base(const struct desc_struct *desc)
16401 +static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16402 {
16403 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16404 }
16405 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16406 }
16407
16408 #ifdef CONFIG_X86_64
16409 -static inline void set_nmi_gate(int gate, void *addr)
16410 +static inline void set_nmi_gate(int gate, const void *addr)
16411 {
16412 gate_desc s;
16413
16414 @@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16415 #endif
16416
16417 #ifdef CONFIG_TRACING
16418 -extern struct desc_ptr trace_idt_descr;
16419 -extern gate_desc trace_idt_table[];
16420 +extern const struct desc_ptr trace_idt_descr;
16421 +extern gate_desc trace_idt_table[IDT_ENTRIES];
16422 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16423 {
16424 write_idt_entry(trace_idt_table, entry, gate);
16425 }
16426
16427 -static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16428 +static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16429 unsigned dpl, unsigned ist, unsigned seg)
16430 {
16431 gate_desc s;
16432 @@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16433 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16434 #endif
16435
16436 -static inline void _set_gate(int gate, unsigned type, void *addr,
16437 +static inline void _set_gate(int gate, unsigned type, const void *addr,
16438 unsigned dpl, unsigned ist, unsigned seg)
16439 {
16440 gate_desc s;
16441 @@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16442 #define set_intr_gate(n, addr) \
16443 do { \
16444 BUG_ON((unsigned)n > 0xFF); \
16445 - _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16446 + _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16447 __KERNEL_CS); \
16448 - _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16449 + _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16450 0, 0, __KERNEL_CS); \
16451 } while (0)
16452
16453 @@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
16454 /*
16455 * This routine sets up an interrupt gate at directory privilege level 3.
16456 */
16457 -static inline void set_system_intr_gate(unsigned int n, void *addr)
16458 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
16459 {
16460 BUG_ON((unsigned)n > 0xFF);
16461 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16462 }
16463
16464 -static inline void set_system_trap_gate(unsigned int n, void *addr)
16465 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
16466 {
16467 BUG_ON((unsigned)n > 0xFF);
16468 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16469 }
16470
16471 -static inline void set_trap_gate(unsigned int n, void *addr)
16472 +static inline void set_trap_gate(unsigned int n, const void *addr)
16473 {
16474 BUG_ON((unsigned)n > 0xFF);
16475 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16476 @@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16477 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16478 {
16479 BUG_ON((unsigned)n > 0xFF);
16480 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16481 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16482 }
16483
16484 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16485 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16486 {
16487 BUG_ON((unsigned)n > 0xFF);
16488 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16489 }
16490
16491 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16492 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16493 {
16494 BUG_ON((unsigned)n > 0xFF);
16495 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16496 @@ -503,4 +516,17 @@ static inline void load_current_idt(void)
16497 else
16498 load_idt((const struct desc_ptr *)&idt_descr);
16499 }
16500 +
16501 +#ifdef CONFIG_X86_32
16502 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16503 +{
16504 + struct desc_struct d;
16505 +
16506 + if (likely(limit))
16507 + limit = (limit - 1UL) >> PAGE_SHIFT;
16508 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
16509 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16510 +}
16511 +#endif
16512 +
16513 #endif /* _ASM_X86_DESC_H */
16514 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16515 index 278441f..b95a174 100644
16516 --- a/arch/x86/include/asm/desc_defs.h
16517 +++ b/arch/x86/include/asm/desc_defs.h
16518 @@ -31,6 +31,12 @@ struct desc_struct {
16519 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16520 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16521 };
16522 + struct {
16523 + u16 offset_low;
16524 + u16 seg;
16525 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16526 + unsigned offset_high: 16;
16527 + } gate;
16528 };
16529 } __attribute__((packed));
16530
16531 diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16532 index ced283a..ffe04cc 100644
16533 --- a/arch/x86/include/asm/div64.h
16534 +++ b/arch/x86/include/asm/div64.h
16535 @@ -39,7 +39,7 @@
16536 __mod; \
16537 })
16538
16539 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16540 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16541 {
16542 union {
16543 u64 v64;
16544 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16545 index 2c71182..731124d 100644
16546 --- a/arch/x86/include/asm/elf.h
16547 +++ b/arch/x86/include/asm/elf.h
16548 @@ -243,7 +243,25 @@ extern int force_personality32;
16549 the loader. We need to make sure that it is out of the way of the program
16550 that it will "exec", and that there is sufficient room for the brk. */
16551
16552 +#ifdef CONFIG_PAX_SEGMEXEC
16553 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
16554 +#else
16555 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
16556 +#endif
16557 +
16558 +#ifdef CONFIG_PAX_ASLR
16559 +#ifdef CONFIG_X86_32
16560 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
16561 +
16562 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16563 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16564 +#else
16565 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
16566 +
16567 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16568 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16569 +#endif
16570 +#endif
16571
16572 /* This yields a mask that user programs can use to figure out what
16573 instruction set this CPU supports. This could be done in user space,
16574 @@ -292,16 +310,12 @@ do { \
16575
16576 #define ARCH_DLINFO \
16577 do { \
16578 - if (vdso_enabled) \
16579 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16580 - (unsigned long)current->mm->context.vdso); \
16581 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16582 } while (0)
16583
16584 #define ARCH_DLINFO_X32 \
16585 do { \
16586 - if (vdso_enabled) \
16587 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16588 - (unsigned long)current->mm->context.vdso); \
16589 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16590 } while (0)
16591
16592 #define AT_SYSINFO 32
16593 @@ -316,7 +330,7 @@ else \
16594
16595 #endif /* !CONFIG_X86_32 */
16596
16597 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
16598 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
16599
16600 #define VDSO_ENTRY \
16601 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
16602 @@ -332,9 +346,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
16603 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
16604 #define compat_arch_setup_additional_pages syscall32_setup_pages
16605
16606 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
16607 -#define arch_randomize_brk arch_randomize_brk
16608 -
16609 /*
16610 * True on X86_32 or when emulating IA32 on X86_64
16611 */
16612 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
16613 index 77a99ac..39ff7f5 100644
16614 --- a/arch/x86/include/asm/emergency-restart.h
16615 +++ b/arch/x86/include/asm/emergency-restart.h
16616 @@ -1,6 +1,6 @@
16617 #ifndef _ASM_X86_EMERGENCY_RESTART_H
16618 #define _ASM_X86_EMERGENCY_RESTART_H
16619
16620 -extern void machine_emergency_restart(void);
16621 +extern void machine_emergency_restart(void) __noreturn;
16622
16623 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
16624 diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
16625 index 1c7eefe..d0e4702 100644
16626 --- a/arch/x86/include/asm/floppy.h
16627 +++ b/arch/x86/include/asm/floppy.h
16628 @@ -229,18 +229,18 @@ static struct fd_routine_l {
16629 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16630 } fd_routine[] = {
16631 {
16632 - request_dma,
16633 - free_dma,
16634 - get_dma_residue,
16635 - dma_mem_alloc,
16636 - hard_dma_setup
16637 + ._request_dma = request_dma,
16638 + ._free_dma = free_dma,
16639 + ._get_dma_residue = get_dma_residue,
16640 + ._dma_mem_alloc = dma_mem_alloc,
16641 + ._dma_setup = hard_dma_setup
16642 },
16643 {
16644 - vdma_request_dma,
16645 - vdma_nop,
16646 - vdma_get_dma_residue,
16647 - vdma_mem_alloc,
16648 - vdma_dma_setup
16649 + ._request_dma = vdma_request_dma,
16650 + ._free_dma = vdma_nop,
16651 + ._get_dma_residue = vdma_get_dma_residue,
16652 + ._dma_mem_alloc = vdma_mem_alloc,
16653 + ._dma_setup = vdma_dma_setup
16654 }
16655 };
16656
16657 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16658 index cea1c76..6c0d79b 100644
16659 --- a/arch/x86/include/asm/fpu-internal.h
16660 +++ b/arch/x86/include/asm/fpu-internal.h
16661 @@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16662 #define user_insn(insn, output, input...) \
16663 ({ \
16664 int err; \
16665 + pax_open_userland(); \
16666 asm volatile(ASM_STAC "\n" \
16667 - "1:" #insn "\n\t" \
16668 + "1:" \
16669 + __copyuser_seg \
16670 + #insn "\n\t" \
16671 "2: " ASM_CLAC "\n" \
16672 ".section .fixup,\"ax\"\n" \
16673 "3: movl $-1,%[err]\n" \
16674 @@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16675 _ASM_EXTABLE(1b, 3b) \
16676 : [err] "=r" (err), output \
16677 : "0"(0), input); \
16678 + pax_close_userland(); \
16679 err; \
16680 })
16681
16682 @@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16683 "fnclex\n\t"
16684 "emms\n\t"
16685 "fildl %P[addr]" /* set F?P to defined value */
16686 - : : [addr] "m" (tsk->thread.fpu.has_fpu));
16687 + : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16688 }
16689
16690 return fpu_restore_checking(&tsk->thread.fpu);
16691 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16692 index b4c1f54..e290c08 100644
16693 --- a/arch/x86/include/asm/futex.h
16694 +++ b/arch/x86/include/asm/futex.h
16695 @@ -12,6 +12,7 @@
16696 #include <asm/smap.h>
16697
16698 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16699 + typecheck(u32 __user *, uaddr); \
16700 asm volatile("\t" ASM_STAC "\n" \
16701 "1:\t" insn "\n" \
16702 "2:\t" ASM_CLAC "\n" \
16703 @@ -20,15 +21,16 @@
16704 "\tjmp\t2b\n" \
16705 "\t.previous\n" \
16706 _ASM_EXTABLE(1b, 3b) \
16707 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16708 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16709 : "i" (-EFAULT), "0" (oparg), "1" (0))
16710
16711 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16712 + typecheck(u32 __user *, uaddr); \
16713 asm volatile("\t" ASM_STAC "\n" \
16714 "1:\tmovl %2, %0\n" \
16715 "\tmovl\t%0, %3\n" \
16716 "\t" insn "\n" \
16717 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16718 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16719 "\tjnz\t1b\n" \
16720 "3:\t" ASM_CLAC "\n" \
16721 "\t.section .fixup,\"ax\"\n" \
16722 @@ -38,7 +40,7 @@
16723 _ASM_EXTABLE(1b, 4b) \
16724 _ASM_EXTABLE(2b, 4b) \
16725 : "=&a" (oldval), "=&r" (ret), \
16726 - "+m" (*uaddr), "=&r" (tem) \
16727 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
16728 : "r" (oparg), "i" (-EFAULT), "1" (0))
16729
16730 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16731 @@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16732
16733 pagefault_disable();
16734
16735 + pax_open_userland();
16736 switch (op) {
16737 case FUTEX_OP_SET:
16738 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
16739 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
16740 break;
16741 case FUTEX_OP_ADD:
16742 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
16743 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
16744 uaddr, oparg);
16745 break;
16746 case FUTEX_OP_OR:
16747 @@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16748 default:
16749 ret = -ENOSYS;
16750 }
16751 + pax_close_userland();
16752
16753 pagefault_enable();
16754
16755 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
16756 index a307b75..ec74ca2 100644
16757 --- a/arch/x86/include/asm/hw_irq.h
16758 +++ b/arch/x86/include/asm/hw_irq.h
16759 @@ -164,8 +164,8 @@ extern void setup_ioapic_dest(void);
16760 extern void enable_IO_APIC(void);
16761
16762 /* Statistics */
16763 -extern atomic_t irq_err_count;
16764 -extern atomic_t irq_mis_count;
16765 +extern atomic_unchecked_t irq_err_count;
16766 +extern atomic_unchecked_t irq_mis_count;
16767
16768 /* EISA */
16769 extern void eisa_set_level_irq(unsigned int irq);
16770 diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
16771 index a203659..9889f1c 100644
16772 --- a/arch/x86/include/asm/i8259.h
16773 +++ b/arch/x86/include/asm/i8259.h
16774 @@ -62,7 +62,7 @@ struct legacy_pic {
16775 void (*init)(int auto_eoi);
16776 int (*irq_pending)(unsigned int irq);
16777 void (*make_irq)(unsigned int irq);
16778 -};
16779 +} __do_const;
16780
16781 extern struct legacy_pic *legacy_pic;
16782 extern struct legacy_pic null_legacy_pic;
16783 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
16784 index b8237d8..3e8864e 100644
16785 --- a/arch/x86/include/asm/io.h
16786 +++ b/arch/x86/include/asm/io.h
16787 @@ -52,12 +52,12 @@ static inline void name(type val, volatile void __iomem *addr) \
16788 "m" (*(volatile type __force *)addr) barrier); }
16789
16790 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
16791 -build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
16792 -build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
16793 +build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
16794 +build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
16795
16796 build_mmio_read(__readb, "b", unsigned char, "=q", )
16797 -build_mmio_read(__readw, "w", unsigned short, "=r", )
16798 -build_mmio_read(__readl, "l", unsigned int, "=r", )
16799 +build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
16800 +build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
16801
16802 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
16803 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
16804 @@ -109,7 +109,7 @@ build_mmio_write(writeq, "q", unsigned long, "r", :"memory")
16805 * this function
16806 */
16807
16808 -static inline phys_addr_t virt_to_phys(volatile void *address)
16809 +static inline phys_addr_t __intentional_overflow(-1) virt_to_phys(volatile void *address)
16810 {
16811 return __pa(address);
16812 }
16813 @@ -185,7 +185,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
16814 return ioremap_nocache(offset, size);
16815 }
16816
16817 -extern void iounmap(volatile void __iomem *addr);
16818 +extern void iounmap(const volatile void __iomem *addr);
16819
16820 extern void set_iounmap_nonlazy(void);
16821
16822 @@ -195,6 +195,17 @@ extern void set_iounmap_nonlazy(void);
16823
16824 #include <linux/vmalloc.h>
16825
16826 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
16827 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
16828 +{
16829 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16830 +}
16831 +
16832 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
16833 +{
16834 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16835 +}
16836 +
16837 /*
16838 * Convert a virtual cached pointer to an uncached pointer
16839 */
16840 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
16841 index 0a8b519..80e7d5b 100644
16842 --- a/arch/x86/include/asm/irqflags.h
16843 +++ b/arch/x86/include/asm/irqflags.h
16844 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
16845 sti; \
16846 sysexit
16847
16848 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
16849 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
16850 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
16851 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
16852 +
16853 #else
16854 #define INTERRUPT_RETURN iret
16855 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
16856 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
16857 index 9454c16..e4100e3 100644
16858 --- a/arch/x86/include/asm/kprobes.h
16859 +++ b/arch/x86/include/asm/kprobes.h
16860 @@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
16861 #define RELATIVEJUMP_SIZE 5
16862 #define RELATIVECALL_OPCODE 0xe8
16863 #define RELATIVE_ADDR_SIZE 4
16864 -#define MAX_STACK_SIZE 64
16865 -#define MIN_STACK_SIZE(ADDR) \
16866 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
16867 - THREAD_SIZE - (unsigned long)(ADDR))) \
16868 - ? (MAX_STACK_SIZE) \
16869 - : (((unsigned long)current_thread_info()) + \
16870 - THREAD_SIZE - (unsigned long)(ADDR)))
16871 +#define MAX_STACK_SIZE 64UL
16872 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
16873
16874 #define flush_insn_slot(p) do { } while (0)
16875
16876 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
16877 index 4ad6560..75c7bdd 100644
16878 --- a/arch/x86/include/asm/local.h
16879 +++ b/arch/x86/include/asm/local.h
16880 @@ -10,33 +10,97 @@ typedef struct {
16881 atomic_long_t a;
16882 } local_t;
16883
16884 +typedef struct {
16885 + atomic_long_unchecked_t a;
16886 +} local_unchecked_t;
16887 +
16888 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
16889
16890 #define local_read(l) atomic_long_read(&(l)->a)
16891 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
16892 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
16893 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
16894
16895 static inline void local_inc(local_t *l)
16896 {
16897 - asm volatile(_ASM_INC "%0"
16898 + asm volatile(_ASM_INC "%0\n"
16899 +
16900 +#ifdef CONFIG_PAX_REFCOUNT
16901 + "jno 0f\n"
16902 + _ASM_DEC "%0\n"
16903 + "int $4\n0:\n"
16904 + _ASM_EXTABLE(0b, 0b)
16905 +#endif
16906 +
16907 + : "+m" (l->a.counter));
16908 +}
16909 +
16910 +static inline void local_inc_unchecked(local_unchecked_t *l)
16911 +{
16912 + asm volatile(_ASM_INC "%0\n"
16913 : "+m" (l->a.counter));
16914 }
16915
16916 static inline void local_dec(local_t *l)
16917 {
16918 - asm volatile(_ASM_DEC "%0"
16919 + asm volatile(_ASM_DEC "%0\n"
16920 +
16921 +#ifdef CONFIG_PAX_REFCOUNT
16922 + "jno 0f\n"
16923 + _ASM_INC "%0\n"
16924 + "int $4\n0:\n"
16925 + _ASM_EXTABLE(0b, 0b)
16926 +#endif
16927 +
16928 + : "+m" (l->a.counter));
16929 +}
16930 +
16931 +static inline void local_dec_unchecked(local_unchecked_t *l)
16932 +{
16933 + asm volatile(_ASM_DEC "%0\n"
16934 : "+m" (l->a.counter));
16935 }
16936
16937 static inline void local_add(long i, local_t *l)
16938 {
16939 - asm volatile(_ASM_ADD "%1,%0"
16940 + asm volatile(_ASM_ADD "%1,%0\n"
16941 +
16942 +#ifdef CONFIG_PAX_REFCOUNT
16943 + "jno 0f\n"
16944 + _ASM_SUB "%1,%0\n"
16945 + "int $4\n0:\n"
16946 + _ASM_EXTABLE(0b, 0b)
16947 +#endif
16948 +
16949 + : "+m" (l->a.counter)
16950 + : "ir" (i));
16951 +}
16952 +
16953 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
16954 +{
16955 + asm volatile(_ASM_ADD "%1,%0\n"
16956 : "+m" (l->a.counter)
16957 : "ir" (i));
16958 }
16959
16960 static inline void local_sub(long i, local_t *l)
16961 {
16962 - asm volatile(_ASM_SUB "%1,%0"
16963 + asm volatile(_ASM_SUB "%1,%0\n"
16964 +
16965 +#ifdef CONFIG_PAX_REFCOUNT
16966 + "jno 0f\n"
16967 + _ASM_ADD "%1,%0\n"
16968 + "int $4\n0:\n"
16969 + _ASM_EXTABLE(0b, 0b)
16970 +#endif
16971 +
16972 + : "+m" (l->a.counter)
16973 + : "ir" (i));
16974 +}
16975 +
16976 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
16977 +{
16978 + asm volatile(_ASM_SUB "%1,%0\n"
16979 : "+m" (l->a.counter)
16980 : "ir" (i));
16981 }
16982 @@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
16983 */
16984 static inline int local_sub_and_test(long i, local_t *l)
16985 {
16986 - GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
16987 + GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
16988 }
16989
16990 /**
16991 @@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
16992 */
16993 static inline int local_dec_and_test(local_t *l)
16994 {
16995 - GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
16996 + GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
16997 }
16998
16999 /**
17000 @@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
17001 */
17002 static inline int local_inc_and_test(local_t *l)
17003 {
17004 - GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
17005 + GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
17006 }
17007
17008 /**
17009 @@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
17010 */
17011 static inline int local_add_negative(long i, local_t *l)
17012 {
17013 - GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
17014 + GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
17015 }
17016
17017 /**
17018 @@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
17019 static inline long local_add_return(long i, local_t *l)
17020 {
17021 long __i = i;
17022 + asm volatile(_ASM_XADD "%0, %1\n"
17023 +
17024 +#ifdef CONFIG_PAX_REFCOUNT
17025 + "jno 0f\n"
17026 + _ASM_MOV "%0,%1\n"
17027 + "int $4\n0:\n"
17028 + _ASM_EXTABLE(0b, 0b)
17029 +#endif
17030 +
17031 + : "+r" (i), "+m" (l->a.counter)
17032 + : : "memory");
17033 + return i + __i;
17034 +}
17035 +
17036 +/**
17037 + * local_add_return_unchecked - add and return
17038 + * @i: integer value to add
17039 + * @l: pointer to type local_unchecked_t
17040 + *
17041 + * Atomically adds @i to @l and returns @i + @l
17042 + */
17043 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
17044 +{
17045 + long __i = i;
17046 asm volatile(_ASM_XADD "%0, %1;"
17047 : "+r" (i), "+m" (l->a.counter)
17048 : : "memory");
17049 @@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
17050
17051 #define local_cmpxchg(l, o, n) \
17052 (cmpxchg_local(&((l)->a.counter), (o), (n)))
17053 +#define local_cmpxchg_unchecked(l, o, n) \
17054 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
17055 /* Always has a lock prefix */
17056 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
17057
17058 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
17059 new file mode 100644
17060 index 0000000..2bfd3ba
17061 --- /dev/null
17062 +++ b/arch/x86/include/asm/mman.h
17063 @@ -0,0 +1,15 @@
17064 +#ifndef _X86_MMAN_H
17065 +#define _X86_MMAN_H
17066 +
17067 +#include <uapi/asm/mman.h>
17068 +
17069 +#ifdef __KERNEL__
17070 +#ifndef __ASSEMBLY__
17071 +#ifdef CONFIG_X86_32
17072 +#define arch_mmap_check i386_mmap_check
17073 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
17074 +#endif
17075 +#endif
17076 +#endif
17077 +
17078 +#endif /* X86_MMAN_H */
17079 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
17080 index 5f55e69..e20bfb1 100644
17081 --- a/arch/x86/include/asm/mmu.h
17082 +++ b/arch/x86/include/asm/mmu.h
17083 @@ -9,7 +9,7 @@
17084 * we put the segment information here.
17085 */
17086 typedef struct {
17087 - void *ldt;
17088 + struct desc_struct *ldt;
17089 int size;
17090
17091 #ifdef CONFIG_X86_64
17092 @@ -18,7 +18,19 @@ typedef struct {
17093 #endif
17094
17095 struct mutex lock;
17096 - void *vdso;
17097 + unsigned long vdso;
17098 +
17099 +#ifdef CONFIG_X86_32
17100 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17101 + unsigned long user_cs_base;
17102 + unsigned long user_cs_limit;
17103 +
17104 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17105 + cpumask_t cpu_user_cs_mask;
17106 +#endif
17107 +
17108 +#endif
17109 +#endif
17110 } mm_context_t;
17111
17112 #ifdef CONFIG_SMP
17113 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
17114 index be12c53..4d24039 100644
17115 --- a/arch/x86/include/asm/mmu_context.h
17116 +++ b/arch/x86/include/asm/mmu_context.h
17117 @@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
17118
17119 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
17120 {
17121 +
17122 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17123 + if (!(static_cpu_has(X86_FEATURE_PCID))) {
17124 + unsigned int i;
17125 + pgd_t *pgd;
17126 +
17127 + pax_open_kernel();
17128 + pgd = get_cpu_pgd(smp_processor_id(), kernel);
17129 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
17130 + set_pgd_batched(pgd+i, native_make_pgd(0));
17131 + pax_close_kernel();
17132 + }
17133 +#endif
17134 +
17135 #ifdef CONFIG_SMP
17136 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
17137 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
17138 @@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17139 struct task_struct *tsk)
17140 {
17141 unsigned cpu = smp_processor_id();
17142 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17143 + int tlbstate = TLBSTATE_OK;
17144 +#endif
17145
17146 if (likely(prev != next)) {
17147 #ifdef CONFIG_SMP
17148 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17149 + tlbstate = this_cpu_read(cpu_tlbstate.state);
17150 +#endif
17151 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17152 this_cpu_write(cpu_tlbstate.active_mm, next);
17153 #endif
17154 cpumask_set_cpu(cpu, mm_cpumask(next));
17155
17156 /* Re-load page tables */
17157 +#ifdef CONFIG_PAX_PER_CPU_PGD
17158 + pax_open_kernel();
17159 +
17160 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17161 + if (static_cpu_has(X86_FEATURE_PCID))
17162 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17163 + else
17164 +#endif
17165 +
17166 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17167 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17168 + pax_close_kernel();
17169 + 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));
17170 +
17171 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17172 + if (static_cpu_has(X86_FEATURE_PCID)) {
17173 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17174 + u64 descriptor[2];
17175 + descriptor[0] = PCID_USER;
17176 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17177 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17178 + descriptor[0] = PCID_KERNEL;
17179 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17180 + }
17181 + } else {
17182 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17183 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17184 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17185 + else
17186 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17187 + }
17188 + } else
17189 +#endif
17190 +
17191 + load_cr3(get_cpu_pgd(cpu, kernel));
17192 +#else
17193 load_cr3(next->pgd);
17194 +#endif
17195
17196 /* Stop flush ipis for the previous mm */
17197 cpumask_clear_cpu(cpu, mm_cpumask(prev));
17198 @@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17199 /* Load the LDT, if the LDT is different: */
17200 if (unlikely(prev->context.ldt != next->context.ldt))
17201 load_LDT_nolock(&next->context);
17202 +
17203 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17204 + if (!(__supported_pte_mask & _PAGE_NX)) {
17205 + smp_mb__before_clear_bit();
17206 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
17207 + smp_mb__after_clear_bit();
17208 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17209 + }
17210 +#endif
17211 +
17212 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17213 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
17214 + prev->context.user_cs_limit != next->context.user_cs_limit))
17215 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17216 +#ifdef CONFIG_SMP
17217 + else if (unlikely(tlbstate != TLBSTATE_OK))
17218 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17219 +#endif
17220 +#endif
17221 +
17222 }
17223 + else {
17224 +
17225 +#ifdef CONFIG_PAX_PER_CPU_PGD
17226 + pax_open_kernel();
17227 +
17228 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17229 + if (static_cpu_has(X86_FEATURE_PCID))
17230 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17231 + else
17232 +#endif
17233 +
17234 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17235 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17236 + pax_close_kernel();
17237 + 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));
17238 +
17239 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17240 + if (static_cpu_has(X86_FEATURE_PCID)) {
17241 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17242 + u64 descriptor[2];
17243 + descriptor[0] = PCID_USER;
17244 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17245 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17246 + descriptor[0] = PCID_KERNEL;
17247 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17248 + }
17249 + } else {
17250 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17251 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17252 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17253 + else
17254 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17255 + }
17256 + } else
17257 +#endif
17258 +
17259 + load_cr3(get_cpu_pgd(cpu, kernel));
17260 +#endif
17261 +
17262 #ifdef CONFIG_SMP
17263 - else {
17264 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17265 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17266
17267 @@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17268 * tlb flush IPI delivery. We must reload CR3
17269 * to make sure to use no freed page tables.
17270 */
17271 +
17272 +#ifndef CONFIG_PAX_PER_CPU_PGD
17273 load_cr3(next->pgd);
17274 +#endif
17275 +
17276 load_LDT_nolock(&next->context);
17277 +
17278 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17279 + if (!(__supported_pte_mask & _PAGE_NX))
17280 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17281 +#endif
17282 +
17283 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17284 +#ifdef CONFIG_PAX_PAGEEXEC
17285 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17286 +#endif
17287 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17288 +#endif
17289 +
17290 }
17291 +#endif
17292 }
17293 -#endif
17294 }
17295
17296 #define activate_mm(prev, next) \
17297 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17298 index e3b7819..b257c64 100644
17299 --- a/arch/x86/include/asm/module.h
17300 +++ b/arch/x86/include/asm/module.h
17301 @@ -5,6 +5,7 @@
17302
17303 #ifdef CONFIG_X86_64
17304 /* X86_64 does not define MODULE_PROC_FAMILY */
17305 +#define MODULE_PROC_FAMILY ""
17306 #elif defined CONFIG_M486
17307 #define MODULE_PROC_FAMILY "486 "
17308 #elif defined CONFIG_M586
17309 @@ -57,8 +58,20 @@
17310 #error unknown processor family
17311 #endif
17312
17313 -#ifdef CONFIG_X86_32
17314 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17315 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17316 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17317 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17318 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17319 +#else
17320 +#define MODULE_PAX_KERNEXEC ""
17321 #endif
17322
17323 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17324 +#define MODULE_PAX_UDEREF "UDEREF "
17325 +#else
17326 +#define MODULE_PAX_UDEREF ""
17327 +#endif
17328 +
17329 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17330 +
17331 #endif /* _ASM_X86_MODULE_H */
17332 diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17333 index 5f2fc44..106caa6 100644
17334 --- a/arch/x86/include/asm/nmi.h
17335 +++ b/arch/x86/include/asm/nmi.h
17336 @@ -36,26 +36,35 @@ enum {
17337
17338 typedef int (*nmi_handler_t)(unsigned int, struct pt_regs *);
17339
17340 +struct nmiaction;
17341 +
17342 +struct nmiwork {
17343 + const struct nmiaction *action;
17344 + u64 max_duration;
17345 + struct irq_work irq_work;
17346 +};
17347 +
17348 struct nmiaction {
17349 struct list_head list;
17350 nmi_handler_t handler;
17351 - u64 max_duration;
17352 - struct irq_work irq_work;
17353 unsigned long flags;
17354 const char *name;
17355 -};
17356 + struct nmiwork *work;
17357 +} __do_const;
17358
17359 #define register_nmi_handler(t, fn, fg, n, init...) \
17360 ({ \
17361 - static struct nmiaction init fn##_na = { \
17362 + static struct nmiwork fn##_nw; \
17363 + static const struct nmiaction init fn##_na = { \
17364 .handler = (fn), \
17365 .name = (n), \
17366 .flags = (fg), \
17367 + .work = &fn##_nw, \
17368 }; \
17369 __register_nmi_handler((t), &fn##_na); \
17370 })
17371
17372 -int __register_nmi_handler(unsigned int, struct nmiaction *);
17373 +int __register_nmi_handler(unsigned int, const struct nmiaction *);
17374
17375 void unregister_nmi_handler(unsigned int, const char *);
17376
17377 diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17378 index 775873d..04cd306 100644
17379 --- a/arch/x86/include/asm/page.h
17380 +++ b/arch/x86/include/asm/page.h
17381 @@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17382 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17383
17384 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17385 +#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17386
17387 #define __boot_va(x) __va(x)
17388 #define __boot_pa(x) __pa(x)
17389 @@ -60,11 +61,21 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17390 * virt_to_page(kaddr) returns a valid pointer if and only if
17391 * virt_addr_valid(kaddr) returns true.
17392 */
17393 -#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17394 #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
17395 extern bool __virt_addr_valid(unsigned long kaddr);
17396 #define virt_addr_valid(kaddr) __virt_addr_valid((unsigned long) (kaddr))
17397
17398 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
17399 +#define virt_to_page(kaddr) \
17400 + ({ \
17401 + const void *__kaddr = (const void *)(kaddr); \
17402 + BUG_ON(!virt_addr_valid(__kaddr)); \
17403 + pfn_to_page(__pa(__kaddr) >> PAGE_SHIFT); \
17404 + })
17405 +#else
17406 +#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17407 +#endif
17408 +
17409 #endif /* __ASSEMBLY__ */
17410
17411 #include <asm-generic/memory_model.h>
17412 diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17413 index 0f1ddee..e2fc3d1 100644
17414 --- a/arch/x86/include/asm/page_64.h
17415 +++ b/arch/x86/include/asm/page_64.h
17416 @@ -7,9 +7,9 @@
17417
17418 /* duplicated to the one in bootmem.h */
17419 extern unsigned long max_pfn;
17420 -extern unsigned long phys_base;
17421 +extern const unsigned long phys_base;
17422
17423 -static inline unsigned long __phys_addr_nodebug(unsigned long x)
17424 +static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17425 {
17426 unsigned long y = x - __START_KERNEL_map;
17427
17428 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17429 index cd6e1610..70f4418 100644
17430 --- a/arch/x86/include/asm/paravirt.h
17431 +++ b/arch/x86/include/asm/paravirt.h
17432 @@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17433 return (pmd_t) { ret };
17434 }
17435
17436 -static inline pmdval_t pmd_val(pmd_t pmd)
17437 +static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17438 {
17439 pmdval_t ret;
17440
17441 @@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17442 val);
17443 }
17444
17445 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17446 +{
17447 + pgdval_t val = native_pgd_val(pgd);
17448 +
17449 + if (sizeof(pgdval_t) > sizeof(long))
17450 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17451 + val, (u64)val >> 32);
17452 + else
17453 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17454 + val);
17455 +}
17456 +
17457 static inline void pgd_clear(pgd_t *pgdp)
17458 {
17459 set_pgd(pgdp, __pgd(0));
17460 @@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17461 pv_mmu_ops.set_fixmap(idx, phys, flags);
17462 }
17463
17464 +#ifdef CONFIG_PAX_KERNEXEC
17465 +static inline unsigned long pax_open_kernel(void)
17466 +{
17467 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17468 +}
17469 +
17470 +static inline unsigned long pax_close_kernel(void)
17471 +{
17472 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17473 +}
17474 +#else
17475 +static inline unsigned long pax_open_kernel(void) { return 0; }
17476 +static inline unsigned long pax_close_kernel(void) { return 0; }
17477 +#endif
17478 +
17479 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17480
17481 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17482 @@ -906,7 +933,7 @@ extern void default_banner(void);
17483
17484 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17485 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17486 -#define PARA_INDIRECT(addr) *%cs:addr
17487 +#define PARA_INDIRECT(addr) *%ss:addr
17488 #endif
17489
17490 #define INTERRUPT_RETURN \
17491 @@ -981,6 +1008,21 @@ extern void default_banner(void);
17492 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17493 CLBR_NONE, \
17494 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17495 +
17496 +#define GET_CR0_INTO_RDI \
17497 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17498 + mov %rax,%rdi
17499 +
17500 +#define SET_RDI_INTO_CR0 \
17501 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17502 +
17503 +#define GET_CR3_INTO_RDI \
17504 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17505 + mov %rax,%rdi
17506 +
17507 +#define SET_RDI_INTO_CR3 \
17508 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17509 +
17510 #endif /* CONFIG_X86_32 */
17511
17512 #endif /* __ASSEMBLY__ */
17513 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17514 index 7549b8b..f0edfda 100644
17515 --- a/arch/x86/include/asm/paravirt_types.h
17516 +++ b/arch/x86/include/asm/paravirt_types.h
17517 @@ -84,7 +84,7 @@ struct pv_init_ops {
17518 */
17519 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17520 unsigned long addr, unsigned len);
17521 -};
17522 +} __no_const __no_randomize_layout;
17523
17524
17525 struct pv_lazy_ops {
17526 @@ -92,13 +92,13 @@ struct pv_lazy_ops {
17527 void (*enter)(void);
17528 void (*leave)(void);
17529 void (*flush)(void);
17530 -};
17531 +} __no_randomize_layout;
17532
17533 struct pv_time_ops {
17534 unsigned long long (*sched_clock)(void);
17535 unsigned long long (*steal_clock)(int cpu);
17536 unsigned long (*get_tsc_khz)(void);
17537 -};
17538 +} __no_const __no_randomize_layout;
17539
17540 struct pv_cpu_ops {
17541 /* hooks for various privileged instructions */
17542 @@ -192,7 +192,7 @@ struct pv_cpu_ops {
17543
17544 void (*start_context_switch)(struct task_struct *prev);
17545 void (*end_context_switch)(struct task_struct *next);
17546 -};
17547 +} __no_const __no_randomize_layout;
17548
17549 struct pv_irq_ops {
17550 /*
17551 @@ -215,7 +215,7 @@ struct pv_irq_ops {
17552 #ifdef CONFIG_X86_64
17553 void (*adjust_exception_frame)(void);
17554 #endif
17555 -};
17556 +} __no_randomize_layout;
17557
17558 struct pv_apic_ops {
17559 #ifdef CONFIG_X86_LOCAL_APIC
17560 @@ -223,7 +223,7 @@ struct pv_apic_ops {
17561 unsigned long start_eip,
17562 unsigned long start_esp);
17563 #endif
17564 -};
17565 +} __no_const __no_randomize_layout;
17566
17567 struct pv_mmu_ops {
17568 unsigned long (*read_cr2)(void);
17569 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
17570 struct paravirt_callee_save make_pud;
17571
17572 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
17573 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
17574 #endif /* PAGETABLE_LEVELS == 4 */
17575 #endif /* PAGETABLE_LEVELS >= 3 */
17576
17577 @@ -324,7 +325,13 @@ struct pv_mmu_ops {
17578 an mfn. We can tell which is which from the index. */
17579 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
17580 phys_addr_t phys, pgprot_t flags);
17581 -};
17582 +
17583 +#ifdef CONFIG_PAX_KERNEXEC
17584 + unsigned long (*pax_open_kernel)(void);
17585 + unsigned long (*pax_close_kernel)(void);
17586 +#endif
17587 +
17588 +} __no_randomize_layout;
17589
17590 struct arch_spinlock;
17591 #ifdef CONFIG_SMP
17592 @@ -336,11 +343,14 @@ typedef u16 __ticket_t;
17593 struct pv_lock_ops {
17594 struct paravirt_callee_save lock_spinning;
17595 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
17596 -};
17597 +} __no_randomize_layout;
17598
17599 /* This contains all the paravirt structures: we get a convenient
17600 * number for each function using the offset which we use to indicate
17601 - * what to patch. */
17602 + * what to patch.
17603 + * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
17604 + */
17605 +
17606 struct paravirt_patch_template {
17607 struct pv_init_ops pv_init_ops;
17608 struct pv_time_ops pv_time_ops;
17609 @@ -349,7 +359,7 @@ struct paravirt_patch_template {
17610 struct pv_apic_ops pv_apic_ops;
17611 struct pv_mmu_ops pv_mmu_ops;
17612 struct pv_lock_ops pv_lock_ops;
17613 -};
17614 +} __no_randomize_layout;
17615
17616 extern struct pv_info pv_info;
17617 extern struct pv_init_ops pv_init_ops;
17618 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
17619 index c4412e9..90e88c5 100644
17620 --- a/arch/x86/include/asm/pgalloc.h
17621 +++ b/arch/x86/include/asm/pgalloc.h
17622 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
17623 pmd_t *pmd, pte_t *pte)
17624 {
17625 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17626 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
17627 +}
17628 +
17629 +static inline void pmd_populate_user(struct mm_struct *mm,
17630 + pmd_t *pmd, pte_t *pte)
17631 +{
17632 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17633 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
17634 }
17635
17636 @@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
17637
17638 #ifdef CONFIG_X86_PAE
17639 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
17640 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
17641 +{
17642 + pud_populate(mm, pudp, pmd);
17643 +}
17644 #else /* !CONFIG_X86_PAE */
17645 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17646 {
17647 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17648 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
17649 }
17650 +
17651 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17652 +{
17653 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17654 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
17655 +}
17656 #endif /* CONFIG_X86_PAE */
17657
17658 #if PAGETABLE_LEVELS > 3
17659 @@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17660 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17661 }
17662
17663 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17664 +{
17665 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17666 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17667 +}
17668 +
17669 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17670 {
17671 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17672 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17673 index 0d193e2..bf59aeb 100644
17674 --- a/arch/x86/include/asm/pgtable-2level.h
17675 +++ b/arch/x86/include/asm/pgtable-2level.h
17676 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17677
17678 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17679 {
17680 + pax_open_kernel();
17681 *pmdp = pmd;
17682 + pax_close_kernel();
17683 }
17684
17685 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17686 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
17687 index 81bb91b..9392125 100644
17688 --- a/arch/x86/include/asm/pgtable-3level.h
17689 +++ b/arch/x86/include/asm/pgtable-3level.h
17690 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17691
17692 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17693 {
17694 + pax_open_kernel();
17695 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
17696 + pax_close_kernel();
17697 }
17698
17699 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17700 {
17701 + pax_open_kernel();
17702 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
17703 + pax_close_kernel();
17704 }
17705
17706 /*
17707 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
17708 index b459ddf..b44081b 100644
17709 --- a/arch/x86/include/asm/pgtable.h
17710 +++ b/arch/x86/include/asm/pgtable.h
17711 @@ -46,6 +46,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17712
17713 #ifndef __PAGETABLE_PUD_FOLDED
17714 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
17715 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
17716 #define pgd_clear(pgd) native_pgd_clear(pgd)
17717 #endif
17718
17719 @@ -83,12 +84,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17720
17721 #define arch_end_context_switch(prev) do {} while(0)
17722
17723 +#define pax_open_kernel() native_pax_open_kernel()
17724 +#define pax_close_kernel() native_pax_close_kernel()
17725 #endif /* CONFIG_PARAVIRT */
17726
17727 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
17728 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
17729 +
17730 +#ifdef CONFIG_PAX_KERNEXEC
17731 +static inline unsigned long native_pax_open_kernel(void)
17732 +{
17733 + unsigned long cr0;
17734 +
17735 + preempt_disable();
17736 + barrier();
17737 + cr0 = read_cr0() ^ X86_CR0_WP;
17738 + BUG_ON(cr0 & X86_CR0_WP);
17739 + write_cr0(cr0);
17740 + return cr0 ^ X86_CR0_WP;
17741 +}
17742 +
17743 +static inline unsigned long native_pax_close_kernel(void)
17744 +{
17745 + unsigned long cr0;
17746 +
17747 + cr0 = read_cr0() ^ X86_CR0_WP;
17748 + BUG_ON(!(cr0 & X86_CR0_WP));
17749 + write_cr0(cr0);
17750 + barrier();
17751 + preempt_enable_no_resched();
17752 + return cr0 ^ X86_CR0_WP;
17753 +}
17754 +#else
17755 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
17756 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
17757 +#endif
17758 +
17759 /*
17760 * The following only work if pte_present() is true.
17761 * Undefined behaviour if not..
17762 */
17763 +static inline int pte_user(pte_t pte)
17764 +{
17765 + return pte_val(pte) & _PAGE_USER;
17766 +}
17767 +
17768 static inline int pte_dirty(pte_t pte)
17769 {
17770 return pte_flags(pte) & _PAGE_DIRTY;
17771 @@ -149,6 +189,11 @@ static inline unsigned long pud_pfn(pud_t pud)
17772 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
17773 }
17774
17775 +static inline unsigned long pgd_pfn(pgd_t pgd)
17776 +{
17777 + return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
17778 +}
17779 +
17780 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
17781
17782 static inline int pmd_large(pmd_t pte)
17783 @@ -202,9 +247,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
17784 return pte_clear_flags(pte, _PAGE_RW);
17785 }
17786
17787 +static inline pte_t pte_mkread(pte_t pte)
17788 +{
17789 + return __pte(pte_val(pte) | _PAGE_USER);
17790 +}
17791 +
17792 static inline pte_t pte_mkexec(pte_t pte)
17793 {
17794 - return pte_clear_flags(pte, _PAGE_NX);
17795 +#ifdef CONFIG_X86_PAE
17796 + if (__supported_pte_mask & _PAGE_NX)
17797 + return pte_clear_flags(pte, _PAGE_NX);
17798 + else
17799 +#endif
17800 + return pte_set_flags(pte, _PAGE_USER);
17801 +}
17802 +
17803 +static inline pte_t pte_exprotect(pte_t pte)
17804 +{
17805 +#ifdef CONFIG_X86_PAE
17806 + if (__supported_pte_mask & _PAGE_NX)
17807 + return pte_set_flags(pte, _PAGE_NX);
17808 + else
17809 +#endif
17810 + return pte_clear_flags(pte, _PAGE_USER);
17811 }
17812
17813 static inline pte_t pte_mkdirty(pte_t pte)
17814 @@ -431,6 +496,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
17815 #endif
17816
17817 #ifndef __ASSEMBLY__
17818 +
17819 +#ifdef CONFIG_PAX_PER_CPU_PGD
17820 +extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
17821 +enum cpu_pgd_type {kernel = 0, user = 1};
17822 +static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
17823 +{
17824 + return cpu_pgd[cpu][type];
17825 +}
17826 +#endif
17827 +
17828 #include <linux/mm_types.h>
17829 #include <linux/mmdebug.h>
17830 #include <linux/log2.h>
17831 @@ -571,7 +646,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
17832 * Currently stuck as a macro due to indirect forward reference to
17833 * linux/mmzone.h's __section_mem_map_addr() definition:
17834 */
17835 -#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
17836 +#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
17837
17838 /* Find an entry in the second-level page table.. */
17839 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
17840 @@ -611,7 +686,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
17841 * Currently stuck as a macro due to indirect forward reference to
17842 * linux/mmzone.h's __section_mem_map_addr() definition:
17843 */
17844 -#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
17845 +#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
17846
17847 /* to find an entry in a page-table-directory. */
17848 static inline unsigned long pud_index(unsigned long address)
17849 @@ -626,7 +701,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
17850
17851 static inline int pgd_bad(pgd_t pgd)
17852 {
17853 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
17854 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
17855 }
17856
17857 static inline int pgd_none(pgd_t pgd)
17858 @@ -649,7 +724,12 @@ static inline int pgd_none(pgd_t pgd)
17859 * pgd_offset() returns a (pgd_t *)
17860 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
17861 */
17862 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
17863 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
17864 +
17865 +#ifdef CONFIG_PAX_PER_CPU_PGD
17866 +#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
17867 +#endif
17868 +
17869 /*
17870 * a shortcut which implies the use of the kernel's pgd, instead
17871 * of a process's
17872 @@ -660,6 +740,23 @@ static inline int pgd_none(pgd_t pgd)
17873 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
17874 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
17875
17876 +#ifdef CONFIG_X86_32
17877 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
17878 +#else
17879 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
17880 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
17881 +
17882 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17883 +#ifdef __ASSEMBLY__
17884 +#define pax_user_shadow_base pax_user_shadow_base(%rip)
17885 +#else
17886 +extern unsigned long pax_user_shadow_base;
17887 +extern pgdval_t clone_pgd_mask;
17888 +#endif
17889 +#endif
17890 +
17891 +#endif
17892 +
17893 #ifndef __ASSEMBLY__
17894
17895 extern int direct_gbpages;
17896 @@ -826,11 +923,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
17897 * dst and src can be on the same page, but the range must not overlap,
17898 * and must not cross a page boundary.
17899 */
17900 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
17901 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
17902 {
17903 - memcpy(dst, src, count * sizeof(pgd_t));
17904 + pax_open_kernel();
17905 + while (count--)
17906 + *dst++ = *src++;
17907 + pax_close_kernel();
17908 }
17909
17910 +#ifdef CONFIG_PAX_PER_CPU_PGD
17911 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
17912 +#endif
17913 +
17914 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17915 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
17916 +#else
17917 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
17918 +#endif
17919 +
17920 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
17921 static inline int page_level_shift(enum pg_level level)
17922 {
17923 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
17924 index 9ee3221..b979c6b 100644
17925 --- a/arch/x86/include/asm/pgtable_32.h
17926 +++ b/arch/x86/include/asm/pgtable_32.h
17927 @@ -25,9 +25,6 @@
17928 struct mm_struct;
17929 struct vm_area_struct;
17930
17931 -extern pgd_t swapper_pg_dir[1024];
17932 -extern pgd_t initial_page_table[1024];
17933 -
17934 static inline void pgtable_cache_init(void) { }
17935 static inline void check_pgt_cache(void) { }
17936 void paging_init(void);
17937 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17938 # include <asm/pgtable-2level.h>
17939 #endif
17940
17941 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
17942 +extern pgd_t initial_page_table[PTRS_PER_PGD];
17943 +#ifdef CONFIG_X86_PAE
17944 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
17945 +#endif
17946 +
17947 #if defined(CONFIG_HIGHPTE)
17948 #define pte_offset_map(dir, address) \
17949 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
17950 @@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17951 /* Clear a kernel PTE and flush it from the TLB */
17952 #define kpte_clear_flush(ptep, vaddr) \
17953 do { \
17954 + pax_open_kernel(); \
17955 pte_clear(&init_mm, (vaddr), (ptep)); \
17956 + pax_close_kernel(); \
17957 __flush_tlb_one((vaddr)); \
17958 } while (0)
17959
17960 #endif /* !__ASSEMBLY__ */
17961
17962 +#define HAVE_ARCH_UNMAPPED_AREA
17963 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
17964 +
17965 /*
17966 * kern_addr_valid() is (1) for FLATMEM and (0) for
17967 * SPARSEMEM and DISCONTIGMEM
17968 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
17969 index ed5903b..c7fe163 100644
17970 --- a/arch/x86/include/asm/pgtable_32_types.h
17971 +++ b/arch/x86/include/asm/pgtable_32_types.h
17972 @@ -8,7 +8,7 @@
17973 */
17974 #ifdef CONFIG_X86_PAE
17975 # include <asm/pgtable-3level_types.h>
17976 -# define PMD_SIZE (1UL << PMD_SHIFT)
17977 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
17978 # define PMD_MASK (~(PMD_SIZE - 1))
17979 #else
17980 # include <asm/pgtable-2level_types.h>
17981 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
17982 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
17983 #endif
17984
17985 +#ifdef CONFIG_PAX_KERNEXEC
17986 +#ifndef __ASSEMBLY__
17987 +extern unsigned char MODULES_EXEC_VADDR[];
17988 +extern unsigned char MODULES_EXEC_END[];
17989 +#endif
17990 +#include <asm/boot.h>
17991 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
17992 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
17993 +#else
17994 +#define ktla_ktva(addr) (addr)
17995 +#define ktva_ktla(addr) (addr)
17996 +#endif
17997 +
17998 #define MODULES_VADDR VMALLOC_START
17999 #define MODULES_END VMALLOC_END
18000 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
18001 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
18002 index e22c1db..23a625a 100644
18003 --- a/arch/x86/include/asm/pgtable_64.h
18004 +++ b/arch/x86/include/asm/pgtable_64.h
18005 @@ -16,10 +16,14 @@
18006
18007 extern pud_t level3_kernel_pgt[512];
18008 extern pud_t level3_ident_pgt[512];
18009 +extern pud_t level3_vmalloc_start_pgt[512];
18010 +extern pud_t level3_vmalloc_end_pgt[512];
18011 +extern pud_t level3_vmemmap_pgt[512];
18012 +extern pud_t level2_vmemmap_pgt[512];
18013 extern pmd_t level2_kernel_pgt[512];
18014 extern pmd_t level2_fixmap_pgt[512];
18015 -extern pmd_t level2_ident_pgt[512];
18016 -extern pgd_t init_level4_pgt[];
18017 +extern pmd_t level2_ident_pgt[512*2];
18018 +extern pgd_t init_level4_pgt[512];
18019
18020 #define swapper_pg_dir init_level4_pgt
18021
18022 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18023
18024 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18025 {
18026 + pax_open_kernel();
18027 *pmdp = pmd;
18028 + pax_close_kernel();
18029 }
18030
18031 static inline void native_pmd_clear(pmd_t *pmd)
18032 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
18033
18034 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18035 {
18036 + pax_open_kernel();
18037 *pudp = pud;
18038 + pax_close_kernel();
18039 }
18040
18041 static inline void native_pud_clear(pud_t *pud)
18042 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
18043
18044 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
18045 {
18046 + pax_open_kernel();
18047 + *pgdp = pgd;
18048 + pax_close_kernel();
18049 +}
18050 +
18051 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
18052 +{
18053 *pgdp = pgd;
18054 }
18055
18056 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
18057 index 7166e25..baaa6fe 100644
18058 --- a/arch/x86/include/asm/pgtable_64_types.h
18059 +++ b/arch/x86/include/asm/pgtable_64_types.h
18060 @@ -61,9 +61,14 @@ typedef struct { pteval_t pte; } pte_t;
18061 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
18062 #define MODULES_END _AC(0xffffffffff000000, UL)
18063 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
18064 +#define MODULES_EXEC_VADDR MODULES_VADDR
18065 +#define MODULES_EXEC_END MODULES_END
18066 #define ESPFIX_PGD_ENTRY _AC(-2, UL)
18067 #define ESPFIX_BASE_ADDR (ESPFIX_PGD_ENTRY << PGDIR_SHIFT)
18068
18069 +#define ktla_ktva(addr) (addr)
18070 +#define ktva_ktla(addr) (addr)
18071 +
18072 #define EARLY_DYNAMIC_PAGE_TABLES 64
18073
18074 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
18075 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
18076 index eb3d449..8d95316 100644
18077 --- a/arch/x86/include/asm/pgtable_types.h
18078 +++ b/arch/x86/include/asm/pgtable_types.h
18079 @@ -16,13 +16,12 @@
18080 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
18081 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
18082 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
18083 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
18084 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
18085 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
18086 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
18087 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
18088 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
18089 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
18090 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
18091 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
18092 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
18093 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
18094
18095 /* If _PAGE_BIT_PRESENT is clear, we use these: */
18096 @@ -40,7 +39,6 @@
18097 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
18098 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
18099 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
18100 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
18101 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
18102 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
18103 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
18104 @@ -87,8 +85,10 @@
18105
18106 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
18107 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
18108 -#else
18109 +#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
18110 #define _PAGE_NX (_AT(pteval_t, 0))
18111 +#else
18112 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
18113 #endif
18114
18115 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
18116 @@ -147,6 +147,9 @@
18117 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
18118 _PAGE_ACCESSED)
18119
18120 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
18121 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
18122 +
18123 #define __PAGE_KERNEL_EXEC \
18124 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
18125 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
18126 @@ -157,7 +160,7 @@
18127 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
18128 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
18129 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
18130 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
18131 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
18132 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
18133 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
18134 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
18135 @@ -214,7 +217,7 @@
18136 #ifdef CONFIG_X86_64
18137 #define __PAGE_KERNEL_IDENT_LARGE_EXEC __PAGE_KERNEL_LARGE_EXEC
18138 #else
18139 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
18140 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18141 #define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18142 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
18143 #endif
18144 @@ -253,7 +256,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
18145 {
18146 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
18147 }
18148 +#endif
18149
18150 +#if PAGETABLE_LEVELS == 3
18151 +#include <asm-generic/pgtable-nopud.h>
18152 +#endif
18153 +
18154 +#if PAGETABLE_LEVELS == 2
18155 +#include <asm-generic/pgtable-nopmd.h>
18156 +#endif
18157 +
18158 +#ifndef __ASSEMBLY__
18159 #if PAGETABLE_LEVELS > 3
18160 typedef struct { pudval_t pud; } pud_t;
18161
18162 @@ -267,8 +280,6 @@ static inline pudval_t native_pud_val(pud_t pud)
18163 return pud.pud;
18164 }
18165 #else
18166 -#include <asm-generic/pgtable-nopud.h>
18167 -
18168 static inline pudval_t native_pud_val(pud_t pud)
18169 {
18170 return native_pgd_val(pud.pgd);
18171 @@ -288,8 +299,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
18172 return pmd.pmd;
18173 }
18174 #else
18175 -#include <asm-generic/pgtable-nopmd.h>
18176 -
18177 static inline pmdval_t native_pmd_val(pmd_t pmd)
18178 {
18179 return native_pgd_val(pmd.pud.pgd);
18180 @@ -329,7 +338,6 @@ typedef struct page *pgtable_t;
18181
18182 extern pteval_t __supported_pte_mask;
18183 extern void set_nx(void);
18184 -extern int nx_enabled;
18185
18186 #define pgprot_writecombine pgprot_writecombine
18187 extern pgprot_t pgprot_writecombine(pgprot_t prot);
18188 diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
18189 index 7024c12..71c46b9 100644
18190 --- a/arch/x86/include/asm/preempt.h
18191 +++ b/arch/x86/include/asm/preempt.h
18192 @@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
18193 */
18194 static __always_inline bool __preempt_count_dec_and_test(void)
18195 {
18196 - GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
18197 + GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
18198 }
18199
18200 /*
18201 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
18202 index a4ea023..33aa874 100644
18203 --- a/arch/x86/include/asm/processor.h
18204 +++ b/arch/x86/include/asm/processor.h
18205 @@ -128,7 +128,7 @@ struct cpuinfo_x86 {
18206 /* Index into per_cpu list: */
18207 u16 cpu_index;
18208 u32 microcode;
18209 -} __attribute__((__aligned__(SMP_CACHE_BYTES)));
18210 +} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
18211
18212 #define X86_VENDOR_INTEL 0
18213 #define X86_VENDOR_CYRIX 1
18214 @@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
18215 : "memory");
18216 }
18217
18218 +/* invpcid (%rdx),%rax */
18219 +#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
18220 +
18221 +#define INVPCID_SINGLE_ADDRESS 0UL
18222 +#define INVPCID_SINGLE_CONTEXT 1UL
18223 +#define INVPCID_ALL_GLOBAL 2UL
18224 +#define INVPCID_ALL_MONGLOBAL 3UL
18225 +
18226 +#define PCID_KERNEL 0UL
18227 +#define PCID_USER 1UL
18228 +#define PCID_NOFLUSH (1UL << 63)
18229 +
18230 static inline void load_cr3(pgd_t *pgdir)
18231 {
18232 - write_cr3(__pa(pgdir));
18233 + write_cr3(__pa(pgdir) | PCID_KERNEL);
18234 }
18235
18236 #ifdef CONFIG_X86_32
18237 @@ -283,7 +295,7 @@ struct tss_struct {
18238
18239 } ____cacheline_aligned;
18240
18241 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
18242 +extern struct tss_struct init_tss[NR_CPUS];
18243
18244 /*
18245 * Save the original ist values for checking stack pointers during debugging
18246 @@ -479,6 +491,7 @@ struct thread_struct {
18247 unsigned short ds;
18248 unsigned short fsindex;
18249 unsigned short gsindex;
18250 + unsigned short ss;
18251 #endif
18252 #ifdef CONFIG_X86_32
18253 unsigned long ip;
18254 @@ -588,29 +601,8 @@ static inline void load_sp0(struct tss_struct *tss,
18255 extern unsigned long mmu_cr4_features;
18256 extern u32 *trampoline_cr4_features;
18257
18258 -static inline void set_in_cr4(unsigned long mask)
18259 -{
18260 - unsigned long cr4;
18261 -
18262 - mmu_cr4_features |= mask;
18263 - if (trampoline_cr4_features)
18264 - *trampoline_cr4_features = mmu_cr4_features;
18265 - cr4 = read_cr4();
18266 - cr4 |= mask;
18267 - write_cr4(cr4);
18268 -}
18269 -
18270 -static inline void clear_in_cr4(unsigned long mask)
18271 -{
18272 - unsigned long cr4;
18273 -
18274 - mmu_cr4_features &= ~mask;
18275 - if (trampoline_cr4_features)
18276 - *trampoline_cr4_features = mmu_cr4_features;
18277 - cr4 = read_cr4();
18278 - cr4 &= ~mask;
18279 - write_cr4(cr4);
18280 -}
18281 +extern void set_in_cr4(unsigned long mask);
18282 +extern void clear_in_cr4(unsigned long mask);
18283
18284 typedef struct {
18285 unsigned long seg;
18286 @@ -836,11 +828,18 @@ static inline void spin_lock_prefetch(const void *x)
18287 */
18288 #define TASK_SIZE PAGE_OFFSET
18289 #define TASK_SIZE_MAX TASK_SIZE
18290 +
18291 +#ifdef CONFIG_PAX_SEGMEXEC
18292 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18293 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18294 +#else
18295 #define STACK_TOP TASK_SIZE
18296 -#define STACK_TOP_MAX STACK_TOP
18297 +#endif
18298 +
18299 +#define STACK_TOP_MAX TASK_SIZE
18300
18301 #define INIT_THREAD { \
18302 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18303 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18304 .vm86_info = NULL, \
18305 .sysenter_cs = __KERNEL_CS, \
18306 .io_bitmap_ptr = NULL, \
18307 @@ -854,7 +853,7 @@ static inline void spin_lock_prefetch(const void *x)
18308 */
18309 #define INIT_TSS { \
18310 .x86_tss = { \
18311 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18312 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18313 .ss0 = __KERNEL_DS, \
18314 .ss1 = __KERNEL_CS, \
18315 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18316 @@ -865,11 +864,7 @@ static inline void spin_lock_prefetch(const void *x)
18317 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18318
18319 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18320 -#define KSTK_TOP(info) \
18321 -({ \
18322 - unsigned long *__ptr = (unsigned long *)(info); \
18323 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18324 -})
18325 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18326
18327 /*
18328 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18329 @@ -884,7 +879,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18330 #define task_pt_regs(task) \
18331 ({ \
18332 struct pt_regs *__regs__; \
18333 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18334 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18335 __regs__ - 1; \
18336 })
18337
18338 @@ -894,13 +889,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18339 /*
18340 * User space process size. 47bits minus one guard page.
18341 */
18342 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18343 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18344
18345 /* This decides where the kernel will search for a free chunk of vm
18346 * space during mmap's.
18347 */
18348 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18349 - 0xc0000000 : 0xFFFFe000)
18350 + 0xc0000000 : 0xFFFFf000)
18351
18352 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18353 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18354 @@ -911,11 +906,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18355 #define STACK_TOP_MAX TASK_SIZE_MAX
18356
18357 #define INIT_THREAD { \
18358 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18359 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18360 }
18361
18362 #define INIT_TSS { \
18363 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18364 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18365 }
18366
18367 /*
18368 @@ -943,6 +938,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18369 */
18370 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18371
18372 +#ifdef CONFIG_PAX_SEGMEXEC
18373 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18374 +#endif
18375 +
18376 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18377
18378 /* Get/set a process' ability to use the timestamp counter instruction */
18379 @@ -969,7 +968,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18380 return 0;
18381 }
18382
18383 -extern unsigned long arch_align_stack(unsigned long sp);
18384 +#define arch_align_stack(x) ((x) & ~0xfUL)
18385 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18386
18387 void default_idle(void);
18388 @@ -979,6 +978,6 @@ bool xen_set_default_idle(void);
18389 #define xen_set_default_idle 0
18390 #endif
18391
18392 -void stop_this_cpu(void *dummy);
18393 +void stop_this_cpu(void *dummy) __noreturn;
18394 void df_debug(struct pt_regs *regs, long error_code);
18395 #endif /* _ASM_X86_PROCESSOR_H */
18396 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18397 index 6205f0c..688a3a9 100644
18398 --- a/arch/x86/include/asm/ptrace.h
18399 +++ b/arch/x86/include/asm/ptrace.h
18400 @@ -84,28 +84,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18401 }
18402
18403 /*
18404 - * user_mode_vm(regs) determines whether a register set came from user mode.
18405 + * user_mode(regs) determines whether a register set came from user mode.
18406 * This is true if V8086 mode was enabled OR if the register set was from
18407 * protected mode with RPL-3 CS value. This tricky test checks that with
18408 * one comparison. Many places in the kernel can bypass this full check
18409 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18410 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18411 + * be used.
18412 */
18413 -static inline int user_mode(struct pt_regs *regs)
18414 +static inline int user_mode_novm(struct pt_regs *regs)
18415 {
18416 #ifdef CONFIG_X86_32
18417 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18418 #else
18419 - return !!(regs->cs & 3);
18420 + return !!(regs->cs & SEGMENT_RPL_MASK);
18421 #endif
18422 }
18423
18424 -static inline int user_mode_vm(struct pt_regs *regs)
18425 +static inline int user_mode(struct pt_regs *regs)
18426 {
18427 #ifdef CONFIG_X86_32
18428 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18429 USER_RPL;
18430 #else
18431 - return user_mode(regs);
18432 + return user_mode_novm(regs);
18433 #endif
18434 }
18435
18436 @@ -121,15 +122,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18437 #ifdef CONFIG_X86_64
18438 static inline bool user_64bit_mode(struct pt_regs *regs)
18439 {
18440 + unsigned long cs = regs->cs & 0xffff;
18441 #ifndef CONFIG_PARAVIRT
18442 /*
18443 * On non-paravirt systems, this is the only long mode CPL 3
18444 * selector. We do not allow long mode selectors in the LDT.
18445 */
18446 - return regs->cs == __USER_CS;
18447 + return cs == __USER_CS;
18448 #else
18449 /* Headers are too twisted for this to go in paravirt.h. */
18450 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18451 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18452 #endif
18453 }
18454
18455 @@ -180,9 +182,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18456 * Traps from the kernel do not save sp and ss.
18457 * Use the helper function to retrieve sp.
18458 */
18459 - if (offset == offsetof(struct pt_regs, sp) &&
18460 - regs->cs == __KERNEL_CS)
18461 - return kernel_stack_pointer(regs);
18462 + if (offset == offsetof(struct pt_regs, sp)) {
18463 + unsigned long cs = regs->cs & 0xffff;
18464 + if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18465 + return kernel_stack_pointer(regs);
18466 + }
18467 #endif
18468 return *(unsigned long *)((unsigned long)regs + offset);
18469 }
18470 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18471 index 9c6b890..5305f53 100644
18472 --- a/arch/x86/include/asm/realmode.h
18473 +++ b/arch/x86/include/asm/realmode.h
18474 @@ -22,16 +22,14 @@ struct real_mode_header {
18475 #endif
18476 /* APM/BIOS reboot */
18477 u32 machine_real_restart_asm;
18478 -#ifdef CONFIG_X86_64
18479 u32 machine_real_restart_seg;
18480 -#endif
18481 };
18482
18483 /* This must match data at trampoline_32/64.S */
18484 struct trampoline_header {
18485 #ifdef CONFIG_X86_32
18486 u32 start;
18487 - u16 gdt_pad;
18488 + u16 boot_cs;
18489 u16 gdt_limit;
18490 u32 gdt_base;
18491 #else
18492 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18493 index a82c4f1..ac45053 100644
18494 --- a/arch/x86/include/asm/reboot.h
18495 +++ b/arch/x86/include/asm/reboot.h
18496 @@ -6,13 +6,13 @@
18497 struct pt_regs;
18498
18499 struct machine_ops {
18500 - void (*restart)(char *cmd);
18501 - void (*halt)(void);
18502 - void (*power_off)(void);
18503 + void (* __noreturn restart)(char *cmd);
18504 + void (* __noreturn halt)(void);
18505 + void (* __noreturn power_off)(void);
18506 void (*shutdown)(void);
18507 void (*crash_shutdown)(struct pt_regs *);
18508 - void (*emergency_restart)(void);
18509 -};
18510 + void (* __noreturn emergency_restart)(void);
18511 +} __no_const;
18512
18513 extern struct machine_ops machine_ops;
18514
18515 diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18516 index 8f7866a..e442f20 100644
18517 --- a/arch/x86/include/asm/rmwcc.h
18518 +++ b/arch/x86/include/asm/rmwcc.h
18519 @@ -3,7 +3,34 @@
18520
18521 #ifdef CC_HAVE_ASM_GOTO
18522
18523 -#define __GEN_RMWcc(fullop, var, cc, ...) \
18524 +#ifdef CONFIG_PAX_REFCOUNT
18525 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18526 +do { \
18527 + asm_volatile_goto (fullop \
18528 + ";jno 0f\n" \
18529 + fullantiop \
18530 + ";int $4\n0:\n" \
18531 + _ASM_EXTABLE(0b, 0b) \
18532 + ";j" cc " %l[cc_label]" \
18533 + : : "m" (var), ## __VA_ARGS__ \
18534 + : "memory" : cc_label); \
18535 + return 0; \
18536 +cc_label: \
18537 + return 1; \
18538 +} while (0)
18539 +#else
18540 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18541 +do { \
18542 + asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
18543 + : : "m" (var), ## __VA_ARGS__ \
18544 + : "memory" : cc_label); \
18545 + return 0; \
18546 +cc_label: \
18547 + return 1; \
18548 +} while (0)
18549 +#endif
18550 +
18551 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18552 do { \
18553 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
18554 : : "m" (var), ## __VA_ARGS__ \
18555 @@ -13,15 +40,46 @@ cc_label: \
18556 return 1; \
18557 } while (0)
18558
18559 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18560 - __GEN_RMWcc(op " " arg0, var, cc)
18561 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18562 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18563
18564 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18565 - __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
18566 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18567 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18568 +
18569 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18570 + __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
18571 +
18572 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18573 + __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
18574
18575 #else /* !CC_HAVE_ASM_GOTO */
18576
18577 -#define __GEN_RMWcc(fullop, var, cc, ...) \
18578 +#ifdef CONFIG_PAX_REFCOUNT
18579 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18580 +do { \
18581 + char c; \
18582 + asm volatile (fullop \
18583 + ";jno 0f\n" \
18584 + fullantiop \
18585 + ";int $4\n0:\n" \
18586 + _ASM_EXTABLE(0b, 0b) \
18587 + "; set" cc " %1" \
18588 + : "+m" (var), "=qm" (c) \
18589 + : __VA_ARGS__ : "memory"); \
18590 + return c != 0; \
18591 +} while (0)
18592 +#else
18593 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18594 +do { \
18595 + char c; \
18596 + asm volatile (fullop "; set" cc " %1" \
18597 + : "+m" (var), "=qm" (c) \
18598 + : __VA_ARGS__ : "memory"); \
18599 + return c != 0; \
18600 +} while (0)
18601 +#endif
18602 +
18603 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18604 do { \
18605 char c; \
18606 asm volatile (fullop "; set" cc " %1" \
18607 @@ -30,11 +88,17 @@ do { \
18608 return c != 0; \
18609 } while (0)
18610
18611 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18612 - __GEN_RMWcc(op " " arg0, var, cc)
18613 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18614 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18615 +
18616 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18617 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18618 +
18619 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18620 + __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
18621
18622 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18623 - __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
18624 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18625 + __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
18626
18627 #endif /* CC_HAVE_ASM_GOTO */
18628
18629 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
18630 index cad82c9..2e5c5c1 100644
18631 --- a/arch/x86/include/asm/rwsem.h
18632 +++ b/arch/x86/include/asm/rwsem.h
18633 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
18634 {
18635 asm volatile("# beginning down_read\n\t"
18636 LOCK_PREFIX _ASM_INC "(%1)\n\t"
18637 +
18638 +#ifdef CONFIG_PAX_REFCOUNT
18639 + "jno 0f\n"
18640 + LOCK_PREFIX _ASM_DEC "(%1)\n"
18641 + "int $4\n0:\n"
18642 + _ASM_EXTABLE(0b, 0b)
18643 +#endif
18644 +
18645 /* adds 0x00000001 */
18646 " jns 1f\n"
18647 " call call_rwsem_down_read_failed\n"
18648 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
18649 "1:\n\t"
18650 " mov %1,%2\n\t"
18651 " add %3,%2\n\t"
18652 +
18653 +#ifdef CONFIG_PAX_REFCOUNT
18654 + "jno 0f\n"
18655 + "sub %3,%2\n"
18656 + "int $4\n0:\n"
18657 + _ASM_EXTABLE(0b, 0b)
18658 +#endif
18659 +
18660 " jle 2f\n\t"
18661 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18662 " jnz 1b\n\t"
18663 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18664 long tmp;
18665 asm volatile("# beginning down_write\n\t"
18666 LOCK_PREFIX " xadd %1,(%2)\n\t"
18667 +
18668 +#ifdef CONFIG_PAX_REFCOUNT
18669 + "jno 0f\n"
18670 + "mov %1,(%2)\n"
18671 + "int $4\n0:\n"
18672 + _ASM_EXTABLE(0b, 0b)
18673 +#endif
18674 +
18675 /* adds 0xffff0001, returns the old value */
18676 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18677 /* was the active mask 0 before? */
18678 @@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18679 long tmp;
18680 asm volatile("# beginning __up_read\n\t"
18681 LOCK_PREFIX " xadd %1,(%2)\n\t"
18682 +
18683 +#ifdef CONFIG_PAX_REFCOUNT
18684 + "jno 0f\n"
18685 + "mov %1,(%2)\n"
18686 + "int $4\n0:\n"
18687 + _ASM_EXTABLE(0b, 0b)
18688 +#endif
18689 +
18690 /* subtracts 1, returns the old value */
18691 " jns 1f\n\t"
18692 " call call_rwsem_wake\n" /* expects old value in %edx */
18693 @@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
18694 long tmp;
18695 asm volatile("# beginning __up_write\n\t"
18696 LOCK_PREFIX " xadd %1,(%2)\n\t"
18697 +
18698 +#ifdef CONFIG_PAX_REFCOUNT
18699 + "jno 0f\n"
18700 + "mov %1,(%2)\n"
18701 + "int $4\n0:\n"
18702 + _ASM_EXTABLE(0b, 0b)
18703 +#endif
18704 +
18705 /* subtracts 0xffff0001, returns the old value */
18706 " jns 1f\n\t"
18707 " call call_rwsem_wake\n" /* expects old value in %edx */
18708 @@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18709 {
18710 asm volatile("# beginning __downgrade_write\n\t"
18711 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
18712 +
18713 +#ifdef CONFIG_PAX_REFCOUNT
18714 + "jno 0f\n"
18715 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
18716 + "int $4\n0:\n"
18717 + _ASM_EXTABLE(0b, 0b)
18718 +#endif
18719 +
18720 /*
18721 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
18722 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
18723 @@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18724 */
18725 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18726 {
18727 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
18728 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
18729 +
18730 +#ifdef CONFIG_PAX_REFCOUNT
18731 + "jno 0f\n"
18732 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
18733 + "int $4\n0:\n"
18734 + _ASM_EXTABLE(0b, 0b)
18735 +#endif
18736 +
18737 : "+m" (sem->count)
18738 : "er" (delta));
18739 }
18740 @@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18741 */
18742 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
18743 {
18744 - return delta + xadd(&sem->count, delta);
18745 + return delta + xadd_check_overflow(&sem->count, delta);
18746 }
18747
18748 #endif /* __KERNEL__ */
18749 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
18750 index 6f1c3a8..7744f19 100644
18751 --- a/arch/x86/include/asm/segment.h
18752 +++ b/arch/x86/include/asm/segment.h
18753 @@ -64,10 +64,15 @@
18754 * 26 - ESPFIX small SS
18755 * 27 - per-cpu [ offset to per-cpu data area ]
18756 * 28 - stack_canary-20 [ for stack protector ]
18757 - * 29 - unused
18758 - * 30 - unused
18759 + * 29 - PCI BIOS CS
18760 + * 30 - PCI BIOS DS
18761 * 31 - TSS for double fault handler
18762 */
18763 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
18764 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
18765 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
18766 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
18767 +
18768 #define GDT_ENTRY_TLS_MIN 6
18769 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
18770
18771 @@ -79,6 +84,8 @@
18772
18773 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
18774
18775 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
18776 +
18777 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
18778
18779 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
18780 @@ -104,6 +111,12 @@
18781 #define __KERNEL_STACK_CANARY 0
18782 #endif
18783
18784 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
18785 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
18786 +
18787 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
18788 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
18789 +
18790 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
18791
18792 /*
18793 @@ -141,7 +154,7 @@
18794 */
18795
18796 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
18797 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
18798 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
18799
18800
18801 #else
18802 @@ -165,6 +178,8 @@
18803 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
18804 #define __USER32_DS __USER_DS
18805
18806 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
18807 +
18808 #define GDT_ENTRY_TSS 8 /* needs two entries */
18809 #define GDT_ENTRY_LDT 10 /* needs two entries */
18810 #define GDT_ENTRY_TLS_MIN 12
18811 @@ -173,6 +188,8 @@
18812 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
18813 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
18814
18815 +#define GDT_ENTRY_UDEREF_KERNEL_DS 16
18816 +
18817 /* TLS indexes for 64bit - hardcoded in arch_prctl */
18818 #define FS_TLS 0
18819 #define GS_TLS 1
18820 @@ -180,12 +197,14 @@
18821 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
18822 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
18823
18824 -#define GDT_ENTRIES 16
18825 +#define GDT_ENTRIES 17
18826
18827 #endif
18828
18829 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
18830 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
18831 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
18832 +#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
18833 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
18834 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
18835 #ifndef CONFIG_PARAVIRT
18836 @@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
18837 {
18838 unsigned long __limit;
18839 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
18840 - return __limit + 1;
18841 + return __limit;
18842 }
18843
18844 #endif /* !__ASSEMBLY__ */
18845 diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
18846 index 8d3120f..352b440 100644
18847 --- a/arch/x86/include/asm/smap.h
18848 +++ b/arch/x86/include/asm/smap.h
18849 @@ -25,11 +25,40 @@
18850
18851 #include <asm/alternative-asm.h>
18852
18853 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18854 +#define ASM_PAX_OPEN_USERLAND \
18855 + 661: jmp 663f; \
18856 + .pushsection .altinstr_replacement, "a" ; \
18857 + 662: pushq %rax; nop; \
18858 + .popsection ; \
18859 + .pushsection .altinstructions, "a" ; \
18860 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18861 + .popsection ; \
18862 + call __pax_open_userland; \
18863 + popq %rax; \
18864 + 663:
18865 +
18866 +#define ASM_PAX_CLOSE_USERLAND \
18867 + 661: jmp 663f; \
18868 + .pushsection .altinstr_replacement, "a" ; \
18869 + 662: pushq %rax; nop; \
18870 + .popsection; \
18871 + .pushsection .altinstructions, "a" ; \
18872 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18873 + .popsection; \
18874 + call __pax_close_userland; \
18875 + popq %rax; \
18876 + 663:
18877 +#else
18878 +#define ASM_PAX_OPEN_USERLAND
18879 +#define ASM_PAX_CLOSE_USERLAND
18880 +#endif
18881 +
18882 #ifdef CONFIG_X86_SMAP
18883
18884 #define ASM_CLAC \
18885 661: ASM_NOP3 ; \
18886 - .pushsection .altinstr_replacement, "ax" ; \
18887 + .pushsection .altinstr_replacement, "a" ; \
18888 662: __ASM_CLAC ; \
18889 .popsection ; \
18890 .pushsection .altinstructions, "a" ; \
18891 @@ -38,7 +67,7 @@
18892
18893 #define ASM_STAC \
18894 661: ASM_NOP3 ; \
18895 - .pushsection .altinstr_replacement, "ax" ; \
18896 + .pushsection .altinstr_replacement, "a" ; \
18897 662: __ASM_STAC ; \
18898 .popsection ; \
18899 .pushsection .altinstructions, "a" ; \
18900 @@ -56,6 +85,37 @@
18901
18902 #include <asm/alternative.h>
18903
18904 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
18905 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
18906 +
18907 +extern void __pax_open_userland(void);
18908 +static __always_inline unsigned long pax_open_userland(void)
18909 +{
18910 +
18911 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18912 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
18913 + :
18914 + : [open] "i" (__pax_open_userland)
18915 + : "memory", "rax");
18916 +#endif
18917 +
18918 + return 0;
18919 +}
18920 +
18921 +extern void __pax_close_userland(void);
18922 +static __always_inline unsigned long pax_close_userland(void)
18923 +{
18924 +
18925 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18926 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
18927 + :
18928 + : [close] "i" (__pax_close_userland)
18929 + : "memory", "rax");
18930 +#endif
18931 +
18932 + return 0;
18933 +}
18934 +
18935 #ifdef CONFIG_X86_SMAP
18936
18937 static __always_inline void clac(void)
18938 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
18939 index 8cd27e0..7f05ec8 100644
18940 --- a/arch/x86/include/asm/smp.h
18941 +++ b/arch/x86/include/asm/smp.h
18942 @@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
18943 /* cpus sharing the last level cache: */
18944 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
18945 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
18946 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
18947 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
18948
18949 static inline struct cpumask *cpu_sibling_mask(int cpu)
18950 {
18951 @@ -78,7 +78,7 @@ struct smp_ops {
18952
18953 void (*send_call_func_ipi)(const struct cpumask *mask);
18954 void (*send_call_func_single_ipi)(int cpu);
18955 -};
18956 +} __no_const;
18957
18958 /* Globals due to paravirt */
18959 extern void set_cpu_sibling_map(int cpu);
18960 @@ -190,14 +190,8 @@ extern unsigned disabled_cpus;
18961 extern int safe_smp_processor_id(void);
18962
18963 #elif defined(CONFIG_X86_64_SMP)
18964 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18965 -
18966 -#define stack_smp_processor_id() \
18967 -({ \
18968 - struct thread_info *ti; \
18969 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
18970 - ti->cpu; \
18971 -})
18972 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18973 +#define stack_smp_processor_id() raw_smp_processor_id()
18974 #define safe_smp_processor_id() smp_processor_id()
18975
18976 #endif
18977 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
18978 index 0f62f54..cb5d0dd 100644
18979 --- a/arch/x86/include/asm/spinlock.h
18980 +++ b/arch/x86/include/asm/spinlock.h
18981 @@ -222,6 +222,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
18982 static inline void arch_read_lock(arch_rwlock_t *rw)
18983 {
18984 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
18985 +
18986 +#ifdef CONFIG_PAX_REFCOUNT
18987 + "jno 0f\n"
18988 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
18989 + "int $4\n0:\n"
18990 + _ASM_EXTABLE(0b, 0b)
18991 +#endif
18992 +
18993 "jns 1f\n"
18994 "call __read_lock_failed\n\t"
18995 "1:\n"
18996 @@ -231,6 +239,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
18997 static inline void arch_write_lock(arch_rwlock_t *rw)
18998 {
18999 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
19000 +
19001 +#ifdef CONFIG_PAX_REFCOUNT
19002 + "jno 0f\n"
19003 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
19004 + "int $4\n0:\n"
19005 + _ASM_EXTABLE(0b, 0b)
19006 +#endif
19007 +
19008 "jz 1f\n"
19009 "call __write_lock_failed\n\t"
19010 "1:\n"
19011 @@ -260,13 +276,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
19012
19013 static inline void arch_read_unlock(arch_rwlock_t *rw)
19014 {
19015 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
19016 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
19017 +
19018 +#ifdef CONFIG_PAX_REFCOUNT
19019 + "jno 0f\n"
19020 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
19021 + "int $4\n0:\n"
19022 + _ASM_EXTABLE(0b, 0b)
19023 +#endif
19024 +
19025 :"+m" (rw->lock) : : "memory");
19026 }
19027
19028 static inline void arch_write_unlock(arch_rwlock_t *rw)
19029 {
19030 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
19031 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
19032 +
19033 +#ifdef CONFIG_PAX_REFCOUNT
19034 + "jno 0f\n"
19035 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
19036 + "int $4\n0:\n"
19037 + _ASM_EXTABLE(0b, 0b)
19038 +#endif
19039 +
19040 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
19041 }
19042
19043 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
19044 index 6a99859..03cb807 100644
19045 --- a/arch/x86/include/asm/stackprotector.h
19046 +++ b/arch/x86/include/asm/stackprotector.h
19047 @@ -47,7 +47,7 @@
19048 * head_32 for boot CPU and setup_per_cpu_areas() for others.
19049 */
19050 #define GDT_STACK_CANARY_INIT \
19051 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
19052 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
19053
19054 /*
19055 * Initialize the stackprotector canary value.
19056 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
19057
19058 static inline void load_stack_canary_segment(void)
19059 {
19060 -#ifdef CONFIG_X86_32
19061 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19062 asm volatile ("mov %0, %%gs" : : "r" (0));
19063 #endif
19064 }
19065 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
19066 index 70bbe39..4ae2bd4 100644
19067 --- a/arch/x86/include/asm/stacktrace.h
19068 +++ b/arch/x86/include/asm/stacktrace.h
19069 @@ -11,28 +11,20 @@
19070
19071 extern int kstack_depth_to_print;
19072
19073 -struct thread_info;
19074 +struct task_struct;
19075 struct stacktrace_ops;
19076
19077 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
19078 - unsigned long *stack,
19079 - unsigned long bp,
19080 - const struct stacktrace_ops *ops,
19081 - void *data,
19082 - unsigned long *end,
19083 - int *graph);
19084 +typedef unsigned long walk_stack_t(struct task_struct *task,
19085 + void *stack_start,
19086 + unsigned long *stack,
19087 + unsigned long bp,
19088 + const struct stacktrace_ops *ops,
19089 + void *data,
19090 + unsigned long *end,
19091 + int *graph);
19092
19093 -extern unsigned long
19094 -print_context_stack(struct thread_info *tinfo,
19095 - unsigned long *stack, unsigned long bp,
19096 - const struct stacktrace_ops *ops, void *data,
19097 - unsigned long *end, int *graph);
19098 -
19099 -extern unsigned long
19100 -print_context_stack_bp(struct thread_info *tinfo,
19101 - unsigned long *stack, unsigned long bp,
19102 - const struct stacktrace_ops *ops, void *data,
19103 - unsigned long *end, int *graph);
19104 +extern walk_stack_t print_context_stack;
19105 +extern walk_stack_t print_context_stack_bp;
19106
19107 /* Generic stack tracer with callbacks */
19108
19109 @@ -40,7 +32,7 @@ struct stacktrace_ops {
19110 void (*address)(void *data, unsigned long address, int reliable);
19111 /* On negative return stop dumping */
19112 int (*stack)(void *data, char *name);
19113 - walk_stack_t walk_stack;
19114 + walk_stack_t *walk_stack;
19115 };
19116
19117 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
19118 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
19119 index d7f3b3b..3cc39f1 100644
19120 --- a/arch/x86/include/asm/switch_to.h
19121 +++ b/arch/x86/include/asm/switch_to.h
19122 @@ -108,7 +108,7 @@ do { \
19123 "call __switch_to\n\t" \
19124 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
19125 __switch_canary \
19126 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
19127 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
19128 "movq %%rax,%%rdi\n\t" \
19129 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
19130 "jnz ret_from_fork\n\t" \
19131 @@ -119,7 +119,7 @@ do { \
19132 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
19133 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
19134 [_tif_fork] "i" (_TIF_FORK), \
19135 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
19136 + [thread_info] "m" (current_tinfo), \
19137 [current_task] "m" (current_task) \
19138 __switch_canary_iparam \
19139 : "memory", "cc" __EXTRA_CLOBBER)
19140 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
19141 index 47e5de2..d3dda54 100644
19142 --- a/arch/x86/include/asm/thread_info.h
19143 +++ b/arch/x86/include/asm/thread_info.h
19144 @@ -24,7 +24,6 @@ struct exec_domain;
19145 #include <linux/atomic.h>
19146
19147 struct thread_info {
19148 - struct task_struct *task; /* main task structure */
19149 struct exec_domain *exec_domain; /* execution domain */
19150 __u32 flags; /* low level flags */
19151 __u32 status; /* thread synchronous flags */
19152 @@ -33,13 +32,13 @@ struct thread_info {
19153 mm_segment_t addr_limit;
19154 struct restart_block restart_block;
19155 void __user *sysenter_return;
19156 + unsigned long lowest_stack;
19157 unsigned int sig_on_uaccess_error:1;
19158 unsigned int uaccess_err:1; /* uaccess failed */
19159 };
19160
19161 -#define INIT_THREAD_INFO(tsk) \
19162 +#define INIT_THREAD_INFO \
19163 { \
19164 - .task = &tsk, \
19165 .exec_domain = &default_exec_domain, \
19166 .flags = 0, \
19167 .cpu = 0, \
19168 @@ -50,7 +49,7 @@ struct thread_info {
19169 }, \
19170 }
19171
19172 -#define init_thread_info (init_thread_union.thread_info)
19173 +#define init_thread_info (init_thread_union.stack)
19174 #define init_stack (init_thread_union.stack)
19175
19176 #else /* !__ASSEMBLY__ */
19177 @@ -90,6 +89,7 @@ struct thread_info {
19178 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
19179 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
19180 #define TIF_X32 30 /* 32-bit native x86-64 binary */
19181 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
19182
19183 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
19184 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
19185 @@ -113,17 +113,18 @@ struct thread_info {
19186 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
19187 #define _TIF_ADDR32 (1 << TIF_ADDR32)
19188 #define _TIF_X32 (1 << TIF_X32)
19189 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
19190
19191 /* work to do in syscall_trace_enter() */
19192 #define _TIF_WORK_SYSCALL_ENTRY \
19193 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
19194 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
19195 - _TIF_NOHZ)
19196 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
19197
19198 /* work to do in syscall_trace_leave() */
19199 #define _TIF_WORK_SYSCALL_EXIT \
19200 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
19201 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
19202 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
19203
19204 /* work to do on interrupt/exception return */
19205 #define _TIF_WORK_MASK \
19206 @@ -134,7 +135,7 @@ struct thread_info {
19207 /* work to do on any return to user space */
19208 #define _TIF_ALLWORK_MASK \
19209 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
19210 - _TIF_NOHZ)
19211 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
19212
19213 /* Only used for 64 bit */
19214 #define _TIF_DO_NOTIFY_MASK \
19215 @@ -149,7 +150,6 @@ struct thread_info {
19216 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
19217
19218 #define STACK_WARN (THREAD_SIZE/8)
19219 -#define KERNEL_STACK_OFFSET (5*(BITS_PER_LONG/8))
19220
19221 /*
19222 * macros/functions for gaining access to the thread information structure
19223 @@ -160,26 +160,18 @@ struct thread_info {
19224
19225 DECLARE_PER_CPU(unsigned long, kernel_stack);
19226
19227 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
19228 +
19229 static inline struct thread_info *current_thread_info(void)
19230 {
19231 - struct thread_info *ti;
19232 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
19233 - KERNEL_STACK_OFFSET - THREAD_SIZE);
19234 - return ti;
19235 + return this_cpu_read_stable(current_tinfo);
19236 }
19237
19238 #else /* !__ASSEMBLY__ */
19239
19240 /* how to get the thread information struct from ASM */
19241 #define GET_THREAD_INFO(reg) \
19242 - _ASM_MOV PER_CPU_VAR(kernel_stack),reg ; \
19243 - _ASM_SUB $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg ;
19244 -
19245 -/*
19246 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19247 - * a certain register (to be used in assembler memory operands).
19248 - */
19249 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19250 + _ASM_MOV PER_CPU_VAR(current_tinfo),reg ;
19251
19252 #endif
19253
19254 @@ -237,5 +229,12 @@ static inline bool is_ia32_task(void)
19255 extern void arch_task_cache_init(void);
19256 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19257 extern void arch_release_task_struct(struct task_struct *tsk);
19258 +
19259 +#define __HAVE_THREAD_FUNCTIONS
19260 +#define task_thread_info(task) (&(task)->tinfo)
19261 +#define task_stack_page(task) ((task)->stack)
19262 +#define setup_thread_stack(p, org) do {} while (0)
19263 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19264 +
19265 #endif
19266 #endif /* _ASM_X86_THREAD_INFO_H */
19267 diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19268 index 04905bf..49203ca 100644
19269 --- a/arch/x86/include/asm/tlbflush.h
19270 +++ b/arch/x86/include/asm/tlbflush.h
19271 @@ -17,18 +17,44 @@
19272
19273 static inline void __native_flush_tlb(void)
19274 {
19275 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19276 + u64 descriptor[2];
19277 +
19278 + descriptor[0] = PCID_KERNEL;
19279 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
19280 + return;
19281 + }
19282 +
19283 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19284 + if (static_cpu_has(X86_FEATURE_PCID)) {
19285 + unsigned int cpu = raw_get_cpu();
19286 +
19287 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19288 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19289 + raw_put_cpu_no_resched();
19290 + return;
19291 + }
19292 +#endif
19293 +
19294 native_write_cr3(native_read_cr3());
19295 }
19296
19297 static inline void __native_flush_tlb_global_irq_disabled(void)
19298 {
19299 - unsigned long cr4;
19300 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19301 + u64 descriptor[2];
19302
19303 - cr4 = native_read_cr4();
19304 - /* clear PGE */
19305 - native_write_cr4(cr4 & ~X86_CR4_PGE);
19306 - /* write old PGE again and flush TLBs */
19307 - native_write_cr4(cr4);
19308 + descriptor[0] = PCID_KERNEL;
19309 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19310 + } else {
19311 + unsigned long cr4;
19312 +
19313 + cr4 = native_read_cr4();
19314 + /* clear PGE */
19315 + native_write_cr4(cr4 & ~X86_CR4_PGE);
19316 + /* write old PGE again and flush TLBs */
19317 + native_write_cr4(cr4);
19318 + }
19319 }
19320
19321 static inline void __native_flush_tlb_global(void)
19322 @@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19323
19324 static inline void __native_flush_tlb_single(unsigned long addr)
19325 {
19326 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19327 + u64 descriptor[2];
19328 +
19329 + descriptor[0] = PCID_KERNEL;
19330 + descriptor[1] = addr;
19331 +
19332 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19333 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19334 + if (addr < TASK_SIZE_MAX)
19335 + descriptor[1] += pax_user_shadow_base;
19336 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19337 + }
19338 +
19339 + descriptor[0] = PCID_USER;
19340 + descriptor[1] = addr;
19341 +#endif
19342 +
19343 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19344 + return;
19345 + }
19346 +
19347 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19348 + if (static_cpu_has(X86_FEATURE_PCID)) {
19349 + unsigned int cpu = raw_get_cpu();
19350 +
19351 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19352 + asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19353 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19354 + raw_put_cpu_no_resched();
19355 +
19356 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19357 + addr += pax_user_shadow_base;
19358 + }
19359 +#endif
19360 +
19361 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19362 }
19363
19364 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19365 index 0d592e0..526f797 100644
19366 --- a/arch/x86/include/asm/uaccess.h
19367 +++ b/arch/x86/include/asm/uaccess.h
19368 @@ -7,6 +7,7 @@
19369 #include <linux/compiler.h>
19370 #include <linux/thread_info.h>
19371 #include <linux/string.h>
19372 +#include <linux/spinlock.h>
19373 #include <asm/asm.h>
19374 #include <asm/page.h>
19375 #include <asm/smap.h>
19376 @@ -29,7 +30,12 @@
19377
19378 #define get_ds() (KERNEL_DS)
19379 #define get_fs() (current_thread_info()->addr_limit)
19380 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19381 +void __set_fs(mm_segment_t x);
19382 +void set_fs(mm_segment_t x);
19383 +#else
19384 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19385 +#endif
19386
19387 #define segment_eq(a, b) ((a).seg == (b).seg)
19388
19389 @@ -85,8 +91,36 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
19390 * checks that the pointer is in the user space range - after calling
19391 * this function, memory access functions may still return -EFAULT.
19392 */
19393 -#define access_ok(type, addr, size) \
19394 - likely(!__range_not_ok(addr, size, user_addr_max()))
19395 +extern int _cond_resched(void);
19396 +#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
19397 +#define access_ok(type, addr, size) \
19398 +({ \
19399 + unsigned long __size = size; \
19400 + unsigned long __addr = (unsigned long)addr; \
19401 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19402 + if (__ret_ao && __size) { \
19403 + unsigned long __addr_ao = __addr & PAGE_MASK; \
19404 + unsigned long __end_ao = __addr + __size - 1; \
19405 + if (unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19406 + while (__addr_ao <= __end_ao) { \
19407 + char __c_ao; \
19408 + __addr_ao += PAGE_SIZE; \
19409 + if (__size > PAGE_SIZE) \
19410 + _cond_resched(); \
19411 + if (__get_user(__c_ao, (char __user *)__addr)) \
19412 + break; \
19413 + if (type != VERIFY_WRITE) { \
19414 + __addr = __addr_ao; \
19415 + continue; \
19416 + } \
19417 + if (__put_user(__c_ao, (char __user *)__addr)) \
19418 + break; \
19419 + __addr = __addr_ao; \
19420 + } \
19421 + } \
19422 + } \
19423 + __ret_ao; \
19424 +})
19425
19426 /*
19427 * The exception table consists of pairs of addresses relative to the
19428 @@ -176,10 +210,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19429 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19430 __chk_user_ptr(ptr); \
19431 might_fault(); \
19432 + pax_open_userland(); \
19433 asm volatile("call __get_user_%P3" \
19434 : "=a" (__ret_gu), "=r" (__val_gu) \
19435 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19436 (x) = (__typeof__(*(ptr))) __val_gu; \
19437 + pax_close_userland(); \
19438 __ret_gu; \
19439 })
19440
19441 @@ -187,13 +223,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19442 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19443 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19444
19445 -
19446 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19447 +#define __copyuser_seg "gs;"
19448 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19449 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19450 +#else
19451 +#define __copyuser_seg
19452 +#define __COPYUSER_SET_ES
19453 +#define __COPYUSER_RESTORE_ES
19454 +#endif
19455
19456 #ifdef CONFIG_X86_32
19457 #define __put_user_asm_u64(x, addr, err, errret) \
19458 asm volatile(ASM_STAC "\n" \
19459 - "1: movl %%eax,0(%2)\n" \
19460 - "2: movl %%edx,4(%2)\n" \
19461 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19462 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19463 "3: " ASM_CLAC "\n" \
19464 ".section .fixup,\"ax\"\n" \
19465 "4: movl %3,%0\n" \
19466 @@ -206,8 +250,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19467
19468 #define __put_user_asm_ex_u64(x, addr) \
19469 asm volatile(ASM_STAC "\n" \
19470 - "1: movl %%eax,0(%1)\n" \
19471 - "2: movl %%edx,4(%1)\n" \
19472 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19473 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19474 "3: " ASM_CLAC "\n" \
19475 _ASM_EXTABLE_EX(1b, 2b) \
19476 _ASM_EXTABLE_EX(2b, 3b) \
19477 @@ -257,7 +301,8 @@ extern void __put_user_8(void);
19478 __typeof__(*(ptr)) __pu_val; \
19479 __chk_user_ptr(ptr); \
19480 might_fault(); \
19481 - __pu_val = x; \
19482 + __pu_val = (x); \
19483 + pax_open_userland(); \
19484 switch (sizeof(*(ptr))) { \
19485 case 1: \
19486 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19487 @@ -275,6 +320,7 @@ extern void __put_user_8(void);
19488 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19489 break; \
19490 } \
19491 + pax_close_userland(); \
19492 __ret_pu; \
19493 })
19494
19495 @@ -355,8 +401,10 @@ do { \
19496 } while (0)
19497
19498 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19499 +do { \
19500 + pax_open_userland(); \
19501 asm volatile(ASM_STAC "\n" \
19502 - "1: mov"itype" %2,%"rtype"1\n" \
19503 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19504 "2: " ASM_CLAC "\n" \
19505 ".section .fixup,\"ax\"\n" \
19506 "3: mov %3,%0\n" \
19507 @@ -364,8 +412,10 @@ do { \
19508 " jmp 2b\n" \
19509 ".previous\n" \
19510 _ASM_EXTABLE(1b, 3b) \
19511 - : "=r" (err), ltype(x) \
19512 - : "m" (__m(addr)), "i" (errret), "0" (err))
19513 + : "=r" (err), ltype (x) \
19514 + : "m" (__m(addr)), "i" (errret), "0" (err)); \
19515 + pax_close_userland(); \
19516 +} while (0)
19517
19518 #define __get_user_size_ex(x, ptr, size) \
19519 do { \
19520 @@ -389,7 +439,7 @@ do { \
19521 } while (0)
19522
19523 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19524 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19525 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19526 "2:\n" \
19527 _ASM_EXTABLE_EX(1b, 2b) \
19528 : ltype(x) : "m" (__m(addr)))
19529 @@ -406,13 +456,24 @@ do { \
19530 int __gu_err; \
19531 unsigned long __gu_val; \
19532 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19533 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
19534 + (x) = (__typeof__(*(ptr)))__gu_val; \
19535 __gu_err; \
19536 })
19537
19538 /* FIXME: this hack is definitely wrong -AK */
19539 struct __large_struct { unsigned long buf[100]; };
19540 -#define __m(x) (*(struct __large_struct __user *)(x))
19541 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19542 +#define ____m(x) \
19543 +({ \
19544 + unsigned long ____x = (unsigned long)(x); \
19545 + if (____x < pax_user_shadow_base) \
19546 + ____x += pax_user_shadow_base; \
19547 + (typeof(x))____x; \
19548 +})
19549 +#else
19550 +#define ____m(x) (x)
19551 +#endif
19552 +#define __m(x) (*(struct __large_struct __user *)____m(x))
19553
19554 /*
19555 * Tell gcc we read from memory instead of writing: this is because
19556 @@ -420,8 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
19557 * aliasing issues.
19558 */
19559 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19560 +do { \
19561 + pax_open_userland(); \
19562 asm volatile(ASM_STAC "\n" \
19563 - "1: mov"itype" %"rtype"1,%2\n" \
19564 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
19565 "2: " ASM_CLAC "\n" \
19566 ".section .fixup,\"ax\"\n" \
19567 "3: mov %3,%0\n" \
19568 @@ -429,10 +492,12 @@ struct __large_struct { unsigned long buf[100]; };
19569 ".previous\n" \
19570 _ASM_EXTABLE(1b, 3b) \
19571 : "=r"(err) \
19572 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
19573 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
19574 + pax_close_userland(); \
19575 +} while (0)
19576
19577 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
19578 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
19579 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19580 "2:\n" \
19581 _ASM_EXTABLE_EX(1b, 2b) \
19582 : : ltype(x), "m" (__m(addr)))
19583 @@ -442,11 +507,13 @@ struct __large_struct { unsigned long buf[100]; };
19584 */
19585 #define uaccess_try do { \
19586 current_thread_info()->uaccess_err = 0; \
19587 + pax_open_userland(); \
19588 stac(); \
19589 barrier();
19590
19591 #define uaccess_catch(err) \
19592 clac(); \
19593 + pax_close_userland(); \
19594 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19595 } while (0)
19596
19597 @@ -471,8 +538,12 @@ struct __large_struct { unsigned long buf[100]; };
19598 * On error, the variable @x is set to zero.
19599 */
19600
19601 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19602 +#define __get_user(x, ptr) get_user((x), (ptr))
19603 +#else
19604 #define __get_user(x, ptr) \
19605 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19606 +#endif
19607
19608 /**
19609 * __put_user: - Write a simple value into user space, with less checking.
19610 @@ -494,8 +565,12 @@ struct __large_struct { unsigned long buf[100]; };
19611 * Returns zero on success, or -EFAULT on error.
19612 */
19613
19614 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19615 +#define __put_user(x, ptr) put_user((x), (ptr))
19616 +#else
19617 #define __put_user(x, ptr) \
19618 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19619 +#endif
19620
19621 #define __get_user_unaligned __get_user
19622 #define __put_user_unaligned __put_user
19623 @@ -513,7 +588,7 @@ struct __large_struct { unsigned long buf[100]; };
19624 #define get_user_ex(x, ptr) do { \
19625 unsigned long __gue_val; \
19626 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19627 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
19628 + (x) = (__typeof__(*(ptr)))__gue_val; \
19629 } while (0)
19630
19631 #define put_user_try uaccess_try
19632 @@ -542,18 +617,19 @@ extern void __cmpxchg_wrong_size(void)
19633 __typeof__(ptr) __uval = (uval); \
19634 __typeof__(*(ptr)) __old = (old); \
19635 __typeof__(*(ptr)) __new = (new); \
19636 + pax_open_userland(); \
19637 switch (size) { \
19638 case 1: \
19639 { \
19640 asm volatile("\t" ASM_STAC "\n" \
19641 - "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
19642 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
19643 "2:\t" ASM_CLAC "\n" \
19644 "\t.section .fixup, \"ax\"\n" \
19645 "3:\tmov %3, %0\n" \
19646 "\tjmp 2b\n" \
19647 "\t.previous\n" \
19648 _ASM_EXTABLE(1b, 3b) \
19649 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19650 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19651 : "i" (-EFAULT), "q" (__new), "1" (__old) \
19652 : "memory" \
19653 ); \
19654 @@ -562,14 +638,14 @@ extern void __cmpxchg_wrong_size(void)
19655 case 2: \
19656 { \
19657 asm volatile("\t" ASM_STAC "\n" \
19658 - "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
19659 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
19660 "2:\t" ASM_CLAC "\n" \
19661 "\t.section .fixup, \"ax\"\n" \
19662 "3:\tmov %3, %0\n" \
19663 "\tjmp 2b\n" \
19664 "\t.previous\n" \
19665 _ASM_EXTABLE(1b, 3b) \
19666 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19667 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19668 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19669 : "memory" \
19670 ); \
19671 @@ -578,14 +654,14 @@ extern void __cmpxchg_wrong_size(void)
19672 case 4: \
19673 { \
19674 asm volatile("\t" ASM_STAC "\n" \
19675 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
19676 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
19677 "2:\t" ASM_CLAC "\n" \
19678 "\t.section .fixup, \"ax\"\n" \
19679 "3:\tmov %3, %0\n" \
19680 "\tjmp 2b\n" \
19681 "\t.previous\n" \
19682 _ASM_EXTABLE(1b, 3b) \
19683 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19684 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19685 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19686 : "memory" \
19687 ); \
19688 @@ -597,14 +673,14 @@ extern void __cmpxchg_wrong_size(void)
19689 __cmpxchg_wrong_size(); \
19690 \
19691 asm volatile("\t" ASM_STAC "\n" \
19692 - "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
19693 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
19694 "2:\t" ASM_CLAC "\n" \
19695 "\t.section .fixup, \"ax\"\n" \
19696 "3:\tmov %3, %0\n" \
19697 "\tjmp 2b\n" \
19698 "\t.previous\n" \
19699 _ASM_EXTABLE(1b, 3b) \
19700 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19701 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19702 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19703 : "memory" \
19704 ); \
19705 @@ -613,6 +689,7 @@ extern void __cmpxchg_wrong_size(void)
19706 default: \
19707 __cmpxchg_wrong_size(); \
19708 } \
19709 + pax_close_userland(); \
19710 *__uval = __old; \
19711 __ret; \
19712 })
19713 @@ -636,17 +713,6 @@ extern struct movsl_mask {
19714
19715 #define ARCH_HAS_NOCACHE_UACCESS 1
19716
19717 -#ifdef CONFIG_X86_32
19718 -# include <asm/uaccess_32.h>
19719 -#else
19720 -# include <asm/uaccess_64.h>
19721 -#endif
19722 -
19723 -unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19724 - unsigned n);
19725 -unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19726 - unsigned n);
19727 -
19728 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19729 # define copy_user_diag __compiletime_error
19730 #else
19731 @@ -656,7 +722,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19732 extern void copy_user_diag("copy_from_user() buffer size is too small")
19733 copy_from_user_overflow(void);
19734 extern void copy_user_diag("copy_to_user() buffer size is too small")
19735 -copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19736 +copy_to_user_overflow(void);
19737
19738 #undef copy_user_diag
19739
19740 @@ -669,7 +735,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19741
19742 extern void
19743 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19744 -__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19745 +__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19746 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19747
19748 #else
19749 @@ -684,10 +750,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19750
19751 #endif
19752
19753 +#ifdef CONFIG_X86_32
19754 +# include <asm/uaccess_32.h>
19755 +#else
19756 +# include <asm/uaccess_64.h>
19757 +#endif
19758 +
19759 static inline unsigned long __must_check
19760 copy_from_user(void *to, const void __user *from, unsigned long n)
19761 {
19762 - int sz = __compiletime_object_size(to);
19763 + size_t sz = __compiletime_object_size(to);
19764
19765 might_fault();
19766
19767 @@ -709,12 +781,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19768 * case, and do only runtime checking for non-constant sizes.
19769 */
19770
19771 - if (likely(sz < 0 || sz >= n))
19772 - n = _copy_from_user(to, from, n);
19773 - else if(__builtin_constant_p(n))
19774 - copy_from_user_overflow();
19775 - else
19776 - __copy_from_user_overflow(sz, n);
19777 + if (likely(sz != (size_t)-1 && sz < n)) {
19778 + if(__builtin_constant_p(n))
19779 + copy_from_user_overflow();
19780 + else
19781 + __copy_from_user_overflow(sz, n);
19782 + } else if (access_ok(VERIFY_READ, from, n))
19783 + n = __copy_from_user(to, from, n);
19784 + else if ((long)n > 0)
19785 + memset(to, 0, n);
19786
19787 return n;
19788 }
19789 @@ -722,17 +797,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19790 static inline unsigned long __must_check
19791 copy_to_user(void __user *to, const void *from, unsigned long n)
19792 {
19793 - int sz = __compiletime_object_size(from);
19794 + size_t sz = __compiletime_object_size(from);
19795
19796 might_fault();
19797
19798 /* See the comment in copy_from_user() above. */
19799 - if (likely(sz < 0 || sz >= n))
19800 - n = _copy_to_user(to, from, n);
19801 - else if(__builtin_constant_p(n))
19802 - copy_to_user_overflow();
19803 - else
19804 - __copy_to_user_overflow(sz, n);
19805 + if (likely(sz != (size_t)-1 && sz < n)) {
19806 + if(__builtin_constant_p(n))
19807 + copy_to_user_overflow();
19808 + else
19809 + __copy_to_user_overflow(sz, n);
19810 + } else if (access_ok(VERIFY_WRITE, to, n))
19811 + n = __copy_to_user(to, from, n);
19812
19813 return n;
19814 }
19815 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
19816 index 3c03a5d..1071638 100644
19817 --- a/arch/x86/include/asm/uaccess_32.h
19818 +++ b/arch/x86/include/asm/uaccess_32.h
19819 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
19820 static __always_inline unsigned long __must_check
19821 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
19822 {
19823 + if ((long)n < 0)
19824 + return n;
19825 +
19826 + check_object_size(from, n, true);
19827 +
19828 if (__builtin_constant_p(n)) {
19829 unsigned long ret;
19830
19831 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
19832 __copy_to_user(void __user *to, const void *from, unsigned long n)
19833 {
19834 might_fault();
19835 +
19836 return __copy_to_user_inatomic(to, from, n);
19837 }
19838
19839 static __always_inline unsigned long
19840 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
19841 {
19842 + if ((long)n < 0)
19843 + return n;
19844 +
19845 /* Avoid zeroing the tail if the copy fails..
19846 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
19847 * but as the zeroing behaviour is only significant when n is not
19848 @@ -137,6 +146,12 @@ static __always_inline unsigned long
19849 __copy_from_user(void *to, const void __user *from, unsigned long n)
19850 {
19851 might_fault();
19852 +
19853 + if ((long)n < 0)
19854 + return n;
19855 +
19856 + check_object_size(to, n, false);
19857 +
19858 if (__builtin_constant_p(n)) {
19859 unsigned long ret;
19860
19861 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
19862 const void __user *from, unsigned long n)
19863 {
19864 might_fault();
19865 +
19866 + if ((long)n < 0)
19867 + return n;
19868 +
19869 if (__builtin_constant_p(n)) {
19870 unsigned long ret;
19871
19872 @@ -181,7 +200,10 @@ static __always_inline unsigned long
19873 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
19874 unsigned long n)
19875 {
19876 - return __copy_from_user_ll_nocache_nozero(to, from, n);
19877 + if ((long)n < 0)
19878 + return n;
19879 +
19880 + return __copy_from_user_ll_nocache_nozero(to, from, n);
19881 }
19882
19883 #endif /* _ASM_X86_UACCESS_32_H */
19884 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
19885 index 12a26b9..206c200 100644
19886 --- a/arch/x86/include/asm/uaccess_64.h
19887 +++ b/arch/x86/include/asm/uaccess_64.h
19888 @@ -10,6 +10,9 @@
19889 #include <asm/alternative.h>
19890 #include <asm/cpufeature.h>
19891 #include <asm/page.h>
19892 +#include <asm/pgtable.h>
19893 +
19894 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
19895
19896 /*
19897 * Copy To/From Userspace
19898 @@ -17,14 +20,14 @@
19899
19900 /* Handles exceptions in both to and from, but doesn't do access_ok */
19901 __must_check unsigned long
19902 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
19903 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
19904 __must_check unsigned long
19905 -copy_user_generic_string(void *to, const void *from, unsigned len);
19906 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
19907 __must_check unsigned long
19908 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
19909 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
19910
19911 static __always_inline __must_check unsigned long
19912 -copy_user_generic(void *to, const void *from, unsigned len)
19913 +copy_user_generic(void *to, const void *from, unsigned long len)
19914 {
19915 unsigned ret;
19916
19917 @@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
19918 }
19919
19920 __must_check unsigned long
19921 -copy_in_user(void __user *to, const void __user *from, unsigned len);
19922 +copy_in_user(void __user *to, const void __user *from, unsigned long len);
19923
19924 static __always_inline __must_check
19925 -int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
19926 +unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
19927 {
19928 - int ret = 0;
19929 + size_t sz = __compiletime_object_size(dst);
19930 + unsigned ret = 0;
19931 +
19932 + if (size > INT_MAX)
19933 + return size;
19934 +
19935 + check_object_size(dst, size, false);
19936 +
19937 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19938 + if (!access_ok_noprefault(VERIFY_READ, src, size))
19939 + return size;
19940 +#endif
19941 +
19942 + if (unlikely(sz != (size_t)-1 && sz < size)) {
19943 + if(__builtin_constant_p(size))
19944 + copy_from_user_overflow();
19945 + else
19946 + __copy_from_user_overflow(sz, size);
19947 + return size;
19948 + }
19949
19950 if (!__builtin_constant_p(size))
19951 - return copy_user_generic(dst, (__force void *)src, size);
19952 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19953 switch (size) {
19954 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
19955 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
19956 ret, "b", "b", "=q", 1);
19957 return ret;
19958 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
19959 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
19960 ret, "w", "w", "=r", 2);
19961 return ret;
19962 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
19963 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
19964 ret, "l", "k", "=r", 4);
19965 return ret;
19966 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
19967 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19968 ret, "q", "", "=r", 8);
19969 return ret;
19970 case 10:
19971 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19972 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19973 ret, "q", "", "=r", 10);
19974 if (unlikely(ret))
19975 return ret;
19976 __get_user_asm(*(u16 *)(8 + (char *)dst),
19977 - (u16 __user *)(8 + (char __user *)src),
19978 + (const u16 __user *)(8 + (const char __user *)src),
19979 ret, "w", "w", "=r", 2);
19980 return ret;
19981 case 16:
19982 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19983 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19984 ret, "q", "", "=r", 16);
19985 if (unlikely(ret))
19986 return ret;
19987 __get_user_asm(*(u64 *)(8 + (char *)dst),
19988 - (u64 __user *)(8 + (char __user *)src),
19989 + (const u64 __user *)(8 + (const char __user *)src),
19990 ret, "q", "", "=r", 8);
19991 return ret;
19992 default:
19993 - return copy_user_generic(dst, (__force void *)src, size);
19994 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19995 }
19996 }
19997
19998 static __always_inline __must_check
19999 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
20000 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
20001 {
20002 might_fault();
20003 return __copy_from_user_nocheck(dst, src, size);
20004 }
20005
20006 static __always_inline __must_check
20007 -int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
20008 +unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
20009 {
20010 - int ret = 0;
20011 + size_t sz = __compiletime_object_size(src);
20012 + unsigned ret = 0;
20013 +
20014 + if (size > INT_MAX)
20015 + return size;
20016 +
20017 + check_object_size(src, size, true);
20018 +
20019 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20020 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20021 + return size;
20022 +#endif
20023 +
20024 + if (unlikely(sz != (size_t)-1 && sz < size)) {
20025 + if(__builtin_constant_p(size))
20026 + copy_to_user_overflow();
20027 + else
20028 + __copy_to_user_overflow(sz, size);
20029 + return size;
20030 + }
20031
20032 if (!__builtin_constant_p(size))
20033 - return copy_user_generic((__force void *)dst, src, size);
20034 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20035 switch (size) {
20036 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
20037 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
20038 ret, "b", "b", "iq", 1);
20039 return ret;
20040 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
20041 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
20042 ret, "w", "w", "ir", 2);
20043 return ret;
20044 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
20045 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
20046 ret, "l", "k", "ir", 4);
20047 return ret;
20048 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
20049 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20050 ret, "q", "", "er", 8);
20051 return ret;
20052 case 10:
20053 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20054 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20055 ret, "q", "", "er", 10);
20056 if (unlikely(ret))
20057 return ret;
20058 asm("":::"memory");
20059 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
20060 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
20061 ret, "w", "w", "ir", 2);
20062 return ret;
20063 case 16:
20064 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20065 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20066 ret, "q", "", "er", 16);
20067 if (unlikely(ret))
20068 return ret;
20069 asm("":::"memory");
20070 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
20071 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
20072 ret, "q", "", "er", 8);
20073 return ret;
20074 default:
20075 - return copy_user_generic((__force void *)dst, src, size);
20076 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20077 }
20078 }
20079
20080 static __always_inline __must_check
20081 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
20082 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
20083 {
20084 might_fault();
20085 return __copy_to_user_nocheck(dst, src, size);
20086 }
20087
20088 static __always_inline __must_check
20089 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20090 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20091 {
20092 - int ret = 0;
20093 + unsigned ret = 0;
20094
20095 might_fault();
20096 +
20097 + if (size > INT_MAX)
20098 + return size;
20099 +
20100 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20101 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20102 + return size;
20103 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20104 + return size;
20105 +#endif
20106 +
20107 if (!__builtin_constant_p(size))
20108 - return copy_user_generic((__force void *)dst,
20109 - (__force void *)src, size);
20110 + return copy_user_generic((__force_kernel void *)____m(dst),
20111 + (__force_kernel const void *)____m(src), size);
20112 switch (size) {
20113 case 1: {
20114 u8 tmp;
20115 - __get_user_asm(tmp, (u8 __user *)src,
20116 + __get_user_asm(tmp, (const u8 __user *)src,
20117 ret, "b", "b", "=q", 1);
20118 if (likely(!ret))
20119 __put_user_asm(tmp, (u8 __user *)dst,
20120 @@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20121 }
20122 case 2: {
20123 u16 tmp;
20124 - __get_user_asm(tmp, (u16 __user *)src,
20125 + __get_user_asm(tmp, (const u16 __user *)src,
20126 ret, "w", "w", "=r", 2);
20127 if (likely(!ret))
20128 __put_user_asm(tmp, (u16 __user *)dst,
20129 @@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20130
20131 case 4: {
20132 u32 tmp;
20133 - __get_user_asm(tmp, (u32 __user *)src,
20134 + __get_user_asm(tmp, (const u32 __user *)src,
20135 ret, "l", "k", "=r", 4);
20136 if (likely(!ret))
20137 __put_user_asm(tmp, (u32 __user *)dst,
20138 @@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20139 }
20140 case 8: {
20141 u64 tmp;
20142 - __get_user_asm(tmp, (u64 __user *)src,
20143 + __get_user_asm(tmp, (const u64 __user *)src,
20144 ret, "q", "", "=r", 8);
20145 if (likely(!ret))
20146 __put_user_asm(tmp, (u64 __user *)dst,
20147 @@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20148 return ret;
20149 }
20150 default:
20151 - return copy_user_generic((__force void *)dst,
20152 - (__force void *)src, size);
20153 + return copy_user_generic((__force_kernel void *)____m(dst),
20154 + (__force_kernel const void *)____m(src), size);
20155 }
20156 }
20157
20158 -static __must_check __always_inline int
20159 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
20160 +static __must_check __always_inline unsigned long
20161 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
20162 {
20163 return __copy_from_user_nocheck(dst, src, size);
20164 }
20165
20166 -static __must_check __always_inline int
20167 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
20168 +static __must_check __always_inline unsigned long
20169 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
20170 {
20171 return __copy_to_user_nocheck(dst, src, size);
20172 }
20173
20174 -extern long __copy_user_nocache(void *dst, const void __user *src,
20175 - unsigned size, int zerorest);
20176 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
20177 + unsigned long size, int zerorest);
20178
20179 -static inline int
20180 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
20181 +static inline unsigned long
20182 +__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
20183 {
20184 might_fault();
20185 +
20186 + if (size > INT_MAX)
20187 + return size;
20188 +
20189 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20190 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20191 + return size;
20192 +#endif
20193 +
20194 return __copy_user_nocache(dst, src, size, 1);
20195 }
20196
20197 -static inline int
20198 +static inline unsigned long
20199 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20200 - unsigned size)
20201 + unsigned long size)
20202 {
20203 + if (size > INT_MAX)
20204 + return size;
20205 +
20206 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20207 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20208 + return size;
20209 +#endif
20210 +
20211 return __copy_user_nocache(dst, src, size, 0);
20212 }
20213
20214 unsigned long
20215 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20216 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20217
20218 #endif /* _ASM_X86_UACCESS_64_H */
20219 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20220 index 5b238981..77fdd78 100644
20221 --- a/arch/x86/include/asm/word-at-a-time.h
20222 +++ b/arch/x86/include/asm/word-at-a-time.h
20223 @@ -11,7 +11,7 @@
20224 * and shift, for example.
20225 */
20226 struct word_at_a_time {
20227 - const unsigned long one_bits, high_bits;
20228 + unsigned long one_bits, high_bits;
20229 };
20230
20231 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20232 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20233 index e45e4da..44e8572 100644
20234 --- a/arch/x86/include/asm/x86_init.h
20235 +++ b/arch/x86/include/asm/x86_init.h
20236 @@ -129,7 +129,7 @@ struct x86_init_ops {
20237 struct x86_init_timers timers;
20238 struct x86_init_iommu iommu;
20239 struct x86_init_pci pci;
20240 -};
20241 +} __no_const;
20242
20243 /**
20244 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20245 @@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20246 void (*setup_percpu_clockev)(void);
20247 void (*early_percpu_clock_init)(void);
20248 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20249 -};
20250 +} __no_const;
20251
20252 struct timespec;
20253
20254 @@ -168,7 +168,7 @@ struct x86_platform_ops {
20255 void (*save_sched_clock_state)(void);
20256 void (*restore_sched_clock_state)(void);
20257 void (*apic_post_init)(void);
20258 -};
20259 +} __no_const;
20260
20261 struct pci_dev;
20262 struct msi_msg;
20263 @@ -185,7 +185,7 @@ struct x86_msi_ops {
20264 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20265 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20266 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20267 -};
20268 +} __no_const;
20269
20270 struct IO_APIC_route_entry;
20271 struct io_apic_irq_attr;
20272 @@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20273 unsigned int destination, int vector,
20274 struct io_apic_irq_attr *attr);
20275 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20276 -};
20277 +} __no_const;
20278
20279 extern struct x86_init_ops x86_init;
20280 extern struct x86_cpuinit_ops x86_cpuinit;
20281 diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20282 index c949923..c22bfa4 100644
20283 --- a/arch/x86/include/asm/xen/page.h
20284 +++ b/arch/x86/include/asm/xen/page.h
20285 @@ -63,7 +63,7 @@ extern int m2p_remove_override(struct page *page,
20286 extern struct page *m2p_find_override(unsigned long mfn);
20287 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20288
20289 -static inline unsigned long pfn_to_mfn(unsigned long pfn)
20290 +static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20291 {
20292 unsigned long mfn;
20293
20294 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20295 index d949ef2..479b9d1 100644
20296 --- a/arch/x86/include/asm/xsave.h
20297 +++ b/arch/x86/include/asm/xsave.h
20298 @@ -82,8 +82,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20299 if (unlikely(err))
20300 return -EFAULT;
20301
20302 + pax_open_userland();
20303 __asm__ __volatile__(ASM_STAC "\n"
20304 - "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
20305 + "1:"
20306 + __copyuser_seg
20307 + ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
20308 "2: " ASM_CLAC "\n"
20309 ".section .fixup,\"ax\"\n"
20310 "3: movl $-1,%[err]\n"
20311 @@ -93,18 +96,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20312 : [err] "=r" (err)
20313 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20314 : "memory");
20315 + pax_close_userland();
20316 return err;
20317 }
20318
20319 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20320 {
20321 int err;
20322 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20323 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20324 u32 lmask = mask;
20325 u32 hmask = mask >> 32;
20326
20327 + pax_open_userland();
20328 __asm__ __volatile__(ASM_STAC "\n"
20329 - "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20330 + "1:"
20331 + __copyuser_seg
20332 + ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20333 "2: " ASM_CLAC "\n"
20334 ".section .fixup,\"ax\"\n"
20335 "3: movl $-1,%[err]\n"
20336 @@ -114,6 +121,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20337 : [err] "=r" (err)
20338 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20339 : "memory"); /* memory required? */
20340 + pax_close_userland();
20341 return err;
20342 }
20343
20344 diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20345 index bbae024..e1528f9 100644
20346 --- a/arch/x86/include/uapi/asm/e820.h
20347 +++ b/arch/x86/include/uapi/asm/e820.h
20348 @@ -63,7 +63,7 @@ struct e820map {
20349 #define ISA_START_ADDRESS 0xa0000
20350 #define ISA_END_ADDRESS 0x100000
20351
20352 -#define BIOS_BEGIN 0x000a0000
20353 +#define BIOS_BEGIN 0x000c0000
20354 #define BIOS_END 0x00100000
20355
20356 #define BIOS_ROM_BASE 0xffe00000
20357 diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20358 index 7b0a55a..ad115bf 100644
20359 --- a/arch/x86/include/uapi/asm/ptrace-abi.h
20360 +++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20361 @@ -49,7 +49,6 @@
20362 #define EFLAGS 144
20363 #define RSP 152
20364 #define SS 160
20365 -#define ARGOFFSET R11
20366 #endif /* __ASSEMBLY__ */
20367
20368 /* top of stack page */
20369 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20370 index 491ef3e..7da98ce 100644
20371 --- a/arch/x86/kernel/Makefile
20372 +++ b/arch/x86/kernel/Makefile
20373 @@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20374 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20375 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20376 obj-y += probe_roms.o
20377 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20378 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20379 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20380 obj-y += syscall_$(BITS).o vsyscall_gtod.o
20381 obj-$(CONFIG_X86_64) += vsyscall_64.o
20382 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20383 index 86281ff..e046fc2 100644
20384 --- a/arch/x86/kernel/acpi/boot.c
20385 +++ b/arch/x86/kernel/acpi/boot.c
20386 @@ -1296,7 +1296,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20387 * If your system is blacklisted here, but you find that acpi=force
20388 * works for you, please contact linux-acpi@vger.kernel.org
20389 */
20390 -static struct dmi_system_id __initdata acpi_dmi_table[] = {
20391 +static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20392 /*
20393 * Boxes that need ACPI disabled
20394 */
20395 @@ -1371,7 +1371,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20396 };
20397
20398 /* second table for DMI checks that should run after early-quirks */
20399 -static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20400 +static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20401 /*
20402 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20403 * which includes some code which overrides all temperature
20404 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20405 index 3136820..e2c6577 100644
20406 --- a/arch/x86/kernel/acpi/sleep.c
20407 +++ b/arch/x86/kernel/acpi/sleep.c
20408 @@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20409 #else /* CONFIG_64BIT */
20410 #ifdef CONFIG_SMP
20411 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20412 +
20413 + pax_open_kernel();
20414 early_gdt_descr.address =
20415 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20416 + pax_close_kernel();
20417 +
20418 initial_gs = per_cpu_offset(smp_processor_id());
20419 #endif
20420 initial_code = (unsigned long)wakeup_long64;
20421 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20422 index 665c6b7..eae4d56 100644
20423 --- a/arch/x86/kernel/acpi/wakeup_32.S
20424 +++ b/arch/x86/kernel/acpi/wakeup_32.S
20425 @@ -29,13 +29,11 @@ wakeup_pmode_return:
20426 # and restore the stack ... but you need gdt for this to work
20427 movl saved_context_esp, %esp
20428
20429 - movl %cs:saved_magic, %eax
20430 - cmpl $0x12345678, %eax
20431 + cmpl $0x12345678, saved_magic
20432 jne bogus_magic
20433
20434 # jump to place where we left off
20435 - movl saved_eip, %eax
20436 - jmp *%eax
20437 + jmp *(saved_eip)
20438
20439 bogus_magic:
20440 jmp bogus_magic
20441 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20442 index df94598..b7162f9 100644
20443 --- a/arch/x86/kernel/alternative.c
20444 +++ b/arch/x86/kernel/alternative.c
20445 @@ -269,6 +269,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20446 */
20447 for (a = start; a < end; a++) {
20448 instr = (u8 *)&a->instr_offset + a->instr_offset;
20449 +
20450 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20451 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20452 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20453 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20454 +#endif
20455 +
20456 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20457 BUG_ON(a->replacementlen > a->instrlen);
20458 BUG_ON(a->instrlen > sizeof(insnbuf));
20459 @@ -285,6 +292,11 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20460 add_nops(insnbuf + a->replacementlen,
20461 a->instrlen - a->replacementlen);
20462
20463 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20464 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20465 + instr = ktva_ktla(instr);
20466 +#endif
20467 +
20468 text_poke_early(instr, insnbuf, a->instrlen);
20469 }
20470 }
20471 @@ -300,10 +312,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20472 for (poff = start; poff < end; poff++) {
20473 u8 *ptr = (u8 *)poff + *poff;
20474
20475 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20476 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20477 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20478 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20479 +#endif
20480 +
20481 if (!*poff || ptr < text || ptr >= text_end)
20482 continue;
20483 /* turn DS segment override prefix into lock prefix */
20484 - if (*ptr == 0x3e)
20485 + if (*ktla_ktva(ptr) == 0x3e)
20486 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20487 }
20488 mutex_unlock(&text_mutex);
20489 @@ -318,10 +336,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20490 for (poff = start; poff < end; poff++) {
20491 u8 *ptr = (u8 *)poff + *poff;
20492
20493 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20494 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20495 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20496 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20497 +#endif
20498 +
20499 if (!*poff || ptr < text || ptr >= text_end)
20500 continue;
20501 /* turn lock prefix into DS segment override prefix */
20502 - if (*ptr == 0xf0)
20503 + if (*ktla_ktva(ptr) == 0xf0)
20504 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20505 }
20506 mutex_unlock(&text_mutex);
20507 @@ -458,7 +482,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20508
20509 BUG_ON(p->len > MAX_PATCH_LEN);
20510 /* prep the buffer with the original instructions */
20511 - memcpy(insnbuf, p->instr, p->len);
20512 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20513 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20514 (unsigned long)p->instr, p->len);
20515
20516 @@ -505,7 +529,7 @@ void __init alternative_instructions(void)
20517 if (!uniproc_patched || num_possible_cpus() == 1)
20518 free_init_pages("SMP alternatives",
20519 (unsigned long)__smp_locks,
20520 - (unsigned long)__smp_locks_end);
20521 + PAGE_ALIGN((unsigned long)__smp_locks_end));
20522 #endif
20523
20524 apply_paravirt(__parainstructions, __parainstructions_end);
20525 @@ -525,13 +549,17 @@ void __init alternative_instructions(void)
20526 * instructions. And on the local CPU you need to be protected again NMI or MCE
20527 * handlers seeing an inconsistent instruction while you patch.
20528 */
20529 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
20530 +void *__kprobes text_poke_early(void *addr, const void *opcode,
20531 size_t len)
20532 {
20533 unsigned long flags;
20534 local_irq_save(flags);
20535 - memcpy(addr, opcode, len);
20536 +
20537 + pax_open_kernel();
20538 + memcpy(ktla_ktva(addr), opcode, len);
20539 sync_core();
20540 + pax_close_kernel();
20541 +
20542 local_irq_restore(flags);
20543 /* Could also do a CLFLUSH here to speed up CPU recovery; but
20544 that causes hangs on some VIA CPUs. */
20545 @@ -553,36 +581,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
20546 */
20547 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
20548 {
20549 - unsigned long flags;
20550 - char *vaddr;
20551 + unsigned char *vaddr = ktla_ktva(addr);
20552 struct page *pages[2];
20553 - int i;
20554 + size_t i;
20555
20556 if (!core_kernel_text((unsigned long)addr)) {
20557 - pages[0] = vmalloc_to_page(addr);
20558 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
20559 + pages[0] = vmalloc_to_page(vaddr);
20560 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
20561 } else {
20562 - pages[0] = virt_to_page(addr);
20563 + pages[0] = virt_to_page(vaddr);
20564 WARN_ON(!PageReserved(pages[0]));
20565 - pages[1] = virt_to_page(addr + PAGE_SIZE);
20566 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
20567 }
20568 BUG_ON(!pages[0]);
20569 - local_irq_save(flags);
20570 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
20571 - if (pages[1])
20572 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
20573 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
20574 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
20575 - clear_fixmap(FIX_TEXT_POKE0);
20576 - if (pages[1])
20577 - clear_fixmap(FIX_TEXT_POKE1);
20578 - local_flush_tlb();
20579 - sync_core();
20580 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
20581 - that causes hangs on some VIA CPUs. */
20582 + text_poke_early(addr, opcode, len);
20583 for (i = 0; i < len; i++)
20584 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
20585 - local_irq_restore(flags);
20586 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
20587 return addr;
20588 }
20589
20590 @@ -602,7 +616,7 @@ int poke_int3_handler(struct pt_regs *regs)
20591 if (likely(!bp_patching_in_progress))
20592 return 0;
20593
20594 - if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
20595 + if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
20596 return 0;
20597
20598 /* set up the specified breakpoint handler */
20599 @@ -636,7 +650,7 @@ int poke_int3_handler(struct pt_regs *regs)
20600 */
20601 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
20602 {
20603 - unsigned char int3 = 0xcc;
20604 + const unsigned char int3 = 0xcc;
20605
20606 bp_int3_handler = handler;
20607 bp_int3_addr = (u8 *)addr + sizeof(int3);
20608 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
20609 index ad28db7..c538b2c 100644
20610 --- a/arch/x86/kernel/apic/apic.c
20611 +++ b/arch/x86/kernel/apic/apic.c
20612 @@ -201,7 +201,7 @@ int first_system_vector = 0xfe;
20613 /*
20614 * Debug level, exported for io_apic.c
20615 */
20616 -unsigned int apic_verbosity;
20617 +int apic_verbosity;
20618
20619 int pic_mode;
20620
20621 @@ -2000,7 +2000,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
20622 apic_write(APIC_ESR, 0);
20623 v = apic_read(APIC_ESR);
20624 ack_APIC_irq();
20625 - atomic_inc(&irq_err_count);
20626 + atomic_inc_unchecked(&irq_err_count);
20627
20628 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
20629 smp_processor_id(), v);
20630 diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
20631 index 7c1b294..e71d27f 100644
20632 --- a/arch/x86/kernel/apic/apic_flat_64.c
20633 +++ b/arch/x86/kernel/apic/apic_flat_64.c
20634 @@ -154,7 +154,7 @@ static int flat_probe(void)
20635 return 1;
20636 }
20637
20638 -static struct apic apic_flat = {
20639 +static struct apic apic_flat __read_only = {
20640 .name = "flat",
20641 .probe = flat_probe,
20642 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
20643 @@ -268,7 +268,7 @@ static int physflat_probe(void)
20644 return 0;
20645 }
20646
20647 -static struct apic apic_physflat = {
20648 +static struct apic apic_physflat __read_only = {
20649
20650 .name = "physical flat",
20651 .probe = physflat_probe,
20652 diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
20653 index 8c7c982..a225910 100644
20654 --- a/arch/x86/kernel/apic/apic_noop.c
20655 +++ b/arch/x86/kernel/apic/apic_noop.c
20656 @@ -118,7 +118,7 @@ static void noop_apic_write(u32 reg, u32 v)
20657 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
20658 }
20659
20660 -struct apic apic_noop = {
20661 +struct apic apic_noop __read_only = {
20662 .name = "noop",
20663 .probe = noop_probe,
20664 .acpi_madt_oem_check = NULL,
20665 diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
20666 index e4840aa..e7d9dac 100644
20667 --- a/arch/x86/kernel/apic/bigsmp_32.c
20668 +++ b/arch/x86/kernel/apic/bigsmp_32.c
20669 @@ -152,7 +152,7 @@ static int probe_bigsmp(void)
20670 return dmi_bigsmp;
20671 }
20672
20673 -static struct apic apic_bigsmp = {
20674 +static struct apic apic_bigsmp __read_only = {
20675
20676 .name = "bigsmp",
20677 .probe = probe_bigsmp,
20678 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20679 index 992060e..ecdc3b3 100644
20680 --- a/arch/x86/kernel/apic/io_apic.c
20681 +++ b/arch/x86/kernel/apic/io_apic.c
20682 @@ -1057,7 +1057,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
20683 }
20684 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20685
20686 -void lock_vector_lock(void)
20687 +void lock_vector_lock(void) __acquires(vector_lock)
20688 {
20689 /* Used to the online set of cpus does not change
20690 * during assign_irq_vector.
20691 @@ -1065,7 +1065,7 @@ void lock_vector_lock(void)
20692 raw_spin_lock(&vector_lock);
20693 }
20694
20695 -void unlock_vector_lock(void)
20696 +void unlock_vector_lock(void) __releases(vector_lock)
20697 {
20698 raw_spin_unlock(&vector_lock);
20699 }
20700 @@ -2364,7 +2364,7 @@ static void ack_apic_edge(struct irq_data *data)
20701 ack_APIC_irq();
20702 }
20703
20704 -atomic_t irq_mis_count;
20705 +atomic_unchecked_t irq_mis_count;
20706
20707 #ifdef CONFIG_GENERIC_PENDING_IRQ
20708 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20709 @@ -2505,7 +2505,7 @@ static void ack_apic_level(struct irq_data *data)
20710 * at the cpu.
20711 */
20712 if (!(v & (1 << (i & 0x1f)))) {
20713 - atomic_inc(&irq_mis_count);
20714 + atomic_inc_unchecked(&irq_mis_count);
20715
20716 eoi_ioapic_irq(irq, cfg);
20717 }
20718 diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20719 index cceb352..a635fd8 100644
20720 --- a/arch/x86/kernel/apic/probe_32.c
20721 +++ b/arch/x86/kernel/apic/probe_32.c
20722 @@ -72,7 +72,7 @@ static int probe_default(void)
20723 return 1;
20724 }
20725
20726 -static struct apic apic_default = {
20727 +static struct apic apic_default __read_only = {
20728
20729 .name = "default",
20730 .probe = probe_default,
20731 diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
20732 index e66766b..1c008ba 100644
20733 --- a/arch/x86/kernel/apic/x2apic_cluster.c
20734 +++ b/arch/x86/kernel/apic/x2apic_cluster.c
20735 @@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
20736 return notifier_from_errno(err);
20737 }
20738
20739 -static struct notifier_block __refdata x2apic_cpu_notifier = {
20740 +static struct notifier_block x2apic_cpu_notifier = {
20741 .notifier_call = update_clusterinfo,
20742 };
20743
20744 @@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
20745 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
20746 }
20747
20748 -static struct apic apic_x2apic_cluster = {
20749 +static struct apic apic_x2apic_cluster __read_only = {
20750
20751 .name = "cluster x2apic",
20752 .probe = x2apic_cluster_probe,
20753 diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
20754 index 6d600eb..0300c00 100644
20755 --- a/arch/x86/kernel/apic/x2apic_phys.c
20756 +++ b/arch/x86/kernel/apic/x2apic_phys.c
20757 @@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
20758 return apic == &apic_x2apic_phys;
20759 }
20760
20761 -static struct apic apic_x2apic_phys = {
20762 +static struct apic apic_x2apic_phys __read_only = {
20763
20764 .name = "physical x2apic",
20765 .probe = x2apic_phys_probe,
20766 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
20767 index 7834389..4ffc9c8 100644
20768 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
20769 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
20770 @@ -350,7 +350,7 @@ static int uv_probe(void)
20771 return apic == &apic_x2apic_uv_x;
20772 }
20773
20774 -static struct apic __refdata apic_x2apic_uv_x = {
20775 +static struct apic apic_x2apic_uv_x __read_only = {
20776
20777 .name = "UV large system",
20778 .probe = uv_probe,
20779 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
20780 index 3ab0343..814c4787 100644
20781 --- a/arch/x86/kernel/apm_32.c
20782 +++ b/arch/x86/kernel/apm_32.c
20783 @@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
20784 * This is for buggy BIOS's that refer to (real mode) segment 0x40
20785 * even though they are called in protected mode.
20786 */
20787 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
20788 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
20789 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
20790
20791 static const char driver_version[] = "1.16ac"; /* no spaces */
20792 @@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
20793 BUG_ON(cpu != 0);
20794 gdt = get_cpu_gdt_table(cpu);
20795 save_desc_40 = gdt[0x40 / 8];
20796 +
20797 + pax_open_kernel();
20798 gdt[0x40 / 8] = bad_bios_desc;
20799 + pax_close_kernel();
20800
20801 apm_irq_save(flags);
20802 APM_DO_SAVE_SEGS;
20803 @@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
20804 &call->esi);
20805 APM_DO_RESTORE_SEGS;
20806 apm_irq_restore(flags);
20807 +
20808 + pax_open_kernel();
20809 gdt[0x40 / 8] = save_desc_40;
20810 + pax_close_kernel();
20811 +
20812 put_cpu();
20813
20814 return call->eax & 0xff;
20815 @@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
20816 BUG_ON(cpu != 0);
20817 gdt = get_cpu_gdt_table(cpu);
20818 save_desc_40 = gdt[0x40 / 8];
20819 +
20820 + pax_open_kernel();
20821 gdt[0x40 / 8] = bad_bios_desc;
20822 + pax_close_kernel();
20823
20824 apm_irq_save(flags);
20825 APM_DO_SAVE_SEGS;
20826 @@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
20827 &call->eax);
20828 APM_DO_RESTORE_SEGS;
20829 apm_irq_restore(flags);
20830 +
20831 + pax_open_kernel();
20832 gdt[0x40 / 8] = save_desc_40;
20833 + pax_close_kernel();
20834 +
20835 put_cpu();
20836 return error;
20837 }
20838 @@ -2362,12 +2376,15 @@ static int __init apm_init(void)
20839 * code to that CPU.
20840 */
20841 gdt = get_cpu_gdt_table(0);
20842 +
20843 + pax_open_kernel();
20844 set_desc_base(&gdt[APM_CS >> 3],
20845 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
20846 set_desc_base(&gdt[APM_CS_16 >> 3],
20847 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
20848 set_desc_base(&gdt[APM_DS >> 3],
20849 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
20850 + pax_close_kernel();
20851
20852 proc_create("apm", 0, NULL, &apm_file_ops);
20853
20854 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
20855 index 9f6b934..cf5ffb3 100644
20856 --- a/arch/x86/kernel/asm-offsets.c
20857 +++ b/arch/x86/kernel/asm-offsets.c
20858 @@ -32,6 +32,8 @@ void common(void) {
20859 OFFSET(TI_flags, thread_info, flags);
20860 OFFSET(TI_status, thread_info, status);
20861 OFFSET(TI_addr_limit, thread_info, addr_limit);
20862 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
20863 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
20864
20865 BLANK();
20866 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
20867 @@ -52,8 +54,26 @@ void common(void) {
20868 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
20869 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
20870 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
20871 +
20872 +#ifdef CONFIG_PAX_KERNEXEC
20873 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
20874 #endif
20875
20876 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20877 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
20878 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
20879 +#ifdef CONFIG_X86_64
20880 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
20881 +#endif
20882 +#endif
20883 +
20884 +#endif
20885 +
20886 + BLANK();
20887 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
20888 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
20889 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
20890 +
20891 #ifdef CONFIG_XEN
20892 BLANK();
20893 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
20894 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
20895 index e7c798b..2b2019b 100644
20896 --- a/arch/x86/kernel/asm-offsets_64.c
20897 +++ b/arch/x86/kernel/asm-offsets_64.c
20898 @@ -77,6 +77,7 @@ int main(void)
20899 BLANK();
20900 #undef ENTRY
20901
20902 + DEFINE(TSS_size, sizeof(struct tss_struct));
20903 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
20904 BLANK();
20905
20906 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
20907 index 7fd54f0..0691410 100644
20908 --- a/arch/x86/kernel/cpu/Makefile
20909 +++ b/arch/x86/kernel/cpu/Makefile
20910 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
20911 CFLAGS_REMOVE_perf_event.o = -pg
20912 endif
20913
20914 -# Make sure load_percpu_segment has no stackprotector
20915 -nostackp := $(call cc-option, -fno-stack-protector)
20916 -CFLAGS_common.o := $(nostackp)
20917 -
20918 obj-y := intel_cacheinfo.o scattered.o topology.o
20919 obj-y += proc.o capflags.o powerflags.o common.o
20920 obj-y += rdrand.o
20921 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
20922 index ce8b8ff..d7d8851 100644
20923 --- a/arch/x86/kernel/cpu/amd.c
20924 +++ b/arch/x86/kernel/cpu/amd.c
20925 @@ -728,7 +728,7 @@ static void init_amd(struct cpuinfo_x86 *c)
20926 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
20927 {
20928 /* AMD errata T13 (order #21922) */
20929 - if ((c->x86 == 6)) {
20930 + if (c->x86 == 6) {
20931 /* Duron Rev A0 */
20932 if (c->x86_model == 3 && c->x86_mask == 0)
20933 size = 64;
20934 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
20935 index a135239..41fb30a 100644
20936 --- a/arch/x86/kernel/cpu/common.c
20937 +++ b/arch/x86/kernel/cpu/common.c
20938 @@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
20939
20940 static const struct cpu_dev *this_cpu = &default_cpu;
20941
20942 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
20943 -#ifdef CONFIG_X86_64
20944 - /*
20945 - * We need valid kernel segments for data and code in long mode too
20946 - * IRET will check the segment types kkeil 2000/10/28
20947 - * Also sysret mandates a special GDT layout
20948 - *
20949 - * TLS descriptors are currently at a different place compared to i386.
20950 - * Hopefully nobody expects them at a fixed place (Wine?)
20951 - */
20952 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
20953 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
20954 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
20955 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
20956 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
20957 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
20958 -#else
20959 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
20960 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20961 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
20962 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
20963 - /*
20964 - * Segments used for calling PnP BIOS have byte granularity.
20965 - * They code segments and data segments have fixed 64k limits,
20966 - * the transfer segment sizes are set at run time.
20967 - */
20968 - /* 32-bit code */
20969 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20970 - /* 16-bit code */
20971 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20972 - /* 16-bit data */
20973 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
20974 - /* 16-bit data */
20975 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
20976 - /* 16-bit data */
20977 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
20978 - /*
20979 - * The APM segments have byte granularity and their bases
20980 - * are set at run time. All have 64k limits.
20981 - */
20982 - /* 32-bit code */
20983 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20984 - /* 16-bit code */
20985 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20986 - /* data */
20987 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
20988 -
20989 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20990 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20991 - GDT_STACK_CANARY_INIT
20992 -#endif
20993 -} };
20994 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
20995 -
20996 static int __init x86_xsave_setup(char *s)
20997 {
20998 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
20999 @@ -293,6 +239,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
21000 }
21001 }
21002
21003 +#ifdef CONFIG_X86_64
21004 +static __init int setup_disable_pcid(char *arg)
21005 +{
21006 + setup_clear_cpu_cap(X86_FEATURE_PCID);
21007 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
21008 +
21009 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21010 + if (clone_pgd_mask != ~(pgdval_t)0UL)
21011 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21012 +#endif
21013 +
21014 + return 1;
21015 +}
21016 +__setup("nopcid", setup_disable_pcid);
21017 +
21018 +static void setup_pcid(struct cpuinfo_x86 *c)
21019 +{
21020 + if (!cpu_has(c, X86_FEATURE_PCID)) {
21021 + clear_cpu_cap(c, X86_FEATURE_INVPCID);
21022 +
21023 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21024 + if (clone_pgd_mask != ~(pgdval_t)0UL) {
21025 + pax_open_kernel();
21026 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21027 + pax_close_kernel();
21028 + printk("PAX: slow and weak UDEREF enabled\n");
21029 + } else
21030 + printk("PAX: UDEREF disabled\n");
21031 +#endif
21032 +
21033 + return;
21034 + }
21035 +
21036 + printk("PAX: PCID detected\n");
21037 + set_in_cr4(X86_CR4_PCIDE);
21038 +
21039 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21040 + pax_open_kernel();
21041 + clone_pgd_mask = ~(pgdval_t)0UL;
21042 + pax_close_kernel();
21043 + if (pax_user_shadow_base)
21044 + printk("PAX: weak UDEREF enabled\n");
21045 + else {
21046 + set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
21047 + printk("PAX: strong UDEREF enabled\n");
21048 + }
21049 +#endif
21050 +
21051 + if (cpu_has(c, X86_FEATURE_INVPCID))
21052 + printk("PAX: INVPCID detected\n");
21053 +}
21054 +#endif
21055 +
21056 /*
21057 * Some CPU features depend on higher CPUID levels, which may not always
21058 * be available due to CPUID level capping or broken virtualization
21059 @@ -393,7 +392,7 @@ void switch_to_new_gdt(int cpu)
21060 {
21061 struct desc_ptr gdt_descr;
21062
21063 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
21064 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
21065 gdt_descr.size = GDT_SIZE - 1;
21066 load_gdt(&gdt_descr);
21067 /* Reload the per-cpu base */
21068 @@ -883,6 +882,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21069 setup_smep(c);
21070 setup_smap(c);
21071
21072 +#ifdef CONFIG_X86_64
21073 + setup_pcid(c);
21074 +#endif
21075 +
21076 /*
21077 * The vendor-specific functions might have changed features.
21078 * Now we do "generic changes."
21079 @@ -891,6 +894,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21080 /* Filter out anything that depends on CPUID levels we don't have */
21081 filter_cpuid_features(c, true);
21082
21083 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
21084 + setup_clear_cpu_cap(X86_FEATURE_SEP);
21085 +#endif
21086 +
21087 /* If the model name is still unset, do table lookup. */
21088 if (!c->x86_model_id[0]) {
21089 const char *p;
21090 @@ -1079,14 +1086,16 @@ static __init int setup_disablecpuid(char *arg)
21091 }
21092 __setup("clearcpuid=", setup_disablecpuid);
21093
21094 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
21095 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
21096 +
21097 DEFINE_PER_CPU(unsigned long, kernel_stack) =
21098 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
21099 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
21100 EXPORT_PER_CPU_SYMBOL(kernel_stack);
21101
21102 #ifdef CONFIG_X86_64
21103 -struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21104 -struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
21105 - (unsigned long) debug_idt_table };
21106 +struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21107 +const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
21108
21109 DEFINE_PER_CPU_FIRST(union irq_stack_union,
21110 irq_stack_union) __aligned(PAGE_SIZE) __visible;
21111 @@ -1246,7 +1255,7 @@ void cpu_init(void)
21112 load_ucode_ap();
21113
21114 cpu = stack_smp_processor_id();
21115 - t = &per_cpu(init_tss, cpu);
21116 + t = init_tss + cpu;
21117 oist = &per_cpu(orig_ist, cpu);
21118
21119 #ifdef CONFIG_NUMA
21120 @@ -1281,7 +1290,6 @@ void cpu_init(void)
21121 wrmsrl(MSR_KERNEL_GS_BASE, 0);
21122 barrier();
21123
21124 - x86_configure_nx();
21125 enable_x2apic();
21126
21127 /*
21128 @@ -1333,7 +1341,7 @@ void cpu_init(void)
21129 {
21130 int cpu = smp_processor_id();
21131 struct task_struct *curr = current;
21132 - struct tss_struct *t = &per_cpu(init_tss, cpu);
21133 + struct tss_struct *t = init_tss + cpu;
21134 struct thread_struct *thread = &curr->thread;
21135
21136 show_ucode_info_early();
21137 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
21138 index a952e9c..58a4cbb 100644
21139 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
21140 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
21141 @@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
21142 };
21143
21144 #ifdef CONFIG_AMD_NB
21145 +static struct attribute *default_attrs_amd_nb[] = {
21146 + &type.attr,
21147 + &level.attr,
21148 + &coherency_line_size.attr,
21149 + &physical_line_partition.attr,
21150 + &ways_of_associativity.attr,
21151 + &number_of_sets.attr,
21152 + &size.attr,
21153 + &shared_cpu_map.attr,
21154 + &shared_cpu_list.attr,
21155 + NULL,
21156 + NULL,
21157 + NULL,
21158 + NULL
21159 +};
21160 +
21161 static struct attribute **amd_l3_attrs(void)
21162 {
21163 static struct attribute **attrs;
21164 @@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
21165
21166 n = ARRAY_SIZE(default_attrs);
21167
21168 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21169 - n += 2;
21170 -
21171 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21172 - n += 1;
21173 -
21174 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21175 - if (attrs == NULL)
21176 - return attrs = default_attrs;
21177 -
21178 - for (n = 0; default_attrs[n]; n++)
21179 - attrs[n] = default_attrs[n];
21180 + attrs = default_attrs_amd_nb;
21181
21182 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21183 attrs[n++] = &cache_disable_0.attr;
21184 @@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
21185 .default_attrs = default_attrs,
21186 };
21187
21188 +#ifdef CONFIG_AMD_NB
21189 +static struct kobj_type ktype_cache_amd_nb = {
21190 + .sysfs_ops = &sysfs_ops,
21191 + .default_attrs = default_attrs_amd_nb,
21192 +};
21193 +#endif
21194 +
21195 static struct kobj_type ktype_percpu_entry = {
21196 .sysfs_ops = &sysfs_ops,
21197 };
21198 @@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
21199 return retval;
21200 }
21201
21202 +#ifdef CONFIG_AMD_NB
21203 + amd_l3_attrs();
21204 +#endif
21205 +
21206 for (i = 0; i < num_cache_leaves; i++) {
21207 + struct kobj_type *ktype;
21208 +
21209 this_object = INDEX_KOBJECT_PTR(cpu, i);
21210 this_object->cpu = cpu;
21211 this_object->index = i;
21212
21213 this_leaf = CPUID4_INFO_IDX(cpu, i);
21214
21215 - ktype_cache.default_attrs = default_attrs;
21216 + ktype = &ktype_cache;
21217 #ifdef CONFIG_AMD_NB
21218 if (this_leaf->base.nb)
21219 - ktype_cache.default_attrs = amd_l3_attrs();
21220 + ktype = &ktype_cache_amd_nb;
21221 #endif
21222 retval = kobject_init_and_add(&(this_object->kobj),
21223 - &ktype_cache,
21224 + ktype,
21225 per_cpu(ici_cache_kobject, cpu),
21226 "index%1lu", i);
21227 if (unlikely(retval)) {
21228 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21229 index 68317c8..c860d41 100644
21230 --- a/arch/x86/kernel/cpu/mcheck/mce.c
21231 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
21232 @@ -45,6 +45,7 @@
21233 #include <asm/processor.h>
21234 #include <asm/mce.h>
21235 #include <asm/msr.h>
21236 +#include <asm/local.h>
21237
21238 #include "mce-internal.h"
21239
21240 @@ -261,7 +262,7 @@ static void print_mce(struct mce *m)
21241 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21242 m->cs, m->ip);
21243
21244 - if (m->cs == __KERNEL_CS)
21245 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21246 print_symbol("{%s}", m->ip);
21247 pr_cont("\n");
21248 }
21249 @@ -294,10 +295,10 @@ static void print_mce(struct mce *m)
21250
21251 #define PANIC_TIMEOUT 5 /* 5 seconds */
21252
21253 -static atomic_t mce_paniced;
21254 +static atomic_unchecked_t mce_paniced;
21255
21256 static int fake_panic;
21257 -static atomic_t mce_fake_paniced;
21258 +static atomic_unchecked_t mce_fake_paniced;
21259
21260 /* Panic in progress. Enable interrupts and wait for final IPI */
21261 static void wait_for_panic(void)
21262 @@ -321,7 +322,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21263 /*
21264 * Make sure only one CPU runs in machine check panic
21265 */
21266 - if (atomic_inc_return(&mce_paniced) > 1)
21267 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21268 wait_for_panic();
21269 barrier();
21270
21271 @@ -329,7 +330,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21272 console_verbose();
21273 } else {
21274 /* Don't log too much for fake panic */
21275 - if (atomic_inc_return(&mce_fake_paniced) > 1)
21276 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21277 return;
21278 }
21279 /* First print corrected ones that are still unlogged */
21280 @@ -368,7 +369,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21281 if (!fake_panic) {
21282 if (panic_timeout == 0)
21283 panic_timeout = mca_cfg.panic_timeout;
21284 - panic(msg);
21285 + panic("%s", msg);
21286 } else
21287 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21288 }
21289 @@ -699,7 +700,7 @@ static int mce_timed_out(u64 *t)
21290 * might have been modified by someone else.
21291 */
21292 rmb();
21293 - if (atomic_read(&mce_paniced))
21294 + if (atomic_read_unchecked(&mce_paniced))
21295 wait_for_panic();
21296 if (!mca_cfg.monarch_timeout)
21297 goto out;
21298 @@ -1680,7 +1681,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21299 }
21300
21301 /* Call the installed machine check handler for this CPU setup. */
21302 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
21303 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21304 unexpected_machine_check;
21305
21306 /*
21307 @@ -1703,7 +1704,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21308 return;
21309 }
21310
21311 + pax_open_kernel();
21312 machine_check_vector = do_machine_check;
21313 + pax_close_kernel();
21314
21315 __mcheck_cpu_init_generic();
21316 __mcheck_cpu_init_vendor(c);
21317 @@ -1717,7 +1720,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21318 */
21319
21320 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21321 -static int mce_chrdev_open_count; /* #times opened */
21322 +static local_t mce_chrdev_open_count; /* #times opened */
21323 static int mce_chrdev_open_exclu; /* already open exclusive? */
21324
21325 static int mce_chrdev_open(struct inode *inode, struct file *file)
21326 @@ -1725,7 +1728,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21327 spin_lock(&mce_chrdev_state_lock);
21328
21329 if (mce_chrdev_open_exclu ||
21330 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21331 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21332 spin_unlock(&mce_chrdev_state_lock);
21333
21334 return -EBUSY;
21335 @@ -1733,7 +1736,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21336
21337 if (file->f_flags & O_EXCL)
21338 mce_chrdev_open_exclu = 1;
21339 - mce_chrdev_open_count++;
21340 + local_inc(&mce_chrdev_open_count);
21341
21342 spin_unlock(&mce_chrdev_state_lock);
21343
21344 @@ -1744,7 +1747,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21345 {
21346 spin_lock(&mce_chrdev_state_lock);
21347
21348 - mce_chrdev_open_count--;
21349 + local_dec(&mce_chrdev_open_count);
21350 mce_chrdev_open_exclu = 0;
21351
21352 spin_unlock(&mce_chrdev_state_lock);
21353 @@ -2420,7 +2423,7 @@ static __init void mce_init_banks(void)
21354
21355 for (i = 0; i < mca_cfg.banks; i++) {
21356 struct mce_bank *b = &mce_banks[i];
21357 - struct device_attribute *a = &b->attr;
21358 + device_attribute_no_const *a = &b->attr;
21359
21360 sysfs_attr_init(&a->attr);
21361 a->attr.name = b->attrname;
21362 @@ -2492,7 +2495,7 @@ struct dentry *mce_get_debugfs_dir(void)
21363 static void mce_reset(void)
21364 {
21365 cpu_missing = 0;
21366 - atomic_set(&mce_fake_paniced, 0);
21367 + atomic_set_unchecked(&mce_fake_paniced, 0);
21368 atomic_set(&mce_executing, 0);
21369 atomic_set(&mce_callin, 0);
21370 atomic_set(&global_nwo, 0);
21371 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21372 index a304298..49b6d06 100644
21373 --- a/arch/x86/kernel/cpu/mcheck/p5.c
21374 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
21375 @@ -10,6 +10,7 @@
21376 #include <asm/processor.h>
21377 #include <asm/mce.h>
21378 #include <asm/msr.h>
21379 +#include <asm/pgtable.h>
21380
21381 /* By default disabled */
21382 int mce_p5_enabled __read_mostly;
21383 @@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21384 if (!cpu_has(c, X86_FEATURE_MCE))
21385 return;
21386
21387 + pax_open_kernel();
21388 machine_check_vector = pentium_machine_check;
21389 + pax_close_kernel();
21390 /* Make sure the vector pointer is visible before we enable MCEs: */
21391 wmb();
21392
21393 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21394 index 7dc5564..1273569 100644
21395 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
21396 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21397 @@ -9,6 +9,7 @@
21398 #include <asm/processor.h>
21399 #include <asm/mce.h>
21400 #include <asm/msr.h>
21401 +#include <asm/pgtable.h>
21402
21403 /* Machine check handler for WinChip C6: */
21404 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21405 @@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21406 {
21407 u32 lo, hi;
21408
21409 + pax_open_kernel();
21410 machine_check_vector = winchip_machine_check;
21411 + pax_close_kernel();
21412 /* Make sure the vector pointer is visible before we enable MCEs: */
21413 wmb();
21414
21415 diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
21416 index 15c9876..0a43909 100644
21417 --- a/arch/x86/kernel/cpu/microcode/core.c
21418 +++ b/arch/x86/kernel/cpu/microcode/core.c
21419 @@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21420 return NOTIFY_OK;
21421 }
21422
21423 -static struct notifier_block __refdata mc_cpu_notifier = {
21424 +static struct notifier_block mc_cpu_notifier = {
21425 .notifier_call = mc_cpu_callback,
21426 };
21427
21428 diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
21429 index a276fa7..e66810f 100644
21430 --- a/arch/x86/kernel/cpu/microcode/intel.c
21431 +++ b/arch/x86/kernel/cpu/microcode/intel.c
21432 @@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21433
21434 static int get_ucode_user(void *to, const void *from, size_t n)
21435 {
21436 - return copy_from_user(to, from, n);
21437 + return copy_from_user(to, (const void __force_user *)from, n);
21438 }
21439
21440 static enum ucode_state
21441 request_microcode_user(int cpu, const void __user *buf, size_t size)
21442 {
21443 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21444 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21445 }
21446
21447 static void microcode_fini_cpu(int cpu)
21448 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21449 index f961de9..8a9d332 100644
21450 --- a/arch/x86/kernel/cpu/mtrr/main.c
21451 +++ b/arch/x86/kernel/cpu/mtrr/main.c
21452 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21453 u64 size_or_mask, size_and_mask;
21454 static bool mtrr_aps_delayed_init;
21455
21456 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21457 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21458
21459 const struct mtrr_ops *mtrr_if;
21460
21461 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21462 index df5e41f..816c719 100644
21463 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21464 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21465 @@ -25,7 +25,7 @@ struct mtrr_ops {
21466 int (*validate_add_page)(unsigned long base, unsigned long size,
21467 unsigned int type);
21468 int (*have_wrcomb)(void);
21469 -};
21470 +} __do_const;
21471
21472 extern int generic_get_free_region(unsigned long base, unsigned long size,
21473 int replace_reg);
21474 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21475 index ae407f7..39c5b00 100644
21476 --- a/arch/x86/kernel/cpu/perf_event.c
21477 +++ b/arch/x86/kernel/cpu/perf_event.c
21478 @@ -1367,7 +1367,7 @@ static void __init pmu_check_apic(void)
21479 pr_info("no hardware sampling interrupt available.\n");
21480 }
21481
21482 -static struct attribute_group x86_pmu_format_group = {
21483 +static attribute_group_no_const x86_pmu_format_group = {
21484 .name = "format",
21485 .attrs = NULL,
21486 };
21487 @@ -1466,7 +1466,7 @@ static struct attribute *events_attr[] = {
21488 NULL,
21489 };
21490
21491 -static struct attribute_group x86_pmu_events_group = {
21492 +static attribute_group_no_const x86_pmu_events_group = {
21493 .name = "events",
21494 .attrs = events_attr,
21495 };
21496 @@ -1990,7 +1990,7 @@ static unsigned long get_segment_base(unsigned int segment)
21497 if (idx > GDT_ENTRIES)
21498 return 0;
21499
21500 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
21501 + desc = get_cpu_gdt_table(smp_processor_id());
21502 }
21503
21504 return get_desc_base(desc + idx);
21505 @@ -2080,7 +2080,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
21506 break;
21507
21508 perf_callchain_store(entry, frame.return_address);
21509 - fp = frame.next_frame;
21510 + fp = (const void __force_user *)frame.next_frame;
21511 }
21512 }
21513
21514 diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21515 index 639d128..e92d7e5 100644
21516 --- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21517 +++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21518 @@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
21519 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
21520 {
21521 struct attribute **attrs;
21522 - struct attribute_group *attr_group;
21523 + attribute_group_no_const *attr_group;
21524 int i = 0, j;
21525
21526 while (amd_iommu_v2_event_descs[i].attr.attr.name)
21527 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
21528 index 07846d7..a40ec4a 100644
21529 --- a/arch/x86/kernel/cpu/perf_event_intel.c
21530 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
21531 @@ -2317,10 +2317,10 @@ __init int intel_pmu_init(void)
21532 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
21533
21534 if (boot_cpu_has(X86_FEATURE_PDCM)) {
21535 - u64 capabilities;
21536 + u64 capabilities = x86_pmu.intel_cap.capabilities;
21537
21538 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
21539 - x86_pmu.intel_cap.capabilities = capabilities;
21540 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
21541 + x86_pmu.intel_cap.capabilities = capabilities;
21542 }
21543
21544 intel_ds_init();
21545 diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21546 index 619f769..d510008 100644
21547 --- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21548 +++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21549 @@ -449,7 +449,7 @@ static struct attribute *rapl_events_hsw_attr[] = {
21550 NULL,
21551 };
21552
21553 -static struct attribute_group rapl_pmu_events_group = {
21554 +static attribute_group_no_const rapl_pmu_events_group __read_only = {
21555 .name = "events",
21556 .attrs = NULL, /* patched at runtime */
21557 };
21558 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21559 index 65bbbea..1438d9e 100644
21560 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21561 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21562 @@ -3693,7 +3693,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
21563 static int __init uncore_type_init(struct intel_uncore_type *type)
21564 {
21565 struct intel_uncore_pmu *pmus;
21566 - struct attribute_group *attr_group;
21567 + attribute_group_no_const *attr_group;
21568 struct attribute **attrs;
21569 int i, j;
21570
21571 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21572 index 90236f0..54cb20d 100644
21573 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21574 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21575 @@ -503,7 +503,7 @@ struct intel_uncore_box {
21576 struct uncore_event_desc {
21577 struct kobj_attribute attr;
21578 const char *config;
21579 -};
21580 +} __do_const;
21581
21582 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
21583 { \
21584 diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
21585 index 3225ae6c..ee3c6db 100644
21586 --- a/arch/x86/kernel/cpuid.c
21587 +++ b/arch/x86/kernel/cpuid.c
21588 @@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
21589 return notifier_from_errno(err);
21590 }
21591
21592 -static struct notifier_block __refdata cpuid_class_cpu_notifier =
21593 +static struct notifier_block cpuid_class_cpu_notifier =
21594 {
21595 .notifier_call = cpuid_class_cpu_callback,
21596 };
21597 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
21598 index 507de80..ebaae2a 100644
21599 --- a/arch/x86/kernel/crash.c
21600 +++ b/arch/x86/kernel/crash.c
21601 @@ -58,7 +58,7 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
21602 #ifdef CONFIG_X86_32
21603 struct pt_regs fixed_regs;
21604
21605 - if (!user_mode_vm(regs)) {
21606 + if (!user_mode(regs)) {
21607 crash_fixup_ss_esp(&fixed_regs, regs);
21608 regs = &fixed_regs;
21609 }
21610 diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
21611 index afa64ad..dce67dd 100644
21612 --- a/arch/x86/kernel/crash_dump_64.c
21613 +++ b/arch/x86/kernel/crash_dump_64.c
21614 @@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
21615 return -ENOMEM;
21616
21617 if (userbuf) {
21618 - if (copy_to_user(buf, vaddr + offset, csize)) {
21619 + if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
21620 iounmap(vaddr);
21621 return -EFAULT;
21622 }
21623 diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
21624 index f6dfd93..892ade4 100644
21625 --- a/arch/x86/kernel/doublefault.c
21626 +++ b/arch/x86/kernel/doublefault.c
21627 @@ -12,7 +12,7 @@
21628
21629 #define DOUBLEFAULT_STACKSIZE (1024)
21630 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
21631 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
21632 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
21633
21634 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
21635
21636 @@ -22,7 +22,7 @@ static void doublefault_fn(void)
21637 unsigned long gdt, tss;
21638
21639 native_store_gdt(&gdt_desc);
21640 - gdt = gdt_desc.address;
21641 + gdt = (unsigned long)gdt_desc.address;
21642
21643 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
21644
21645 @@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
21646 /* 0x2 bit is always set */
21647 .flags = X86_EFLAGS_SF | 0x2,
21648 .sp = STACK_START,
21649 - .es = __USER_DS,
21650 + .es = __KERNEL_DS,
21651 .cs = __KERNEL_CS,
21652 .ss = __KERNEL_DS,
21653 - .ds = __USER_DS,
21654 + .ds = __KERNEL_DS,
21655 .fs = __KERNEL_PERCPU,
21656
21657 .__cr3 = __pa_nodebug(swapper_pg_dir),
21658 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
21659 index d9c12d3..7858b62 100644
21660 --- a/arch/x86/kernel/dumpstack.c
21661 +++ b/arch/x86/kernel/dumpstack.c
21662 @@ -2,6 +2,9 @@
21663 * Copyright (C) 1991, 1992 Linus Torvalds
21664 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
21665 */
21666 +#ifdef CONFIG_GRKERNSEC_HIDESYM
21667 +#define __INCLUDED_BY_HIDESYM 1
21668 +#endif
21669 #include <linux/kallsyms.h>
21670 #include <linux/kprobes.h>
21671 #include <linux/uaccess.h>
21672 @@ -40,16 +43,14 @@ void printk_address(unsigned long address)
21673 static void
21674 print_ftrace_graph_addr(unsigned long addr, void *data,
21675 const struct stacktrace_ops *ops,
21676 - struct thread_info *tinfo, int *graph)
21677 + struct task_struct *task, int *graph)
21678 {
21679 - struct task_struct *task;
21680 unsigned long ret_addr;
21681 int index;
21682
21683 if (addr != (unsigned long)return_to_handler)
21684 return;
21685
21686 - task = tinfo->task;
21687 index = task->curr_ret_stack;
21688
21689 if (!task->ret_stack || index < *graph)
21690 @@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21691 static inline void
21692 print_ftrace_graph_addr(unsigned long addr, void *data,
21693 const struct stacktrace_ops *ops,
21694 - struct thread_info *tinfo, int *graph)
21695 + struct task_struct *task, int *graph)
21696 { }
21697 #endif
21698
21699 @@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21700 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
21701 */
21702
21703 -static inline int valid_stack_ptr(struct thread_info *tinfo,
21704 - void *p, unsigned int size, void *end)
21705 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21706 {
21707 - void *t = tinfo;
21708 if (end) {
21709 if (p < end && p >= (end-THREAD_SIZE))
21710 return 1;
21711 @@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21712 }
21713
21714 unsigned long
21715 -print_context_stack(struct thread_info *tinfo,
21716 +print_context_stack(struct task_struct *task, void *stack_start,
21717 unsigned long *stack, unsigned long bp,
21718 const struct stacktrace_ops *ops, void *data,
21719 unsigned long *end, int *graph)
21720 {
21721 struct stack_frame *frame = (struct stack_frame *)bp;
21722
21723 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
21724 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
21725 unsigned long addr;
21726
21727 addr = *stack;
21728 @@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
21729 } else {
21730 ops->address(data, addr, 0);
21731 }
21732 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21733 + print_ftrace_graph_addr(addr, data, ops, task, graph);
21734 }
21735 stack++;
21736 }
21737 @@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
21738 EXPORT_SYMBOL_GPL(print_context_stack);
21739
21740 unsigned long
21741 -print_context_stack_bp(struct thread_info *tinfo,
21742 +print_context_stack_bp(struct task_struct *task, void *stack_start,
21743 unsigned long *stack, unsigned long bp,
21744 const struct stacktrace_ops *ops, void *data,
21745 unsigned long *end, int *graph)
21746 @@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21747 struct stack_frame *frame = (struct stack_frame *)bp;
21748 unsigned long *ret_addr = &frame->return_address;
21749
21750 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
21751 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
21752 unsigned long addr = *ret_addr;
21753
21754 if (!__kernel_text_address(addr))
21755 @@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21756 ops->address(data, addr, 1);
21757 frame = frame->next_frame;
21758 ret_addr = &frame->return_address;
21759 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21760 + print_ftrace_graph_addr(addr, data, ops, task, graph);
21761 }
21762
21763 return (unsigned long)frame;
21764 @@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
21765 static void print_trace_address(void *data, unsigned long addr, int reliable)
21766 {
21767 touch_nmi_watchdog();
21768 - printk(data);
21769 + printk("%s", (char *)data);
21770 printk_stack_address(addr, reliable);
21771 }
21772
21773 @@ -224,6 +223,8 @@ unsigned __kprobes long oops_begin(void)
21774 }
21775 EXPORT_SYMBOL_GPL(oops_begin);
21776
21777 +extern void gr_handle_kernel_exploit(void);
21778 +
21779 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21780 {
21781 if (regs && kexec_should_crash(current))
21782 @@ -245,7 +246,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21783 panic("Fatal exception in interrupt");
21784 if (panic_on_oops)
21785 panic("Fatal exception");
21786 - do_exit(signr);
21787 +
21788 + gr_handle_kernel_exploit();
21789 +
21790 + do_group_exit(signr);
21791 }
21792
21793 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21794 @@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21795 print_modules();
21796 show_regs(regs);
21797 #ifdef CONFIG_X86_32
21798 - if (user_mode_vm(regs)) {
21799 + if (user_mode(regs)) {
21800 sp = regs->sp;
21801 ss = regs->ss & 0xffff;
21802 } else {
21803 @@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
21804 unsigned long flags = oops_begin();
21805 int sig = SIGSEGV;
21806
21807 - if (!user_mode_vm(regs))
21808 + if (!user_mode(regs))
21809 report_bug(regs->ip, regs);
21810
21811 if (__die(str, regs, err))
21812 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
21813 index 5abd4cd..c65733b 100644
21814 --- a/arch/x86/kernel/dumpstack_32.c
21815 +++ b/arch/x86/kernel/dumpstack_32.c
21816 @@ -61,15 +61,14 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21817 bp = stack_frame(task, regs);
21818
21819 for (;;) {
21820 - struct thread_info *context;
21821 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21822 void *end_stack;
21823
21824 end_stack = is_hardirq_stack(stack, cpu);
21825 if (!end_stack)
21826 end_stack = is_softirq_stack(stack, cpu);
21827
21828 - context = task_thread_info(task);
21829 - bp = ops->walk_stack(context, stack, bp, ops, data,
21830 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data,
21831 end_stack, &graph);
21832
21833 /* Stop if not on irq stack */
21834 @@ -123,27 +122,28 @@ void show_regs(struct pt_regs *regs)
21835 int i;
21836
21837 show_regs_print_info(KERN_EMERG);
21838 - __show_regs(regs, !user_mode_vm(regs));
21839 + __show_regs(regs, !user_mode(regs));
21840
21841 /*
21842 * When in-kernel, we also print out the stack and code at the
21843 * time of the fault..
21844 */
21845 - if (!user_mode_vm(regs)) {
21846 + if (!user_mode(regs)) {
21847 unsigned int code_prologue = code_bytes * 43 / 64;
21848 unsigned int code_len = code_bytes;
21849 unsigned char c;
21850 u8 *ip;
21851 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
21852
21853 pr_emerg("Stack:\n");
21854 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
21855
21856 pr_emerg("Code:");
21857
21858 - ip = (u8 *)regs->ip - code_prologue;
21859 + ip = (u8 *)regs->ip - code_prologue + cs_base;
21860 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
21861 /* try starting at IP */
21862 - ip = (u8 *)regs->ip;
21863 + ip = (u8 *)regs->ip + cs_base;
21864 code_len = code_len - code_prologue + 1;
21865 }
21866 for (i = 0; i < code_len; i++, ip++) {
21867 @@ -152,7 +152,7 @@ void show_regs(struct pt_regs *regs)
21868 pr_cont(" Bad EIP value.");
21869 break;
21870 }
21871 - if (ip == (u8 *)regs->ip)
21872 + if (ip == (u8 *)regs->ip + cs_base)
21873 pr_cont(" <%02x>", c);
21874 else
21875 pr_cont(" %02x", c);
21876 @@ -165,6 +165,7 @@ int is_valid_bugaddr(unsigned long ip)
21877 {
21878 unsigned short ud2;
21879
21880 + ip = ktla_ktva(ip);
21881 if (ip < PAGE_OFFSET)
21882 return 0;
21883 if (probe_kernel_address((unsigned short *)ip, ud2))
21884 @@ -172,3 +173,15 @@ int is_valid_bugaddr(unsigned long ip)
21885
21886 return ud2 == 0x0b0f;
21887 }
21888 +
21889 +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
21890 +void pax_check_alloca(unsigned long size)
21891 +{
21892 + unsigned long sp = (unsigned long)&sp, stack_left;
21893 +
21894 + /* all kernel stacks are of the same size */
21895 + stack_left = sp & (THREAD_SIZE - 1);
21896 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21897 +}
21898 +EXPORT_SYMBOL(pax_check_alloca);
21899 +#endif
21900 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
21901 index 1abcb50..6c8d702 100644
21902 --- a/arch/x86/kernel/dumpstack_64.c
21903 +++ b/arch/x86/kernel/dumpstack_64.c
21904 @@ -154,12 +154,12 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21905 const struct stacktrace_ops *ops, void *data)
21906 {
21907 const unsigned cpu = get_cpu();
21908 - struct thread_info *tinfo;
21909 unsigned long *irq_stack = (unsigned long *)per_cpu(irq_stack_ptr, cpu);
21910 unsigned long dummy;
21911 unsigned used = 0;
21912 int graph = 0;
21913 int done = 0;
21914 + void *stack_start;
21915
21916 if (!task)
21917 task = current;
21918 @@ -180,7 +180,6 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21919 * current stack address. If the stacks consist of nested
21920 * exceptions
21921 */
21922 - tinfo = task_thread_info(task);
21923 while (!done) {
21924 unsigned long *stack_end;
21925 enum stack_type stype;
21926 @@ -203,7 +202,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21927 if (ops->stack(data, id) < 0)
21928 break;
21929
21930 - bp = ops->walk_stack(tinfo, stack, bp, ops,
21931 + bp = ops->walk_stack(task, stack_end - EXCEPTION_STKSZ, stack, bp, ops,
21932 data, stack_end, &graph);
21933 ops->stack(data, "<EOE>");
21934 /*
21935 @@ -211,6 +210,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21936 * second-to-last pointer (index -2 to end) in the
21937 * exception stack:
21938 */
21939 + if ((u16)stack_end[-1] != __KERNEL_DS)
21940 + goto out;
21941 stack = (unsigned long *) stack_end[-2];
21942 done = 0;
21943 break;
21944 @@ -219,7 +220,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21945
21946 if (ops->stack(data, "IRQ") < 0)
21947 break;
21948 - bp = ops->walk_stack(tinfo, stack, bp,
21949 + bp = ops->walk_stack(task, irq_stack, stack, bp,
21950 ops, data, stack_end, &graph);
21951 /*
21952 * We link to the next stack (which would be
21953 @@ -241,7 +242,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21954 /*
21955 * This handles the process stack:
21956 */
21957 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
21958 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21959 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21960 +out:
21961 put_cpu();
21962 }
21963 EXPORT_SYMBOL(dump_trace);
21964 @@ -350,3 +353,50 @@ int is_valid_bugaddr(unsigned long ip)
21965
21966 return ud2 == 0x0b0f;
21967 }
21968 +
21969 +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
21970 +void pax_check_alloca(unsigned long size)
21971 +{
21972 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
21973 + unsigned cpu, used;
21974 + char *id;
21975 +
21976 + /* check the process stack first */
21977 + stack_start = (unsigned long)task_stack_page(current);
21978 + stack_end = stack_start + THREAD_SIZE;
21979 + if (likely(stack_start <= sp && sp < stack_end)) {
21980 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
21981 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21982 + return;
21983 + }
21984 +
21985 + cpu = get_cpu();
21986 +
21987 + /* check the irq stacks */
21988 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
21989 + stack_start = stack_end - IRQ_STACK_SIZE;
21990 + if (stack_start <= sp && sp < stack_end) {
21991 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
21992 + put_cpu();
21993 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21994 + return;
21995 + }
21996 +
21997 + /* check the exception stacks */
21998 + used = 0;
21999 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
22000 + stack_start = stack_end - EXCEPTION_STKSZ;
22001 + if (stack_end && stack_start <= sp && sp < stack_end) {
22002 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
22003 + put_cpu();
22004 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22005 + return;
22006 + }
22007 +
22008 + put_cpu();
22009 +
22010 + /* unknown stack */
22011 + BUG();
22012 +}
22013 +EXPORT_SYMBOL(pax_check_alloca);
22014 +#endif
22015 diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
22016 index 988c00a..4f673b6 100644
22017 --- a/arch/x86/kernel/e820.c
22018 +++ b/arch/x86/kernel/e820.c
22019 @@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
22020
22021 static void early_panic(char *msg)
22022 {
22023 - early_printk(msg);
22024 - panic(msg);
22025 + early_printk("%s", msg);
22026 + panic("%s", msg);
22027 }
22028
22029 static int userdef __initdata;
22030 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
22031 index 01d1c18..8073693 100644
22032 --- a/arch/x86/kernel/early_printk.c
22033 +++ b/arch/x86/kernel/early_printk.c
22034 @@ -7,6 +7,7 @@
22035 #include <linux/pci_regs.h>
22036 #include <linux/pci_ids.h>
22037 #include <linux/errno.h>
22038 +#include <linux/sched.h>
22039 #include <asm/io.h>
22040 #include <asm/processor.h>
22041 #include <asm/fcntl.h>
22042 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
22043 index c5a9cb9..228d280 100644
22044 --- a/arch/x86/kernel/entry_32.S
22045 +++ b/arch/x86/kernel/entry_32.S
22046 @@ -177,13 +177,153 @@
22047 /*CFI_REL_OFFSET gs, PT_GS*/
22048 .endm
22049 .macro SET_KERNEL_GS reg
22050 +
22051 +#ifdef CONFIG_CC_STACKPROTECTOR
22052 movl $(__KERNEL_STACK_CANARY), \reg
22053 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22054 + movl $(__USER_DS), \reg
22055 +#else
22056 + xorl \reg, \reg
22057 +#endif
22058 +
22059 movl \reg, %gs
22060 .endm
22061
22062 #endif /* CONFIG_X86_32_LAZY_GS */
22063
22064 -.macro SAVE_ALL
22065 +.macro pax_enter_kernel
22066 +#ifdef CONFIG_PAX_KERNEXEC
22067 + call pax_enter_kernel
22068 +#endif
22069 +.endm
22070 +
22071 +.macro pax_exit_kernel
22072 +#ifdef CONFIG_PAX_KERNEXEC
22073 + call pax_exit_kernel
22074 +#endif
22075 +.endm
22076 +
22077 +#ifdef CONFIG_PAX_KERNEXEC
22078 +ENTRY(pax_enter_kernel)
22079 +#ifdef CONFIG_PARAVIRT
22080 + pushl %eax
22081 + pushl %ecx
22082 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
22083 + mov %eax, %esi
22084 +#else
22085 + mov %cr0, %esi
22086 +#endif
22087 + bts $16, %esi
22088 + jnc 1f
22089 + mov %cs, %esi
22090 + cmp $__KERNEL_CS, %esi
22091 + jz 3f
22092 + ljmp $__KERNEL_CS, $3f
22093 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
22094 +2:
22095 +#ifdef CONFIG_PARAVIRT
22096 + mov %esi, %eax
22097 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
22098 +#else
22099 + mov %esi, %cr0
22100 +#endif
22101 +3:
22102 +#ifdef CONFIG_PARAVIRT
22103 + popl %ecx
22104 + popl %eax
22105 +#endif
22106 + ret
22107 +ENDPROC(pax_enter_kernel)
22108 +
22109 +ENTRY(pax_exit_kernel)
22110 +#ifdef CONFIG_PARAVIRT
22111 + pushl %eax
22112 + pushl %ecx
22113 +#endif
22114 + mov %cs, %esi
22115 + cmp $__KERNEXEC_KERNEL_CS, %esi
22116 + jnz 2f
22117 +#ifdef CONFIG_PARAVIRT
22118 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
22119 + mov %eax, %esi
22120 +#else
22121 + mov %cr0, %esi
22122 +#endif
22123 + btr $16, %esi
22124 + ljmp $__KERNEL_CS, $1f
22125 +1:
22126 +#ifdef CONFIG_PARAVIRT
22127 + mov %esi, %eax
22128 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
22129 +#else
22130 + mov %esi, %cr0
22131 +#endif
22132 +2:
22133 +#ifdef CONFIG_PARAVIRT
22134 + popl %ecx
22135 + popl %eax
22136 +#endif
22137 + ret
22138 +ENDPROC(pax_exit_kernel)
22139 +#endif
22140 +
22141 + .macro pax_erase_kstack
22142 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22143 + call pax_erase_kstack
22144 +#endif
22145 + .endm
22146 +
22147 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22148 +/*
22149 + * ebp: thread_info
22150 + */
22151 +ENTRY(pax_erase_kstack)
22152 + pushl %edi
22153 + pushl %ecx
22154 + pushl %eax
22155 +
22156 + mov TI_lowest_stack(%ebp), %edi
22157 + mov $-0xBEEF, %eax
22158 + std
22159 +
22160 +1: mov %edi, %ecx
22161 + and $THREAD_SIZE_asm - 1, %ecx
22162 + shr $2, %ecx
22163 + repne scasl
22164 + jecxz 2f
22165 +
22166 + cmp $2*16, %ecx
22167 + jc 2f
22168 +
22169 + mov $2*16, %ecx
22170 + repe scasl
22171 + jecxz 2f
22172 + jne 1b
22173 +
22174 +2: cld
22175 + mov %esp, %ecx
22176 + sub %edi, %ecx
22177 +
22178 + cmp $THREAD_SIZE_asm, %ecx
22179 + jb 3f
22180 + ud2
22181 +3:
22182 +
22183 + shr $2, %ecx
22184 + rep stosl
22185 +
22186 + mov TI_task_thread_sp0(%ebp), %edi
22187 + sub $128, %edi
22188 + mov %edi, TI_lowest_stack(%ebp)
22189 +
22190 + popl %eax
22191 + popl %ecx
22192 + popl %edi
22193 + ret
22194 +ENDPROC(pax_erase_kstack)
22195 +#endif
22196 +
22197 +.macro __SAVE_ALL _DS
22198 cld
22199 PUSH_GS
22200 pushl_cfi %fs
22201 @@ -206,7 +346,7 @@
22202 CFI_REL_OFFSET ecx, 0
22203 pushl_cfi %ebx
22204 CFI_REL_OFFSET ebx, 0
22205 - movl $(__USER_DS), %edx
22206 + movl $\_DS, %edx
22207 movl %edx, %ds
22208 movl %edx, %es
22209 movl $(__KERNEL_PERCPU), %edx
22210 @@ -214,6 +354,15 @@
22211 SET_KERNEL_GS %edx
22212 .endm
22213
22214 +.macro SAVE_ALL
22215 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22216 + __SAVE_ALL __KERNEL_DS
22217 + pax_enter_kernel
22218 +#else
22219 + __SAVE_ALL __USER_DS
22220 +#endif
22221 +.endm
22222 +
22223 .macro RESTORE_INT_REGS
22224 popl_cfi %ebx
22225 CFI_RESTORE ebx
22226 @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
22227 popfl_cfi
22228 jmp syscall_exit
22229 CFI_ENDPROC
22230 -END(ret_from_fork)
22231 +ENDPROC(ret_from_fork)
22232
22233 ENTRY(ret_from_kernel_thread)
22234 CFI_STARTPROC
22235 @@ -344,7 +493,15 @@ ret_from_intr:
22236 andl $SEGMENT_RPL_MASK, %eax
22237 #endif
22238 cmpl $USER_RPL, %eax
22239 +
22240 +#ifdef CONFIG_PAX_KERNEXEC
22241 + jae resume_userspace
22242 +
22243 + pax_exit_kernel
22244 + jmp resume_kernel
22245 +#else
22246 jb resume_kernel # not returning to v8086 or userspace
22247 +#endif
22248
22249 ENTRY(resume_userspace)
22250 LOCKDEP_SYS_EXIT
22251 @@ -356,8 +513,8 @@ ENTRY(resume_userspace)
22252 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22253 # int/exception return?
22254 jne work_pending
22255 - jmp restore_all
22256 -END(ret_from_exception)
22257 + jmp restore_all_pax
22258 +ENDPROC(ret_from_exception)
22259
22260 #ifdef CONFIG_PREEMPT
22261 ENTRY(resume_kernel)
22262 @@ -369,7 +526,7 @@ need_resched:
22263 jz restore_all
22264 call preempt_schedule_irq
22265 jmp need_resched
22266 -END(resume_kernel)
22267 +ENDPROC(resume_kernel)
22268 #endif
22269 CFI_ENDPROC
22270 /*
22271 @@ -403,30 +560,45 @@ sysenter_past_esp:
22272 /*CFI_REL_OFFSET cs, 0*/
22273 /*
22274 * Push current_thread_info()->sysenter_return to the stack.
22275 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22276 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
22277 */
22278 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22279 + pushl_cfi $0
22280 CFI_REL_OFFSET eip, 0
22281
22282 pushl_cfi %eax
22283 SAVE_ALL
22284 + GET_THREAD_INFO(%ebp)
22285 + movl TI_sysenter_return(%ebp),%ebp
22286 + movl %ebp,PT_EIP(%esp)
22287 ENABLE_INTERRUPTS(CLBR_NONE)
22288
22289 /*
22290 * Load the potential sixth argument from user stack.
22291 * Careful about security.
22292 */
22293 + movl PT_OLDESP(%esp),%ebp
22294 +
22295 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22296 + mov PT_OLDSS(%esp),%ds
22297 +1: movl %ds:(%ebp),%ebp
22298 + push %ss
22299 + pop %ds
22300 +#else
22301 cmpl $__PAGE_OFFSET-3,%ebp
22302 jae syscall_fault
22303 ASM_STAC
22304 1: movl (%ebp),%ebp
22305 ASM_CLAC
22306 +#endif
22307 +
22308 movl %ebp,PT_EBP(%esp)
22309 _ASM_EXTABLE(1b,syscall_fault)
22310
22311 GET_THREAD_INFO(%ebp)
22312
22313 +#ifdef CONFIG_PAX_RANDKSTACK
22314 + pax_erase_kstack
22315 +#endif
22316 +
22317 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22318 jnz sysenter_audit
22319 sysenter_do_call:
22320 @@ -442,12 +614,24 @@ sysenter_after_call:
22321 testl $_TIF_ALLWORK_MASK, %ecx
22322 jne sysexit_audit
22323 sysenter_exit:
22324 +
22325 +#ifdef CONFIG_PAX_RANDKSTACK
22326 + pushl_cfi %eax
22327 + movl %esp, %eax
22328 + call pax_randomize_kstack
22329 + popl_cfi %eax
22330 +#endif
22331 +
22332 + pax_erase_kstack
22333 +
22334 /* if something modifies registers it must also disable sysexit */
22335 movl PT_EIP(%esp), %edx
22336 movl PT_OLDESP(%esp), %ecx
22337 xorl %ebp,%ebp
22338 TRACE_IRQS_ON
22339 1: mov PT_FS(%esp), %fs
22340 +2: mov PT_DS(%esp), %ds
22341 +3: mov PT_ES(%esp), %es
22342 PTGS_TO_GS
22343 ENABLE_INTERRUPTS_SYSEXIT
22344
22345 @@ -464,6 +648,9 @@ sysenter_audit:
22346 movl %eax,%edx /* 2nd arg: syscall number */
22347 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
22348 call __audit_syscall_entry
22349 +
22350 + pax_erase_kstack
22351 +
22352 pushl_cfi %ebx
22353 movl PT_EAX(%esp),%eax /* reload syscall number */
22354 jmp sysenter_do_call
22355 @@ -489,10 +676,16 @@ sysexit_audit:
22356
22357 CFI_ENDPROC
22358 .pushsection .fixup,"ax"
22359 -2: movl $0,PT_FS(%esp)
22360 +4: movl $0,PT_FS(%esp)
22361 + jmp 1b
22362 +5: movl $0,PT_DS(%esp)
22363 + jmp 1b
22364 +6: movl $0,PT_ES(%esp)
22365 jmp 1b
22366 .popsection
22367 - _ASM_EXTABLE(1b,2b)
22368 + _ASM_EXTABLE(1b,4b)
22369 + _ASM_EXTABLE(2b,5b)
22370 + _ASM_EXTABLE(3b,6b)
22371 PTGS_TO_GS_EX
22372 ENDPROC(ia32_sysenter_target)
22373
22374 @@ -507,6 +700,11 @@ ENTRY(system_call)
22375 pushl_cfi %eax # save orig_eax
22376 SAVE_ALL
22377 GET_THREAD_INFO(%ebp)
22378 +
22379 +#ifdef CONFIG_PAX_RANDKSTACK
22380 + pax_erase_kstack
22381 +#endif
22382 +
22383 # system call tracing in operation / emulation
22384 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22385 jnz syscall_trace_entry
22386 @@ -526,6 +724,15 @@ syscall_exit:
22387 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22388 jne syscall_exit_work
22389
22390 +restore_all_pax:
22391 +
22392 +#ifdef CONFIG_PAX_RANDKSTACK
22393 + movl %esp, %eax
22394 + call pax_randomize_kstack
22395 +#endif
22396 +
22397 + pax_erase_kstack
22398 +
22399 restore_all:
22400 TRACE_IRQS_IRET
22401 restore_all_notrace:
22402 @@ -580,14 +787,34 @@ ldt_ss:
22403 * compensating for the offset by changing to the ESPFIX segment with
22404 * a base address that matches for the difference.
22405 */
22406 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22407 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22408 mov %esp, %edx /* load kernel esp */
22409 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22410 mov %dx, %ax /* eax: new kernel esp */
22411 sub %eax, %edx /* offset (low word is 0) */
22412 +#ifdef CONFIG_SMP
22413 + movl PER_CPU_VAR(cpu_number), %ebx
22414 + shll $PAGE_SHIFT_asm, %ebx
22415 + addl $cpu_gdt_table, %ebx
22416 +#else
22417 + movl $cpu_gdt_table, %ebx
22418 +#endif
22419 shr $16, %edx
22420 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22421 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22422 +
22423 +#ifdef CONFIG_PAX_KERNEXEC
22424 + mov %cr0, %esi
22425 + btr $16, %esi
22426 + mov %esi, %cr0
22427 +#endif
22428 +
22429 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22430 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22431 +
22432 +#ifdef CONFIG_PAX_KERNEXEC
22433 + bts $16, %esi
22434 + mov %esi, %cr0
22435 +#endif
22436 +
22437 pushl_cfi $__ESPFIX_SS
22438 pushl_cfi %eax /* new kernel esp */
22439 /* Disable interrupts, but do not irqtrace this section: we
22440 @@ -617,20 +844,18 @@ work_resched:
22441 movl TI_flags(%ebp), %ecx
22442 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22443 # than syscall tracing?
22444 - jz restore_all
22445 + jz restore_all_pax
22446 testb $_TIF_NEED_RESCHED, %cl
22447 jnz work_resched
22448
22449 work_notifysig: # deal with pending signals and
22450 # notify-resume requests
22451 + movl %esp, %eax
22452 #ifdef CONFIG_VM86
22453 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22454 - movl %esp, %eax
22455 jne work_notifysig_v86 # returning to kernel-space or
22456 # vm86-space
22457 1:
22458 -#else
22459 - movl %esp, %eax
22460 #endif
22461 TRACE_IRQS_ON
22462 ENABLE_INTERRUPTS(CLBR_NONE)
22463 @@ -651,7 +876,7 @@ work_notifysig_v86:
22464 movl %eax, %esp
22465 jmp 1b
22466 #endif
22467 -END(work_pending)
22468 +ENDPROC(work_pending)
22469
22470 # perform syscall exit tracing
22471 ALIGN
22472 @@ -659,11 +884,14 @@ syscall_trace_entry:
22473 movl $-ENOSYS,PT_EAX(%esp)
22474 movl %esp, %eax
22475 call syscall_trace_enter
22476 +
22477 + pax_erase_kstack
22478 +
22479 /* What it returned is what we'll actually use. */
22480 cmpl $(NR_syscalls), %eax
22481 jnae syscall_call
22482 jmp syscall_exit
22483 -END(syscall_trace_entry)
22484 +ENDPROC(syscall_trace_entry)
22485
22486 # perform syscall exit tracing
22487 ALIGN
22488 @@ -676,26 +904,30 @@ syscall_exit_work:
22489 movl %esp, %eax
22490 call syscall_trace_leave
22491 jmp resume_userspace
22492 -END(syscall_exit_work)
22493 +ENDPROC(syscall_exit_work)
22494 CFI_ENDPROC
22495
22496 RING0_INT_FRAME # can't unwind into user space anyway
22497 syscall_fault:
22498 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22499 + push %ss
22500 + pop %ds
22501 +#endif
22502 ASM_CLAC
22503 GET_THREAD_INFO(%ebp)
22504 movl $-EFAULT,PT_EAX(%esp)
22505 jmp resume_userspace
22506 -END(syscall_fault)
22507 +ENDPROC(syscall_fault)
22508
22509 syscall_badsys:
22510 movl $-ENOSYS,%eax
22511 jmp syscall_after_call
22512 -END(syscall_badsys)
22513 +ENDPROC(syscall_badsys)
22514
22515 sysenter_badsys:
22516 movl $-ENOSYS,%eax
22517 jmp sysenter_after_call
22518 -END(syscall_badsys)
22519 +ENDPROC(sysenter_badsys)
22520 CFI_ENDPROC
22521 /*
22522 * End of kprobes section
22523 @@ -712,8 +944,15 @@ END(syscall_badsys)
22524 */
22525 #ifdef CONFIG_X86_ESPFIX32
22526 /* fixup the stack */
22527 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22528 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22529 +#ifdef CONFIG_SMP
22530 + movl PER_CPU_VAR(cpu_number), %ebx
22531 + shll $PAGE_SHIFT_asm, %ebx
22532 + addl $cpu_gdt_table, %ebx
22533 +#else
22534 + movl $cpu_gdt_table, %ebx
22535 +#endif
22536 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
22537 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
22538 shl $16, %eax
22539 addl %esp, %eax /* the adjusted stack pointer */
22540 pushl_cfi $__KERNEL_DS
22541 @@ -769,7 +1008,7 @@ vector=vector+1
22542 .endr
22543 2: jmp common_interrupt
22544 .endr
22545 -END(irq_entries_start)
22546 +ENDPROC(irq_entries_start)
22547
22548 .previous
22549 END(interrupt)
22550 @@ -830,7 +1069,7 @@ ENTRY(coprocessor_error)
22551 pushl_cfi $do_coprocessor_error
22552 jmp error_code
22553 CFI_ENDPROC
22554 -END(coprocessor_error)
22555 +ENDPROC(coprocessor_error)
22556
22557 ENTRY(simd_coprocessor_error)
22558 RING0_INT_FRAME
22559 @@ -843,7 +1082,7 @@ ENTRY(simd_coprocessor_error)
22560 .section .altinstructions,"a"
22561 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
22562 .previous
22563 -.section .altinstr_replacement,"ax"
22564 +.section .altinstr_replacement,"a"
22565 663: pushl $do_simd_coprocessor_error
22566 664:
22567 .previous
22568 @@ -852,7 +1091,7 @@ ENTRY(simd_coprocessor_error)
22569 #endif
22570 jmp error_code
22571 CFI_ENDPROC
22572 -END(simd_coprocessor_error)
22573 +ENDPROC(simd_coprocessor_error)
22574
22575 ENTRY(device_not_available)
22576 RING0_INT_FRAME
22577 @@ -861,18 +1100,18 @@ ENTRY(device_not_available)
22578 pushl_cfi $do_device_not_available
22579 jmp error_code
22580 CFI_ENDPROC
22581 -END(device_not_available)
22582 +ENDPROC(device_not_available)
22583
22584 #ifdef CONFIG_PARAVIRT
22585 ENTRY(native_iret)
22586 iret
22587 _ASM_EXTABLE(native_iret, iret_exc)
22588 -END(native_iret)
22589 +ENDPROC(native_iret)
22590
22591 ENTRY(native_irq_enable_sysexit)
22592 sti
22593 sysexit
22594 -END(native_irq_enable_sysexit)
22595 +ENDPROC(native_irq_enable_sysexit)
22596 #endif
22597
22598 ENTRY(overflow)
22599 @@ -882,7 +1121,7 @@ ENTRY(overflow)
22600 pushl_cfi $do_overflow
22601 jmp error_code
22602 CFI_ENDPROC
22603 -END(overflow)
22604 +ENDPROC(overflow)
22605
22606 ENTRY(bounds)
22607 RING0_INT_FRAME
22608 @@ -891,7 +1130,7 @@ ENTRY(bounds)
22609 pushl_cfi $do_bounds
22610 jmp error_code
22611 CFI_ENDPROC
22612 -END(bounds)
22613 +ENDPROC(bounds)
22614
22615 ENTRY(invalid_op)
22616 RING0_INT_FRAME
22617 @@ -900,7 +1139,7 @@ ENTRY(invalid_op)
22618 pushl_cfi $do_invalid_op
22619 jmp error_code
22620 CFI_ENDPROC
22621 -END(invalid_op)
22622 +ENDPROC(invalid_op)
22623
22624 ENTRY(coprocessor_segment_overrun)
22625 RING0_INT_FRAME
22626 @@ -909,7 +1148,7 @@ ENTRY(coprocessor_segment_overrun)
22627 pushl_cfi $do_coprocessor_segment_overrun
22628 jmp error_code
22629 CFI_ENDPROC
22630 -END(coprocessor_segment_overrun)
22631 +ENDPROC(coprocessor_segment_overrun)
22632
22633 ENTRY(invalid_TSS)
22634 RING0_EC_FRAME
22635 @@ -917,7 +1156,7 @@ ENTRY(invalid_TSS)
22636 pushl_cfi $do_invalid_TSS
22637 jmp error_code
22638 CFI_ENDPROC
22639 -END(invalid_TSS)
22640 +ENDPROC(invalid_TSS)
22641
22642 ENTRY(segment_not_present)
22643 RING0_EC_FRAME
22644 @@ -925,7 +1164,7 @@ ENTRY(segment_not_present)
22645 pushl_cfi $do_segment_not_present
22646 jmp error_code
22647 CFI_ENDPROC
22648 -END(segment_not_present)
22649 +ENDPROC(segment_not_present)
22650
22651 ENTRY(stack_segment)
22652 RING0_EC_FRAME
22653 @@ -933,7 +1172,7 @@ ENTRY(stack_segment)
22654 pushl_cfi $do_stack_segment
22655 jmp error_code
22656 CFI_ENDPROC
22657 -END(stack_segment)
22658 +ENDPROC(stack_segment)
22659
22660 ENTRY(alignment_check)
22661 RING0_EC_FRAME
22662 @@ -941,7 +1180,7 @@ ENTRY(alignment_check)
22663 pushl_cfi $do_alignment_check
22664 jmp error_code
22665 CFI_ENDPROC
22666 -END(alignment_check)
22667 +ENDPROC(alignment_check)
22668
22669 ENTRY(divide_error)
22670 RING0_INT_FRAME
22671 @@ -950,7 +1189,7 @@ ENTRY(divide_error)
22672 pushl_cfi $do_divide_error
22673 jmp error_code
22674 CFI_ENDPROC
22675 -END(divide_error)
22676 +ENDPROC(divide_error)
22677
22678 #ifdef CONFIG_X86_MCE
22679 ENTRY(machine_check)
22680 @@ -960,7 +1199,7 @@ ENTRY(machine_check)
22681 pushl_cfi machine_check_vector
22682 jmp error_code
22683 CFI_ENDPROC
22684 -END(machine_check)
22685 +ENDPROC(machine_check)
22686 #endif
22687
22688 ENTRY(spurious_interrupt_bug)
22689 @@ -970,7 +1209,7 @@ ENTRY(spurious_interrupt_bug)
22690 pushl_cfi $do_spurious_interrupt_bug
22691 jmp error_code
22692 CFI_ENDPROC
22693 -END(spurious_interrupt_bug)
22694 +ENDPROC(spurious_interrupt_bug)
22695 /*
22696 * End of kprobes section
22697 */
22698 @@ -1080,7 +1319,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22699
22700 ENTRY(mcount)
22701 ret
22702 -END(mcount)
22703 +ENDPROC(mcount)
22704
22705 ENTRY(ftrace_caller)
22706 cmpl $0, function_trace_stop
22707 @@ -1113,7 +1352,7 @@ ftrace_graph_call:
22708 .globl ftrace_stub
22709 ftrace_stub:
22710 ret
22711 -END(ftrace_caller)
22712 +ENDPROC(ftrace_caller)
22713
22714 ENTRY(ftrace_regs_caller)
22715 pushf /* push flags before compare (in cs location) */
22716 @@ -1217,7 +1456,7 @@ trace:
22717 popl %ecx
22718 popl %eax
22719 jmp ftrace_stub
22720 -END(mcount)
22721 +ENDPROC(mcount)
22722 #endif /* CONFIG_DYNAMIC_FTRACE */
22723 #endif /* CONFIG_FUNCTION_TRACER */
22724
22725 @@ -1235,7 +1474,7 @@ ENTRY(ftrace_graph_caller)
22726 popl %ecx
22727 popl %eax
22728 ret
22729 -END(ftrace_graph_caller)
22730 +ENDPROC(ftrace_graph_caller)
22731
22732 .globl return_to_handler
22733 return_to_handler:
22734 @@ -1301,15 +1540,18 @@ error_code:
22735 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
22736 REG_TO_PTGS %ecx
22737 SET_KERNEL_GS %ecx
22738 - movl $(__USER_DS), %ecx
22739 + movl $(__KERNEL_DS), %ecx
22740 movl %ecx, %ds
22741 movl %ecx, %es
22742 +
22743 + pax_enter_kernel
22744 +
22745 TRACE_IRQS_OFF
22746 movl %esp,%eax # pt_regs pointer
22747 call *%edi
22748 jmp ret_from_exception
22749 CFI_ENDPROC
22750 -END(page_fault)
22751 +ENDPROC(page_fault)
22752
22753 /*
22754 * Debug traps and NMI can happen at the one SYSENTER instruction
22755 @@ -1352,7 +1594,7 @@ debug_stack_correct:
22756 call do_debug
22757 jmp ret_from_exception
22758 CFI_ENDPROC
22759 -END(debug)
22760 +ENDPROC(debug)
22761
22762 /*
22763 * NMI is doubly nasty. It can happen _while_ we're handling
22764 @@ -1392,6 +1634,9 @@ nmi_stack_correct:
22765 xorl %edx,%edx # zero error code
22766 movl %esp,%eax # pt_regs pointer
22767 call do_nmi
22768 +
22769 + pax_exit_kernel
22770 +
22771 jmp restore_all_notrace
22772 CFI_ENDPROC
22773
22774 @@ -1429,13 +1674,16 @@ nmi_espfix_stack:
22775 FIXUP_ESPFIX_STACK # %eax == %esp
22776 xorl %edx,%edx # zero error code
22777 call do_nmi
22778 +
22779 + pax_exit_kernel
22780 +
22781 RESTORE_REGS
22782 lss 12+4(%esp), %esp # back to espfix stack
22783 CFI_ADJUST_CFA_OFFSET -24
22784 jmp irq_return
22785 #endif
22786 CFI_ENDPROC
22787 -END(nmi)
22788 +ENDPROC(nmi)
22789
22790 ENTRY(int3)
22791 RING0_INT_FRAME
22792 @@ -1448,14 +1696,14 @@ ENTRY(int3)
22793 call do_int3
22794 jmp ret_from_exception
22795 CFI_ENDPROC
22796 -END(int3)
22797 +ENDPROC(int3)
22798
22799 ENTRY(general_protection)
22800 RING0_EC_FRAME
22801 pushl_cfi $do_general_protection
22802 jmp error_code
22803 CFI_ENDPROC
22804 -END(general_protection)
22805 +ENDPROC(general_protection)
22806
22807 #ifdef CONFIG_KVM_GUEST
22808 ENTRY(async_page_fault)
22809 @@ -1464,7 +1712,7 @@ ENTRY(async_page_fault)
22810 pushl_cfi $do_async_page_fault
22811 jmp error_code
22812 CFI_ENDPROC
22813 -END(async_page_fault)
22814 +ENDPROC(async_page_fault)
22815 #endif
22816
22817 /*
22818 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
22819 index 03cd2a8..05a9aed 100644
22820 --- a/arch/x86/kernel/entry_64.S
22821 +++ b/arch/x86/kernel/entry_64.S
22822 @@ -60,6 +60,8 @@
22823 #include <asm/smap.h>
22824 #include <asm/pgtable_types.h>
22825 #include <linux/err.h>
22826 +#include <asm/pgtable.h>
22827 +#include <asm/alternative-asm.h>
22828
22829 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
22830 #include <linux/elf-em.h>
22831 @@ -81,8 +83,9 @@
22832 #ifdef CONFIG_DYNAMIC_FTRACE
22833
22834 ENTRY(function_hook)
22835 + pax_force_retaddr
22836 retq
22837 -END(function_hook)
22838 +ENDPROC(function_hook)
22839
22840 /* skip is set if stack has been adjusted */
22841 .macro ftrace_caller_setup skip=0
22842 @@ -123,8 +126,9 @@ GLOBAL(ftrace_graph_call)
22843 #endif
22844
22845 GLOBAL(ftrace_stub)
22846 + pax_force_retaddr
22847 retq
22848 -END(ftrace_caller)
22849 +ENDPROC(ftrace_caller)
22850
22851 ENTRY(ftrace_regs_caller)
22852 /* Save the current flags before compare (in SS location)*/
22853 @@ -192,7 +196,7 @@ ftrace_restore_flags:
22854 popfq
22855 jmp ftrace_stub
22856
22857 -END(ftrace_regs_caller)
22858 +ENDPROC(ftrace_regs_caller)
22859
22860
22861 #else /* ! CONFIG_DYNAMIC_FTRACE */
22862 @@ -213,6 +217,7 @@ ENTRY(function_hook)
22863 #endif
22864
22865 GLOBAL(ftrace_stub)
22866 + pax_force_retaddr
22867 retq
22868
22869 trace:
22870 @@ -226,12 +231,13 @@ trace:
22871 #endif
22872 subq $MCOUNT_INSN_SIZE, %rdi
22873
22874 + pax_force_fptr ftrace_trace_function
22875 call *ftrace_trace_function
22876
22877 MCOUNT_RESTORE_FRAME
22878
22879 jmp ftrace_stub
22880 -END(function_hook)
22881 +ENDPROC(function_hook)
22882 #endif /* CONFIG_DYNAMIC_FTRACE */
22883 #endif /* CONFIG_FUNCTION_TRACER */
22884
22885 @@ -253,8 +259,9 @@ ENTRY(ftrace_graph_caller)
22886
22887 MCOUNT_RESTORE_FRAME
22888
22889 + pax_force_retaddr
22890 retq
22891 -END(ftrace_graph_caller)
22892 +ENDPROC(ftrace_graph_caller)
22893
22894 GLOBAL(return_to_handler)
22895 subq $24, %rsp
22896 @@ -270,7 +277,9 @@ GLOBAL(return_to_handler)
22897 movq 8(%rsp), %rdx
22898 movq (%rsp), %rax
22899 addq $24, %rsp
22900 + pax_force_fptr %rdi
22901 jmp *%rdi
22902 +ENDPROC(return_to_handler)
22903 #endif
22904
22905
22906 @@ -285,6 +294,430 @@ ENTRY(native_usergs_sysret64)
22907 ENDPROC(native_usergs_sysret64)
22908 #endif /* CONFIG_PARAVIRT */
22909
22910 + .macro ljmpq sel, off
22911 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
22912 + .byte 0x48; ljmp *1234f(%rip)
22913 + .pushsection .rodata
22914 + .align 16
22915 + 1234: .quad \off; .word \sel
22916 + .popsection
22917 +#else
22918 + pushq $\sel
22919 + pushq $\off
22920 + lretq
22921 +#endif
22922 + .endm
22923 +
22924 + .macro pax_enter_kernel
22925 + pax_set_fptr_mask
22926 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22927 + call pax_enter_kernel
22928 +#endif
22929 + .endm
22930 +
22931 + .macro pax_exit_kernel
22932 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22933 + call pax_exit_kernel
22934 +#endif
22935 +
22936 + .endm
22937 +
22938 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22939 +ENTRY(pax_enter_kernel)
22940 + pushq %rdi
22941 +
22942 +#ifdef CONFIG_PARAVIRT
22943 + PV_SAVE_REGS(CLBR_RDI)
22944 +#endif
22945 +
22946 +#ifdef CONFIG_PAX_KERNEXEC
22947 + GET_CR0_INTO_RDI
22948 + bts $16,%rdi
22949 + jnc 3f
22950 + mov %cs,%edi
22951 + cmp $__KERNEL_CS,%edi
22952 + jnz 2f
22953 +1:
22954 +#endif
22955 +
22956 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22957 + 661: jmp 111f
22958 + .pushsection .altinstr_replacement, "a"
22959 + 662: ASM_NOP2
22960 + .popsection
22961 + .pushsection .altinstructions, "a"
22962 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22963 + .popsection
22964 + GET_CR3_INTO_RDI
22965 + cmp $0,%dil
22966 + jnz 112f
22967 + mov $__KERNEL_DS,%edi
22968 + mov %edi,%ss
22969 + jmp 111f
22970 +112: cmp $1,%dil
22971 + jz 113f
22972 + ud2
22973 +113: sub $4097,%rdi
22974 + bts $63,%rdi
22975 + SET_RDI_INTO_CR3
22976 + mov $__UDEREF_KERNEL_DS,%edi
22977 + mov %edi,%ss
22978 +111:
22979 +#endif
22980 +
22981 +#ifdef CONFIG_PARAVIRT
22982 + PV_RESTORE_REGS(CLBR_RDI)
22983 +#endif
22984 +
22985 + popq %rdi
22986 + pax_force_retaddr
22987 + retq
22988 +
22989 +#ifdef CONFIG_PAX_KERNEXEC
22990 +2: ljmpq __KERNEL_CS,1b
22991 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
22992 +4: SET_RDI_INTO_CR0
22993 + jmp 1b
22994 +#endif
22995 +ENDPROC(pax_enter_kernel)
22996 +
22997 +ENTRY(pax_exit_kernel)
22998 + pushq %rdi
22999 +
23000 +#ifdef CONFIG_PARAVIRT
23001 + PV_SAVE_REGS(CLBR_RDI)
23002 +#endif
23003 +
23004 +#ifdef CONFIG_PAX_KERNEXEC
23005 + mov %cs,%rdi
23006 + cmp $__KERNEXEC_KERNEL_CS,%edi
23007 + jz 2f
23008 + GET_CR0_INTO_RDI
23009 + bts $16,%rdi
23010 + jnc 4f
23011 +1:
23012 +#endif
23013 +
23014 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23015 + 661: jmp 111f
23016 + .pushsection .altinstr_replacement, "a"
23017 + 662: ASM_NOP2
23018 + .popsection
23019 + .pushsection .altinstructions, "a"
23020 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23021 + .popsection
23022 + mov %ss,%edi
23023 + cmp $__UDEREF_KERNEL_DS,%edi
23024 + jnz 111f
23025 + GET_CR3_INTO_RDI
23026 + cmp $0,%dil
23027 + jz 112f
23028 + ud2
23029 +112: add $4097,%rdi
23030 + bts $63,%rdi
23031 + SET_RDI_INTO_CR3
23032 + mov $__KERNEL_DS,%edi
23033 + mov %edi,%ss
23034 +111:
23035 +#endif
23036 +
23037 +#ifdef CONFIG_PARAVIRT
23038 + PV_RESTORE_REGS(CLBR_RDI);
23039 +#endif
23040 +
23041 + popq %rdi
23042 + pax_force_retaddr
23043 + retq
23044 +
23045 +#ifdef CONFIG_PAX_KERNEXEC
23046 +2: GET_CR0_INTO_RDI
23047 + btr $16,%rdi
23048 + jnc 4f
23049 + ljmpq __KERNEL_CS,3f
23050 +3: SET_RDI_INTO_CR0
23051 + jmp 1b
23052 +4: ud2
23053 + jmp 4b
23054 +#endif
23055 +ENDPROC(pax_exit_kernel)
23056 +#endif
23057 +
23058 + .macro pax_enter_kernel_user
23059 + pax_set_fptr_mask
23060 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23061 + call pax_enter_kernel_user
23062 +#endif
23063 + .endm
23064 +
23065 + .macro pax_exit_kernel_user
23066 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23067 + call pax_exit_kernel_user
23068 +#endif
23069 +#ifdef CONFIG_PAX_RANDKSTACK
23070 + pushq %rax
23071 + pushq %r11
23072 + call pax_randomize_kstack
23073 + popq %r11
23074 + popq %rax
23075 +#endif
23076 + .endm
23077 +
23078 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23079 +ENTRY(pax_enter_kernel_user)
23080 + pushq %rdi
23081 + pushq %rbx
23082 +
23083 +#ifdef CONFIG_PARAVIRT
23084 + PV_SAVE_REGS(CLBR_RDI)
23085 +#endif
23086 +
23087 + 661: jmp 111f
23088 + .pushsection .altinstr_replacement, "a"
23089 + 662: ASM_NOP2
23090 + .popsection
23091 + .pushsection .altinstructions, "a"
23092 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23093 + .popsection
23094 + GET_CR3_INTO_RDI
23095 + cmp $1,%dil
23096 + jnz 4f
23097 + sub $4097,%rdi
23098 + bts $63,%rdi
23099 + SET_RDI_INTO_CR3
23100 + jmp 3f
23101 +111:
23102 +
23103 + GET_CR3_INTO_RDI
23104 + mov %rdi,%rbx
23105 + add $__START_KERNEL_map,%rbx
23106 + sub phys_base(%rip),%rbx
23107 +
23108 +#ifdef CONFIG_PARAVIRT
23109 + cmpl $0, pv_info+PARAVIRT_enabled
23110 + jz 1f
23111 + pushq %rdi
23112 + i = 0
23113 + .rept USER_PGD_PTRS
23114 + mov i*8(%rbx),%rsi
23115 + mov $0,%sil
23116 + lea i*8(%rbx),%rdi
23117 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23118 + i = i + 1
23119 + .endr
23120 + popq %rdi
23121 + jmp 2f
23122 +1:
23123 +#endif
23124 +
23125 + i = 0
23126 + .rept USER_PGD_PTRS
23127 + movb $0,i*8(%rbx)
23128 + i = i + 1
23129 + .endr
23130 +
23131 +2: SET_RDI_INTO_CR3
23132 +
23133 +#ifdef CONFIG_PAX_KERNEXEC
23134 + GET_CR0_INTO_RDI
23135 + bts $16,%rdi
23136 + SET_RDI_INTO_CR0
23137 +#endif
23138 +
23139 +3:
23140 +
23141 +#ifdef CONFIG_PARAVIRT
23142 + PV_RESTORE_REGS(CLBR_RDI)
23143 +#endif
23144 +
23145 + popq %rbx
23146 + popq %rdi
23147 + pax_force_retaddr
23148 + retq
23149 +4: ud2
23150 +ENDPROC(pax_enter_kernel_user)
23151 +
23152 +ENTRY(pax_exit_kernel_user)
23153 + pushq %rdi
23154 + pushq %rbx
23155 +
23156 +#ifdef CONFIG_PARAVIRT
23157 + PV_SAVE_REGS(CLBR_RDI)
23158 +#endif
23159 +
23160 + GET_CR3_INTO_RDI
23161 + 661: jmp 1f
23162 + .pushsection .altinstr_replacement, "a"
23163 + 662: ASM_NOP2
23164 + .popsection
23165 + .pushsection .altinstructions, "a"
23166 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23167 + .popsection
23168 + cmp $0,%dil
23169 + jnz 3f
23170 + add $4097,%rdi
23171 + bts $63,%rdi
23172 + SET_RDI_INTO_CR3
23173 + jmp 2f
23174 +1:
23175 +
23176 + mov %rdi,%rbx
23177 +
23178 +#ifdef CONFIG_PAX_KERNEXEC
23179 + GET_CR0_INTO_RDI
23180 + btr $16,%rdi
23181 + jnc 3f
23182 + SET_RDI_INTO_CR0
23183 +#endif
23184 +
23185 + add $__START_KERNEL_map,%rbx
23186 + sub phys_base(%rip),%rbx
23187 +
23188 +#ifdef CONFIG_PARAVIRT
23189 + cmpl $0, pv_info+PARAVIRT_enabled
23190 + jz 1f
23191 + i = 0
23192 + .rept USER_PGD_PTRS
23193 + mov i*8(%rbx),%rsi
23194 + mov $0x67,%sil
23195 + lea i*8(%rbx),%rdi
23196 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23197 + i = i + 1
23198 + .endr
23199 + jmp 2f
23200 +1:
23201 +#endif
23202 +
23203 + i = 0
23204 + .rept USER_PGD_PTRS
23205 + movb $0x67,i*8(%rbx)
23206 + i = i + 1
23207 + .endr
23208 +2:
23209 +
23210 +#ifdef CONFIG_PARAVIRT
23211 + PV_RESTORE_REGS(CLBR_RDI)
23212 +#endif
23213 +
23214 + popq %rbx
23215 + popq %rdi
23216 + pax_force_retaddr
23217 + retq
23218 +3: ud2
23219 +ENDPROC(pax_exit_kernel_user)
23220 +#endif
23221 +
23222 + .macro pax_enter_kernel_nmi
23223 + pax_set_fptr_mask
23224 +
23225 +#ifdef CONFIG_PAX_KERNEXEC
23226 + GET_CR0_INTO_RDI
23227 + bts $16,%rdi
23228 + jc 110f
23229 + SET_RDI_INTO_CR0
23230 + or $2,%ebx
23231 +110:
23232 +#endif
23233 +
23234 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23235 + 661: jmp 111f
23236 + .pushsection .altinstr_replacement, "a"
23237 + 662: ASM_NOP2
23238 + .popsection
23239 + .pushsection .altinstructions, "a"
23240 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23241 + .popsection
23242 + GET_CR3_INTO_RDI
23243 + cmp $0,%dil
23244 + jz 111f
23245 + sub $4097,%rdi
23246 + or $4,%ebx
23247 + bts $63,%rdi
23248 + SET_RDI_INTO_CR3
23249 + mov $__UDEREF_KERNEL_DS,%edi
23250 + mov %edi,%ss
23251 +111:
23252 +#endif
23253 + .endm
23254 +
23255 + .macro pax_exit_kernel_nmi
23256 +#ifdef CONFIG_PAX_KERNEXEC
23257 + btr $1,%ebx
23258 + jnc 110f
23259 + GET_CR0_INTO_RDI
23260 + btr $16,%rdi
23261 + SET_RDI_INTO_CR0
23262 +110:
23263 +#endif
23264 +
23265 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23266 + btr $2,%ebx
23267 + jnc 111f
23268 + GET_CR3_INTO_RDI
23269 + add $4097,%rdi
23270 + bts $63,%rdi
23271 + SET_RDI_INTO_CR3
23272 + mov $__KERNEL_DS,%edi
23273 + mov %edi,%ss
23274 +111:
23275 +#endif
23276 + .endm
23277 +
23278 + .macro pax_erase_kstack
23279 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23280 + call pax_erase_kstack
23281 +#endif
23282 + .endm
23283 +
23284 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23285 +ENTRY(pax_erase_kstack)
23286 + pushq %rdi
23287 + pushq %rcx
23288 + pushq %rax
23289 + pushq %r11
23290 +
23291 + GET_THREAD_INFO(%r11)
23292 + mov TI_lowest_stack(%r11), %rdi
23293 + mov $-0xBEEF, %rax
23294 + std
23295 +
23296 +1: mov %edi, %ecx
23297 + and $THREAD_SIZE_asm - 1, %ecx
23298 + shr $3, %ecx
23299 + repne scasq
23300 + jecxz 2f
23301 +
23302 + cmp $2*8, %ecx
23303 + jc 2f
23304 +
23305 + mov $2*8, %ecx
23306 + repe scasq
23307 + jecxz 2f
23308 + jne 1b
23309 +
23310 +2: cld
23311 + mov %esp, %ecx
23312 + sub %edi, %ecx
23313 +
23314 + cmp $THREAD_SIZE_asm, %rcx
23315 + jb 3f
23316 + ud2
23317 +3:
23318 +
23319 + shr $3, %ecx
23320 + rep stosq
23321 +
23322 + mov TI_task_thread_sp0(%r11), %rdi
23323 + sub $256, %rdi
23324 + mov %rdi, TI_lowest_stack(%r11)
23325 +
23326 + popq %r11
23327 + popq %rax
23328 + popq %rcx
23329 + popq %rdi
23330 + pax_force_retaddr
23331 + ret
23332 +ENDPROC(pax_erase_kstack)
23333 +#endif
23334
23335 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23336 #ifdef CONFIG_TRACE_IRQFLAGS
23337 @@ -321,7 +754,7 @@ ENDPROC(native_usergs_sysret64)
23338 .endm
23339
23340 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23341 - bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23342 + bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23343 jnc 1f
23344 TRACE_IRQS_ON_DEBUG
23345 1:
23346 @@ -359,27 +792,6 @@ ENDPROC(native_usergs_sysret64)
23347 movq \tmp,R11+\offset(%rsp)
23348 .endm
23349
23350 - .macro FAKE_STACK_FRAME child_rip
23351 - /* push in order ss, rsp, eflags, cs, rip */
23352 - xorl %eax, %eax
23353 - pushq_cfi $__KERNEL_DS /* ss */
23354 - /*CFI_REL_OFFSET ss,0*/
23355 - pushq_cfi %rax /* rsp */
23356 - CFI_REL_OFFSET rsp,0
23357 - pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23358 - /*CFI_REL_OFFSET rflags,0*/
23359 - pushq_cfi $__KERNEL_CS /* cs */
23360 - /*CFI_REL_OFFSET cs,0*/
23361 - pushq_cfi \child_rip /* rip */
23362 - CFI_REL_OFFSET rip,0
23363 - pushq_cfi %rax /* orig rax */
23364 - .endm
23365 -
23366 - .macro UNFAKE_STACK_FRAME
23367 - addq $8*6, %rsp
23368 - CFI_ADJUST_CFA_OFFSET -(6*8)
23369 - .endm
23370 -
23371 /*
23372 * initial frame state for interrupts (and exceptions without error code)
23373 */
23374 @@ -446,25 +858,26 @@ ENDPROC(native_usergs_sysret64)
23375 /* save partial stack frame */
23376 .macro SAVE_ARGS_IRQ
23377 cld
23378 - /* start from rbp in pt_regs and jump over */
23379 - movq_cfi rdi, (RDI-RBP)
23380 - movq_cfi rsi, (RSI-RBP)
23381 - movq_cfi rdx, (RDX-RBP)
23382 - movq_cfi rcx, (RCX-RBP)
23383 - movq_cfi rax, (RAX-RBP)
23384 - movq_cfi r8, (R8-RBP)
23385 - movq_cfi r9, (R9-RBP)
23386 - movq_cfi r10, (R10-RBP)
23387 - movq_cfi r11, (R11-RBP)
23388 + /* start from r15 in pt_regs and jump over */
23389 + movq_cfi rdi, RDI
23390 + movq_cfi rsi, RSI
23391 + movq_cfi rdx, RDX
23392 + movq_cfi rcx, RCX
23393 + movq_cfi rax, RAX
23394 + movq_cfi r8, R8
23395 + movq_cfi r9, R9
23396 + movq_cfi r10, R10
23397 + movq_cfi r11, R11
23398 + movq_cfi r12, R12
23399
23400 /* Save rbp so that we can unwind from get_irq_regs() */
23401 - movq_cfi rbp, 0
23402 + movq_cfi rbp, RBP
23403
23404 /* Save previous stack value */
23405 movq %rsp, %rsi
23406
23407 - leaq -RBP(%rsp),%rdi /* arg1 for handler */
23408 - testl $3, CS-RBP(%rsi)
23409 + movq %rsp,%rdi /* arg1 for handler */
23410 + testb $3, CS(%rsi)
23411 je 1f
23412 SWAPGS
23413 /*
23414 @@ -484,6 +897,18 @@ ENDPROC(native_usergs_sysret64)
23415 0x06 /* DW_OP_deref */, \
23416 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23417 0x22 /* DW_OP_plus */
23418 +
23419 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23420 + testb $3, CS(%rdi)
23421 + jnz 1f
23422 + pax_enter_kernel
23423 + jmp 2f
23424 +1: pax_enter_kernel_user
23425 +2:
23426 +#else
23427 + pax_enter_kernel
23428 +#endif
23429 +
23430 /* We entered an interrupt context - irqs are off: */
23431 TRACE_IRQS_OFF
23432 .endm
23433 @@ -515,9 +940,52 @@ ENTRY(save_paranoid)
23434 js 1f /* negative -> in kernel */
23435 SWAPGS
23436 xorl %ebx,%ebx
23437 -1: ret
23438 +1:
23439 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23440 + testb $3, CS+8(%rsp)
23441 + jnz 1f
23442 + pax_enter_kernel
23443 + jmp 2f
23444 +1: pax_enter_kernel_user
23445 +2:
23446 +#else
23447 + pax_enter_kernel
23448 +#endif
23449 + pax_force_retaddr
23450 + ret
23451 CFI_ENDPROC
23452 -END(save_paranoid)
23453 +ENDPROC(save_paranoid)
23454 +
23455 +ENTRY(save_paranoid_nmi)
23456 + XCPT_FRAME 1 RDI+8
23457 + cld
23458 + movq_cfi rdi, RDI+8
23459 + movq_cfi rsi, RSI+8
23460 + movq_cfi rdx, RDX+8
23461 + movq_cfi rcx, RCX+8
23462 + movq_cfi rax, RAX+8
23463 + movq_cfi r8, R8+8
23464 + movq_cfi r9, R9+8
23465 + movq_cfi r10, R10+8
23466 + movq_cfi r11, R11+8
23467 + movq_cfi rbx, RBX+8
23468 + movq_cfi rbp, RBP+8
23469 + movq_cfi r12, R12+8
23470 + movq_cfi r13, R13+8
23471 + movq_cfi r14, R14+8
23472 + movq_cfi r15, R15+8
23473 + movl $1,%ebx
23474 + movl $MSR_GS_BASE,%ecx
23475 + rdmsr
23476 + testl %edx,%edx
23477 + js 1f /* negative -> in kernel */
23478 + SWAPGS
23479 + xorl %ebx,%ebx
23480 +1: pax_enter_kernel_nmi
23481 + pax_force_retaddr
23482 + ret
23483 + CFI_ENDPROC
23484 +ENDPROC(save_paranoid_nmi)
23485 .popsection
23486
23487 /*
23488 @@ -539,7 +1007,7 @@ ENTRY(ret_from_fork)
23489
23490 RESTORE_REST
23491
23492 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23493 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23494 jz 1f
23495
23496 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23497 @@ -549,15 +1017,13 @@ ENTRY(ret_from_fork)
23498 jmp ret_from_sys_call # go to the SYSRET fastpath
23499
23500 1:
23501 - subq $REST_SKIP, %rsp # leave space for volatiles
23502 - CFI_ADJUST_CFA_OFFSET REST_SKIP
23503 movq %rbp, %rdi
23504 call *%rbx
23505 movl $0, RAX(%rsp)
23506 RESTORE_REST
23507 jmp int_ret_from_sys_call
23508 CFI_ENDPROC
23509 -END(ret_from_fork)
23510 +ENDPROC(ret_from_fork)
23511
23512 /*
23513 * System call entry. Up to 6 arguments in registers are supported.
23514 @@ -594,7 +1060,7 @@ END(ret_from_fork)
23515 ENTRY(system_call)
23516 CFI_STARTPROC simple
23517 CFI_SIGNAL_FRAME
23518 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23519 + CFI_DEF_CFA rsp,0
23520 CFI_REGISTER rip,rcx
23521 /*CFI_REGISTER rflags,r11*/
23522 SWAPGS_UNSAFE_STACK
23523 @@ -607,16 +1073,23 @@ GLOBAL(system_call_after_swapgs)
23524
23525 movq %rsp,PER_CPU_VAR(old_rsp)
23526 movq PER_CPU_VAR(kernel_stack),%rsp
23527 + SAVE_ARGS 8*6,0
23528 + pax_enter_kernel_user
23529 +
23530 +#ifdef CONFIG_PAX_RANDKSTACK
23531 + pax_erase_kstack
23532 +#endif
23533 +
23534 /*
23535 * No need to follow this irqs off/on section - it's straight
23536 * and short:
23537 */
23538 ENABLE_INTERRUPTS(CLBR_NONE)
23539 - SAVE_ARGS 8,0
23540 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
23541 movq %rcx,RIP-ARGOFFSET(%rsp)
23542 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23543 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23544 + GET_THREAD_INFO(%rcx)
23545 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23546 jnz tracesys
23547 system_call_fastpath:
23548 #if __SYSCALL_MASK == ~0
23549 @@ -640,10 +1113,13 @@ sysret_check:
23550 LOCKDEP_SYS_EXIT
23551 DISABLE_INTERRUPTS(CLBR_NONE)
23552 TRACE_IRQS_OFF
23553 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23554 + GET_THREAD_INFO(%rcx)
23555 + movl TI_flags(%rcx),%edx
23556 andl %edi,%edx
23557 jnz sysret_careful
23558 CFI_REMEMBER_STATE
23559 + pax_exit_kernel_user
23560 + pax_erase_kstack
23561 /*
23562 * sysretq will re-enable interrupts:
23563 */
23564 @@ -702,6 +1178,9 @@ auditsys:
23565 movq %rax,%rsi /* 2nd arg: syscall number */
23566 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
23567 call __audit_syscall_entry
23568 +
23569 + pax_erase_kstack
23570 +
23571 LOAD_ARGS 0 /* reload call-clobbered registers */
23572 jmp system_call_fastpath
23573
23574 @@ -723,7 +1202,7 @@ sysret_audit:
23575 /* Do syscall tracing */
23576 tracesys:
23577 #ifdef CONFIG_AUDITSYSCALL
23578 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23579 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
23580 jz auditsys
23581 #endif
23582 SAVE_REST
23583 @@ -731,12 +1210,15 @@ tracesys:
23584 FIXUP_TOP_OF_STACK %rdi
23585 movq %rsp,%rdi
23586 call syscall_trace_enter
23587 +
23588 + pax_erase_kstack
23589 +
23590 /*
23591 * Reload arg registers from stack in case ptrace changed them.
23592 * We don't reload %rax because syscall_trace_enter() returned
23593 * the value it wants us to use in the table lookup.
23594 */
23595 - LOAD_ARGS ARGOFFSET, 1
23596 + LOAD_ARGS 1
23597 RESTORE_REST
23598 #if __SYSCALL_MASK == ~0
23599 cmpq $__NR_syscall_max,%rax
23600 @@ -766,7 +1248,9 @@ GLOBAL(int_with_check)
23601 andl %edi,%edx
23602 jnz int_careful
23603 andl $~TS_COMPAT,TI_status(%rcx)
23604 - jmp retint_swapgs
23605 + pax_exit_kernel_user
23606 + pax_erase_kstack
23607 + jmp retint_swapgs_pax
23608
23609 /* Either reschedule or signal or syscall exit tracking needed. */
23610 /* First do a reschedule test. */
23611 @@ -812,7 +1296,7 @@ int_restore_rest:
23612 TRACE_IRQS_OFF
23613 jmp int_with_check
23614 CFI_ENDPROC
23615 -END(system_call)
23616 +ENDPROC(system_call)
23617
23618 .macro FORK_LIKE func
23619 ENTRY(stub_\func)
23620 @@ -825,9 +1309,10 @@ ENTRY(stub_\func)
23621 DEFAULT_FRAME 0 8 /* offset 8: return address */
23622 call sys_\func
23623 RESTORE_TOP_OF_STACK %r11, 8
23624 - ret $REST_SKIP /* pop extended registers */
23625 + pax_force_retaddr
23626 + ret
23627 CFI_ENDPROC
23628 -END(stub_\func)
23629 +ENDPROC(stub_\func)
23630 .endm
23631
23632 .macro FIXED_FRAME label,func
23633 @@ -837,9 +1322,10 @@ ENTRY(\label)
23634 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
23635 call \func
23636 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
23637 + pax_force_retaddr
23638 ret
23639 CFI_ENDPROC
23640 -END(\label)
23641 +ENDPROC(\label)
23642 .endm
23643
23644 FORK_LIKE clone
23645 @@ -847,19 +1333,6 @@ END(\label)
23646 FORK_LIKE vfork
23647 FIXED_FRAME stub_iopl, sys_iopl
23648
23649 -ENTRY(ptregscall_common)
23650 - DEFAULT_FRAME 1 8 /* offset 8: return address */
23651 - RESTORE_TOP_OF_STACK %r11, 8
23652 - movq_cfi_restore R15+8, r15
23653 - movq_cfi_restore R14+8, r14
23654 - movq_cfi_restore R13+8, r13
23655 - movq_cfi_restore R12+8, r12
23656 - movq_cfi_restore RBP+8, rbp
23657 - movq_cfi_restore RBX+8, rbx
23658 - ret $REST_SKIP /* pop extended registers */
23659 - CFI_ENDPROC
23660 -END(ptregscall_common)
23661 -
23662 ENTRY(stub_execve)
23663 CFI_STARTPROC
23664 addq $8, %rsp
23665 @@ -871,7 +1344,7 @@ ENTRY(stub_execve)
23666 RESTORE_REST
23667 jmp int_ret_from_sys_call
23668 CFI_ENDPROC
23669 -END(stub_execve)
23670 +ENDPROC(stub_execve)
23671
23672 /*
23673 * sigreturn is special because it needs to restore all registers on return.
23674 @@ -888,7 +1361,7 @@ ENTRY(stub_rt_sigreturn)
23675 RESTORE_REST
23676 jmp int_ret_from_sys_call
23677 CFI_ENDPROC
23678 -END(stub_rt_sigreturn)
23679 +ENDPROC(stub_rt_sigreturn)
23680
23681 #ifdef CONFIG_X86_X32_ABI
23682 ENTRY(stub_x32_rt_sigreturn)
23683 @@ -902,7 +1375,7 @@ ENTRY(stub_x32_rt_sigreturn)
23684 RESTORE_REST
23685 jmp int_ret_from_sys_call
23686 CFI_ENDPROC
23687 -END(stub_x32_rt_sigreturn)
23688 +ENDPROC(stub_x32_rt_sigreturn)
23689
23690 ENTRY(stub_x32_execve)
23691 CFI_STARTPROC
23692 @@ -916,7 +1389,7 @@ ENTRY(stub_x32_execve)
23693 RESTORE_REST
23694 jmp int_ret_from_sys_call
23695 CFI_ENDPROC
23696 -END(stub_x32_execve)
23697 +ENDPROC(stub_x32_execve)
23698
23699 #endif
23700
23701 @@ -953,7 +1426,7 @@ vector=vector+1
23702 2: jmp common_interrupt
23703 .endr
23704 CFI_ENDPROC
23705 -END(irq_entries_start)
23706 +ENDPROC(irq_entries_start)
23707
23708 .previous
23709 END(interrupt)
23710 @@ -970,8 +1443,8 @@ END(interrupt)
23711 /* 0(%rsp): ~(interrupt number) */
23712 .macro interrupt func
23713 /* reserve pt_regs for scratch regs and rbp */
23714 - subq $ORIG_RAX-RBP, %rsp
23715 - CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23716 + subq $ORIG_RAX, %rsp
23717 + CFI_ADJUST_CFA_OFFSET ORIG_RAX
23718 SAVE_ARGS_IRQ
23719 call \func
23720 .endm
23721 @@ -998,14 +1471,14 @@ ret_from_intr:
23722
23723 /* Restore saved previous stack */
23724 popq %rsi
23725 - CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23726 - leaq ARGOFFSET-RBP(%rsi), %rsp
23727 + CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
23728 + movq %rsi, %rsp
23729 CFI_DEF_CFA_REGISTER rsp
23730 - CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
23731 + CFI_ADJUST_CFA_OFFSET -ARGOFFSET
23732
23733 exit_intr:
23734 GET_THREAD_INFO(%rcx)
23735 - testl $3,CS-ARGOFFSET(%rsp)
23736 + testb $3,CS-ARGOFFSET(%rsp)
23737 je retint_kernel
23738
23739 /* Interrupt came from user space */
23740 @@ -1027,12 +1500,16 @@ retint_swapgs: /* return to user-space */
23741 * The iretq could re-enable interrupts:
23742 */
23743 DISABLE_INTERRUPTS(CLBR_ANY)
23744 + pax_exit_kernel_user
23745 +retint_swapgs_pax:
23746 TRACE_IRQS_IRETQ
23747 SWAPGS
23748 jmp restore_args
23749
23750 retint_restore_args: /* return to kernel space */
23751 DISABLE_INTERRUPTS(CLBR_ANY)
23752 + pax_exit_kernel
23753 + pax_force_retaddr (RIP-ARGOFFSET)
23754 /*
23755 * The iretq could re-enable interrupts:
23756 */
23757 @@ -1145,7 +1622,7 @@ ENTRY(retint_kernel)
23758 jmp exit_intr
23759 #endif
23760 CFI_ENDPROC
23761 -END(common_interrupt)
23762 +ENDPROC(common_interrupt)
23763
23764 /*
23765 * If IRET takes a fault on the espfix stack, then we
23766 @@ -1167,13 +1644,13 @@ __do_double_fault:
23767 cmpq $native_irq_return_iret,%rax
23768 jne do_double_fault /* This shouldn't happen... */
23769 movq PER_CPU_VAR(kernel_stack),%rax
23770 - subq $(6*8-KERNEL_STACK_OFFSET),%rax /* Reset to original stack */
23771 + subq $(6*8),%rax /* Reset to original stack */
23772 movq %rax,RSP(%rdi)
23773 movq $0,(%rax) /* Missing (lost) #GP error code */
23774 movq $general_protection,RIP(%rdi)
23775 retq
23776 CFI_ENDPROC
23777 -END(__do_double_fault)
23778 +ENDPROC(__do_double_fault)
23779 #else
23780 # define __do_double_fault do_double_fault
23781 #endif
23782 @@ -1195,7 +1672,7 @@ ENTRY(\sym)
23783 interrupt \do_sym
23784 jmp ret_from_intr
23785 CFI_ENDPROC
23786 -END(\sym)
23787 +ENDPROC(\sym)
23788 .endm
23789
23790 #ifdef CONFIG_TRACING
23791 @@ -1283,7 +1760,7 @@ ENTRY(\sym)
23792 call \do_sym
23793 jmp error_exit /* %ebx: no swapgs flag */
23794 CFI_ENDPROC
23795 -END(\sym)
23796 +ENDPROC(\sym)
23797 .endm
23798
23799 .macro paranoidzeroentry sym do_sym
23800 @@ -1301,10 +1778,10 @@ ENTRY(\sym)
23801 call \do_sym
23802 jmp paranoid_exit /* %ebx: no swapgs flag */
23803 CFI_ENDPROC
23804 -END(\sym)
23805 +ENDPROC(\sym)
23806 .endm
23807
23808 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
23809 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
23810 .macro paranoidzeroentry_ist sym do_sym ist
23811 ENTRY(\sym)
23812 INTR_FRAME
23813 @@ -1317,12 +1794,18 @@ ENTRY(\sym)
23814 TRACE_IRQS_OFF_DEBUG
23815 movq %rsp,%rdi /* pt_regs pointer */
23816 xorl %esi,%esi /* no error code */
23817 +#ifdef CONFIG_SMP
23818 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
23819 + lea init_tss(%r13), %r13
23820 +#else
23821 + lea init_tss(%rip), %r13
23822 +#endif
23823 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23824 call \do_sym
23825 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23826 jmp paranoid_exit /* %ebx: no swapgs flag */
23827 CFI_ENDPROC
23828 -END(\sym)
23829 +ENDPROC(\sym)
23830 .endm
23831
23832 .macro errorentry sym do_sym
23833 @@ -1340,7 +1823,7 @@ ENTRY(\sym)
23834 call \do_sym
23835 jmp error_exit /* %ebx: no swapgs flag */
23836 CFI_ENDPROC
23837 -END(\sym)
23838 +ENDPROC(\sym)
23839 .endm
23840
23841 #ifdef CONFIG_TRACING
23842 @@ -1371,7 +1854,7 @@ ENTRY(\sym)
23843 call \do_sym
23844 jmp paranoid_exit /* %ebx: no swapgs flag */
23845 CFI_ENDPROC
23846 -END(\sym)
23847 +ENDPROC(\sym)
23848 .endm
23849
23850 zeroentry divide_error do_divide_error
23851 @@ -1401,9 +1884,10 @@ gs_change:
23852 2: mfence /* workaround */
23853 SWAPGS
23854 popfq_cfi
23855 + pax_force_retaddr
23856 ret
23857 CFI_ENDPROC
23858 -END(native_load_gs_index)
23859 +ENDPROC(native_load_gs_index)
23860
23861 _ASM_EXTABLE(gs_change,bad_gs)
23862 .section .fixup,"ax"
23863 @@ -1431,9 +1915,10 @@ ENTRY(do_softirq_own_stack)
23864 CFI_DEF_CFA_REGISTER rsp
23865 CFI_ADJUST_CFA_OFFSET -8
23866 decl PER_CPU_VAR(irq_count)
23867 + pax_force_retaddr
23868 ret
23869 CFI_ENDPROC
23870 -END(do_softirq_own_stack)
23871 +ENDPROC(do_softirq_own_stack)
23872
23873 #ifdef CONFIG_XEN
23874 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
23875 @@ -1471,7 +1956,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
23876 decl PER_CPU_VAR(irq_count)
23877 jmp error_exit
23878 CFI_ENDPROC
23879 -END(xen_do_hypervisor_callback)
23880 +ENDPROC(xen_do_hypervisor_callback)
23881
23882 /*
23883 * Hypervisor uses this for application faults while it executes.
23884 @@ -1530,7 +2015,7 @@ ENTRY(xen_failsafe_callback)
23885 SAVE_ALL
23886 jmp error_exit
23887 CFI_ENDPROC
23888 -END(xen_failsafe_callback)
23889 +ENDPROC(xen_failsafe_callback)
23890
23891 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
23892 xen_hvm_callback_vector xen_evtchn_do_upcall
23893 @@ -1582,18 +2067,33 @@ ENTRY(paranoid_exit)
23894 DEFAULT_FRAME
23895 DISABLE_INTERRUPTS(CLBR_NONE)
23896 TRACE_IRQS_OFF_DEBUG
23897 - testl %ebx,%ebx /* swapgs needed? */
23898 + testl $1,%ebx /* swapgs needed? */
23899 jnz paranoid_restore
23900 - testl $3,CS(%rsp)
23901 + testb $3,CS(%rsp)
23902 jnz paranoid_userspace
23903 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23904 + pax_exit_kernel
23905 + TRACE_IRQS_IRETQ 0
23906 + SWAPGS_UNSAFE_STACK
23907 + RESTORE_ALL 8
23908 + pax_force_retaddr_bts
23909 + jmp irq_return
23910 +#endif
23911 paranoid_swapgs:
23912 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23913 + pax_exit_kernel_user
23914 +#else
23915 + pax_exit_kernel
23916 +#endif
23917 TRACE_IRQS_IRETQ 0
23918 SWAPGS_UNSAFE_STACK
23919 RESTORE_ALL 8
23920 jmp irq_return
23921 paranoid_restore:
23922 + pax_exit_kernel
23923 TRACE_IRQS_IRETQ_DEBUG 0
23924 RESTORE_ALL 8
23925 + pax_force_retaddr_bts
23926 jmp irq_return
23927 paranoid_userspace:
23928 GET_THREAD_INFO(%rcx)
23929 @@ -1622,7 +2122,7 @@ paranoid_schedule:
23930 TRACE_IRQS_OFF
23931 jmp paranoid_userspace
23932 CFI_ENDPROC
23933 -END(paranoid_exit)
23934 +ENDPROC(paranoid_exit)
23935
23936 /*
23937 * Exception entry point. This expects an error code/orig_rax on the stack.
23938 @@ -1649,12 +2149,23 @@ ENTRY(error_entry)
23939 movq_cfi r14, R14+8
23940 movq_cfi r15, R15+8
23941 xorl %ebx,%ebx
23942 - testl $3,CS+8(%rsp)
23943 + testb $3,CS+8(%rsp)
23944 je error_kernelspace
23945 error_swapgs:
23946 SWAPGS
23947 error_sti:
23948 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23949 + testb $3, CS+8(%rsp)
23950 + jnz 1f
23951 + pax_enter_kernel
23952 + jmp 2f
23953 +1: pax_enter_kernel_user
23954 +2:
23955 +#else
23956 + pax_enter_kernel
23957 +#endif
23958 TRACE_IRQS_OFF
23959 + pax_force_retaddr
23960 ret
23961
23962 /*
23963 @@ -1681,7 +2192,7 @@ bstep_iret:
23964 movq %rcx,RIP+8(%rsp)
23965 jmp error_swapgs
23966 CFI_ENDPROC
23967 -END(error_entry)
23968 +ENDPROC(error_entry)
23969
23970
23971 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
23972 @@ -1692,7 +2203,7 @@ ENTRY(error_exit)
23973 DISABLE_INTERRUPTS(CLBR_NONE)
23974 TRACE_IRQS_OFF
23975 GET_THREAD_INFO(%rcx)
23976 - testl %eax,%eax
23977 + testl $1,%eax
23978 jne retint_kernel
23979 LOCKDEP_SYS_EXIT_IRQ
23980 movl TI_flags(%rcx),%edx
23981 @@ -1701,7 +2212,7 @@ ENTRY(error_exit)
23982 jnz retint_careful
23983 jmp retint_swapgs
23984 CFI_ENDPROC
23985 -END(error_exit)
23986 +ENDPROC(error_exit)
23987
23988 /*
23989 * Test if a given stack is an NMI stack or not.
23990 @@ -1759,9 +2270,11 @@ ENTRY(nmi)
23991 * If %cs was not the kernel segment, then the NMI triggered in user
23992 * space, which means it is definitely not nested.
23993 */
23994 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
23995 + je 1f
23996 cmpl $__KERNEL_CS, 16(%rsp)
23997 jne first_nmi
23998 -
23999 +1:
24000 /*
24001 * Check the special variable on the stack to see if NMIs are
24002 * executing.
24003 @@ -1795,8 +2308,7 @@ nested_nmi:
24004
24005 1:
24006 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
24007 - leaq -1*8(%rsp), %rdx
24008 - movq %rdx, %rsp
24009 + subq $8, %rsp
24010 CFI_ADJUST_CFA_OFFSET 1*8
24011 leaq -10*8(%rsp), %rdx
24012 pushq_cfi $__KERNEL_DS
24013 @@ -1814,6 +2326,7 @@ nested_nmi_out:
24014 CFI_RESTORE rdx
24015
24016 /* No need to check faults here */
24017 +# pax_force_retaddr_bts
24018 INTERRUPT_RETURN
24019
24020 CFI_RESTORE_STATE
24021 @@ -1910,13 +2423,13 @@ end_repeat_nmi:
24022 subq $ORIG_RAX-R15, %rsp
24023 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
24024 /*
24025 - * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
24026 + * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
24027 * as we should not be calling schedule in NMI context.
24028 * Even with normal interrupts enabled. An NMI should not be
24029 * setting NEED_RESCHED or anything that normal interrupts and
24030 * exceptions might do.
24031 */
24032 - call save_paranoid
24033 + call save_paranoid_nmi
24034 DEFAULT_FRAME 0
24035
24036 /*
24037 @@ -1926,9 +2439,9 @@ end_repeat_nmi:
24038 * NMI itself takes a page fault, the page fault that was preempted
24039 * will read the information from the NMI page fault and not the
24040 * origin fault. Save it off and restore it if it changes.
24041 - * Use the r12 callee-saved register.
24042 + * Use the r13 callee-saved register.
24043 */
24044 - movq %cr2, %r12
24045 + movq %cr2, %r13
24046
24047 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
24048 movq %rsp,%rdi
24049 @@ -1937,31 +2450,36 @@ end_repeat_nmi:
24050
24051 /* Did the NMI take a page fault? Restore cr2 if it did */
24052 movq %cr2, %rcx
24053 - cmpq %rcx, %r12
24054 + cmpq %rcx, %r13
24055 je 1f
24056 - movq %r12, %cr2
24057 + movq %r13, %cr2
24058 1:
24059
24060 - testl %ebx,%ebx /* swapgs needed? */
24061 + testl $1,%ebx /* swapgs needed? */
24062 jnz nmi_restore
24063 nmi_swapgs:
24064 SWAPGS_UNSAFE_STACK
24065 nmi_restore:
24066 + pax_exit_kernel_nmi
24067 /* Pop the extra iret frame at once */
24068 RESTORE_ALL 6*8
24069 + testb $3, 8(%rsp)
24070 + jnz 1f
24071 + pax_force_retaddr_bts
24072 +1:
24073
24074 /* Clear the NMI executing stack variable */
24075 movq $0, 5*8(%rsp)
24076 jmp irq_return
24077 CFI_ENDPROC
24078 -END(nmi)
24079 +ENDPROC(nmi)
24080
24081 ENTRY(ignore_sysret)
24082 CFI_STARTPROC
24083 mov $-ENOSYS,%eax
24084 sysret
24085 CFI_ENDPROC
24086 -END(ignore_sysret)
24087 +ENDPROC(ignore_sysret)
24088
24089 /*
24090 * End of kprobes section
24091 diff --git a/arch/x86/kernel/espfix_64.c b/arch/x86/kernel/espfix_64.c
24092 index 94d857f..bf1f0bf 100644
24093 --- a/arch/x86/kernel/espfix_64.c
24094 +++ b/arch/x86/kernel/espfix_64.c
24095 @@ -197,7 +197,7 @@ void init_espfix_ap(void)
24096 set_pte(&pte_p[n*PTE_STRIDE], pte);
24097
24098 /* Job is done for this CPU and any CPU which shares this page */
24099 - ACCESS_ONCE(espfix_pages[page]) = stack_page;
24100 + ACCESS_ONCE_RW(espfix_pages[page]) = stack_page;
24101
24102 unlock_done:
24103 mutex_unlock(&espfix_init_mutex);
24104 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
24105 index 52819e8..b6d1dbd 100644
24106 --- a/arch/x86/kernel/ftrace.c
24107 +++ b/arch/x86/kernel/ftrace.c
24108 @@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
24109 {
24110 unsigned char replaced[MCOUNT_INSN_SIZE];
24111
24112 + ip = ktla_ktva(ip);
24113 +
24114 /*
24115 * Note: Due to modules and __init, code can
24116 * disappear and change, we need to protect against faulting
24117 @@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
24118 unsigned char old[MCOUNT_INSN_SIZE];
24119 int ret;
24120
24121 - memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
24122 + memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
24123
24124 ftrace_update_func = ip;
24125 /* Make sure the breakpoints see the ftrace_update_func update */
24126 @@ -306,7 +308,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
24127 * kernel identity mapping to modify code.
24128 */
24129 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
24130 - ip = (unsigned long)__va(__pa_symbol(ip));
24131 + ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
24132
24133 if (probe_kernel_write((void *)ip, val, size))
24134 return -EPERM;
24135 @@ -319,7 +321,7 @@ static int add_break(unsigned long ip, const char *old)
24136 unsigned char replaced[MCOUNT_INSN_SIZE];
24137 unsigned char brk = BREAKPOINT_INSTRUCTION;
24138
24139 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
24140 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
24141 return -EFAULT;
24142
24143 /* Make sure it is what we expect it to be */
24144 diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
24145 index 068054f..c248bcd 100644
24146 --- a/arch/x86/kernel/head64.c
24147 +++ b/arch/x86/kernel/head64.c
24148 @@ -67,12 +67,12 @@ again:
24149 pgd = *pgd_p;
24150
24151 /*
24152 - * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
24153 - * critical -- __PAGE_OFFSET would point us back into the dynamic
24154 + * The use of __early_va rather than __va here is critical:
24155 + * __va would point us back into the dynamic
24156 * range and we might end up looping forever...
24157 */
24158 if (pgd)
24159 - pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24160 + pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
24161 else {
24162 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24163 reset_early_page_tables();
24164 @@ -82,13 +82,13 @@ again:
24165 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
24166 for (i = 0; i < PTRS_PER_PUD; i++)
24167 pud_p[i] = 0;
24168 - *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24169 + *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
24170 }
24171 pud_p += pud_index(address);
24172 pud = *pud_p;
24173
24174 if (pud)
24175 - pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24176 + pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
24177 else {
24178 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24179 reset_early_page_tables();
24180 @@ -98,7 +98,7 @@ again:
24181 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24182 for (i = 0; i < PTRS_PER_PMD; i++)
24183 pmd_p[i] = 0;
24184 - *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24185 + *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24186 }
24187 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24188 pmd_p[pmd_index(address)] = pmd;
24189 @@ -175,7 +175,6 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data)
24190 if (console_loglevel == 10)
24191 early_printk("Kernel alive\n");
24192
24193 - clear_page(init_level4_pgt);
24194 /* set init_level4_pgt kernel high mapping*/
24195 init_level4_pgt[511] = early_level4_pgt[511];
24196
24197 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24198 index f36bd42..0ab4474 100644
24199 --- a/arch/x86/kernel/head_32.S
24200 +++ b/arch/x86/kernel/head_32.S
24201 @@ -26,6 +26,12 @@
24202 /* Physical address */
24203 #define pa(X) ((X) - __PAGE_OFFSET)
24204
24205 +#ifdef CONFIG_PAX_KERNEXEC
24206 +#define ta(X) (X)
24207 +#else
24208 +#define ta(X) ((X) - __PAGE_OFFSET)
24209 +#endif
24210 +
24211 /*
24212 * References to members of the new_cpu_data structure.
24213 */
24214 @@ -55,11 +61,7 @@
24215 * and small than max_low_pfn, otherwise will waste some page table entries
24216 */
24217
24218 -#if PTRS_PER_PMD > 1
24219 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24220 -#else
24221 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24222 -#endif
24223 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24224
24225 /* Number of possible pages in the lowmem region */
24226 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24227 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24228 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24229
24230 /*
24231 + * Real beginning of normal "text" segment
24232 + */
24233 +ENTRY(stext)
24234 +ENTRY(_stext)
24235 +
24236 +/*
24237 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24238 * %esi points to the real-mode code as a 32-bit pointer.
24239 * CS and DS must be 4 GB flat segments, but we don't depend on
24240 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24241 * can.
24242 */
24243 __HEAD
24244 +
24245 +#ifdef CONFIG_PAX_KERNEXEC
24246 + jmp startup_32
24247 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24248 +.fill PAGE_SIZE-5,1,0xcc
24249 +#endif
24250 +
24251 ENTRY(startup_32)
24252 movl pa(stack_start),%ecx
24253
24254 @@ -106,6 +121,59 @@ ENTRY(startup_32)
24255 2:
24256 leal -__PAGE_OFFSET(%ecx),%esp
24257
24258 +#ifdef CONFIG_SMP
24259 + movl $pa(cpu_gdt_table),%edi
24260 + movl $__per_cpu_load,%eax
24261 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24262 + rorl $16,%eax
24263 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24264 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24265 + movl $__per_cpu_end - 1,%eax
24266 + subl $__per_cpu_start,%eax
24267 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24268 +#endif
24269 +
24270 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24271 + movl $NR_CPUS,%ecx
24272 + movl $pa(cpu_gdt_table),%edi
24273 +1:
24274 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24275 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24276 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24277 + addl $PAGE_SIZE_asm,%edi
24278 + loop 1b
24279 +#endif
24280 +
24281 +#ifdef CONFIG_PAX_KERNEXEC
24282 + movl $pa(boot_gdt),%edi
24283 + movl $__LOAD_PHYSICAL_ADDR,%eax
24284 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24285 + rorl $16,%eax
24286 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24287 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24288 + rorl $16,%eax
24289 +
24290 + ljmp $(__BOOT_CS),$1f
24291 +1:
24292 +
24293 + movl $NR_CPUS,%ecx
24294 + movl $pa(cpu_gdt_table),%edi
24295 + addl $__PAGE_OFFSET,%eax
24296 +1:
24297 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24298 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24299 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24300 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24301 + rorl $16,%eax
24302 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24303 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24304 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24305 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24306 + rorl $16,%eax
24307 + addl $PAGE_SIZE_asm,%edi
24308 + loop 1b
24309 +#endif
24310 +
24311 /*
24312 * Clear BSS first so that there are no surprises...
24313 */
24314 @@ -201,8 +269,11 @@ ENTRY(startup_32)
24315 movl %eax, pa(max_pfn_mapped)
24316
24317 /* Do early initialization of the fixmap area */
24318 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24319 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24320 +#ifdef CONFIG_COMPAT_VDSO
24321 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24322 +#else
24323 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24324 +#endif
24325 #else /* Not PAE */
24326
24327 page_pde_offset = (__PAGE_OFFSET >> 20);
24328 @@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24329 movl %eax, pa(max_pfn_mapped)
24330
24331 /* Do early initialization of the fixmap area */
24332 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24333 - movl %eax,pa(initial_page_table+0xffc)
24334 +#ifdef CONFIG_COMPAT_VDSO
24335 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24336 +#else
24337 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24338 +#endif
24339 #endif
24340
24341 #ifdef CONFIG_PARAVIRT
24342 @@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24343 cmpl $num_subarch_entries, %eax
24344 jae bad_subarch
24345
24346 - movl pa(subarch_entries)(,%eax,4), %eax
24347 - subl $__PAGE_OFFSET, %eax
24348 - jmp *%eax
24349 + jmp *pa(subarch_entries)(,%eax,4)
24350
24351 bad_subarch:
24352 WEAK(lguest_entry)
24353 @@ -261,10 +333,10 @@ WEAK(xen_entry)
24354 __INITDATA
24355
24356 subarch_entries:
24357 - .long default_entry /* normal x86/PC */
24358 - .long lguest_entry /* lguest hypervisor */
24359 - .long xen_entry /* Xen hypervisor */
24360 - .long default_entry /* Moorestown MID */
24361 + .long ta(default_entry) /* normal x86/PC */
24362 + .long ta(lguest_entry) /* lguest hypervisor */
24363 + .long ta(xen_entry) /* Xen hypervisor */
24364 + .long ta(default_entry) /* Moorestown MID */
24365 num_subarch_entries = (. - subarch_entries) / 4
24366 .previous
24367 #else
24368 @@ -354,6 +426,7 @@ default_entry:
24369 movl pa(mmu_cr4_features),%eax
24370 movl %eax,%cr4
24371
24372 +#ifdef CONFIG_X86_PAE
24373 testb $X86_CR4_PAE, %al # check if PAE is enabled
24374 jz enable_paging
24375
24376 @@ -382,6 +455,9 @@ default_entry:
24377 /* Make changes effective */
24378 wrmsr
24379
24380 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24381 +#endif
24382 +
24383 enable_paging:
24384
24385 /*
24386 @@ -449,14 +525,20 @@ is486:
24387 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24388 movl %eax,%ss # after changing gdt.
24389
24390 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
24391 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24392 movl %eax,%ds
24393 movl %eax,%es
24394
24395 movl $(__KERNEL_PERCPU), %eax
24396 movl %eax,%fs # set this cpu's percpu
24397
24398 +#ifdef CONFIG_CC_STACKPROTECTOR
24399 movl $(__KERNEL_STACK_CANARY),%eax
24400 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24401 + movl $(__USER_DS),%eax
24402 +#else
24403 + xorl %eax,%eax
24404 +#endif
24405 movl %eax,%gs
24406
24407 xorl %eax,%eax # Clear LDT
24408 @@ -512,8 +594,11 @@ setup_once:
24409 * relocation. Manually set base address in stack canary
24410 * segment descriptor.
24411 */
24412 - movl $gdt_page,%eax
24413 + movl $cpu_gdt_table,%eax
24414 movl $stack_canary,%ecx
24415 +#ifdef CONFIG_SMP
24416 + addl $__per_cpu_load,%ecx
24417 +#endif
24418 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24419 shrl $16, %ecx
24420 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24421 @@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24422 cmpl $2,(%esp) # X86_TRAP_NMI
24423 je is_nmi # Ignore NMI
24424
24425 - cmpl $2,%ss:early_recursion_flag
24426 + cmpl $1,%ss:early_recursion_flag
24427 je hlt_loop
24428 incl %ss:early_recursion_flag
24429
24430 @@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24431 pushl (20+6*4)(%esp) /* trapno */
24432 pushl $fault_msg
24433 call printk
24434 -#endif
24435 call dump_stack
24436 +#endif
24437 hlt_loop:
24438 hlt
24439 jmp hlt_loop
24440 @@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24441 /* This is the default interrupt "handler" :-) */
24442 ALIGN
24443 ignore_int:
24444 - cld
24445 #ifdef CONFIG_PRINTK
24446 + cmpl $2,%ss:early_recursion_flag
24447 + je hlt_loop
24448 + incl %ss:early_recursion_flag
24449 + cld
24450 pushl %eax
24451 pushl %ecx
24452 pushl %edx
24453 @@ -617,9 +705,6 @@ ignore_int:
24454 movl $(__KERNEL_DS),%eax
24455 movl %eax,%ds
24456 movl %eax,%es
24457 - cmpl $2,early_recursion_flag
24458 - je hlt_loop
24459 - incl early_recursion_flag
24460 pushl 16(%esp)
24461 pushl 24(%esp)
24462 pushl 32(%esp)
24463 @@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24464 /*
24465 * BSS section
24466 */
24467 -__PAGE_ALIGNED_BSS
24468 - .align PAGE_SIZE
24469 #ifdef CONFIG_X86_PAE
24470 +.section .initial_pg_pmd,"a",@progbits
24471 initial_pg_pmd:
24472 .fill 1024*KPMDS,4,0
24473 #else
24474 +.section .initial_page_table,"a",@progbits
24475 ENTRY(initial_page_table)
24476 .fill 1024,4,0
24477 #endif
24478 +.section .initial_pg_fixmap,"a",@progbits
24479 initial_pg_fixmap:
24480 .fill 1024,4,0
24481 +.section .empty_zero_page,"a",@progbits
24482 ENTRY(empty_zero_page)
24483 .fill 4096,1,0
24484 +.section .swapper_pg_dir,"a",@progbits
24485 ENTRY(swapper_pg_dir)
24486 +#ifdef CONFIG_X86_PAE
24487 + .fill 4,8,0
24488 +#else
24489 .fill 1024,4,0
24490 +#endif
24491
24492 /*
24493 * This starts the data section.
24494 */
24495 #ifdef CONFIG_X86_PAE
24496 -__PAGE_ALIGNED_DATA
24497 - /* Page-aligned for the benefit of paravirt? */
24498 - .align PAGE_SIZE
24499 +.section .initial_page_table,"a",@progbits
24500 ENTRY(initial_page_table)
24501 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24502 # if KPMDS == 3
24503 @@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24504 # error "Kernel PMDs should be 1, 2 or 3"
24505 # endif
24506 .align PAGE_SIZE /* needs to be page-sized too */
24507 +
24508 +#ifdef CONFIG_PAX_PER_CPU_PGD
24509 +ENTRY(cpu_pgd)
24510 + .rept 2*NR_CPUS
24511 + .fill 4,8,0
24512 + .endr
24513 +#endif
24514 +
24515 #endif
24516
24517 .data
24518 .balign 4
24519 ENTRY(stack_start)
24520 - .long init_thread_union+THREAD_SIZE
24521 + .long init_thread_union+THREAD_SIZE-8
24522
24523 __INITRODATA
24524 int_msg:
24525 @@ -727,7 +825,7 @@ fault_msg:
24526 * segment size, and 32-bit linear address value:
24527 */
24528
24529 - .data
24530 +.section .rodata,"a",@progbits
24531 .globl boot_gdt_descr
24532 .globl idt_descr
24533
24534 @@ -736,7 +834,7 @@ fault_msg:
24535 .word 0 # 32 bit align gdt_desc.address
24536 boot_gdt_descr:
24537 .word __BOOT_DS+7
24538 - .long boot_gdt - __PAGE_OFFSET
24539 + .long pa(boot_gdt)
24540
24541 .word 0 # 32-bit align idt_desc.address
24542 idt_descr:
24543 @@ -747,7 +845,7 @@ idt_descr:
24544 .word 0 # 32 bit align gdt_desc.address
24545 ENTRY(early_gdt_descr)
24546 .word GDT_ENTRIES*8-1
24547 - .long gdt_page /* Overwritten for secondary CPUs */
24548 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
24549
24550 /*
24551 * The boot_gdt must mirror the equivalent in setup.S and is
24552 @@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24553 .align L1_CACHE_BYTES
24554 ENTRY(boot_gdt)
24555 .fill GDT_ENTRY_BOOT_CS,8,0
24556 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24557 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24558 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24559 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24560 +
24561 + .align PAGE_SIZE_asm
24562 +ENTRY(cpu_gdt_table)
24563 + .rept NR_CPUS
24564 + .quad 0x0000000000000000 /* NULL descriptor */
24565 + .quad 0x0000000000000000 /* 0x0b reserved */
24566 + .quad 0x0000000000000000 /* 0x13 reserved */
24567 + .quad 0x0000000000000000 /* 0x1b reserved */
24568 +
24569 +#ifdef CONFIG_PAX_KERNEXEC
24570 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24571 +#else
24572 + .quad 0x0000000000000000 /* 0x20 unused */
24573 +#endif
24574 +
24575 + .quad 0x0000000000000000 /* 0x28 unused */
24576 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24577 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24578 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24579 + .quad 0x0000000000000000 /* 0x4b reserved */
24580 + .quad 0x0000000000000000 /* 0x53 reserved */
24581 + .quad 0x0000000000000000 /* 0x5b reserved */
24582 +
24583 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24584 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24585 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24586 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24587 +
24588 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24589 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24590 +
24591 + /*
24592 + * Segments used for calling PnP BIOS have byte granularity.
24593 + * The code segments and data segments have fixed 64k limits,
24594 + * the transfer segment sizes are set at run time.
24595 + */
24596 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
24597 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
24598 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
24599 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
24600 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
24601 +
24602 + /*
24603 + * The APM segments have byte granularity and their bases
24604 + * are set at run time. All have 64k limits.
24605 + */
24606 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24607 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24608 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
24609 +
24610 + .quad 0x00c093000000ffff /* 0xd0 - ESPFIX SS */
24611 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24612 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24613 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24614 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24615 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24616 +
24617 + /* Be sure this is zeroed to avoid false validations in Xen */
24618 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24619 + .endr
24620 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24621 index a468c0a..c7dec74 100644
24622 --- a/arch/x86/kernel/head_64.S
24623 +++ b/arch/x86/kernel/head_64.S
24624 @@ -20,6 +20,8 @@
24625 #include <asm/processor-flags.h>
24626 #include <asm/percpu.h>
24627 #include <asm/nops.h>
24628 +#include <asm/cpufeature.h>
24629 +#include <asm/alternative-asm.h>
24630
24631 #ifdef CONFIG_PARAVIRT
24632 #include <asm/asm-offsets.h>
24633 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24634 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24635 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24636 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24637 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
24638 +L3_VMALLOC_START = pud_index(VMALLOC_START)
24639 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
24640 +L3_VMALLOC_END = pud_index(VMALLOC_END)
24641 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
24642 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
24643
24644 .text
24645 __HEAD
24646 @@ -89,11 +97,24 @@ startup_64:
24647 * Fixup the physical addresses in the page table
24648 */
24649 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
24650 + addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
24651 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
24652 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
24653 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
24654 + addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
24655
24656 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
24657 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
24658 + addq %rbp, level3_ident_pgt + (0*8)(%rip)
24659 +#ifndef CONFIG_XEN
24660 + addq %rbp, level3_ident_pgt + (1*8)(%rip)
24661 +#endif
24662 +
24663 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
24664 +
24665 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24666 + addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24667
24668 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24669 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24670
24671 /*
24672 * Set up the identity mapping for the switchover. These
24673 @@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
24674 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24675 1:
24676
24677 - /* Enable PAE mode and PGE */
24678 - movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24679 + /* Enable PAE mode and PSE/PGE */
24680 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24681 movq %rcx, %cr4
24682
24683 /* Setup early boot stage 4 level pagetables. */
24684 @@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
24685 movl $MSR_EFER, %ecx
24686 rdmsr
24687 btsl $_EFER_SCE, %eax /* Enable System Call */
24688 - btl $20,%edi /* No Execute supported? */
24689 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24690 jnc 1f
24691 btsl $_EFER_NX, %eax
24692 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24693 +#ifndef CONFIG_EFI
24694 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24695 +#endif
24696 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24697 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24698 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24699 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24700 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24701 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24702 1: wrmsr /* Make changes effective */
24703
24704 /* Setup cr0 */
24705 @@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
24706 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24707 * address given in m16:64.
24708 */
24709 + pax_set_fptr_mask
24710 movq initial_code(%rip),%rax
24711 pushq $0 # fake return address to stop unwinder
24712 pushq $__KERNEL_CS # set correct cs
24713 @@ -313,7 +344,7 @@ ENDPROC(start_cpu0)
24714 .quad INIT_PER_CPU_VAR(irq_stack_union)
24715
24716 GLOBAL(stack_start)
24717 - .quad init_thread_union+THREAD_SIZE-8
24718 + .quad init_thread_union+THREAD_SIZE-16
24719 .word 0
24720 __FINITDATA
24721
24722 @@ -391,7 +422,7 @@ ENTRY(early_idt_handler)
24723 call dump_stack
24724 #ifdef CONFIG_KALLSYMS
24725 leaq early_idt_ripmsg(%rip),%rdi
24726 - movq 40(%rsp),%rsi # %rip again
24727 + movq 88(%rsp),%rsi # %rip again
24728 call __print_symbol
24729 #endif
24730 #endif /* EARLY_PRINTK */
24731 @@ -420,6 +451,7 @@ ENDPROC(early_idt_handler)
24732 early_recursion_flag:
24733 .long 0
24734
24735 + .section .rodata,"a",@progbits
24736 #ifdef CONFIG_EARLY_PRINTK
24737 early_idt_msg:
24738 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24739 @@ -447,29 +479,52 @@ NEXT_PAGE(early_level4_pgt)
24740 NEXT_PAGE(early_dynamic_pgts)
24741 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24742
24743 - .data
24744 + .section .rodata,"a",@progbits
24745
24746 -#ifndef CONFIG_XEN
24747 NEXT_PAGE(init_level4_pgt)
24748 - .fill 512,8,0
24749 -#else
24750 -NEXT_PAGE(init_level4_pgt)
24751 - .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24752 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
24753 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24754 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
24755 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
24756 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
24757 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
24758 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
24759 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24760 .org init_level4_pgt + L4_START_KERNEL*8, 0
24761 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
24762 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
24763
24764 +#ifdef CONFIG_PAX_PER_CPU_PGD
24765 +NEXT_PAGE(cpu_pgd)
24766 + .rept 2*NR_CPUS
24767 + .fill 512,8,0
24768 + .endr
24769 +#endif
24770 +
24771 NEXT_PAGE(level3_ident_pgt)
24772 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24773 +#ifdef CONFIG_XEN
24774 .fill 511, 8, 0
24775 +#else
24776 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
24777 + .fill 510,8,0
24778 +#endif
24779 +
24780 +NEXT_PAGE(level3_vmalloc_start_pgt)
24781 + .fill 512,8,0
24782 +
24783 +NEXT_PAGE(level3_vmalloc_end_pgt)
24784 + .fill 512,8,0
24785 +
24786 +NEXT_PAGE(level3_vmemmap_pgt)
24787 + .fill L3_VMEMMAP_START,8,0
24788 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24789 +
24790 NEXT_PAGE(level2_ident_pgt)
24791 - /* Since I easily can, map the first 1G.
24792 + /* Since I easily can, map the first 2G.
24793 * Don't set NX because code runs from these pages.
24794 */
24795 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
24796 -#endif
24797 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
24798
24799 NEXT_PAGE(level3_kernel_pgt)
24800 .fill L3_START_KERNEL,8,0
24801 @@ -477,6 +532,9 @@ NEXT_PAGE(level3_kernel_pgt)
24802 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
24803 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24804
24805 +NEXT_PAGE(level2_vmemmap_pgt)
24806 + .fill 512,8,0
24807 +
24808 NEXT_PAGE(level2_kernel_pgt)
24809 /*
24810 * 512 MB kernel mapping. We spend a full page on this pagetable
24811 @@ -494,28 +552,64 @@ NEXT_PAGE(level2_kernel_pgt)
24812 NEXT_PAGE(level2_fixmap_pgt)
24813 .fill 506,8,0
24814 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24815 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
24816 - .fill 5,8,0
24817 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
24818 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
24819 + .fill 4,8,0
24820
24821 NEXT_PAGE(level1_fixmap_pgt)
24822 .fill 512,8,0
24823
24824 +NEXT_PAGE(level1_vsyscall_pgt)
24825 + .fill 512,8,0
24826 +
24827 #undef PMDS
24828
24829 - .data
24830 + .align PAGE_SIZE
24831 +ENTRY(cpu_gdt_table)
24832 + .rept NR_CPUS
24833 + .quad 0x0000000000000000 /* NULL descriptor */
24834 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
24835 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
24836 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
24837 + .quad 0x00cffb000000ffff /* __USER32_CS */
24838 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
24839 + .quad 0x00affb000000ffff /* __USER_CS */
24840 +
24841 +#ifdef CONFIG_PAX_KERNEXEC
24842 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
24843 +#else
24844 + .quad 0x0 /* unused */
24845 +#endif
24846 +
24847 + .quad 0,0 /* TSS */
24848 + .quad 0,0 /* LDT */
24849 + .quad 0,0,0 /* three TLS descriptors */
24850 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
24851 + /* asm/segment.h:GDT_ENTRIES must match this */
24852 +
24853 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24854 + .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
24855 +#else
24856 + .quad 0x0 /* unused */
24857 +#endif
24858 +
24859 + /* zero the remaining page */
24860 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
24861 + .endr
24862 +
24863 .align 16
24864 .globl early_gdt_descr
24865 early_gdt_descr:
24866 .word GDT_ENTRIES*8-1
24867 early_gdt_descr_base:
24868 - .quad INIT_PER_CPU_VAR(gdt_page)
24869 + .quad cpu_gdt_table
24870
24871 ENTRY(phys_base)
24872 /* This must match the first entry in level2_kernel_pgt */
24873 .quad 0x0000000000000000
24874
24875 #include "../../x86/xen/xen-head.S"
24876 -
24877 - __PAGE_ALIGNED_BSS
24878 +
24879 + .section .rodata,"a",@progbits
24880 NEXT_PAGE(empty_zero_page)
24881 .skip PAGE_SIZE
24882 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
24883 index 05fd74f..c3548b1 100644
24884 --- a/arch/x86/kernel/i386_ksyms_32.c
24885 +++ b/arch/x86/kernel/i386_ksyms_32.c
24886 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
24887 EXPORT_SYMBOL(cmpxchg8b_emu);
24888 #endif
24889
24890 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
24891 +
24892 /* Networking helper routines. */
24893 EXPORT_SYMBOL(csum_partial_copy_generic);
24894 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
24895 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
24896
24897 EXPORT_SYMBOL(__get_user_1);
24898 EXPORT_SYMBOL(__get_user_2);
24899 @@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
24900 EXPORT_SYMBOL(___preempt_schedule_context);
24901 #endif
24902 #endif
24903 +
24904 +#ifdef CONFIG_PAX_KERNEXEC
24905 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
24906 +#endif
24907 +
24908 +#ifdef CONFIG_PAX_PER_CPU_PGD
24909 +EXPORT_SYMBOL(cpu_pgd);
24910 +#endif
24911 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
24912 index d5dd808..b6432cf 100644
24913 --- a/arch/x86/kernel/i387.c
24914 +++ b/arch/x86/kernel/i387.c
24915 @@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
24916 static inline bool interrupted_user_mode(void)
24917 {
24918 struct pt_regs *regs = get_irq_regs();
24919 - return regs && user_mode_vm(regs);
24920 + return regs && user_mode(regs);
24921 }
24922
24923 /*
24924 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
24925 index 2e977b5..5f2c273 100644
24926 --- a/arch/x86/kernel/i8259.c
24927 +++ b/arch/x86/kernel/i8259.c
24928 @@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
24929 static void make_8259A_irq(unsigned int irq)
24930 {
24931 disable_irq_nosync(irq);
24932 - io_apic_irqs &= ~(1<<irq);
24933 + io_apic_irqs &= ~(1UL<<irq);
24934 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
24935 i8259A_chip.name);
24936 enable_irq(irq);
24937 @@ -209,7 +209,7 @@ spurious_8259A_irq:
24938 "spurious 8259A interrupt: IRQ%d.\n", irq);
24939 spurious_irq_mask |= irqmask;
24940 }
24941 - atomic_inc(&irq_err_count);
24942 + atomic_inc_unchecked(&irq_err_count);
24943 /*
24944 * Theoretically we do not have to handle this IRQ,
24945 * but in Linux this does not cause problems and is
24946 @@ -332,14 +332,16 @@ static void init_8259A(int auto_eoi)
24947 /* (slave's support for AEOI in flat mode is to be investigated) */
24948 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
24949
24950 + pax_open_kernel();
24951 if (auto_eoi)
24952 /*
24953 * In AEOI mode we just have to mask the interrupt
24954 * when acking.
24955 */
24956 - i8259A_chip.irq_mask_ack = disable_8259A_irq;
24957 + *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
24958 else
24959 - i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24960 + *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24961 + pax_close_kernel();
24962
24963 udelay(100); /* wait for 8259A to initialize */
24964
24965 diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
24966 index a979b5b..1d6db75 100644
24967 --- a/arch/x86/kernel/io_delay.c
24968 +++ b/arch/x86/kernel/io_delay.c
24969 @@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
24970 * Quirk table for systems that misbehave (lock up, etc.) if port
24971 * 0x80 is used:
24972 */
24973 -static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
24974 +static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
24975 {
24976 .callback = dmi_io_delay_0xed_port,
24977 .ident = "Compaq Presario V6000",
24978 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
24979 index 4ddaf66..49d5c18 100644
24980 --- a/arch/x86/kernel/ioport.c
24981 +++ b/arch/x86/kernel/ioport.c
24982 @@ -6,6 +6,7 @@
24983 #include <linux/sched.h>
24984 #include <linux/kernel.h>
24985 #include <linux/capability.h>
24986 +#include <linux/security.h>
24987 #include <linux/errno.h>
24988 #include <linux/types.h>
24989 #include <linux/ioport.h>
24990 @@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24991 return -EINVAL;
24992 if (turn_on && !capable(CAP_SYS_RAWIO))
24993 return -EPERM;
24994 +#ifdef CONFIG_GRKERNSEC_IO
24995 + if (turn_on && grsec_disable_privio) {
24996 + gr_handle_ioperm();
24997 + return -ENODEV;
24998 + }
24999 +#endif
25000
25001 /*
25002 * If it's the first ioperm() call in this thread's lifetime, set the
25003 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25004 * because the ->io_bitmap_max value must match the bitmap
25005 * contents:
25006 */
25007 - tss = &per_cpu(init_tss, get_cpu());
25008 + tss = init_tss + get_cpu();
25009
25010 if (turn_on)
25011 bitmap_clear(t->io_bitmap_ptr, from, num);
25012 @@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
25013 if (level > old) {
25014 if (!capable(CAP_SYS_RAWIO))
25015 return -EPERM;
25016 +#ifdef CONFIG_GRKERNSEC_IO
25017 + if (grsec_disable_privio) {
25018 + gr_handle_iopl();
25019 + return -ENODEV;
25020 + }
25021 +#endif
25022 }
25023 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
25024 t->iopl = level << 12;
25025 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
25026 index 11ccfb0..ec1e46f 100644
25027 --- a/arch/x86/kernel/irq.c
25028 +++ b/arch/x86/kernel/irq.c
25029 @@ -22,7 +22,7 @@
25030 #define CREATE_TRACE_POINTS
25031 #include <asm/trace/irq_vectors.h>
25032
25033 -atomic_t irq_err_count;
25034 +atomic_unchecked_t irq_err_count;
25035
25036 /* Function pointer for generic interrupt vector handling */
25037 void (*x86_platform_ipi_callback)(void) = NULL;
25038 @@ -132,9 +132,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
25039 seq_printf(p, "%10u ", irq_stats(j)->irq_hv_callback_count);
25040 seq_printf(p, " Hypervisor callback interrupts\n");
25041 #endif
25042 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
25043 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
25044 #if defined(CONFIG_X86_IO_APIC)
25045 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
25046 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
25047 #endif
25048 return 0;
25049 }
25050 @@ -174,7 +174,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
25051
25052 u64 arch_irq_stat(void)
25053 {
25054 - u64 sum = atomic_read(&irq_err_count);
25055 + u64 sum = atomic_read_unchecked(&irq_err_count);
25056 return sum;
25057 }
25058
25059 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
25060 index 63ce838..2ea3e06 100644
25061 --- a/arch/x86/kernel/irq_32.c
25062 +++ b/arch/x86/kernel/irq_32.c
25063 @@ -29,6 +29,8 @@ EXPORT_PER_CPU_SYMBOL(irq_regs);
25064
25065 #ifdef CONFIG_DEBUG_STACKOVERFLOW
25066
25067 +extern void gr_handle_kernel_exploit(void);
25068 +
25069 int sysctl_panic_on_stackoverflow __read_mostly;
25070
25071 /* Debugging check for stack overflow: is there less than 1KB free? */
25072 @@ -39,13 +41,14 @@ static int check_stack_overflow(void)
25073 __asm__ __volatile__("andl %%esp,%0" :
25074 "=r" (sp) : "0" (THREAD_SIZE - 1));
25075
25076 - return sp < (sizeof(struct thread_info) + STACK_WARN);
25077 + return sp < STACK_WARN;
25078 }
25079
25080 static void print_stack_overflow(void)
25081 {
25082 printk(KERN_WARNING "low stack detected by irq handler\n");
25083 dump_stack();
25084 + gr_handle_kernel_exploit();
25085 if (sysctl_panic_on_stackoverflow)
25086 panic("low stack detected by irq handler - check messages\n");
25087 }
25088 @@ -84,10 +87,9 @@ static inline void *current_stack(void)
25089 static inline int
25090 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25091 {
25092 - struct irq_stack *curstk, *irqstk;
25093 + struct irq_stack *irqstk;
25094 u32 *isp, *prev_esp, arg1, arg2;
25095
25096 - curstk = (struct irq_stack *) current_stack();
25097 irqstk = __this_cpu_read(hardirq_stack);
25098
25099 /*
25100 @@ -96,15 +98,19 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25101 * handler) we can't do that and just have to keep using the
25102 * current stack (which is the irq stack already after all)
25103 */
25104 - if (unlikely(curstk == irqstk))
25105 + if (unlikely((void *)current_stack_pointer - (void *)irqstk < THREAD_SIZE))
25106 return 0;
25107
25108 - isp = (u32 *) ((char *)irqstk + sizeof(*irqstk));
25109 + isp = (u32 *) ((char *)irqstk + sizeof(*irqstk) - 8);
25110
25111 /* Save the next esp at the bottom of the stack */
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 if (unlikely(overflow))
25120 call_on_stack(print_stack_overflow, isp);
25121
25122 @@ -115,6 +121,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25123 : "0" (irq), "1" (desc), "2" (isp),
25124 "D" (desc->handle_irq)
25125 : "memory", "cc", "ecx");
25126 +
25127 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25128 + __set_fs(current_thread_info()->addr_limit);
25129 +#endif
25130 +
25131 return 1;
25132 }
25133
25134 @@ -123,32 +134,18 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25135 */
25136 void irq_ctx_init(int cpu)
25137 {
25138 - struct irq_stack *irqstk;
25139 -
25140 if (per_cpu(hardirq_stack, cpu))
25141 return;
25142
25143 - irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25144 - THREADINFO_GFP,
25145 - THREAD_SIZE_ORDER));
25146 - per_cpu(hardirq_stack, cpu) = irqstk;
25147 -
25148 - irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25149 - THREADINFO_GFP,
25150 - THREAD_SIZE_ORDER));
25151 - per_cpu(softirq_stack, cpu) = irqstk;
25152 -
25153 - printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
25154 - cpu, per_cpu(hardirq_stack, cpu), per_cpu(softirq_stack, cpu));
25155 + per_cpu(hardirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25156 + per_cpu(softirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25157 }
25158
25159 void do_softirq_own_stack(void)
25160 {
25161 - struct thread_info *curstk;
25162 struct irq_stack *irqstk;
25163 u32 *isp, *prev_esp;
25164
25165 - curstk = current_stack();
25166 irqstk = __this_cpu_read(softirq_stack);
25167
25168 /* build the stack frame on the softirq stack */
25169 @@ -158,7 +155,16 @@ void do_softirq_own_stack(void)
25170 prev_esp = (u32 *)irqstk;
25171 *prev_esp = current_stack_pointer;
25172
25173 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25174 + __set_fs(MAKE_MM_SEG(0));
25175 +#endif
25176 +
25177 call_on_stack(__do_softirq, isp);
25178 +
25179 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25180 + __set_fs(current_thread_info()->addr_limit);
25181 +#endif
25182 +
25183 }
25184
25185 bool handle_irq(unsigned irq, struct pt_regs *regs)
25186 @@ -172,7 +178,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25187 if (unlikely(!desc))
25188 return false;
25189
25190 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25191 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25192 if (unlikely(overflow))
25193 print_stack_overflow();
25194 desc->handle_irq(irq, desc);
25195 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25196 index 4d1c746..55a22d6 100644
25197 --- a/arch/x86/kernel/irq_64.c
25198 +++ b/arch/x86/kernel/irq_64.c
25199 @@ -26,6 +26,8 @@ EXPORT_PER_CPU_SYMBOL(irq_stat);
25200 DEFINE_PER_CPU(struct pt_regs *, irq_regs);
25201 EXPORT_PER_CPU_SYMBOL(irq_regs);
25202
25203 +extern void gr_handle_kernel_exploit(void);
25204 +
25205 int sysctl_panic_on_stackoverflow;
25206
25207 /*
25208 @@ -44,7 +46,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25209 u64 estack_top, estack_bottom;
25210 u64 curbase = (u64)task_stack_page(current);
25211
25212 - if (user_mode_vm(regs))
25213 + if (user_mode(regs))
25214 return;
25215
25216 if (regs->sp >= curbase + sizeof(struct thread_info) +
25217 @@ -69,6 +71,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25218 irq_stack_top, irq_stack_bottom,
25219 estack_top, estack_bottom);
25220
25221 + gr_handle_kernel_exploit();
25222 +
25223 if (sysctl_panic_on_stackoverflow)
25224 panic("low stack detected by irq handler - check messages\n");
25225 #endif
25226 diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25227 index 26d5a55..a01160a 100644
25228 --- a/arch/x86/kernel/jump_label.c
25229 +++ b/arch/x86/kernel/jump_label.c
25230 @@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25231 * Jump label is enabled for the first time.
25232 * So we expect a default_nop...
25233 */
25234 - if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25235 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25236 != 0))
25237 bug_at((void *)entry->code, __LINE__);
25238 } else {
25239 @@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25240 * ...otherwise expect an ideal_nop. Otherwise
25241 * something went horribly wrong.
25242 */
25243 - if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25244 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25245 != 0))
25246 bug_at((void *)entry->code, __LINE__);
25247 }
25248 @@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25249 * are converting the default nop to the ideal nop.
25250 */
25251 if (init) {
25252 - if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25253 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25254 bug_at((void *)entry->code, __LINE__);
25255 } else {
25256 code.jump = 0xe9;
25257 code.offset = entry->target -
25258 (entry->code + JUMP_LABEL_NOP_SIZE);
25259 - if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25260 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25261 bug_at((void *)entry->code, __LINE__);
25262 }
25263 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25264 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25265 index 7ec1d5f..5a7d130 100644
25266 --- a/arch/x86/kernel/kgdb.c
25267 +++ b/arch/x86/kernel/kgdb.c
25268 @@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25269 #ifdef CONFIG_X86_32
25270 switch (regno) {
25271 case GDB_SS:
25272 - if (!user_mode_vm(regs))
25273 + if (!user_mode(regs))
25274 *(unsigned long *)mem = __KERNEL_DS;
25275 break;
25276 case GDB_SP:
25277 - if (!user_mode_vm(regs))
25278 + if (!user_mode(regs))
25279 *(unsigned long *)mem = kernel_stack_pointer(regs);
25280 break;
25281 case GDB_GS:
25282 @@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
25283 bp->attr.bp_addr = breakinfo[breakno].addr;
25284 bp->attr.bp_len = breakinfo[breakno].len;
25285 bp->attr.bp_type = breakinfo[breakno].type;
25286 - info->address = breakinfo[breakno].addr;
25287 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25288 + info->address = ktla_ktva(breakinfo[breakno].addr);
25289 + else
25290 + info->address = breakinfo[breakno].addr;
25291 info->len = breakinfo[breakno].len;
25292 info->type = breakinfo[breakno].type;
25293 val = arch_install_hw_breakpoint(bp);
25294 @@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25295 case 'k':
25296 /* clear the trace bit */
25297 linux_regs->flags &= ~X86_EFLAGS_TF;
25298 - atomic_set(&kgdb_cpu_doing_single_step, -1);
25299 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25300
25301 /* set the trace bit if we're stepping */
25302 if (remcomInBuffer[0] == 's') {
25303 linux_regs->flags |= X86_EFLAGS_TF;
25304 - atomic_set(&kgdb_cpu_doing_single_step,
25305 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25306 raw_smp_processor_id());
25307 }
25308
25309 @@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25310
25311 switch (cmd) {
25312 case DIE_DEBUG:
25313 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25314 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25315 if (user_mode(regs))
25316 return single_step_cont(regs, args);
25317 break;
25318 @@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25319 #endif /* CONFIG_DEBUG_RODATA */
25320
25321 bpt->type = BP_BREAKPOINT;
25322 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25323 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25324 BREAK_INSTR_SIZE);
25325 if (err)
25326 return err;
25327 - err = probe_kernel_write((char *)bpt->bpt_addr,
25328 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25329 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25330 #ifdef CONFIG_DEBUG_RODATA
25331 if (!err)
25332 @@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25333 return -EBUSY;
25334 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25335 BREAK_INSTR_SIZE);
25336 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25337 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25338 if (err)
25339 return err;
25340 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25341 @@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25342 if (mutex_is_locked(&text_mutex))
25343 goto knl_write;
25344 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25345 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25346 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25347 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25348 goto knl_write;
25349 return err;
25350 knl_write:
25351 #endif /* CONFIG_DEBUG_RODATA */
25352 - return probe_kernel_write((char *)bpt->bpt_addr,
25353 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25354 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25355 }
25356
25357 diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25358 index 61b17dc..784bfe9 100644
25359 --- a/arch/x86/kernel/kprobes/core.c
25360 +++ b/arch/x86/kernel/kprobes/core.c
25361 @@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
25362 s32 raddr;
25363 } __packed *insn;
25364
25365 - insn = (struct __arch_relative_insn *)from;
25366 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
25367 +
25368 + pax_open_kernel();
25369 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25370 insn->op = op;
25371 + pax_close_kernel();
25372 }
25373
25374 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25375 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
25376 kprobe_opcode_t opcode;
25377 kprobe_opcode_t *orig_opcodes = opcodes;
25378
25379 - if (search_exception_tables((unsigned long)opcodes))
25380 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25381 return 0; /* Page fault may occur on this address. */
25382
25383 retry:
25384 @@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25385 * for the first byte, we can recover the original instruction
25386 * from it and kp->opcode.
25387 */
25388 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25389 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25390 buf[0] = kp->opcode;
25391 - return (unsigned long)buf;
25392 + return ktva_ktla((unsigned long)buf);
25393 }
25394
25395 /*
25396 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25397 /* Another subsystem puts a breakpoint, failed to recover */
25398 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25399 return 0;
25400 + pax_open_kernel();
25401 memcpy(dest, insn.kaddr, insn.length);
25402 + pax_close_kernel();
25403
25404 #ifdef CONFIG_X86_64
25405 if (insn_rip_relative(&insn)) {
25406 @@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25407 return 0;
25408 }
25409 disp = (u8 *) dest + insn_offset_displacement(&insn);
25410 + pax_open_kernel();
25411 *(s32 *) disp = (s32) newdisp;
25412 + pax_close_kernel();
25413 }
25414 #endif
25415 return insn.length;
25416 @@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25417 * nor set current_kprobe, because it doesn't use single
25418 * stepping.
25419 */
25420 - regs->ip = (unsigned long)p->ainsn.insn;
25421 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25422 preempt_enable_no_resched();
25423 return;
25424 }
25425 @@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25426 regs->flags &= ~X86_EFLAGS_IF;
25427 /* single step inline if the instruction is an int3 */
25428 if (p->opcode == BREAKPOINT_INSTRUCTION)
25429 - regs->ip = (unsigned long)p->addr;
25430 + regs->ip = ktla_ktva((unsigned long)p->addr);
25431 else
25432 - regs->ip = (unsigned long)p->ainsn.insn;
25433 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25434 }
25435
25436 /*
25437 @@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
25438 setup_singlestep(p, regs, kcb, 0);
25439 return 1;
25440 }
25441 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
25442 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25443 /*
25444 * The breakpoint instruction was removed right
25445 * after we hit it. Another cpu has removed
25446 @@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
25447 " movq %rax, 152(%rsp)\n"
25448 RESTORE_REGS_STRING
25449 " popfq\n"
25450 +#ifdef KERNEXEC_PLUGIN
25451 + " btsq $63,(%rsp)\n"
25452 +#endif
25453 #else
25454 " pushf\n"
25455 SAVE_REGS_STRING
25456 @@ -779,7 +789,7 @@ static void __kprobes
25457 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
25458 {
25459 unsigned long *tos = stack_addr(regs);
25460 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25461 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25462 unsigned long orig_ip = (unsigned long)p->addr;
25463 kprobe_opcode_t *insn = p->ainsn.insn;
25464
25465 @@ -959,7 +969,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
25466 struct die_args *args = data;
25467 int ret = NOTIFY_DONE;
25468
25469 - if (args->regs && user_mode_vm(args->regs))
25470 + if (args->regs && user_mode(args->regs))
25471 return ret;
25472
25473 switch (val) {
25474 diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25475 index 898160b..758cde8 100644
25476 --- a/arch/x86/kernel/kprobes/opt.c
25477 +++ b/arch/x86/kernel/kprobes/opt.c
25478 @@ -79,6 +79,7 @@ found:
25479 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25480 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25481 {
25482 + pax_open_kernel();
25483 #ifdef CONFIG_X86_64
25484 *addr++ = 0x48;
25485 *addr++ = 0xbf;
25486 @@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
25487 *addr++ = 0xb8;
25488 #endif
25489 *(unsigned long *)addr = val;
25490 + pax_close_kernel();
25491 }
25492
25493 asm (
25494 @@ -335,7 +337,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25495 * Verify if the address gap is in 2GB range, because this uses
25496 * a relative jump.
25497 */
25498 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25499 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25500 if (abs(rel) > 0x7fffffff)
25501 return -ERANGE;
25502
25503 @@ -350,16 +352,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25504 op->optinsn.size = ret;
25505
25506 /* Copy arch-dep-instance from template */
25507 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25508 + pax_open_kernel();
25509 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25510 + pax_close_kernel();
25511
25512 /* Set probe information */
25513 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25514
25515 /* Set probe function call */
25516 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25517 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25518
25519 /* Set returning jmp instruction at the tail of out-of-line buffer */
25520 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25521 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25522 (u8 *)op->kp.addr + op->optinsn.size);
25523
25524 flush_icache_range((unsigned long) buf,
25525 @@ -384,7 +388,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
25526 WARN_ON(kprobe_disabled(&op->kp));
25527
25528 /* Backup instructions which will be replaced by jump address */
25529 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25530 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25531 RELATIVE_ADDR_SIZE);
25532
25533 insn_buf[0] = RELATIVEJUMP_OPCODE;
25534 @@ -433,7 +437,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25535 /* This kprobe is really able to run optimized path. */
25536 op = container_of(p, struct optimized_kprobe, kp);
25537 /* Detour through copied instructions */
25538 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25539 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25540 if (!reenter)
25541 reset_current_kprobe();
25542 preempt_enable_no_resched();
25543 diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
25544 index c2bedae..25e7ab60 100644
25545 --- a/arch/x86/kernel/ksysfs.c
25546 +++ b/arch/x86/kernel/ksysfs.c
25547 @@ -184,7 +184,7 @@ out:
25548
25549 static struct kobj_attribute type_attr = __ATTR_RO(type);
25550
25551 -static struct bin_attribute data_attr = {
25552 +static bin_attribute_no_const data_attr __read_only = {
25553 .attr = {
25554 .name = "data",
25555 .mode = S_IRUGO,
25556 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25557 index c37886d..d851d32 100644
25558 --- a/arch/x86/kernel/ldt.c
25559 +++ b/arch/x86/kernel/ldt.c
25560 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25561 if (reload) {
25562 #ifdef CONFIG_SMP
25563 preempt_disable();
25564 - load_LDT(pc);
25565 + load_LDT_nolock(pc);
25566 if (!cpumask_equal(mm_cpumask(current->mm),
25567 cpumask_of(smp_processor_id())))
25568 smp_call_function(flush_ldt, current->mm, 1);
25569 preempt_enable();
25570 #else
25571 - load_LDT(pc);
25572 + load_LDT_nolock(pc);
25573 #endif
25574 }
25575 if (oldsize) {
25576 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25577 return err;
25578
25579 for (i = 0; i < old->size; i++)
25580 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25581 + write_ldt_entry(new->ldt, i, old->ldt + i);
25582 return 0;
25583 }
25584
25585 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25586 retval = copy_ldt(&mm->context, &old_mm->context);
25587 mutex_unlock(&old_mm->context.lock);
25588 }
25589 +
25590 + if (tsk == current) {
25591 + mm->context.vdso = 0;
25592 +
25593 +#ifdef CONFIG_X86_32
25594 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25595 + mm->context.user_cs_base = 0UL;
25596 + mm->context.user_cs_limit = ~0UL;
25597 +
25598 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25599 + cpus_clear(mm->context.cpu_user_cs_mask);
25600 +#endif
25601 +
25602 +#endif
25603 +#endif
25604 +
25605 + }
25606 +
25607 return retval;
25608 }
25609
25610 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
25611 }
25612 }
25613
25614 +#ifdef CONFIG_PAX_SEGMEXEC
25615 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
25616 + error = -EINVAL;
25617 + goto out_unlock;
25618 + }
25619 +#endif
25620 +
25621 if (!IS_ENABLED(CONFIG_X86_16BIT) && !ldt_info.seg_32bit) {
25622 error = -EINVAL;
25623 goto out_unlock;
25624 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
25625 index 1667b1d..16492c5 100644
25626 --- a/arch/x86/kernel/machine_kexec_32.c
25627 +++ b/arch/x86/kernel/machine_kexec_32.c
25628 @@ -25,7 +25,7 @@
25629 #include <asm/cacheflush.h>
25630 #include <asm/debugreg.h>
25631
25632 -static void set_idt(void *newidt, __u16 limit)
25633 +static void set_idt(struct desc_struct *newidt, __u16 limit)
25634 {
25635 struct desc_ptr curidt;
25636
25637 @@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
25638 }
25639
25640
25641 -static void set_gdt(void *newgdt, __u16 limit)
25642 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
25643 {
25644 struct desc_ptr curgdt;
25645
25646 @@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
25647 }
25648
25649 control_page = page_address(image->control_code_page);
25650 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
25651 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
25652
25653 relocate_kernel_ptr = control_page;
25654 page_list[PA_CONTROL_PAGE] = __pa(control_page);
25655 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
25656 index e69f988..da078ea 100644
25657 --- a/arch/x86/kernel/module.c
25658 +++ b/arch/x86/kernel/module.c
25659 @@ -81,17 +81,62 @@ static unsigned long int get_module_load_offset(void)
25660 }
25661 #endif
25662
25663 -void *module_alloc(unsigned long size)
25664 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
25665 {
25666 - if (PAGE_ALIGN(size) > MODULES_LEN)
25667 + if (!size || PAGE_ALIGN(size) > MODULES_LEN)
25668 return NULL;
25669 return __vmalloc_node_range(size, 1,
25670 MODULES_VADDR + get_module_load_offset(),
25671 - MODULES_END, GFP_KERNEL | __GFP_HIGHMEM,
25672 - PAGE_KERNEL_EXEC, NUMA_NO_NODE,
25673 + MODULES_END, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
25674 + prot, NUMA_NO_NODE,
25675 __builtin_return_address(0));
25676 }
25677
25678 +void *module_alloc(unsigned long size)
25679 +{
25680 +
25681 +#ifdef CONFIG_PAX_KERNEXEC
25682 + return __module_alloc(size, PAGE_KERNEL);
25683 +#else
25684 + return __module_alloc(size, PAGE_KERNEL_EXEC);
25685 +#endif
25686 +
25687 +}
25688 +
25689 +#ifdef CONFIG_PAX_KERNEXEC
25690 +#ifdef CONFIG_X86_32
25691 +void *module_alloc_exec(unsigned long size)
25692 +{
25693 + struct vm_struct *area;
25694 +
25695 + if (size == 0)
25696 + return NULL;
25697 +
25698 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
25699 +return area ? area->addr : NULL;
25700 +}
25701 +EXPORT_SYMBOL(module_alloc_exec);
25702 +
25703 +void module_free_exec(struct module *mod, void *module_region)
25704 +{
25705 + vunmap(module_region);
25706 +}
25707 +EXPORT_SYMBOL(module_free_exec);
25708 +#else
25709 +void module_free_exec(struct module *mod, void *module_region)
25710 +{
25711 + module_free(mod, module_region);
25712 +}
25713 +EXPORT_SYMBOL(module_free_exec);
25714 +
25715 +void *module_alloc_exec(unsigned long size)
25716 +{
25717 + return __module_alloc(size, PAGE_KERNEL_RX);
25718 +}
25719 +EXPORT_SYMBOL(module_alloc_exec);
25720 +#endif
25721 +#endif
25722 +
25723 #ifdef CONFIG_X86_32
25724 int apply_relocate(Elf32_Shdr *sechdrs,
25725 const char *strtab,
25726 @@ -102,14 +147,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25727 unsigned int i;
25728 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
25729 Elf32_Sym *sym;
25730 - uint32_t *location;
25731 + uint32_t *plocation, location;
25732
25733 DEBUGP("Applying relocate section %u to %u\n",
25734 relsec, sechdrs[relsec].sh_info);
25735 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
25736 /* This is where to make the change */
25737 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
25738 - + rel[i].r_offset;
25739 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
25740 + location = (uint32_t)plocation;
25741 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
25742 + plocation = ktla_ktva((void *)plocation);
25743 /* This is the symbol it is referring to. Note that all
25744 undefined symbols have been resolved. */
25745 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
25746 @@ -118,11 +165,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25747 switch (ELF32_R_TYPE(rel[i].r_info)) {
25748 case R_386_32:
25749 /* We add the value into the location given */
25750 - *location += sym->st_value;
25751 + pax_open_kernel();
25752 + *plocation += sym->st_value;
25753 + pax_close_kernel();
25754 break;
25755 case R_386_PC32:
25756 /* Add the value, subtract its position */
25757 - *location += sym->st_value - (uint32_t)location;
25758 + pax_open_kernel();
25759 + *plocation += sym->st_value - location;
25760 + pax_close_kernel();
25761 break;
25762 default:
25763 pr_err("%s: Unknown relocation: %u\n",
25764 @@ -167,21 +218,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
25765 case R_X86_64_NONE:
25766 break;
25767 case R_X86_64_64:
25768 + pax_open_kernel();
25769 *(u64 *)loc = val;
25770 + pax_close_kernel();
25771 break;
25772 case R_X86_64_32:
25773 + pax_open_kernel();
25774 *(u32 *)loc = val;
25775 + pax_close_kernel();
25776 if (val != *(u32 *)loc)
25777 goto overflow;
25778 break;
25779 case R_X86_64_32S:
25780 + pax_open_kernel();
25781 *(s32 *)loc = val;
25782 + pax_close_kernel();
25783 if ((s64)val != *(s32 *)loc)
25784 goto overflow;
25785 break;
25786 case R_X86_64_PC32:
25787 val -= (u64)loc;
25788 + pax_open_kernel();
25789 *(u32 *)loc = val;
25790 + pax_close_kernel();
25791 +
25792 #if 0
25793 if ((s64)val != *(s32 *)loc)
25794 goto overflow;
25795 diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
25796 index c9603ac..9f88728 100644
25797 --- a/arch/x86/kernel/msr.c
25798 +++ b/arch/x86/kernel/msr.c
25799 @@ -37,6 +37,7 @@
25800 #include <linux/notifier.h>
25801 #include <linux/uaccess.h>
25802 #include <linux/gfp.h>
25803 +#include <linux/grsecurity.h>
25804
25805 #include <asm/processor.h>
25806 #include <asm/msr.h>
25807 @@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
25808 int err = 0;
25809 ssize_t bytes = 0;
25810
25811 +#ifdef CONFIG_GRKERNSEC_KMEM
25812 + gr_handle_msr_write();
25813 + return -EPERM;
25814 +#endif
25815 +
25816 if (count % 8)
25817 return -EINVAL; /* Invalid chunk size */
25818
25819 @@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
25820 err = -EBADF;
25821 break;
25822 }
25823 +#ifdef CONFIG_GRKERNSEC_KMEM
25824 + gr_handle_msr_write();
25825 + return -EPERM;
25826 +#endif
25827 if (copy_from_user(&regs, uregs, sizeof regs)) {
25828 err = -EFAULT;
25829 break;
25830 @@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
25831 return notifier_from_errno(err);
25832 }
25833
25834 -static struct notifier_block __refdata msr_class_cpu_notifier = {
25835 +static struct notifier_block msr_class_cpu_notifier = {
25836 .notifier_call = msr_class_cpu_callback,
25837 };
25838
25839 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
25840 index b4872b9..5bf0684 100644
25841 --- a/arch/x86/kernel/nmi.c
25842 +++ b/arch/x86/kernel/nmi.c
25843 @@ -98,16 +98,16 @@ fs_initcall(nmi_warning_debugfs);
25844
25845 static void nmi_max_handler(struct irq_work *w)
25846 {
25847 - struct nmiaction *a = container_of(w, struct nmiaction, irq_work);
25848 + struct nmiwork *n = container_of(w, struct nmiwork, irq_work);
25849 int remainder_ns, decimal_msecs;
25850 - u64 whole_msecs = ACCESS_ONCE(a->max_duration);
25851 + u64 whole_msecs = ACCESS_ONCE(n->max_duration);
25852
25853 remainder_ns = do_div(whole_msecs, (1000 * 1000));
25854 decimal_msecs = remainder_ns / 1000;
25855
25856 printk_ratelimited(KERN_INFO
25857 "INFO: NMI handler (%ps) took too long to run: %lld.%03d msecs\n",
25858 - a->handler, whole_msecs, decimal_msecs);
25859 + n->action->handler, whole_msecs, decimal_msecs);
25860 }
25861
25862 static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
25863 @@ -134,11 +134,11 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
25864 delta = sched_clock() - delta;
25865 trace_nmi_handler(a->handler, (int)delta, thishandled);
25866
25867 - if (delta < nmi_longest_ns || delta < a->max_duration)
25868 + if (delta < nmi_longest_ns || delta < a->work->max_duration)
25869 continue;
25870
25871 - a->max_duration = delta;
25872 - irq_work_queue(&a->irq_work);
25873 + a->work->max_duration = delta;
25874 + irq_work_queue(&a->work->irq_work);
25875 }
25876
25877 rcu_read_unlock();
25878 @@ -147,7 +147,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
25879 return handled;
25880 }
25881
25882 -int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25883 +int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
25884 {
25885 struct nmi_desc *desc = nmi_to_desc(type);
25886 unsigned long flags;
25887 @@ -155,7 +155,8 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25888 if (!action->handler)
25889 return -EINVAL;
25890
25891 - init_irq_work(&action->irq_work, nmi_max_handler);
25892 + action->work->action = action;
25893 + init_irq_work(&action->work->irq_work, nmi_max_handler);
25894
25895 spin_lock_irqsave(&desc->lock, flags);
25896
25897 @@ -173,9 +174,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25898 * event confuses some handlers (kdump uses this flag)
25899 */
25900 if (action->flags & NMI_FLAG_FIRST)
25901 - list_add_rcu(&action->list, &desc->head);
25902 + pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
25903 else
25904 - list_add_tail_rcu(&action->list, &desc->head);
25905 + pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
25906
25907 spin_unlock_irqrestore(&desc->lock, flags);
25908 return 0;
25909 @@ -198,7 +199,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
25910 if (!strcmp(n->name, name)) {
25911 WARN(in_nmi(),
25912 "Trying to free NMI (%s) from NMI context!\n", n->name);
25913 - list_del_rcu(&n->list);
25914 + pax_list_del_rcu((struct list_head *)&n->list);
25915 break;
25916 }
25917 }
25918 @@ -523,6 +524,17 @@ static inline void nmi_nesting_postprocess(void)
25919 dotraplinkage notrace __kprobes void
25920 do_nmi(struct pt_regs *regs, long error_code)
25921 {
25922 +
25923 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25924 + if (!user_mode(regs)) {
25925 + unsigned long cs = regs->cs & 0xFFFF;
25926 + unsigned long ip = ktva_ktla(regs->ip);
25927 +
25928 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
25929 + regs->ip = ip;
25930 + }
25931 +#endif
25932 +
25933 nmi_nesting_preprocess(regs);
25934
25935 nmi_enter();
25936 diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
25937 index 6d9582e..f746287 100644
25938 --- a/arch/x86/kernel/nmi_selftest.c
25939 +++ b/arch/x86/kernel/nmi_selftest.c
25940 @@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
25941 {
25942 /* trap all the unknown NMIs we may generate */
25943 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
25944 - __initdata);
25945 + __initconst);
25946 }
25947
25948 static void __init cleanup_nmi_testsuite(void)
25949 @@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
25950 unsigned long timeout;
25951
25952 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
25953 - NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
25954 + NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
25955 nmi_fail = FAILURE;
25956 return;
25957 }
25958 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
25959 index bbb6c73..24a58ef 100644
25960 --- a/arch/x86/kernel/paravirt-spinlocks.c
25961 +++ b/arch/x86/kernel/paravirt-spinlocks.c
25962 @@ -8,7 +8,7 @@
25963
25964 #include <asm/paravirt.h>
25965
25966 -struct pv_lock_ops pv_lock_ops = {
25967 +struct pv_lock_ops pv_lock_ops __read_only = {
25968 #ifdef CONFIG_SMP
25969 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
25970 .unlock_kick = paravirt_nop,
25971 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
25972 index 1b10af8..45bfbec 100644
25973 --- a/arch/x86/kernel/paravirt.c
25974 +++ b/arch/x86/kernel/paravirt.c
25975 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
25976 {
25977 return x;
25978 }
25979 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25980 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
25981 +#endif
25982
25983 void __init default_banner(void)
25984 {
25985 @@ -141,16 +144,20 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
25986
25987 if (opfunc == NULL)
25988 /* If there's no function, patch it with a ud2a (BUG) */
25989 - ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
25990 - else if (opfunc == _paravirt_nop)
25991 + ret = paravirt_patch_insns(insnbuf, len, ktva_ktla(ud2a), ud2a+sizeof(ud2a));
25992 + else if (opfunc == (void *)_paravirt_nop)
25993 /* If the operation is a nop, then nop the callsite */
25994 ret = paravirt_patch_nop();
25995
25996 /* identity functions just return their single argument */
25997 - else if (opfunc == _paravirt_ident_32)
25998 + else if (opfunc == (void *)_paravirt_ident_32)
25999 ret = paravirt_patch_ident_32(insnbuf, len);
26000 - else if (opfunc == _paravirt_ident_64)
26001 + else if (opfunc == (void *)_paravirt_ident_64)
26002 ret = paravirt_patch_ident_64(insnbuf, len);
26003 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26004 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
26005 + ret = paravirt_patch_ident_64(insnbuf, len);
26006 +#endif
26007
26008 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
26009 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
26010 @@ -175,7 +182,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
26011 if (insn_len > len || start == NULL)
26012 insn_len = len;
26013 else
26014 - memcpy(insnbuf, start, insn_len);
26015 + memcpy(insnbuf, ktla_ktva(start), insn_len);
26016
26017 return insn_len;
26018 }
26019 @@ -299,7 +306,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
26020 return this_cpu_read(paravirt_lazy_mode);
26021 }
26022
26023 -struct pv_info pv_info = {
26024 +struct pv_info pv_info __read_only = {
26025 .name = "bare hardware",
26026 .paravirt_enabled = 0,
26027 .kernel_rpl = 0,
26028 @@ -310,16 +317,16 @@ struct pv_info pv_info = {
26029 #endif
26030 };
26031
26032 -struct pv_init_ops pv_init_ops = {
26033 +struct pv_init_ops pv_init_ops __read_only = {
26034 .patch = native_patch,
26035 };
26036
26037 -struct pv_time_ops pv_time_ops = {
26038 +struct pv_time_ops pv_time_ops __read_only = {
26039 .sched_clock = native_sched_clock,
26040 .steal_clock = native_steal_clock,
26041 };
26042
26043 -__visible struct pv_irq_ops pv_irq_ops = {
26044 +__visible struct pv_irq_ops pv_irq_ops __read_only = {
26045 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
26046 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
26047 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
26048 @@ -331,7 +338,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
26049 #endif
26050 };
26051
26052 -__visible struct pv_cpu_ops pv_cpu_ops = {
26053 +__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
26054 .cpuid = native_cpuid,
26055 .get_debugreg = native_get_debugreg,
26056 .set_debugreg = native_set_debugreg,
26057 @@ -389,21 +396,26 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
26058 .end_context_switch = paravirt_nop,
26059 };
26060
26061 -struct pv_apic_ops pv_apic_ops = {
26062 +struct pv_apic_ops pv_apic_ops __read_only= {
26063 #ifdef CONFIG_X86_LOCAL_APIC
26064 .startup_ipi_hook = paravirt_nop,
26065 #endif
26066 };
26067
26068 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
26069 +#ifdef CONFIG_X86_32
26070 +#ifdef CONFIG_X86_PAE
26071 +/* 64-bit pagetable entries */
26072 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
26073 +#else
26074 /* 32-bit pagetable entries */
26075 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
26076 +#endif
26077 #else
26078 /* 64-bit pagetable entries */
26079 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
26080 #endif
26081
26082 -struct pv_mmu_ops pv_mmu_ops = {
26083 +struct pv_mmu_ops pv_mmu_ops __read_only = {
26084
26085 .read_cr2 = native_read_cr2,
26086 .write_cr2 = native_write_cr2,
26087 @@ -453,6 +465,7 @@ struct pv_mmu_ops pv_mmu_ops = {
26088 .make_pud = PTE_IDENT,
26089
26090 .set_pgd = native_set_pgd,
26091 + .set_pgd_batched = native_set_pgd_batched,
26092 #endif
26093 #endif /* PAGETABLE_LEVELS >= 3 */
26094
26095 @@ -473,6 +486,12 @@ struct pv_mmu_ops pv_mmu_ops = {
26096 },
26097
26098 .set_fixmap = native_set_fixmap,
26099 +
26100 +#ifdef CONFIG_PAX_KERNEXEC
26101 + .pax_open_kernel = native_pax_open_kernel,
26102 + .pax_close_kernel = native_pax_close_kernel,
26103 +#endif
26104 +
26105 };
26106
26107 EXPORT_SYMBOL_GPL(pv_time_ops);
26108 diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
26109 index 0497f71..7186c0d 100644
26110 --- a/arch/x86/kernel/pci-calgary_64.c
26111 +++ b/arch/x86/kernel/pci-calgary_64.c
26112 @@ -1347,7 +1347,7 @@ static void __init get_tce_space_from_tar(void)
26113 tce_space = be64_to_cpu(readq(target));
26114 tce_space = tce_space & TAR_SW_BITS;
26115
26116 - tce_space = tce_space & (~specified_table_size);
26117 + tce_space = tce_space & (~(unsigned long)specified_table_size);
26118 info->tce_space = (u64 *)__va(tce_space);
26119 }
26120 }
26121 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
26122 index 35ccf75..7a15747 100644
26123 --- a/arch/x86/kernel/pci-iommu_table.c
26124 +++ b/arch/x86/kernel/pci-iommu_table.c
26125 @@ -2,7 +2,7 @@
26126 #include <asm/iommu_table.h>
26127 #include <linux/string.h>
26128 #include <linux/kallsyms.h>
26129 -
26130 +#include <linux/sched.h>
26131
26132 #define DEBUG 1
26133
26134 diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
26135 index 6c483ba..d10ce2f 100644
26136 --- a/arch/x86/kernel/pci-swiotlb.c
26137 +++ b/arch/x86/kernel/pci-swiotlb.c
26138 @@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
26139 void *vaddr, dma_addr_t dma_addr,
26140 struct dma_attrs *attrs)
26141 {
26142 - swiotlb_free_coherent(dev, size, vaddr, dma_addr);
26143 + swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
26144 }
26145
26146 static struct dma_map_ops swiotlb_dma_ops = {
26147 diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
26148 index ca7f0d5..8996469 100644
26149 --- a/arch/x86/kernel/preempt.S
26150 +++ b/arch/x86/kernel/preempt.S
26151 @@ -3,12 +3,14 @@
26152 #include <asm/dwarf2.h>
26153 #include <asm/asm.h>
26154 #include <asm/calling.h>
26155 +#include <asm/alternative-asm.h>
26156
26157 ENTRY(___preempt_schedule)
26158 CFI_STARTPROC
26159 SAVE_ALL
26160 call preempt_schedule
26161 RESTORE_ALL
26162 + pax_force_retaddr
26163 ret
26164 CFI_ENDPROC
26165
26166 @@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
26167 SAVE_ALL
26168 call preempt_schedule_context
26169 RESTORE_ALL
26170 + pax_force_retaddr
26171 ret
26172 CFI_ENDPROC
26173
26174 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
26175 index 4505e2a..ae28b0d 100644
26176 --- a/arch/x86/kernel/process.c
26177 +++ b/arch/x86/kernel/process.c
26178 @@ -36,7 +36,8 @@
26179 * section. Since TSS's are completely CPU-local, we want them
26180 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
26181 */
26182 -__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
26183 +struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
26184 +EXPORT_SYMBOL(init_tss);
26185
26186 #ifdef CONFIG_X86_64
26187 static DEFINE_PER_CPU(unsigned char, is_idle);
26188 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
26189 task_xstate_cachep =
26190 kmem_cache_create("task_xstate", xstate_size,
26191 __alignof__(union thread_xstate),
26192 - SLAB_PANIC | SLAB_NOTRACK, NULL);
26193 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
26194 }
26195
26196 /*
26197 @@ -105,7 +106,7 @@ void exit_thread(void)
26198 unsigned long *bp = t->io_bitmap_ptr;
26199
26200 if (bp) {
26201 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
26202 + struct tss_struct *tss = init_tss + get_cpu();
26203
26204 t->io_bitmap_ptr = NULL;
26205 clear_thread_flag(TIF_IO_BITMAP);
26206 @@ -125,6 +126,9 @@ void flush_thread(void)
26207 {
26208 struct task_struct *tsk = current;
26209
26210 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
26211 + loadsegment(gs, 0);
26212 +#endif
26213 flush_ptrace_hw_breakpoint(tsk);
26214 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
26215 drop_init_fpu(tsk);
26216 @@ -271,7 +275,7 @@ static void __exit_idle(void)
26217 void exit_idle(void)
26218 {
26219 /* idle loop has pid 0 */
26220 - if (current->pid)
26221 + if (task_pid_nr(current))
26222 return;
26223 __exit_idle();
26224 }
26225 @@ -324,7 +328,7 @@ bool xen_set_default_idle(void)
26226 return ret;
26227 }
26228 #endif
26229 -void stop_this_cpu(void *dummy)
26230 +__noreturn void stop_this_cpu(void *dummy)
26231 {
26232 local_irq_disable();
26233 /*
26234 @@ -453,16 +457,37 @@ static int __init idle_setup(char *str)
26235 }
26236 early_param("idle", idle_setup);
26237
26238 -unsigned long arch_align_stack(unsigned long sp)
26239 +#ifdef CONFIG_PAX_RANDKSTACK
26240 +void pax_randomize_kstack(struct pt_regs *regs)
26241 {
26242 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26243 - sp -= get_random_int() % 8192;
26244 - return sp & ~0xf;
26245 -}
26246 + struct thread_struct *thread = &current->thread;
26247 + unsigned long time;
26248
26249 -unsigned long arch_randomize_brk(struct mm_struct *mm)
26250 -{
26251 - unsigned long range_end = mm->brk + 0x02000000;
26252 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26253 -}
26254 + if (!randomize_va_space)
26255 + return;
26256 +
26257 + if (v8086_mode(regs))
26258 + return;
26259
26260 + rdtscl(time);
26261 +
26262 + /* P4 seems to return a 0 LSB, ignore it */
26263 +#ifdef CONFIG_MPENTIUM4
26264 + time &= 0x3EUL;
26265 + time <<= 2;
26266 +#elif defined(CONFIG_X86_64)
26267 + time &= 0xFUL;
26268 + time <<= 4;
26269 +#else
26270 + time &= 0x1FUL;
26271 + time <<= 3;
26272 +#endif
26273 +
26274 + thread->sp0 ^= time;
26275 + load_sp0(init_tss + smp_processor_id(), thread);
26276 +
26277 +#ifdef CONFIG_X86_64
26278 + this_cpu_write(kernel_stack, thread->sp0);
26279 +#endif
26280 +}
26281 +#endif
26282 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26283 index 7bc86bb..0ea06e8 100644
26284 --- a/arch/x86/kernel/process_32.c
26285 +++ b/arch/x86/kernel/process_32.c
26286 @@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26287 unsigned long thread_saved_pc(struct task_struct *tsk)
26288 {
26289 return ((unsigned long *)tsk->thread.sp)[3];
26290 +//XXX return tsk->thread.eip;
26291 }
26292
26293 void __show_regs(struct pt_regs *regs, int all)
26294 @@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
26295 unsigned long sp;
26296 unsigned short ss, gs;
26297
26298 - if (user_mode_vm(regs)) {
26299 + if (user_mode(regs)) {
26300 sp = regs->sp;
26301 ss = regs->ss & 0xffff;
26302 - gs = get_user_gs(regs);
26303 } else {
26304 sp = kernel_stack_pointer(regs);
26305 savesegment(ss, ss);
26306 - savesegment(gs, gs);
26307 }
26308 + gs = get_user_gs(regs);
26309
26310 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26311 (u16)regs->cs, regs->ip, regs->flags,
26312 - smp_processor_id());
26313 + raw_smp_processor_id());
26314 print_symbol("EIP is at %s\n", regs->ip);
26315
26316 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26317 @@ -132,20 +132,21 @@ void release_thread(struct task_struct *dead_task)
26318 int copy_thread(unsigned long clone_flags, unsigned long sp,
26319 unsigned long arg, struct task_struct *p)
26320 {
26321 - struct pt_regs *childregs = task_pt_regs(p);
26322 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26323 struct task_struct *tsk;
26324 int err;
26325
26326 p->thread.sp = (unsigned long) childregs;
26327 p->thread.sp0 = (unsigned long) (childregs+1);
26328 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26329
26330 if (unlikely(p->flags & PF_KTHREAD)) {
26331 /* kernel thread */
26332 memset(childregs, 0, sizeof(struct pt_regs));
26333 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26334 - task_user_gs(p) = __KERNEL_STACK_CANARY;
26335 - childregs->ds = __USER_DS;
26336 - childregs->es = __USER_DS;
26337 + savesegment(gs, childregs->gs);
26338 + childregs->ds = __KERNEL_DS;
26339 + childregs->es = __KERNEL_DS;
26340 childregs->fs = __KERNEL_PERCPU;
26341 childregs->bx = sp; /* function */
26342 childregs->bp = arg;
26343 @@ -252,7 +253,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26344 struct thread_struct *prev = &prev_p->thread,
26345 *next = &next_p->thread;
26346 int cpu = smp_processor_id();
26347 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26348 + struct tss_struct *tss = init_tss + cpu;
26349 fpu_switch_t fpu;
26350
26351 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26352 @@ -276,6 +277,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26353 */
26354 lazy_save_gs(prev->gs);
26355
26356 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26357 + __set_fs(task_thread_info(next_p)->addr_limit);
26358 +#endif
26359 +
26360 /*
26361 * Load the per-thread Thread-Local Storage descriptor.
26362 */
26363 @@ -314,9 +319,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26364 */
26365 arch_end_context_switch(next_p);
26366
26367 - this_cpu_write(kernel_stack,
26368 - (unsigned long)task_stack_page(next_p) +
26369 - THREAD_SIZE - KERNEL_STACK_OFFSET);
26370 + this_cpu_write(current_task, next_p);
26371 + this_cpu_write(current_tinfo, &next_p->tinfo);
26372 + this_cpu_write(kernel_stack, next->sp0);
26373
26374 /*
26375 * Restore %gs if needed (which is common)
26376 @@ -326,8 +331,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26377
26378 switch_fpu_finish(next_p, fpu);
26379
26380 - this_cpu_write(current_task, next_p);
26381 -
26382 return prev_p;
26383 }
26384
26385 @@ -357,4 +360,3 @@ unsigned long get_wchan(struct task_struct *p)
26386 } while (count++ < 16);
26387 return 0;
26388 }
26389 -
26390 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26391 index 898d077..4c458ff 100644
26392 --- a/arch/x86/kernel/process_64.c
26393 +++ b/arch/x86/kernel/process_64.c
26394 @@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26395 struct pt_regs *childregs;
26396 struct task_struct *me = current;
26397
26398 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26399 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26400 childregs = task_pt_regs(p);
26401 p->thread.sp = (unsigned long) childregs;
26402 p->thread.usersp = me->thread.usersp;
26403 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26404 set_tsk_thread_flag(p, TIF_FORK);
26405 p->thread.fpu_counter = 0;
26406 p->thread.io_bitmap_ptr = NULL;
26407 @@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26408 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26409 savesegment(es, p->thread.es);
26410 savesegment(ds, p->thread.ds);
26411 + savesegment(ss, p->thread.ss);
26412 + BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26413 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26414
26415 if (unlikely(p->flags & PF_KTHREAD)) {
26416 @@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26417 struct thread_struct *prev = &prev_p->thread;
26418 struct thread_struct *next = &next_p->thread;
26419 int cpu = smp_processor_id();
26420 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26421 + struct tss_struct *tss = init_tss + cpu;
26422 unsigned fsindex, gsindex;
26423 fpu_switch_t fpu;
26424
26425 @@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26426 if (unlikely(next->ds | prev->ds))
26427 loadsegment(ds, next->ds);
26428
26429 + savesegment(ss, prev->ss);
26430 + if (unlikely(next->ss != prev->ss))
26431 + loadsegment(ss, next->ss);
26432
26433 /* We must save %fs and %gs before load_TLS() because
26434 * %fs and %gs may be cleared by load_TLS().
26435 @@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26436 prev->usersp = this_cpu_read(old_rsp);
26437 this_cpu_write(old_rsp, next->usersp);
26438 this_cpu_write(current_task, next_p);
26439 + this_cpu_write(current_tinfo, &next_p->tinfo);
26440
26441 /*
26442 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26443 @@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26444 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26445 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26446
26447 - this_cpu_write(kernel_stack,
26448 - (unsigned long)task_stack_page(next_p) +
26449 - THREAD_SIZE - KERNEL_STACK_OFFSET);
26450 + this_cpu_write(kernel_stack, next->sp0);
26451
26452 /*
26453 * Now maybe reload the debug registers and handle I/O bitmaps
26454 @@ -442,12 +447,11 @@ unsigned long get_wchan(struct task_struct *p)
26455 if (!p || p == current || p->state == TASK_RUNNING)
26456 return 0;
26457 stack = (unsigned long)task_stack_page(p);
26458 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26459 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26460 return 0;
26461 fp = *(u64 *)(p->thread.sp);
26462 do {
26463 - if (fp < (unsigned long)stack ||
26464 - fp >= (unsigned long)stack+THREAD_SIZE)
26465 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26466 return 0;
26467 ip = *(u64 *)(fp+8);
26468 if (!in_sched_functions(ip))
26469 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26470 index 678c0ad..2fc2a7b 100644
26471 --- a/arch/x86/kernel/ptrace.c
26472 +++ b/arch/x86/kernel/ptrace.c
26473 @@ -186,10 +186,10 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26474 unsigned long sp = (unsigned long)&regs->sp;
26475 u32 *prev_esp;
26476
26477 - if (context == (sp & ~(THREAD_SIZE - 1)))
26478 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26479 return sp;
26480
26481 - prev_esp = (u32 *)(context);
26482 + prev_esp = *(u32 **)(context);
26483 if (prev_esp)
26484 return (unsigned long)prev_esp;
26485
26486 @@ -452,6 +452,20 @@ static int putreg(struct task_struct *child,
26487 if (child->thread.gs != value)
26488 return do_arch_prctl(child, ARCH_SET_GS, value);
26489 return 0;
26490 +
26491 + case offsetof(struct user_regs_struct,ip):
26492 + /*
26493 + * Protect against any attempt to set ip to an
26494 + * impossible address. There are dragons lurking if the
26495 + * address is noncanonical. (This explicitly allows
26496 + * setting ip to TASK_SIZE_MAX, because user code can do
26497 + * that all by itself by running off the end of its
26498 + * address space.
26499 + */
26500 + if (value > TASK_SIZE_MAX)
26501 + return -EIO;
26502 + break;
26503 +
26504 #endif
26505 }
26506
26507 @@ -588,7 +602,7 @@ static void ptrace_triggered(struct perf_event *bp,
26508 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26509 {
26510 int i;
26511 - int dr7 = 0;
26512 + unsigned long dr7 = 0;
26513 struct arch_hw_breakpoint *info;
26514
26515 for (i = 0; i < HBP_NUM; i++) {
26516 @@ -822,7 +836,7 @@ long arch_ptrace(struct task_struct *child, long request,
26517 unsigned long addr, unsigned long data)
26518 {
26519 int ret;
26520 - unsigned long __user *datap = (unsigned long __user *)data;
26521 + unsigned long __user *datap = (__force unsigned long __user *)data;
26522
26523 switch (request) {
26524 /* read the word at location addr in the USER area. */
26525 @@ -907,14 +921,14 @@ long arch_ptrace(struct task_struct *child, long request,
26526 if ((int) addr < 0)
26527 return -EIO;
26528 ret = do_get_thread_area(child, addr,
26529 - (struct user_desc __user *)data);
26530 + (__force struct user_desc __user *) data);
26531 break;
26532
26533 case PTRACE_SET_THREAD_AREA:
26534 if ((int) addr < 0)
26535 return -EIO;
26536 ret = do_set_thread_area(child, addr,
26537 - (struct user_desc __user *)data, 0);
26538 + (__force struct user_desc __user *) data, 0);
26539 break;
26540 #endif
26541
26542 @@ -1292,7 +1306,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26543
26544 #ifdef CONFIG_X86_64
26545
26546 -static struct user_regset x86_64_regsets[] __read_mostly = {
26547 +static user_regset_no_const x86_64_regsets[] __read_only = {
26548 [REGSET_GENERAL] = {
26549 .core_note_type = NT_PRSTATUS,
26550 .n = sizeof(struct user_regs_struct) / sizeof(long),
26551 @@ -1333,7 +1347,7 @@ static const struct user_regset_view user_x86_64_view = {
26552 #endif /* CONFIG_X86_64 */
26553
26554 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
26555 -static struct user_regset x86_32_regsets[] __read_mostly = {
26556 +static user_regset_no_const x86_32_regsets[] __read_only = {
26557 [REGSET_GENERAL] = {
26558 .core_note_type = NT_PRSTATUS,
26559 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
26560 @@ -1386,7 +1400,7 @@ static const struct user_regset_view user_x86_32_view = {
26561 */
26562 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
26563
26564 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26565 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26566 {
26567 #ifdef CONFIG_X86_64
26568 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
26569 @@ -1421,7 +1435,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
26570 memset(info, 0, sizeof(*info));
26571 info->si_signo = SIGTRAP;
26572 info->si_code = si_code;
26573 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
26574 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
26575 }
26576
26577 void user_single_step_siginfo(struct task_struct *tsk,
26578 @@ -1450,6 +1464,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
26579 # define IS_IA32 0
26580 #endif
26581
26582 +#ifdef CONFIG_GRKERNSEC_SETXID
26583 +extern void gr_delayed_cred_worker(void);
26584 +#endif
26585 +
26586 /*
26587 * We must return the syscall number to actually look up in the table.
26588 * This can be -1L to skip running any syscall at all.
26589 @@ -1460,6 +1478,11 @@ long syscall_trace_enter(struct pt_regs *regs)
26590
26591 user_exit();
26592
26593 +#ifdef CONFIG_GRKERNSEC_SETXID
26594 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26595 + gr_delayed_cred_worker();
26596 +#endif
26597 +
26598 /*
26599 * If we stepped into a sysenter/syscall insn, it trapped in
26600 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
26601 @@ -1515,6 +1538,11 @@ void syscall_trace_leave(struct pt_regs *regs)
26602 */
26603 user_exit();
26604
26605 +#ifdef CONFIG_GRKERNSEC_SETXID
26606 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26607 + gr_delayed_cred_worker();
26608 +#endif
26609 +
26610 audit_syscall_exit(regs);
26611
26612 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
26613 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
26614 index 2f355d2..e75ed0a 100644
26615 --- a/arch/x86/kernel/pvclock.c
26616 +++ b/arch/x86/kernel/pvclock.c
26617 @@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
26618 reset_hung_task_detector();
26619 }
26620
26621 -static atomic64_t last_value = ATOMIC64_INIT(0);
26622 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
26623
26624 void pvclock_resume(void)
26625 {
26626 - atomic64_set(&last_value, 0);
26627 + atomic64_set_unchecked(&last_value, 0);
26628 }
26629
26630 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
26631 @@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
26632 * updating at the same time, and one of them could be slightly behind,
26633 * making the assumption that last_value always go forward fail to hold.
26634 */
26635 - last = atomic64_read(&last_value);
26636 + last = atomic64_read_unchecked(&last_value);
26637 do {
26638 if (ret < last)
26639 return last;
26640 - last = atomic64_cmpxchg(&last_value, last, ret);
26641 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
26642 } while (unlikely(last != ret));
26643
26644 return ret;
26645 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
26646 index 52b1157..c6e67c4 100644
26647 --- a/arch/x86/kernel/reboot.c
26648 +++ b/arch/x86/kernel/reboot.c
26649 @@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
26650
26651 void __noreturn machine_real_restart(unsigned int type)
26652 {
26653 +
26654 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
26655 + struct desc_struct *gdt;
26656 +#endif
26657 +
26658 local_irq_disable();
26659
26660 /*
26661 @@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
26662
26663 /* Jump to the identity-mapped low memory code */
26664 #ifdef CONFIG_X86_32
26665 - asm volatile("jmpl *%0" : :
26666 +
26667 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
26668 + gdt = get_cpu_gdt_table(smp_processor_id());
26669 + pax_open_kernel();
26670 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26671 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
26672 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
26673 + loadsegment(ds, __KERNEL_DS);
26674 + loadsegment(es, __KERNEL_DS);
26675 + loadsegment(ss, __KERNEL_DS);
26676 +#endif
26677 +#ifdef CONFIG_PAX_KERNEXEC
26678 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
26679 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
26680 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
26681 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
26682 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
26683 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
26684 +#endif
26685 + pax_close_kernel();
26686 +#endif
26687 +
26688 + asm volatile("ljmpl *%0" : :
26689 "rm" (real_mode_header->machine_real_restart_asm),
26690 "a" (type));
26691 #else
26692 @@ -486,7 +513,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
26693 * This means that this function can never return, it can misbehave
26694 * by not rebooting properly and hanging.
26695 */
26696 -static void native_machine_emergency_restart(void)
26697 +static void __noreturn native_machine_emergency_restart(void)
26698 {
26699 int i;
26700 int attempt = 0;
26701 @@ -610,13 +637,13 @@ void native_machine_shutdown(void)
26702 #endif
26703 }
26704
26705 -static void __machine_emergency_restart(int emergency)
26706 +static void __noreturn __machine_emergency_restart(int emergency)
26707 {
26708 reboot_emergency = emergency;
26709 machine_ops.emergency_restart();
26710 }
26711
26712 -static void native_machine_restart(char *__unused)
26713 +static void __noreturn native_machine_restart(char *__unused)
26714 {
26715 pr_notice("machine restart\n");
26716
26717 @@ -625,7 +652,7 @@ static void native_machine_restart(char *__unused)
26718 __machine_emergency_restart(0);
26719 }
26720
26721 -static void native_machine_halt(void)
26722 +static void __noreturn native_machine_halt(void)
26723 {
26724 /* Stop other cpus and apics */
26725 machine_shutdown();
26726 @@ -635,7 +662,7 @@ static void native_machine_halt(void)
26727 stop_this_cpu(NULL);
26728 }
26729
26730 -static void native_machine_power_off(void)
26731 +static void __noreturn native_machine_power_off(void)
26732 {
26733 if (pm_power_off) {
26734 if (!reboot_force)
26735 @@ -644,9 +671,10 @@ static void native_machine_power_off(void)
26736 }
26737 /* A fallback in case there is no PM info available */
26738 tboot_shutdown(TB_SHUTDOWN_HALT);
26739 + unreachable();
26740 }
26741
26742 -struct machine_ops machine_ops = {
26743 +struct machine_ops machine_ops __read_only = {
26744 .power_off = native_machine_power_off,
26745 .shutdown = native_machine_shutdown,
26746 .emergency_restart = native_machine_emergency_restart,
26747 diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
26748 index c8e41e9..64049ef 100644
26749 --- a/arch/x86/kernel/reboot_fixups_32.c
26750 +++ b/arch/x86/kernel/reboot_fixups_32.c
26751 @@ -57,7 +57,7 @@ struct device_fixup {
26752 unsigned int vendor;
26753 unsigned int device;
26754 void (*reboot_fixup)(struct pci_dev *);
26755 -};
26756 +} __do_const;
26757
26758 /*
26759 * PCI ids solely used for fixups_table go here
26760 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
26761 index 3fd2c69..a444264 100644
26762 --- a/arch/x86/kernel/relocate_kernel_64.S
26763 +++ b/arch/x86/kernel/relocate_kernel_64.S
26764 @@ -96,8 +96,7 @@ relocate_kernel:
26765
26766 /* jump to identity mapped page */
26767 addq $(identity_mapped - relocate_kernel), %r8
26768 - pushq %r8
26769 - ret
26770 + jmp *%r8
26771
26772 identity_mapped:
26773 /* set return address to 0 if not preserving context */
26774 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
26775 index 09c76d2..7f33fc2 100644
26776 --- a/arch/x86/kernel/setup.c
26777 +++ b/arch/x86/kernel/setup.c
26778 @@ -110,6 +110,7 @@
26779 #include <asm/mce.h>
26780 #include <asm/alternative.h>
26781 #include <asm/prom.h>
26782 +#include <asm/boot.h>
26783
26784 /*
26785 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
26786 @@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
26787 #endif
26788
26789
26790 -#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
26791 -__visible unsigned long mmu_cr4_features;
26792 +#ifdef CONFIG_X86_64
26793 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
26794 +#elif defined(CONFIG_X86_PAE)
26795 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
26796 #else
26797 -__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
26798 +__visible unsigned long mmu_cr4_features __read_only;
26799 #endif
26800
26801 +void set_in_cr4(unsigned long mask)
26802 +{
26803 + unsigned long cr4 = read_cr4();
26804 +
26805 + if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
26806 + return;
26807 +
26808 + pax_open_kernel();
26809 + mmu_cr4_features |= mask;
26810 + pax_close_kernel();
26811 +
26812 + if (trampoline_cr4_features)
26813 + *trampoline_cr4_features = mmu_cr4_features;
26814 + cr4 |= mask;
26815 + write_cr4(cr4);
26816 +}
26817 +EXPORT_SYMBOL(set_in_cr4);
26818 +
26819 +void clear_in_cr4(unsigned long mask)
26820 +{
26821 + unsigned long cr4 = read_cr4();
26822 +
26823 + if (!(cr4 & mask) && cr4 == mmu_cr4_features)
26824 + return;
26825 +
26826 + pax_open_kernel();
26827 + mmu_cr4_features &= ~mask;
26828 + pax_close_kernel();
26829 +
26830 + if (trampoline_cr4_features)
26831 + *trampoline_cr4_features = mmu_cr4_features;
26832 + cr4 &= ~mask;
26833 + write_cr4(cr4);
26834 +}
26835 +EXPORT_SYMBOL(clear_in_cr4);
26836 +
26837 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
26838 int bootloader_type, bootloader_version;
26839
26840 @@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
26841 * area (640->1Mb) as ram even though it is not.
26842 * take them out.
26843 */
26844 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
26845 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
26846
26847 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
26848 }
26849 @@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
26850 /* called before trim_bios_range() to spare extra sanitize */
26851 static void __init e820_add_kernel_range(void)
26852 {
26853 - u64 start = __pa_symbol(_text);
26854 + u64 start = __pa_symbol(ktla_ktva(_text));
26855 u64 size = __pa_symbol(_end) - start;
26856
26857 /*
26858 @@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
26859
26860 void __init setup_arch(char **cmdline_p)
26861 {
26862 +#ifdef CONFIG_X86_32
26863 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
26864 +#else
26865 memblock_reserve(__pa_symbol(_text),
26866 (unsigned long)__bss_stop - (unsigned long)_text);
26867 +#endif
26868
26869 early_reserve_initrd();
26870
26871 @@ -946,14 +989,14 @@ void __init setup_arch(char **cmdline_p)
26872
26873 if (!boot_params.hdr.root_flags)
26874 root_mountflags &= ~MS_RDONLY;
26875 - init_mm.start_code = (unsigned long) _text;
26876 - init_mm.end_code = (unsigned long) _etext;
26877 + init_mm.start_code = ktla_ktva((unsigned long) _text);
26878 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
26879 init_mm.end_data = (unsigned long) _edata;
26880 init_mm.brk = _brk_end;
26881
26882 - code_resource.start = __pa_symbol(_text);
26883 - code_resource.end = __pa_symbol(_etext)-1;
26884 - data_resource.start = __pa_symbol(_etext);
26885 + code_resource.start = __pa_symbol(ktla_ktva(_text));
26886 + code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
26887 + data_resource.start = __pa_symbol(_sdata);
26888 data_resource.end = __pa_symbol(_edata)-1;
26889 bss_resource.start = __pa_symbol(__bss_start);
26890 bss_resource.end = __pa_symbol(__bss_stop)-1;
26891 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
26892 index 5cdff03..80fa283 100644
26893 --- a/arch/x86/kernel/setup_percpu.c
26894 +++ b/arch/x86/kernel/setup_percpu.c
26895 @@ -21,19 +21,17 @@
26896 #include <asm/cpu.h>
26897 #include <asm/stackprotector.h>
26898
26899 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
26900 +#ifdef CONFIG_SMP
26901 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
26902 EXPORT_PER_CPU_SYMBOL(cpu_number);
26903 +#endif
26904
26905 -#ifdef CONFIG_X86_64
26906 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
26907 -#else
26908 -#define BOOT_PERCPU_OFFSET 0
26909 -#endif
26910
26911 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
26912 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
26913
26914 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
26915 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
26916 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
26917 };
26918 EXPORT_SYMBOL(__per_cpu_offset);
26919 @@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
26920 {
26921 #ifdef CONFIG_NEED_MULTIPLE_NODES
26922 pg_data_t *last = NULL;
26923 - unsigned int cpu;
26924 + int cpu;
26925
26926 for_each_possible_cpu(cpu) {
26927 int node = early_cpu_to_node(cpu);
26928 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
26929 {
26930 #ifdef CONFIG_X86_32
26931 struct desc_struct gdt;
26932 + unsigned long base = per_cpu_offset(cpu);
26933
26934 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
26935 - 0x2 | DESCTYPE_S, 0x8);
26936 - gdt.s = 1;
26937 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
26938 + 0x83 | DESCTYPE_S, 0xC);
26939 write_gdt_entry(get_cpu_gdt_table(cpu),
26940 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
26941 #endif
26942 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
26943 /* alrighty, percpu areas up and running */
26944 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
26945 for_each_possible_cpu(cpu) {
26946 +#ifdef CONFIG_CC_STACKPROTECTOR
26947 +#ifdef CONFIG_X86_32
26948 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
26949 +#endif
26950 +#endif
26951 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
26952 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
26953 per_cpu(cpu_number, cpu) = cpu;
26954 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
26955 */
26956 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
26957 #endif
26958 +#ifdef CONFIG_CC_STACKPROTECTOR
26959 +#ifdef CONFIG_X86_32
26960 + if (!cpu)
26961 + per_cpu(stack_canary.canary, cpu) = canary;
26962 +#endif
26963 +#endif
26964 /*
26965 * Up to this point, the boot CPU has been using .init.data
26966 * area. Reload any changed state for the boot CPU.
26967 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
26968 index 9e5de68..147c254 100644
26969 --- a/arch/x86/kernel/signal.c
26970 +++ b/arch/x86/kernel/signal.c
26971 @@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
26972 * Align the stack pointer according to the i386 ABI,
26973 * i.e. so that on function entry ((sp + 4) & 15) == 0.
26974 */
26975 - sp = ((sp + 4) & -16ul) - 4;
26976 + sp = ((sp - 12) & -16ul) - 4;
26977 #else /* !CONFIG_X86_32 */
26978 sp = round_down(sp, 16) - 8;
26979 #endif
26980 @@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26981 }
26982
26983 if (current->mm->context.vdso)
26984 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26985 + restorer = (void __force_user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26986 else
26987 - restorer = &frame->retcode;
26988 + restorer = (void __user *)&frame->retcode;
26989 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26990 restorer = ksig->ka.sa.sa_restorer;
26991
26992 @@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26993 * reasons and because gdb uses it as a signature to notice
26994 * signal handler stack frames.
26995 */
26996 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
26997 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
26998
26999 if (err)
27000 return -EFAULT;
27001 @@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27002 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
27003
27004 /* Set up to return from userspace. */
27005 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
27006 + if (current->mm->context.vdso)
27007 + restorer = (void __force_user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
27008 + else
27009 + restorer = (void __user *)&frame->retcode;
27010 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27011 restorer = ksig->ka.sa.sa_restorer;
27012 put_user_ex(restorer, &frame->pretcode);
27013 @@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27014 * reasons and because gdb uses it as a signature to notice
27015 * signal handler stack frames.
27016 */
27017 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
27018 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
27019 } put_user_catch(err);
27020
27021 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
27022 @@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27023 {
27024 int usig = signr_convert(ksig->sig);
27025 sigset_t *set = sigmask_to_save();
27026 - compat_sigset_t *cset = (compat_sigset_t *) set;
27027 + sigset_t sigcopy;
27028 + compat_sigset_t *cset;
27029 +
27030 + sigcopy = *set;
27031 +
27032 + cset = (compat_sigset_t *) &sigcopy;
27033
27034 /* Set up the stack frame */
27035 if (is_ia32_frame()) {
27036 @@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27037 } else if (is_x32_frame()) {
27038 return x32_setup_rt_frame(ksig, cset, regs);
27039 } else {
27040 - return __setup_rt_frame(ksig->sig, ksig, set, regs);
27041 + return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
27042 }
27043 }
27044
27045 diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
27046 index be8e1bd..a3d93fa 100644
27047 --- a/arch/x86/kernel/smp.c
27048 +++ b/arch/x86/kernel/smp.c
27049 @@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
27050
27051 __setup("nonmi_ipi", nonmi_ipi_setup);
27052
27053 -struct smp_ops smp_ops = {
27054 +struct smp_ops smp_ops __read_only = {
27055 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
27056 .smp_prepare_cpus = native_smp_prepare_cpus,
27057 .smp_cpus_done = native_smp_cpus_done,
27058 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
27059 index 5492798..a3bd4f2 100644
27060 --- a/arch/x86/kernel/smpboot.c
27061 +++ b/arch/x86/kernel/smpboot.c
27062 @@ -230,14 +230,17 @@ static void notrace start_secondary(void *unused)
27063
27064 enable_start_cpu0 = 0;
27065
27066 -#ifdef CONFIG_X86_32
27067 + /* otherwise gcc will move up smp_processor_id before the cpu_init */
27068 + barrier();
27069 +
27070 /* switch away from the initial page table */
27071 +#ifdef CONFIG_PAX_PER_CPU_PGD
27072 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
27073 +#else
27074 load_cr3(swapper_pg_dir);
27075 +#endif
27076 __flush_tlb_all();
27077 -#endif
27078
27079 - /* otherwise gcc will move up smp_processor_id before the cpu_init */
27080 - barrier();
27081 /*
27082 * Check TSC synchronization with the BP:
27083 */
27084 @@ -764,8 +767,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27085 alternatives_enable_smp();
27086
27087 idle->thread.sp = (unsigned long) (((struct pt_regs *)
27088 - (THREAD_SIZE + task_stack_page(idle))) - 1);
27089 + (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
27090 per_cpu(current_task, cpu) = idle;
27091 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27092
27093 #ifdef CONFIG_X86_32
27094 /* Stack for startup_32 can be just as for start_secondary onwards */
27095 @@ -774,10 +778,10 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27096 clear_tsk_thread_flag(idle, TIF_FORK);
27097 initial_gs = per_cpu_offset(cpu);
27098 #endif
27099 - per_cpu(kernel_stack, cpu) =
27100 - (unsigned long)task_stack_page(idle) -
27101 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27102 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27103 + pax_open_kernel();
27104 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
27105 + pax_close_kernel();
27106 initial_code = (unsigned long)start_secondary;
27107 stack_start = idle->thread.sp;
27108
27109 @@ -923,6 +927,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
27110 /* the FPU context is blank, nobody can own it */
27111 __cpu_disable_lazy_restore(cpu);
27112
27113 +#ifdef CONFIG_PAX_PER_CPU_PGD
27114 + clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
27115 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27116 + KERNEL_PGD_PTRS);
27117 + clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
27118 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27119 + KERNEL_PGD_PTRS);
27120 +#endif
27121 +
27122 err = do_boot_cpu(apicid, cpu, tidle);
27123 if (err) {
27124 pr_err("do_boot_cpu failed(%d) to wakeup CPU#%u\n", err, cpu);
27125 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
27126 index 9b4d51d..5d28b58 100644
27127 --- a/arch/x86/kernel/step.c
27128 +++ b/arch/x86/kernel/step.c
27129 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27130 struct desc_struct *desc;
27131 unsigned long base;
27132
27133 - seg &= ~7UL;
27134 + seg >>= 3;
27135
27136 mutex_lock(&child->mm->context.lock);
27137 - if (unlikely((seg >> 3) >= child->mm->context.size))
27138 + if (unlikely(seg >= child->mm->context.size))
27139 addr = -1L; /* bogus selector, access would fault */
27140 else {
27141 desc = child->mm->context.ldt + seg;
27142 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27143 addr += base;
27144 }
27145 mutex_unlock(&child->mm->context.lock);
27146 - }
27147 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
27148 + addr = ktla_ktva(addr);
27149
27150 return addr;
27151 }
27152 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
27153 unsigned char opcode[15];
27154 unsigned long addr = convert_ip_to_linear(child, regs);
27155
27156 + if (addr == -EINVAL)
27157 + return 0;
27158 +
27159 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
27160 for (i = 0; i < copied; i++) {
27161 switch (opcode[i]) {
27162 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
27163 new file mode 100644
27164 index 0000000..5877189
27165 --- /dev/null
27166 +++ b/arch/x86/kernel/sys_i386_32.c
27167 @@ -0,0 +1,189 @@
27168 +/*
27169 + * This file contains various random system calls that
27170 + * have a non-standard calling sequence on the Linux/i386
27171 + * platform.
27172 + */
27173 +
27174 +#include <linux/errno.h>
27175 +#include <linux/sched.h>
27176 +#include <linux/mm.h>
27177 +#include <linux/fs.h>
27178 +#include <linux/smp.h>
27179 +#include <linux/sem.h>
27180 +#include <linux/msg.h>
27181 +#include <linux/shm.h>
27182 +#include <linux/stat.h>
27183 +#include <linux/syscalls.h>
27184 +#include <linux/mman.h>
27185 +#include <linux/file.h>
27186 +#include <linux/utsname.h>
27187 +#include <linux/ipc.h>
27188 +#include <linux/elf.h>
27189 +
27190 +#include <linux/uaccess.h>
27191 +#include <linux/unistd.h>
27192 +
27193 +#include <asm/syscalls.h>
27194 +
27195 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
27196 +{
27197 + unsigned long pax_task_size = TASK_SIZE;
27198 +
27199 +#ifdef CONFIG_PAX_SEGMEXEC
27200 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
27201 + pax_task_size = SEGMEXEC_TASK_SIZE;
27202 +#endif
27203 +
27204 + if (flags & MAP_FIXED)
27205 + if (len > pax_task_size || addr > pax_task_size - len)
27206 + return -EINVAL;
27207 +
27208 + return 0;
27209 +}
27210 +
27211 +/*
27212 + * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
27213 + */
27214 +static unsigned long get_align_mask(void)
27215 +{
27216 + if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
27217 + return 0;
27218 +
27219 + if (!(current->flags & PF_RANDOMIZE))
27220 + return 0;
27221 +
27222 + return va_align.mask;
27223 +}
27224 +
27225 +unsigned long
27226 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
27227 + unsigned long len, unsigned long pgoff, unsigned long flags)
27228 +{
27229 + struct mm_struct *mm = current->mm;
27230 + struct vm_area_struct *vma;
27231 + unsigned long pax_task_size = TASK_SIZE;
27232 + struct vm_unmapped_area_info info;
27233 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27234 +
27235 +#ifdef CONFIG_PAX_SEGMEXEC
27236 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27237 + pax_task_size = SEGMEXEC_TASK_SIZE;
27238 +#endif
27239 +
27240 + pax_task_size -= PAGE_SIZE;
27241 +
27242 + if (len > pax_task_size)
27243 + return -ENOMEM;
27244 +
27245 + if (flags & MAP_FIXED)
27246 + return addr;
27247 +
27248 +#ifdef CONFIG_PAX_RANDMMAP
27249 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27250 +#endif
27251 +
27252 + if (addr) {
27253 + addr = PAGE_ALIGN(addr);
27254 + if (pax_task_size - len >= addr) {
27255 + vma = find_vma(mm, addr);
27256 + if (check_heap_stack_gap(vma, addr, len, offset))
27257 + return addr;
27258 + }
27259 + }
27260 +
27261 + info.flags = 0;
27262 + info.length = len;
27263 + info.align_mask = filp ? get_align_mask() : 0;
27264 + info.align_offset = pgoff << PAGE_SHIFT;
27265 + info.threadstack_offset = offset;
27266 +
27267 +#ifdef CONFIG_PAX_PAGEEXEC
27268 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27269 + info.low_limit = 0x00110000UL;
27270 + info.high_limit = mm->start_code;
27271 +
27272 +#ifdef CONFIG_PAX_RANDMMAP
27273 + if (mm->pax_flags & MF_PAX_RANDMMAP)
27274 + info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27275 +#endif
27276 +
27277 + if (info.low_limit < info.high_limit) {
27278 + addr = vm_unmapped_area(&info);
27279 + if (!IS_ERR_VALUE(addr))
27280 + return addr;
27281 + }
27282 + } else
27283 +#endif
27284 +
27285 + info.low_limit = mm->mmap_base;
27286 + info.high_limit = pax_task_size;
27287 +
27288 + return vm_unmapped_area(&info);
27289 +}
27290 +
27291 +unsigned long
27292 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27293 + const unsigned long len, const unsigned long pgoff,
27294 + const unsigned long flags)
27295 +{
27296 + struct vm_area_struct *vma;
27297 + struct mm_struct *mm = current->mm;
27298 + unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27299 + struct vm_unmapped_area_info info;
27300 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27301 +
27302 +#ifdef CONFIG_PAX_SEGMEXEC
27303 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27304 + pax_task_size = SEGMEXEC_TASK_SIZE;
27305 +#endif
27306 +
27307 + pax_task_size -= PAGE_SIZE;
27308 +
27309 + /* requested length too big for entire address space */
27310 + if (len > pax_task_size)
27311 + return -ENOMEM;
27312 +
27313 + if (flags & MAP_FIXED)
27314 + return addr;
27315 +
27316 +#ifdef CONFIG_PAX_PAGEEXEC
27317 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27318 + goto bottomup;
27319 +#endif
27320 +
27321 +#ifdef CONFIG_PAX_RANDMMAP
27322 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27323 +#endif
27324 +
27325 + /* requesting a specific address */
27326 + if (addr) {
27327 + addr = PAGE_ALIGN(addr);
27328 + if (pax_task_size - len >= addr) {
27329 + vma = find_vma(mm, addr);
27330 + if (check_heap_stack_gap(vma, addr, len, offset))
27331 + return addr;
27332 + }
27333 + }
27334 +
27335 + info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27336 + info.length = len;
27337 + info.low_limit = PAGE_SIZE;
27338 + info.high_limit = mm->mmap_base;
27339 + info.align_mask = filp ? get_align_mask() : 0;
27340 + info.align_offset = pgoff << PAGE_SHIFT;
27341 + info.threadstack_offset = offset;
27342 +
27343 + addr = vm_unmapped_area(&info);
27344 + if (!(addr & ~PAGE_MASK))
27345 + return addr;
27346 + VM_BUG_ON(addr != -ENOMEM);
27347 +
27348 +bottomup:
27349 + /*
27350 + * A failed mmap() very likely causes application failure,
27351 + * so fall back to the bottom-up function here. This scenario
27352 + * can happen with large stack limits and large mmap()
27353 + * allocations.
27354 + */
27355 + return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27356 +}
27357 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27358 index 30277e2..5664a29 100644
27359 --- a/arch/x86/kernel/sys_x86_64.c
27360 +++ b/arch/x86/kernel/sys_x86_64.c
27361 @@ -81,8 +81,8 @@ out:
27362 return error;
27363 }
27364
27365 -static void find_start_end(unsigned long flags, unsigned long *begin,
27366 - unsigned long *end)
27367 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
27368 + unsigned long *begin, unsigned long *end)
27369 {
27370 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27371 unsigned long new_begin;
27372 @@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27373 *begin = new_begin;
27374 }
27375 } else {
27376 - *begin = current->mm->mmap_legacy_base;
27377 + *begin = mm->mmap_legacy_base;
27378 *end = TASK_SIZE;
27379 }
27380 }
27381 @@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27382 struct vm_area_struct *vma;
27383 struct vm_unmapped_area_info info;
27384 unsigned long begin, end;
27385 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27386
27387 if (flags & MAP_FIXED)
27388 return addr;
27389
27390 - find_start_end(flags, &begin, &end);
27391 + find_start_end(mm, flags, &begin, &end);
27392
27393 if (len > end)
27394 return -ENOMEM;
27395
27396 +#ifdef CONFIG_PAX_RANDMMAP
27397 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27398 +#endif
27399 +
27400 if (addr) {
27401 addr = PAGE_ALIGN(addr);
27402 vma = find_vma(mm, addr);
27403 - if (end - len >= addr &&
27404 - (!vma || addr + len <= vma->vm_start))
27405 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27406 return addr;
27407 }
27408
27409 @@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27410 info.high_limit = end;
27411 info.align_mask = filp ? get_align_mask() : 0;
27412 info.align_offset = pgoff << PAGE_SHIFT;
27413 + info.threadstack_offset = offset;
27414 return vm_unmapped_area(&info);
27415 }
27416
27417 @@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27418 struct mm_struct *mm = current->mm;
27419 unsigned long addr = addr0;
27420 struct vm_unmapped_area_info info;
27421 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27422
27423 /* requested length too big for entire address space */
27424 if (len > TASK_SIZE)
27425 @@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27426 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27427 goto bottomup;
27428
27429 +#ifdef CONFIG_PAX_RANDMMAP
27430 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27431 +#endif
27432 +
27433 /* requesting a specific address */
27434 if (addr) {
27435 addr = PAGE_ALIGN(addr);
27436 vma = find_vma(mm, addr);
27437 - if (TASK_SIZE - len >= addr &&
27438 - (!vma || addr + len <= vma->vm_start))
27439 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27440 return addr;
27441 }
27442
27443 @@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27444 info.high_limit = mm->mmap_base;
27445 info.align_mask = filp ? get_align_mask() : 0;
27446 info.align_offset = pgoff << PAGE_SHIFT;
27447 + info.threadstack_offset = offset;
27448 addr = vm_unmapped_area(&info);
27449 if (!(addr & ~PAGE_MASK))
27450 return addr;
27451 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27452 index 91a4496..bb87552 100644
27453 --- a/arch/x86/kernel/tboot.c
27454 +++ b/arch/x86/kernel/tboot.c
27455 @@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27456
27457 void tboot_shutdown(u32 shutdown_type)
27458 {
27459 - void (*shutdown)(void);
27460 + void (* __noreturn shutdown)(void);
27461
27462 if (!tboot_enabled())
27463 return;
27464 @@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27465
27466 switch_to_tboot_pt();
27467
27468 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27469 + shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27470 shutdown();
27471
27472 /* should not reach here */
27473 @@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27474 return -ENODEV;
27475 }
27476
27477 -static atomic_t ap_wfs_count;
27478 +static atomic_unchecked_t ap_wfs_count;
27479
27480 static int tboot_wait_for_aps(int num_aps)
27481 {
27482 @@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27483 {
27484 switch (action) {
27485 case CPU_DYING:
27486 - atomic_inc(&ap_wfs_count);
27487 + atomic_inc_unchecked(&ap_wfs_count);
27488 if (num_online_cpus() == 1)
27489 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27490 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27491 return NOTIFY_BAD;
27492 break;
27493 }
27494 @@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27495
27496 tboot_create_trampoline();
27497
27498 - atomic_set(&ap_wfs_count, 0);
27499 + atomic_set_unchecked(&ap_wfs_count, 0);
27500 register_hotcpu_notifier(&tboot_cpu_notifier);
27501
27502 #ifdef CONFIG_DEBUG_FS
27503 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27504 index bf7ef5c..59d0ac9 100644
27505 --- a/arch/x86/kernel/time.c
27506 +++ b/arch/x86/kernel/time.c
27507 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27508 {
27509 unsigned long pc = instruction_pointer(regs);
27510
27511 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27512 + if (!user_mode(regs) && in_lock_functions(pc)) {
27513 #ifdef CONFIG_FRAME_POINTER
27514 - return *(unsigned long *)(regs->bp + sizeof(long));
27515 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27516 #else
27517 unsigned long *sp =
27518 (unsigned long *)kernel_stack_pointer(regs);
27519 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27520 * or above a saved flags. Eflags has bits 22-31 zero,
27521 * kernel addresses don't.
27522 */
27523 +
27524 +#ifdef CONFIG_PAX_KERNEXEC
27525 + return ktla_ktva(sp[0]);
27526 +#else
27527 if (sp[0] >> 22)
27528 return sp[0];
27529 if (sp[1] >> 22)
27530 return sp[1];
27531 #endif
27532 +
27533 +#endif
27534 }
27535 return pc;
27536 }
27537 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27538 index f7fec09..9991981 100644
27539 --- a/arch/x86/kernel/tls.c
27540 +++ b/arch/x86/kernel/tls.c
27541 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
27542 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
27543 return -EINVAL;
27544
27545 +#ifdef CONFIG_PAX_SEGMEXEC
27546 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
27547 + return -EINVAL;
27548 +#endif
27549 +
27550 set_tls_desc(p, idx, &info, 1);
27551
27552 return 0;
27553 @@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27554
27555 if (kbuf)
27556 info = kbuf;
27557 - else if (__copy_from_user(infobuf, ubuf, count))
27558 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
27559 return -EFAULT;
27560 else
27561 info = infobuf;
27562 diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
27563 index 1c113db..287b42e 100644
27564 --- a/arch/x86/kernel/tracepoint.c
27565 +++ b/arch/x86/kernel/tracepoint.c
27566 @@ -9,11 +9,11 @@
27567 #include <linux/atomic.h>
27568
27569 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
27570 -struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27571 +const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27572 (unsigned long) trace_idt_table };
27573
27574 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27575 -gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
27576 +gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
27577
27578 static int trace_irq_vector_refcount;
27579 static DEFINE_MUTEX(irq_vector_mutex);
27580 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
27581 index f73b5d4..0adcc9a 100644
27582 --- a/arch/x86/kernel/traps.c
27583 +++ b/arch/x86/kernel/traps.c
27584 @@ -66,7 +66,7 @@
27585 #include <asm/proto.h>
27586
27587 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27588 -gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
27589 +gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
27590 #else
27591 #include <asm/processor-flags.h>
27592 #include <asm/setup.h>
27593 @@ -75,7 +75,7 @@ asmlinkage int system_call(void);
27594 #endif
27595
27596 /* Must be page-aligned because the real IDT is used in a fixmap. */
27597 -gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
27598 +gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
27599
27600 DECLARE_BITMAP(used_vectors, NR_VECTORS);
27601 EXPORT_SYMBOL_GPL(used_vectors);
27602 @@ -107,11 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
27603 }
27604
27605 static int __kprobes
27606 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27607 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
27608 struct pt_regs *regs, long error_code)
27609 {
27610 #ifdef CONFIG_X86_32
27611 - if (regs->flags & X86_VM_MASK) {
27612 + if (v8086_mode(regs)) {
27613 /*
27614 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
27615 * On nmi (interrupt 2), do_trap should not be called.
27616 @@ -124,12 +124,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27617 return -1;
27618 }
27619 #endif
27620 - if (!user_mode(regs)) {
27621 + if (!user_mode_novm(regs)) {
27622 if (!fixup_exception(regs)) {
27623 tsk->thread.error_code = error_code;
27624 tsk->thread.trap_nr = trapnr;
27625 +
27626 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27627 + if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
27628 + str = "PAX: suspicious stack segment fault";
27629 +#endif
27630 +
27631 die(str, regs, error_code);
27632 }
27633 +
27634 +#ifdef CONFIG_PAX_REFCOUNT
27635 + if (trapnr == X86_TRAP_OF)
27636 + pax_report_refcount_overflow(regs);
27637 +#endif
27638 +
27639 return 0;
27640 }
27641
27642 @@ -137,7 +149,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27643 }
27644
27645 static void __kprobes
27646 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27647 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
27648 long error_code, siginfo_t *info)
27649 {
27650 struct task_struct *tsk = current;
27651 @@ -161,7 +173,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27652 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
27653 printk_ratelimit()) {
27654 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
27655 - tsk->comm, tsk->pid, str,
27656 + tsk->comm, task_pid_nr(tsk), str,
27657 regs->ip, regs->sp, error_code);
27658 print_vma_addr(" in ", regs->ip);
27659 pr_cont("\n");
27660 @@ -251,6 +263,11 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
27661 tsk->thread.error_code = error_code;
27662 tsk->thread.trap_nr = X86_TRAP_DF;
27663
27664 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
27665 + if ((unsigned long)tsk->stack - regs->sp <= PAGE_SIZE)
27666 + die("grsec: kernel stack overflow detected", regs, error_code);
27667 +#endif
27668 +
27669 #ifdef CONFIG_DOUBLEFAULT
27670 df_debug(regs, error_code);
27671 #endif
27672 @@ -273,7 +290,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
27673 conditional_sti(regs);
27674
27675 #ifdef CONFIG_X86_32
27676 - if (regs->flags & X86_VM_MASK) {
27677 + if (v8086_mode(regs)) {
27678 local_irq_enable();
27679 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
27680 goto exit;
27681 @@ -281,18 +298,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
27682 #endif
27683
27684 tsk = current;
27685 - if (!user_mode(regs)) {
27686 + if (!user_mode_novm(regs)) {
27687 if (fixup_exception(regs))
27688 goto exit;
27689
27690 tsk->thread.error_code = error_code;
27691 tsk->thread.trap_nr = X86_TRAP_GP;
27692 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
27693 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
27694 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
27695 +
27696 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27697 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
27698 + die("PAX: suspicious general protection fault", regs, error_code);
27699 + else
27700 +#endif
27701 +
27702 die("general protection fault", regs, error_code);
27703 + }
27704 goto exit;
27705 }
27706
27707 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27708 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
27709 + struct mm_struct *mm = tsk->mm;
27710 + unsigned long limit;
27711 +
27712 + down_write(&mm->mmap_sem);
27713 + limit = mm->context.user_cs_limit;
27714 + if (limit < TASK_SIZE) {
27715 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
27716 + up_write(&mm->mmap_sem);
27717 + return;
27718 + }
27719 + up_write(&mm->mmap_sem);
27720 + }
27721 +#endif
27722 +
27723 tsk->thread.error_code = error_code;
27724 tsk->thread.trap_nr = X86_TRAP_GP;
27725
27726 @@ -453,7 +494,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27727 /* It's safe to allow irq's after DR6 has been saved */
27728 preempt_conditional_sti(regs);
27729
27730 - if (regs->flags & X86_VM_MASK) {
27731 + if (v8086_mode(regs)) {
27732 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
27733 X86_TRAP_DB);
27734 preempt_conditional_cli(regs);
27735 @@ -468,7 +509,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27736 * We already checked v86 mode above, so we can check for kernel mode
27737 * by just checking the CPL of CS.
27738 */
27739 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
27740 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
27741 tsk->thread.debugreg6 &= ~DR_STEP;
27742 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
27743 regs->flags &= ~X86_EFLAGS_TF;
27744 @@ -500,7 +541,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
27745 return;
27746 conditional_sti(regs);
27747
27748 - if (!user_mode_vm(regs))
27749 + if (!user_mode(regs))
27750 {
27751 if (!fixup_exception(regs)) {
27752 task->thread.error_code = error_code;
27753 diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
27754 index ea03031..34a5cdda 100644
27755 --- a/arch/x86/kernel/tsc.c
27756 +++ b/arch/x86/kernel/tsc.c
27757 @@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
27758 */
27759 smp_wmb();
27760
27761 - ACCESS_ONCE(c2n->head) = data;
27762 + ACCESS_ONCE_RW(c2n->head) = data;
27763 }
27764
27765 /*
27766 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
27767 index 2ed8459..7cf329f 100644
27768 --- a/arch/x86/kernel/uprobes.c
27769 +++ b/arch/x86/kernel/uprobes.c
27770 @@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
27771 int ret = NOTIFY_DONE;
27772
27773 /* We are only interested in userspace traps */
27774 - if (regs && !user_mode_vm(regs))
27775 + if (regs && !user_mode(regs))
27776 return NOTIFY_DONE;
27777
27778 switch (val) {
27779 @@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
27780
27781 if (ncopied != rasize) {
27782 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
27783 - "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
27784 + "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
27785
27786 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
27787 }
27788 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
27789 index b9242ba..50c5edd 100644
27790 --- a/arch/x86/kernel/verify_cpu.S
27791 +++ b/arch/x86/kernel/verify_cpu.S
27792 @@ -20,6 +20,7 @@
27793 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
27794 * arch/x86/kernel/trampoline_64.S: secondary processor verification
27795 * arch/x86/kernel/head_32.S: processor startup
27796 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
27797 *
27798 * verify_cpu, returns the status of longmode and SSE in register %eax.
27799 * 0: Success 1: Failure
27800 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
27801 index e8edcf5..27f9344 100644
27802 --- a/arch/x86/kernel/vm86_32.c
27803 +++ b/arch/x86/kernel/vm86_32.c
27804 @@ -44,6 +44,7 @@
27805 #include <linux/ptrace.h>
27806 #include <linux/audit.h>
27807 #include <linux/stddef.h>
27808 +#include <linux/grsecurity.h>
27809
27810 #include <asm/uaccess.h>
27811 #include <asm/io.h>
27812 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
27813 do_exit(SIGSEGV);
27814 }
27815
27816 - tss = &per_cpu(init_tss, get_cpu());
27817 + tss = init_tss + get_cpu();
27818 current->thread.sp0 = current->thread.saved_sp0;
27819 current->thread.sysenter_cs = __KERNEL_CS;
27820 load_sp0(tss, &current->thread);
27821 @@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
27822
27823 if (tsk->thread.saved_sp0)
27824 return -EPERM;
27825 +
27826 +#ifdef CONFIG_GRKERNSEC_VM86
27827 + if (!capable(CAP_SYS_RAWIO)) {
27828 + gr_handle_vm86();
27829 + return -EPERM;
27830 + }
27831 +#endif
27832 +
27833 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
27834 offsetof(struct kernel_vm86_struct, vm86plus) -
27835 sizeof(info.regs));
27836 @@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
27837 int tmp;
27838 struct vm86plus_struct __user *v86;
27839
27840 +#ifdef CONFIG_GRKERNSEC_VM86
27841 + if (!capable(CAP_SYS_RAWIO)) {
27842 + gr_handle_vm86();
27843 + return -EPERM;
27844 + }
27845 +#endif
27846 +
27847 tsk = current;
27848 switch (cmd) {
27849 case VM86_REQUEST_IRQ:
27850 @@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
27851 tsk->thread.saved_fs = info->regs32->fs;
27852 tsk->thread.saved_gs = get_user_gs(info->regs32);
27853
27854 - tss = &per_cpu(init_tss, get_cpu());
27855 + tss = init_tss + get_cpu();
27856 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
27857 if (cpu_has_sep)
27858 tsk->thread.sysenter_cs = 0;
27859 @@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
27860 goto cannot_handle;
27861 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
27862 goto cannot_handle;
27863 - intr_ptr = (unsigned long __user *) (i << 2);
27864 + intr_ptr = (__force unsigned long __user *) (i << 2);
27865 if (get_user(segoffs, intr_ptr))
27866 goto cannot_handle;
27867 if ((segoffs >> 16) == BIOSSEG)
27868 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
27869 index 49edf2d..c0d1362 100644
27870 --- a/arch/x86/kernel/vmlinux.lds.S
27871 +++ b/arch/x86/kernel/vmlinux.lds.S
27872 @@ -26,6 +26,13 @@
27873 #include <asm/page_types.h>
27874 #include <asm/cache.h>
27875 #include <asm/boot.h>
27876 +#include <asm/segment.h>
27877 +
27878 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27879 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
27880 +#else
27881 +#define __KERNEL_TEXT_OFFSET 0
27882 +#endif
27883
27884 #undef i386 /* in case the preprocessor is a 32bit one */
27885
27886 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
27887
27888 PHDRS {
27889 text PT_LOAD FLAGS(5); /* R_E */
27890 +#ifdef CONFIG_X86_32
27891 + module PT_LOAD FLAGS(5); /* R_E */
27892 +#endif
27893 +#ifdef CONFIG_XEN
27894 + rodata PT_LOAD FLAGS(5); /* R_E */
27895 +#else
27896 + rodata PT_LOAD FLAGS(4); /* R__ */
27897 +#endif
27898 data PT_LOAD FLAGS(6); /* RW_ */
27899 -#ifdef CONFIG_X86_64
27900 + init.begin PT_LOAD FLAGS(6); /* RW_ */
27901 #ifdef CONFIG_SMP
27902 percpu PT_LOAD FLAGS(6); /* RW_ */
27903 #endif
27904 + text.init PT_LOAD FLAGS(5); /* R_E */
27905 + text.exit PT_LOAD FLAGS(5); /* R_E */
27906 init PT_LOAD FLAGS(7); /* RWE */
27907 -#endif
27908 note PT_NOTE FLAGS(0); /* ___ */
27909 }
27910
27911 SECTIONS
27912 {
27913 #ifdef CONFIG_X86_32
27914 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
27915 - phys_startup_32 = startup_32 - LOAD_OFFSET;
27916 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
27917 #else
27918 - . = __START_KERNEL;
27919 - phys_startup_64 = startup_64 - LOAD_OFFSET;
27920 + . = __START_KERNEL;
27921 #endif
27922
27923 /* Text and read-only data */
27924 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
27925 - _text = .;
27926 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27927 /* bootstrapping code */
27928 +#ifdef CONFIG_X86_32
27929 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27930 +#else
27931 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27932 +#endif
27933 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27934 + _text = .;
27935 HEAD_TEXT
27936 . = ALIGN(8);
27937 _stext = .;
27938 @@ -104,13 +124,47 @@ SECTIONS
27939 IRQENTRY_TEXT
27940 *(.fixup)
27941 *(.gnu.warning)
27942 - /* End of text section */
27943 - _etext = .;
27944 } :text = 0x9090
27945
27946 - NOTES :text :note
27947 + . += __KERNEL_TEXT_OFFSET;
27948
27949 - EXCEPTION_TABLE(16) :text = 0x9090
27950 +#ifdef CONFIG_X86_32
27951 + . = ALIGN(PAGE_SIZE);
27952 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
27953 +
27954 +#ifdef CONFIG_PAX_KERNEXEC
27955 + MODULES_EXEC_VADDR = .;
27956 + BYTE(0)
27957 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
27958 + . = ALIGN(HPAGE_SIZE) - 1;
27959 + MODULES_EXEC_END = .;
27960 +#endif
27961 +
27962 + } :module
27963 +#endif
27964 +
27965 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
27966 + /* End of text section */
27967 + BYTE(0)
27968 + _etext = . - __KERNEL_TEXT_OFFSET;
27969 + }
27970 +
27971 +#ifdef CONFIG_X86_32
27972 + . = ALIGN(PAGE_SIZE);
27973 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
27974 + . = ALIGN(PAGE_SIZE);
27975 + *(.empty_zero_page)
27976 + *(.initial_pg_fixmap)
27977 + *(.initial_pg_pmd)
27978 + *(.initial_page_table)
27979 + *(.swapper_pg_dir)
27980 + } :rodata
27981 +#endif
27982 +
27983 + . = ALIGN(PAGE_SIZE);
27984 + NOTES :rodata :note
27985 +
27986 + EXCEPTION_TABLE(16) :rodata
27987
27988 #if defined(CONFIG_DEBUG_RODATA)
27989 /* .text should occupy whole number of pages */
27990 @@ -122,16 +176,20 @@ SECTIONS
27991
27992 /* Data */
27993 .data : AT(ADDR(.data) - LOAD_OFFSET) {
27994 +
27995 +#ifdef CONFIG_PAX_KERNEXEC
27996 + . = ALIGN(HPAGE_SIZE);
27997 +#else
27998 + . = ALIGN(PAGE_SIZE);
27999 +#endif
28000 +
28001 /* Start of data section */
28002 _sdata = .;
28003
28004 /* init_task */
28005 INIT_TASK_DATA(THREAD_SIZE)
28006
28007 -#ifdef CONFIG_X86_32
28008 - /* 32 bit has nosave before _edata */
28009 NOSAVE_DATA
28010 -#endif
28011
28012 PAGE_ALIGNED_DATA(PAGE_SIZE)
28013
28014 @@ -174,12 +232,19 @@ SECTIONS
28015 . = ALIGN(__vvar_page + PAGE_SIZE, PAGE_SIZE);
28016
28017 /* Init code and data - will be freed after init */
28018 - . = ALIGN(PAGE_SIZE);
28019 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
28020 + BYTE(0)
28021 +
28022 +#ifdef CONFIG_PAX_KERNEXEC
28023 + . = ALIGN(HPAGE_SIZE);
28024 +#else
28025 + . = ALIGN(PAGE_SIZE);
28026 +#endif
28027 +
28028 __init_begin = .; /* paired with __init_end */
28029 - }
28030 + } :init.begin
28031
28032 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
28033 +#ifdef CONFIG_SMP
28034 /*
28035 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
28036 * output PHDR, so the next output section - .init.text - should
28037 @@ -188,12 +253,27 @@ SECTIONS
28038 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
28039 #endif
28040
28041 - INIT_TEXT_SECTION(PAGE_SIZE)
28042 -#ifdef CONFIG_X86_64
28043 - :init
28044 -#endif
28045 + . = ALIGN(PAGE_SIZE);
28046 + init_begin = .;
28047 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
28048 + VMLINUX_SYMBOL(_sinittext) = .;
28049 + INIT_TEXT
28050 + VMLINUX_SYMBOL(_einittext) = .;
28051 + . = ALIGN(PAGE_SIZE);
28052 + } :text.init
28053
28054 - INIT_DATA_SECTION(16)
28055 + /*
28056 + * .exit.text is discard at runtime, not link time, to deal with
28057 + * references from .altinstructions and .eh_frame
28058 + */
28059 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28060 + EXIT_TEXT
28061 + . = ALIGN(16);
28062 + } :text.exit
28063 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
28064 +
28065 + . = ALIGN(PAGE_SIZE);
28066 + INIT_DATA_SECTION(16) :init
28067
28068 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
28069 __x86_cpu_dev_start = .;
28070 @@ -264,19 +344,12 @@ SECTIONS
28071 }
28072
28073 . = ALIGN(8);
28074 - /*
28075 - * .exit.text is discard at runtime, not link time, to deal with
28076 - * references from .altinstructions and .eh_frame
28077 - */
28078 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
28079 - EXIT_TEXT
28080 - }
28081
28082 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
28083 EXIT_DATA
28084 }
28085
28086 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
28087 +#ifndef CONFIG_SMP
28088 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
28089 #endif
28090
28091 @@ -295,16 +368,10 @@ SECTIONS
28092 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
28093 __smp_locks = .;
28094 *(.smp_locks)
28095 - . = ALIGN(PAGE_SIZE);
28096 __smp_locks_end = .;
28097 + . = ALIGN(PAGE_SIZE);
28098 }
28099
28100 -#ifdef CONFIG_X86_64
28101 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
28102 - NOSAVE_DATA
28103 - }
28104 -#endif
28105 -
28106 /* BSS */
28107 . = ALIGN(PAGE_SIZE);
28108 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
28109 @@ -320,6 +387,7 @@ SECTIONS
28110 __brk_base = .;
28111 . += 64 * 1024; /* 64k alignment slop space */
28112 *(.brk_reservation) /* areas brk users have reserved */
28113 + . = ALIGN(HPAGE_SIZE);
28114 __brk_limit = .;
28115 }
28116
28117 @@ -346,13 +414,12 @@ SECTIONS
28118 * for the boot processor.
28119 */
28120 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
28121 -INIT_PER_CPU(gdt_page);
28122 INIT_PER_CPU(irq_stack_union);
28123
28124 /*
28125 * Build-time check on the image size:
28126 */
28127 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
28128 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
28129 "kernel image bigger than KERNEL_IMAGE_SIZE");
28130
28131 #ifdef CONFIG_SMP
28132 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
28133 index 8b3b3eb..9395aa9 100644
28134 --- a/arch/x86/kernel/vsyscall_64.c
28135 +++ b/arch/x86/kernel/vsyscall_64.c
28136 @@ -54,15 +54,13 @@
28137
28138 DEFINE_VVAR(int, vgetcpu_mode);
28139
28140 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
28141 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
28142
28143 static int __init vsyscall_setup(char *str)
28144 {
28145 if (str) {
28146 if (!strcmp("emulate", str))
28147 vsyscall_mode = EMULATE;
28148 - else if (!strcmp("native", str))
28149 - vsyscall_mode = NATIVE;
28150 else if (!strcmp("none", str))
28151 vsyscall_mode = NONE;
28152 else
28153 @@ -279,8 +277,7 @@ do_ret:
28154 return true;
28155
28156 sigsegv:
28157 - force_sig(SIGSEGV, current);
28158 - return true;
28159 + do_group_exit(SIGKILL);
28160 }
28161
28162 /*
28163 @@ -332,10 +329,7 @@ void __init map_vsyscall(void)
28164 unsigned long physaddr_vsyscall = __pa_symbol(&__vsyscall_page);
28165 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
28166
28167 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
28168 - vsyscall_mode == NATIVE
28169 - ? PAGE_KERNEL_VSYSCALL
28170 - : PAGE_KERNEL_VVAR);
28171 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
28172 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
28173 (unsigned long)VSYSCALL_START);
28174
28175 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
28176 index 04068192..4d75aa6 100644
28177 --- a/arch/x86/kernel/x8664_ksyms_64.c
28178 +++ b/arch/x86/kernel/x8664_ksyms_64.c
28179 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
28180 EXPORT_SYMBOL(copy_user_generic_unrolled);
28181 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
28182 EXPORT_SYMBOL(__copy_user_nocache);
28183 -EXPORT_SYMBOL(_copy_from_user);
28184 -EXPORT_SYMBOL(_copy_to_user);
28185
28186 EXPORT_SYMBOL(copy_page);
28187 EXPORT_SYMBOL(clear_page);
28188 @@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
28189 EXPORT_SYMBOL(___preempt_schedule_context);
28190 #endif
28191 #endif
28192 +
28193 +#ifdef CONFIG_PAX_PER_CPU_PGD
28194 +EXPORT_SYMBOL(cpu_pgd);
28195 +#endif
28196 diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
28197 index e48b674..a451dd9 100644
28198 --- a/arch/x86/kernel/x86_init.c
28199 +++ b/arch/x86/kernel/x86_init.c
28200 @@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
28201 static void default_nmi_init(void) { };
28202 static int default_i8042_detect(void) { return 1; };
28203
28204 -struct x86_platform_ops x86_platform = {
28205 +struct x86_platform_ops x86_platform __read_only = {
28206 .calibrate_tsc = native_calibrate_tsc,
28207 .get_wallclock = mach_get_cmos_time,
28208 .set_wallclock = mach_set_rtc_mmss,
28209 @@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
28210 EXPORT_SYMBOL_GPL(x86_platform);
28211
28212 #if defined(CONFIG_PCI_MSI)
28213 -struct x86_msi_ops x86_msi = {
28214 +struct x86_msi_ops x86_msi __read_only = {
28215 .setup_msi_irqs = native_setup_msi_irqs,
28216 .compose_msi_msg = native_compose_msi_msg,
28217 .teardown_msi_irq = native_teardown_msi_irq,
28218 @@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
28219 }
28220 #endif
28221
28222 -struct x86_io_apic_ops x86_io_apic_ops = {
28223 +struct x86_io_apic_ops x86_io_apic_ops __read_only = {
28224 .init = native_io_apic_init_mappings,
28225 .read = native_io_apic_read,
28226 .write = native_io_apic_write,
28227 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
28228 index a4b451c..8dfe1ad 100644
28229 --- a/arch/x86/kernel/xsave.c
28230 +++ b/arch/x86/kernel/xsave.c
28231 @@ -164,18 +164,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28232
28233 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
28234 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
28235 - err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28236 + err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28237
28238 if (!use_xsave())
28239 return err;
28240
28241 - err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
28242 + err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
28243
28244 /*
28245 * Read the xstate_bv which we copied (directly from the cpu or
28246 * from the state in task struct) to the user buffers.
28247 */
28248 - err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28249 + err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28250
28251 /*
28252 * For legacy compatible, we always set FP/SSE bits in the bit
28253 @@ -190,7 +190,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28254 */
28255 xstate_bv |= XSTATE_FPSSE;
28256
28257 - err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28258 + err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28259
28260 return err;
28261 }
28262 @@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
28263 {
28264 int err;
28265
28266 + buf = (struct xsave_struct __user *)____m(buf);
28267 if (use_xsave())
28268 err = xsave_user(buf);
28269 else if (use_fxsr())
28270 @@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28271 */
28272 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28273 {
28274 + buf = (void __user *)____m(buf);
28275 if (use_xsave()) {
28276 if ((unsigned long)buf % 64 || fx_only) {
28277 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28278 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28279 index f47a104..5ce59a8 100644
28280 --- a/arch/x86/kvm/cpuid.c
28281 +++ b/arch/x86/kvm/cpuid.c
28282 @@ -166,15 +166,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28283 struct kvm_cpuid2 *cpuid,
28284 struct kvm_cpuid_entry2 __user *entries)
28285 {
28286 - int r;
28287 + int r, i;
28288
28289 r = -E2BIG;
28290 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28291 goto out;
28292 r = -EFAULT;
28293 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28294 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28295 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28296 goto out;
28297 + for (i = 0; i < cpuid->nent; ++i) {
28298 + struct kvm_cpuid_entry2 cpuid_entry;
28299 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28300 + goto out;
28301 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
28302 + }
28303 vcpu->arch.cpuid_nent = cpuid->nent;
28304 kvm_apic_set_version(vcpu);
28305 kvm_x86_ops->cpuid_update(vcpu);
28306 @@ -189,15 +194,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28307 struct kvm_cpuid2 *cpuid,
28308 struct kvm_cpuid_entry2 __user *entries)
28309 {
28310 - int r;
28311 + int r, i;
28312
28313 r = -E2BIG;
28314 if (cpuid->nent < vcpu->arch.cpuid_nent)
28315 goto out;
28316 r = -EFAULT;
28317 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28318 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28319 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28320 goto out;
28321 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28322 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28323 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28324 + goto out;
28325 + }
28326 return 0;
28327
28328 out:
28329 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28330 index 0069118..c28ec0a 100644
28331 --- a/arch/x86/kvm/lapic.c
28332 +++ b/arch/x86/kvm/lapic.c
28333 @@ -55,7 +55,7 @@
28334 #define APIC_BUS_CYCLE_NS 1
28335
28336 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28337 -#define apic_debug(fmt, arg...)
28338 +#define apic_debug(fmt, arg...) do {} while (0)
28339
28340 #define APIC_LVT_NUM 6
28341 /* 14 is the version for Xeon and Pentium 8.4.8*/
28342 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28343 index 123efd3..ad7726e 100644
28344 --- a/arch/x86/kvm/paging_tmpl.h
28345 +++ b/arch/x86/kvm/paging_tmpl.h
28346 @@ -331,7 +331,7 @@ retry_walk:
28347 if (unlikely(kvm_is_error_hva(host_addr)))
28348 goto error;
28349
28350 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28351 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28352 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28353 goto error;
28354 walker->ptep_user[walker->level - 1] = ptep_user;
28355 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28356 index 7f4f9c2..67b1db0 100644
28357 --- a/arch/x86/kvm/svm.c
28358 +++ b/arch/x86/kvm/svm.c
28359 @@ -3535,7 +3535,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28360 int cpu = raw_smp_processor_id();
28361
28362 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28363 +
28364 + pax_open_kernel();
28365 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28366 + pax_close_kernel();
28367 +
28368 load_TR_desc();
28369 }
28370
28371 @@ -3936,6 +3940,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28372 #endif
28373 #endif
28374
28375 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28376 + __set_fs(current_thread_info()->addr_limit);
28377 +#endif
28378 +
28379 reload_tss(vcpu);
28380
28381 local_irq_disable();
28382 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28383 index 138ceff..2e584f0 100644
28384 --- a/arch/x86/kvm/vmx.c
28385 +++ b/arch/x86/kvm/vmx.c
28386 @@ -1339,12 +1339,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28387 #endif
28388 }
28389
28390 -static void vmcs_clear_bits(unsigned long field, u32 mask)
28391 +static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28392 {
28393 vmcs_writel(field, vmcs_readl(field) & ~mask);
28394 }
28395
28396 -static void vmcs_set_bits(unsigned long field, u32 mask)
28397 +static void vmcs_set_bits(unsigned long field, unsigned long mask)
28398 {
28399 vmcs_writel(field, vmcs_readl(field) | mask);
28400 }
28401 @@ -1604,7 +1604,11 @@ static void reload_tss(void)
28402 struct desc_struct *descs;
28403
28404 descs = (void *)gdt->address;
28405 +
28406 + pax_open_kernel();
28407 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28408 + pax_close_kernel();
28409 +
28410 load_TR_desc();
28411 }
28412
28413 @@ -1832,6 +1836,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28414 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28415 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28416
28417 +#ifdef CONFIG_PAX_PER_CPU_PGD
28418 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28419 +#endif
28420 +
28421 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28422 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28423 vmx->loaded_vmcs->cpu = cpu;
28424 @@ -2121,7 +2129,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28425 * reads and returns guest's timestamp counter "register"
28426 * guest_tsc = host_tsc + tsc_offset -- 21.3
28427 */
28428 -static u64 guest_read_tsc(void)
28429 +static u64 __intentional_overflow(-1) guest_read_tsc(void)
28430 {
28431 u64 host_tsc, tsc_offset;
28432
28433 @@ -3093,8 +3101,11 @@ static __init int hardware_setup(void)
28434 if (!cpu_has_vmx_flexpriority())
28435 flexpriority_enabled = 0;
28436
28437 - if (!cpu_has_vmx_tpr_shadow())
28438 - kvm_x86_ops->update_cr8_intercept = NULL;
28439 + if (!cpu_has_vmx_tpr_shadow()) {
28440 + pax_open_kernel();
28441 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28442 + pax_close_kernel();
28443 + }
28444
28445 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28446 kvm_disable_largepages();
28447 @@ -3105,13 +3116,15 @@ static __init int hardware_setup(void)
28448 if (!cpu_has_vmx_apicv())
28449 enable_apicv = 0;
28450
28451 + pax_open_kernel();
28452 if (enable_apicv)
28453 - kvm_x86_ops->update_cr8_intercept = NULL;
28454 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28455 else {
28456 - kvm_x86_ops->hwapic_irr_update = NULL;
28457 - kvm_x86_ops->deliver_posted_interrupt = NULL;
28458 - kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28459 + *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28460 + *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28461 + *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28462 }
28463 + pax_close_kernel();
28464
28465 if (nested)
28466 nested_vmx_setup_ctls_msrs();
28467 @@ -4235,7 +4248,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28468
28469 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28470 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
28471 +
28472 +#ifndef CONFIG_PAX_PER_CPU_PGD
28473 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28474 +#endif
28475
28476 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
28477 #ifdef CONFIG_X86_64
28478 @@ -4257,7 +4273,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28479 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28480 vmx->host_idt_base = dt.address;
28481
28482 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28483 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28484
28485 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28486 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28487 @@ -7333,6 +7349,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28488 "jmp 2f \n\t"
28489 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28490 "2: "
28491 +
28492 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28493 + "ljmp %[cs],$3f\n\t"
28494 + "3: "
28495 +#endif
28496 +
28497 /* Save guest registers, load host registers, keep flags */
28498 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28499 "pop %0 \n\t"
28500 @@ -7385,6 +7407,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28501 #endif
28502 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28503 [wordsize]"i"(sizeof(ulong))
28504 +
28505 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28506 + ,[cs]"i"(__KERNEL_CS)
28507 +#endif
28508 +
28509 : "cc", "memory"
28510 #ifdef CONFIG_X86_64
28511 , "rax", "rbx", "rdi", "rsi"
28512 @@ -7398,7 +7425,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28513 if (debugctlmsr)
28514 update_debugctlmsr(debugctlmsr);
28515
28516 -#ifndef CONFIG_X86_64
28517 +#ifdef CONFIG_X86_32
28518 /*
28519 * The sysexit path does not restore ds/es, so we must set them to
28520 * a reasonable value ourselves.
28521 @@ -7407,8 +7434,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28522 * may be executed in interrupt context, which saves and restore segments
28523 * around it, nullifying its effect.
28524 */
28525 - loadsegment(ds, __USER_DS);
28526 - loadsegment(es, __USER_DS);
28527 + loadsegment(ds, __KERNEL_DS);
28528 + loadsegment(es, __KERNEL_DS);
28529 + loadsegment(ss, __KERNEL_DS);
28530 +
28531 +#ifdef CONFIG_PAX_KERNEXEC
28532 + loadsegment(fs, __KERNEL_PERCPU);
28533 +#endif
28534 +
28535 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28536 + __set_fs(current_thread_info()->addr_limit);
28537 +#endif
28538 +
28539 #endif
28540
28541 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
28542 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
28543 index 5521f7c..691b7a3 100644
28544 --- a/arch/x86/kvm/x86.c
28545 +++ b/arch/x86/kvm/x86.c
28546 @@ -1822,8 +1822,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
28547 {
28548 struct kvm *kvm = vcpu->kvm;
28549 int lm = is_long_mode(vcpu);
28550 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28551 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28552 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28553 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28554 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
28555 : kvm->arch.xen_hvm_config.blob_size_32;
28556 u32 page_num = data & ~PAGE_MASK;
28557 @@ -2738,6 +2738,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
28558 if (n < msr_list.nmsrs)
28559 goto out;
28560 r = -EFAULT;
28561 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
28562 + goto out;
28563 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
28564 num_msrs_to_save * sizeof(u32)))
28565 goto out;
28566 @@ -5574,7 +5576,7 @@ static struct notifier_block pvclock_gtod_notifier = {
28567 };
28568 #endif
28569
28570 -int kvm_arch_init(void *opaque)
28571 +int kvm_arch_init(const void *opaque)
28572 {
28573 int r;
28574 struct kvm_x86_ops *ops = opaque;
28575 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
28576 index aae9413..d11e829 100644
28577 --- a/arch/x86/lguest/boot.c
28578 +++ b/arch/x86/lguest/boot.c
28579 @@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
28580 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
28581 * Launcher to reboot us.
28582 */
28583 -static void lguest_restart(char *reason)
28584 +static __noreturn void lguest_restart(char *reason)
28585 {
28586 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
28587 + BUG();
28588 }
28589
28590 /*G:050
28591 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
28592 index 00933d5..3a64af9 100644
28593 --- a/arch/x86/lib/atomic64_386_32.S
28594 +++ b/arch/x86/lib/atomic64_386_32.S
28595 @@ -48,6 +48,10 @@ BEGIN(read)
28596 movl (v), %eax
28597 movl 4(v), %edx
28598 RET_ENDP
28599 +BEGIN(read_unchecked)
28600 + movl (v), %eax
28601 + movl 4(v), %edx
28602 +RET_ENDP
28603 #undef v
28604
28605 #define v %esi
28606 @@ -55,6 +59,10 @@ BEGIN(set)
28607 movl %ebx, (v)
28608 movl %ecx, 4(v)
28609 RET_ENDP
28610 +BEGIN(set_unchecked)
28611 + movl %ebx, (v)
28612 + movl %ecx, 4(v)
28613 +RET_ENDP
28614 #undef v
28615
28616 #define v %esi
28617 @@ -70,6 +78,20 @@ RET_ENDP
28618 BEGIN(add)
28619 addl %eax, (v)
28620 adcl %edx, 4(v)
28621 +
28622 +#ifdef CONFIG_PAX_REFCOUNT
28623 + jno 0f
28624 + subl %eax, (v)
28625 + sbbl %edx, 4(v)
28626 + int $4
28627 +0:
28628 + _ASM_EXTABLE(0b, 0b)
28629 +#endif
28630 +
28631 +RET_ENDP
28632 +BEGIN(add_unchecked)
28633 + addl %eax, (v)
28634 + adcl %edx, 4(v)
28635 RET_ENDP
28636 #undef v
28637
28638 @@ -77,6 +99,24 @@ RET_ENDP
28639 BEGIN(add_return)
28640 addl (v), %eax
28641 adcl 4(v), %edx
28642 +
28643 +#ifdef CONFIG_PAX_REFCOUNT
28644 + into
28645 +1234:
28646 + _ASM_EXTABLE(1234b, 2f)
28647 +#endif
28648 +
28649 + movl %eax, (v)
28650 + movl %edx, 4(v)
28651 +
28652 +#ifdef CONFIG_PAX_REFCOUNT
28653 +2:
28654 +#endif
28655 +
28656 +RET_ENDP
28657 +BEGIN(add_return_unchecked)
28658 + addl (v), %eax
28659 + adcl 4(v), %edx
28660 movl %eax, (v)
28661 movl %edx, 4(v)
28662 RET_ENDP
28663 @@ -86,6 +126,20 @@ RET_ENDP
28664 BEGIN(sub)
28665 subl %eax, (v)
28666 sbbl %edx, 4(v)
28667 +
28668 +#ifdef CONFIG_PAX_REFCOUNT
28669 + jno 0f
28670 + addl %eax, (v)
28671 + adcl %edx, 4(v)
28672 + int $4
28673 +0:
28674 + _ASM_EXTABLE(0b, 0b)
28675 +#endif
28676 +
28677 +RET_ENDP
28678 +BEGIN(sub_unchecked)
28679 + subl %eax, (v)
28680 + sbbl %edx, 4(v)
28681 RET_ENDP
28682 #undef v
28683
28684 @@ -96,6 +150,27 @@ BEGIN(sub_return)
28685 sbbl $0, %edx
28686 addl (v), %eax
28687 adcl 4(v), %edx
28688 +
28689 +#ifdef CONFIG_PAX_REFCOUNT
28690 + into
28691 +1234:
28692 + _ASM_EXTABLE(1234b, 2f)
28693 +#endif
28694 +
28695 + movl %eax, (v)
28696 + movl %edx, 4(v)
28697 +
28698 +#ifdef CONFIG_PAX_REFCOUNT
28699 +2:
28700 +#endif
28701 +
28702 +RET_ENDP
28703 +BEGIN(sub_return_unchecked)
28704 + negl %edx
28705 + negl %eax
28706 + sbbl $0, %edx
28707 + addl (v), %eax
28708 + adcl 4(v), %edx
28709 movl %eax, (v)
28710 movl %edx, 4(v)
28711 RET_ENDP
28712 @@ -105,6 +180,20 @@ RET_ENDP
28713 BEGIN(inc)
28714 addl $1, (v)
28715 adcl $0, 4(v)
28716 +
28717 +#ifdef CONFIG_PAX_REFCOUNT
28718 + jno 0f
28719 + subl $1, (v)
28720 + sbbl $0, 4(v)
28721 + int $4
28722 +0:
28723 + _ASM_EXTABLE(0b, 0b)
28724 +#endif
28725 +
28726 +RET_ENDP
28727 +BEGIN(inc_unchecked)
28728 + addl $1, (v)
28729 + adcl $0, 4(v)
28730 RET_ENDP
28731 #undef v
28732
28733 @@ -114,6 +203,26 @@ BEGIN(inc_return)
28734 movl 4(v), %edx
28735 addl $1, %eax
28736 adcl $0, %edx
28737 +
28738 +#ifdef CONFIG_PAX_REFCOUNT
28739 + into
28740 +1234:
28741 + _ASM_EXTABLE(1234b, 2f)
28742 +#endif
28743 +
28744 + movl %eax, (v)
28745 + movl %edx, 4(v)
28746 +
28747 +#ifdef CONFIG_PAX_REFCOUNT
28748 +2:
28749 +#endif
28750 +
28751 +RET_ENDP
28752 +BEGIN(inc_return_unchecked)
28753 + movl (v), %eax
28754 + movl 4(v), %edx
28755 + addl $1, %eax
28756 + adcl $0, %edx
28757 movl %eax, (v)
28758 movl %edx, 4(v)
28759 RET_ENDP
28760 @@ -123,6 +232,20 @@ RET_ENDP
28761 BEGIN(dec)
28762 subl $1, (v)
28763 sbbl $0, 4(v)
28764 +
28765 +#ifdef CONFIG_PAX_REFCOUNT
28766 + jno 0f
28767 + addl $1, (v)
28768 + adcl $0, 4(v)
28769 + int $4
28770 +0:
28771 + _ASM_EXTABLE(0b, 0b)
28772 +#endif
28773 +
28774 +RET_ENDP
28775 +BEGIN(dec_unchecked)
28776 + subl $1, (v)
28777 + sbbl $0, 4(v)
28778 RET_ENDP
28779 #undef v
28780
28781 @@ -132,6 +255,26 @@ BEGIN(dec_return)
28782 movl 4(v), %edx
28783 subl $1, %eax
28784 sbbl $0, %edx
28785 +
28786 +#ifdef CONFIG_PAX_REFCOUNT
28787 + into
28788 +1234:
28789 + _ASM_EXTABLE(1234b, 2f)
28790 +#endif
28791 +
28792 + movl %eax, (v)
28793 + movl %edx, 4(v)
28794 +
28795 +#ifdef CONFIG_PAX_REFCOUNT
28796 +2:
28797 +#endif
28798 +
28799 +RET_ENDP
28800 +BEGIN(dec_return_unchecked)
28801 + movl (v), %eax
28802 + movl 4(v), %edx
28803 + subl $1, %eax
28804 + sbbl $0, %edx
28805 movl %eax, (v)
28806 movl %edx, 4(v)
28807 RET_ENDP
28808 @@ -143,6 +286,13 @@ BEGIN(add_unless)
28809 adcl %edx, %edi
28810 addl (v), %eax
28811 adcl 4(v), %edx
28812 +
28813 +#ifdef CONFIG_PAX_REFCOUNT
28814 + into
28815 +1234:
28816 + _ASM_EXTABLE(1234b, 2f)
28817 +#endif
28818 +
28819 cmpl %eax, %ecx
28820 je 3f
28821 1:
28822 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
28823 1:
28824 addl $1, %eax
28825 adcl $0, %edx
28826 +
28827 +#ifdef CONFIG_PAX_REFCOUNT
28828 + into
28829 +1234:
28830 + _ASM_EXTABLE(1234b, 2f)
28831 +#endif
28832 +
28833 movl %eax, (v)
28834 movl %edx, 4(v)
28835 movl $1, %eax
28836 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
28837 movl 4(v), %edx
28838 subl $1, %eax
28839 sbbl $0, %edx
28840 +
28841 +#ifdef CONFIG_PAX_REFCOUNT
28842 + into
28843 +1234:
28844 + _ASM_EXTABLE(1234b, 1f)
28845 +#endif
28846 +
28847 js 1f
28848 movl %eax, (v)
28849 movl %edx, 4(v)
28850 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
28851 index f5cc9eb..51fa319 100644
28852 --- a/arch/x86/lib/atomic64_cx8_32.S
28853 +++ b/arch/x86/lib/atomic64_cx8_32.S
28854 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
28855 CFI_STARTPROC
28856
28857 read64 %ecx
28858 + pax_force_retaddr
28859 ret
28860 CFI_ENDPROC
28861 ENDPROC(atomic64_read_cx8)
28862
28863 +ENTRY(atomic64_read_unchecked_cx8)
28864 + CFI_STARTPROC
28865 +
28866 + read64 %ecx
28867 + pax_force_retaddr
28868 + ret
28869 + CFI_ENDPROC
28870 +ENDPROC(atomic64_read_unchecked_cx8)
28871 +
28872 ENTRY(atomic64_set_cx8)
28873 CFI_STARTPROC
28874
28875 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
28876 cmpxchg8b (%esi)
28877 jne 1b
28878
28879 + pax_force_retaddr
28880 ret
28881 CFI_ENDPROC
28882 ENDPROC(atomic64_set_cx8)
28883
28884 +ENTRY(atomic64_set_unchecked_cx8)
28885 + CFI_STARTPROC
28886 +
28887 +1:
28888 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
28889 + * are atomic on 586 and newer */
28890 + cmpxchg8b (%esi)
28891 + jne 1b
28892 +
28893 + pax_force_retaddr
28894 + ret
28895 + CFI_ENDPROC
28896 +ENDPROC(atomic64_set_unchecked_cx8)
28897 +
28898 ENTRY(atomic64_xchg_cx8)
28899 CFI_STARTPROC
28900
28901 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
28902 cmpxchg8b (%esi)
28903 jne 1b
28904
28905 + pax_force_retaddr
28906 ret
28907 CFI_ENDPROC
28908 ENDPROC(atomic64_xchg_cx8)
28909
28910 -.macro addsub_return func ins insc
28911 -ENTRY(atomic64_\func\()_return_cx8)
28912 +.macro addsub_return func ins insc unchecked=""
28913 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28914 CFI_STARTPROC
28915 SAVE ebp
28916 SAVE ebx
28917 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
28918 movl %edx, %ecx
28919 \ins\()l %esi, %ebx
28920 \insc\()l %edi, %ecx
28921 +
28922 +.ifb \unchecked
28923 +#ifdef CONFIG_PAX_REFCOUNT
28924 + into
28925 +2:
28926 + _ASM_EXTABLE(2b, 3f)
28927 +#endif
28928 +.endif
28929 +
28930 LOCK_PREFIX
28931 cmpxchg8b (%ebp)
28932 jne 1b
28933 -
28934 -10:
28935 movl %ebx, %eax
28936 movl %ecx, %edx
28937 +
28938 +.ifb \unchecked
28939 +#ifdef CONFIG_PAX_REFCOUNT
28940 +3:
28941 +#endif
28942 +.endif
28943 +
28944 RESTORE edi
28945 RESTORE esi
28946 RESTORE ebx
28947 RESTORE ebp
28948 + pax_force_retaddr
28949 ret
28950 CFI_ENDPROC
28951 -ENDPROC(atomic64_\func\()_return_cx8)
28952 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28953 .endm
28954
28955 addsub_return add add adc
28956 addsub_return sub sub sbb
28957 +addsub_return add add adc _unchecked
28958 +addsub_return sub sub sbb _unchecked
28959
28960 -.macro incdec_return func ins insc
28961 -ENTRY(atomic64_\func\()_return_cx8)
28962 +.macro incdec_return func ins insc unchecked=""
28963 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28964 CFI_STARTPROC
28965 SAVE ebx
28966
28967 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
28968 movl %edx, %ecx
28969 \ins\()l $1, %ebx
28970 \insc\()l $0, %ecx
28971 +
28972 +.ifb \unchecked
28973 +#ifdef CONFIG_PAX_REFCOUNT
28974 + into
28975 +2:
28976 + _ASM_EXTABLE(2b, 3f)
28977 +#endif
28978 +.endif
28979 +
28980 LOCK_PREFIX
28981 cmpxchg8b (%esi)
28982 jne 1b
28983
28984 -10:
28985 movl %ebx, %eax
28986 movl %ecx, %edx
28987 +
28988 +.ifb \unchecked
28989 +#ifdef CONFIG_PAX_REFCOUNT
28990 +3:
28991 +#endif
28992 +.endif
28993 +
28994 RESTORE ebx
28995 + pax_force_retaddr
28996 ret
28997 CFI_ENDPROC
28998 -ENDPROC(atomic64_\func\()_return_cx8)
28999 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29000 .endm
29001
29002 incdec_return inc add adc
29003 incdec_return dec sub sbb
29004 +incdec_return inc add adc _unchecked
29005 +incdec_return dec sub sbb _unchecked
29006
29007 ENTRY(atomic64_dec_if_positive_cx8)
29008 CFI_STARTPROC
29009 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
29010 movl %edx, %ecx
29011 subl $1, %ebx
29012 sbb $0, %ecx
29013 +
29014 +#ifdef CONFIG_PAX_REFCOUNT
29015 + into
29016 +1234:
29017 + _ASM_EXTABLE(1234b, 2f)
29018 +#endif
29019 +
29020 js 2f
29021 LOCK_PREFIX
29022 cmpxchg8b (%esi)
29023 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
29024 movl %ebx, %eax
29025 movl %ecx, %edx
29026 RESTORE ebx
29027 + pax_force_retaddr
29028 ret
29029 CFI_ENDPROC
29030 ENDPROC(atomic64_dec_if_positive_cx8)
29031 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
29032 movl %edx, %ecx
29033 addl %ebp, %ebx
29034 adcl %edi, %ecx
29035 +
29036 +#ifdef CONFIG_PAX_REFCOUNT
29037 + into
29038 +1234:
29039 + _ASM_EXTABLE(1234b, 3f)
29040 +#endif
29041 +
29042 LOCK_PREFIX
29043 cmpxchg8b (%esi)
29044 jne 1b
29045 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
29046 CFI_ADJUST_CFA_OFFSET -8
29047 RESTORE ebx
29048 RESTORE ebp
29049 + pax_force_retaddr
29050 ret
29051 4:
29052 cmpl %edx, 4(%esp)
29053 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
29054 xorl %ecx, %ecx
29055 addl $1, %ebx
29056 adcl %edx, %ecx
29057 +
29058 +#ifdef CONFIG_PAX_REFCOUNT
29059 + into
29060 +1234:
29061 + _ASM_EXTABLE(1234b, 3f)
29062 +#endif
29063 +
29064 LOCK_PREFIX
29065 cmpxchg8b (%esi)
29066 jne 1b
29067 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
29068 movl $1, %eax
29069 3:
29070 RESTORE ebx
29071 + pax_force_retaddr
29072 ret
29073 CFI_ENDPROC
29074 ENDPROC(atomic64_inc_not_zero_cx8)
29075 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
29076 index e78b8ee..7e173a8 100644
29077 --- a/arch/x86/lib/checksum_32.S
29078 +++ b/arch/x86/lib/checksum_32.S
29079 @@ -29,7 +29,8 @@
29080 #include <asm/dwarf2.h>
29081 #include <asm/errno.h>
29082 #include <asm/asm.h>
29083 -
29084 +#include <asm/segment.h>
29085 +
29086 /*
29087 * computes a partial checksum, e.g. for TCP/UDP fragments
29088 */
29089 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
29090
29091 #define ARGBASE 16
29092 #define FP 12
29093 -
29094 -ENTRY(csum_partial_copy_generic)
29095 +
29096 +ENTRY(csum_partial_copy_generic_to_user)
29097 CFI_STARTPROC
29098 +
29099 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29100 + pushl_cfi %gs
29101 + popl_cfi %es
29102 + jmp csum_partial_copy_generic
29103 +#endif
29104 +
29105 +ENTRY(csum_partial_copy_generic_from_user)
29106 +
29107 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29108 + pushl_cfi %gs
29109 + popl_cfi %ds
29110 +#endif
29111 +
29112 +ENTRY(csum_partial_copy_generic)
29113 subl $4,%esp
29114 CFI_ADJUST_CFA_OFFSET 4
29115 pushl_cfi %edi
29116 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
29117 jmp 4f
29118 SRC(1: movw (%esi), %bx )
29119 addl $2, %esi
29120 -DST( movw %bx, (%edi) )
29121 +DST( movw %bx, %es:(%edi) )
29122 addl $2, %edi
29123 addw %bx, %ax
29124 adcl $0, %eax
29125 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
29126 SRC(1: movl (%esi), %ebx )
29127 SRC( movl 4(%esi), %edx )
29128 adcl %ebx, %eax
29129 -DST( movl %ebx, (%edi) )
29130 +DST( movl %ebx, %es:(%edi) )
29131 adcl %edx, %eax
29132 -DST( movl %edx, 4(%edi) )
29133 +DST( movl %edx, %es:4(%edi) )
29134
29135 SRC( movl 8(%esi), %ebx )
29136 SRC( movl 12(%esi), %edx )
29137 adcl %ebx, %eax
29138 -DST( movl %ebx, 8(%edi) )
29139 +DST( movl %ebx, %es:8(%edi) )
29140 adcl %edx, %eax
29141 -DST( movl %edx, 12(%edi) )
29142 +DST( movl %edx, %es:12(%edi) )
29143
29144 SRC( movl 16(%esi), %ebx )
29145 SRC( movl 20(%esi), %edx )
29146 adcl %ebx, %eax
29147 -DST( movl %ebx, 16(%edi) )
29148 +DST( movl %ebx, %es:16(%edi) )
29149 adcl %edx, %eax
29150 -DST( movl %edx, 20(%edi) )
29151 +DST( movl %edx, %es:20(%edi) )
29152
29153 SRC( movl 24(%esi), %ebx )
29154 SRC( movl 28(%esi), %edx )
29155 adcl %ebx, %eax
29156 -DST( movl %ebx, 24(%edi) )
29157 +DST( movl %ebx, %es:24(%edi) )
29158 adcl %edx, %eax
29159 -DST( movl %edx, 28(%edi) )
29160 +DST( movl %edx, %es:28(%edi) )
29161
29162 lea 32(%esi), %esi
29163 lea 32(%edi), %edi
29164 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
29165 shrl $2, %edx # This clears CF
29166 SRC(3: movl (%esi), %ebx )
29167 adcl %ebx, %eax
29168 -DST( movl %ebx, (%edi) )
29169 +DST( movl %ebx, %es:(%edi) )
29170 lea 4(%esi), %esi
29171 lea 4(%edi), %edi
29172 dec %edx
29173 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
29174 jb 5f
29175 SRC( movw (%esi), %cx )
29176 leal 2(%esi), %esi
29177 -DST( movw %cx, (%edi) )
29178 +DST( movw %cx, %es:(%edi) )
29179 leal 2(%edi), %edi
29180 je 6f
29181 shll $16,%ecx
29182 SRC(5: movb (%esi), %cl )
29183 -DST( movb %cl, (%edi) )
29184 +DST( movb %cl, %es:(%edi) )
29185 6: addl %ecx, %eax
29186 adcl $0, %eax
29187 7:
29188 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
29189
29190 6001:
29191 movl ARGBASE+20(%esp), %ebx # src_err_ptr
29192 - movl $-EFAULT, (%ebx)
29193 + movl $-EFAULT, %ss:(%ebx)
29194
29195 # zero the complete destination - computing the rest
29196 # is too much work
29197 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
29198
29199 6002:
29200 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29201 - movl $-EFAULT,(%ebx)
29202 + movl $-EFAULT,%ss:(%ebx)
29203 jmp 5000b
29204
29205 .previous
29206
29207 + pushl_cfi %ss
29208 + popl_cfi %ds
29209 + pushl_cfi %ss
29210 + popl_cfi %es
29211 popl_cfi %ebx
29212 CFI_RESTORE ebx
29213 popl_cfi %esi
29214 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
29215 popl_cfi %ecx # equivalent to addl $4,%esp
29216 ret
29217 CFI_ENDPROC
29218 -ENDPROC(csum_partial_copy_generic)
29219 +ENDPROC(csum_partial_copy_generic_to_user)
29220
29221 #else
29222
29223 /* Version for PentiumII/PPro */
29224
29225 #define ROUND1(x) \
29226 + nop; nop; nop; \
29227 SRC(movl x(%esi), %ebx ) ; \
29228 addl %ebx, %eax ; \
29229 - DST(movl %ebx, x(%edi) ) ;
29230 + DST(movl %ebx, %es:x(%edi)) ;
29231
29232 #define ROUND(x) \
29233 + nop; nop; nop; \
29234 SRC(movl x(%esi), %ebx ) ; \
29235 adcl %ebx, %eax ; \
29236 - DST(movl %ebx, x(%edi) ) ;
29237 + DST(movl %ebx, %es:x(%edi)) ;
29238
29239 #define ARGBASE 12
29240 -
29241 -ENTRY(csum_partial_copy_generic)
29242 +
29243 +ENTRY(csum_partial_copy_generic_to_user)
29244 CFI_STARTPROC
29245 +
29246 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29247 + pushl_cfi %gs
29248 + popl_cfi %es
29249 + jmp csum_partial_copy_generic
29250 +#endif
29251 +
29252 +ENTRY(csum_partial_copy_generic_from_user)
29253 +
29254 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29255 + pushl_cfi %gs
29256 + popl_cfi %ds
29257 +#endif
29258 +
29259 +ENTRY(csum_partial_copy_generic)
29260 pushl_cfi %ebx
29261 CFI_REL_OFFSET ebx, 0
29262 pushl_cfi %edi
29263 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
29264 subl %ebx, %edi
29265 lea -1(%esi),%edx
29266 andl $-32,%edx
29267 - lea 3f(%ebx,%ebx), %ebx
29268 + lea 3f(%ebx,%ebx,2), %ebx
29269 testl %esi, %esi
29270 jmp *%ebx
29271 1: addl $64,%esi
29272 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29273 jb 5f
29274 SRC( movw (%esi), %dx )
29275 leal 2(%esi), %esi
29276 -DST( movw %dx, (%edi) )
29277 +DST( movw %dx, %es:(%edi) )
29278 leal 2(%edi), %edi
29279 je 6f
29280 shll $16,%edx
29281 5:
29282 SRC( movb (%esi), %dl )
29283 -DST( movb %dl, (%edi) )
29284 +DST( movb %dl, %es:(%edi) )
29285 6: addl %edx, %eax
29286 adcl $0, %eax
29287 7:
29288 .section .fixup, "ax"
29289 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29290 - movl $-EFAULT, (%ebx)
29291 + movl $-EFAULT, %ss:(%ebx)
29292 # zero the complete destination (computing the rest is too much work)
29293 movl ARGBASE+8(%esp),%edi # dst
29294 movl ARGBASE+12(%esp),%ecx # len
29295 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29296 rep; stosb
29297 jmp 7b
29298 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29299 - movl $-EFAULT, (%ebx)
29300 + movl $-EFAULT, %ss:(%ebx)
29301 jmp 7b
29302 .previous
29303
29304 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29305 + pushl_cfi %ss
29306 + popl_cfi %ds
29307 + pushl_cfi %ss
29308 + popl_cfi %es
29309 +#endif
29310 +
29311 popl_cfi %esi
29312 CFI_RESTORE esi
29313 popl_cfi %edi
29314 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29315 CFI_RESTORE ebx
29316 ret
29317 CFI_ENDPROC
29318 -ENDPROC(csum_partial_copy_generic)
29319 +ENDPROC(csum_partial_copy_generic_to_user)
29320
29321 #undef ROUND
29322 #undef ROUND1
29323 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29324 index f2145cf..cea889d 100644
29325 --- a/arch/x86/lib/clear_page_64.S
29326 +++ b/arch/x86/lib/clear_page_64.S
29327 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29328 movl $4096/8,%ecx
29329 xorl %eax,%eax
29330 rep stosq
29331 + pax_force_retaddr
29332 ret
29333 CFI_ENDPROC
29334 ENDPROC(clear_page_c)
29335 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29336 movl $4096,%ecx
29337 xorl %eax,%eax
29338 rep stosb
29339 + pax_force_retaddr
29340 ret
29341 CFI_ENDPROC
29342 ENDPROC(clear_page_c_e)
29343 @@ -43,6 +45,7 @@ ENTRY(clear_page)
29344 leaq 64(%rdi),%rdi
29345 jnz .Lloop
29346 nop
29347 + pax_force_retaddr
29348 ret
29349 CFI_ENDPROC
29350 .Lclear_page_end:
29351 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
29352
29353 #include <asm/cpufeature.h>
29354
29355 - .section .altinstr_replacement,"ax"
29356 + .section .altinstr_replacement,"a"
29357 1: .byte 0xeb /* jmp <disp8> */
29358 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29359 2: .byte 0xeb /* jmp <disp8> */
29360 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29361 index 1e572c5..2a162cd 100644
29362 --- a/arch/x86/lib/cmpxchg16b_emu.S
29363 +++ b/arch/x86/lib/cmpxchg16b_emu.S
29364 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
29365
29366 popf
29367 mov $1, %al
29368 + pax_force_retaddr
29369 ret
29370
29371 not_same:
29372 popf
29373 xor %al,%al
29374 + pax_force_retaddr
29375 ret
29376
29377 CFI_ENDPROC
29378 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29379 index 176cca6..e0d658e 100644
29380 --- a/arch/x86/lib/copy_page_64.S
29381 +++ b/arch/x86/lib/copy_page_64.S
29382 @@ -9,6 +9,7 @@ copy_page_rep:
29383 CFI_STARTPROC
29384 movl $4096/8, %ecx
29385 rep movsq
29386 + pax_force_retaddr
29387 ret
29388 CFI_ENDPROC
29389 ENDPROC(copy_page_rep)
29390 @@ -24,8 +25,8 @@ ENTRY(copy_page)
29391 CFI_ADJUST_CFA_OFFSET 2*8
29392 movq %rbx, (%rsp)
29393 CFI_REL_OFFSET rbx, 0
29394 - movq %r12, 1*8(%rsp)
29395 - CFI_REL_OFFSET r12, 1*8
29396 + movq %r13, 1*8(%rsp)
29397 + CFI_REL_OFFSET r13, 1*8
29398
29399 movl $(4096/64)-5, %ecx
29400 .p2align 4
29401 @@ -38,7 +39,7 @@ ENTRY(copy_page)
29402 movq 0x8*4(%rsi), %r9
29403 movq 0x8*5(%rsi), %r10
29404 movq 0x8*6(%rsi), %r11
29405 - movq 0x8*7(%rsi), %r12
29406 + movq 0x8*7(%rsi), %r13
29407
29408 prefetcht0 5*64(%rsi)
29409
29410 @@ -49,7 +50,7 @@ ENTRY(copy_page)
29411 movq %r9, 0x8*4(%rdi)
29412 movq %r10, 0x8*5(%rdi)
29413 movq %r11, 0x8*6(%rdi)
29414 - movq %r12, 0x8*7(%rdi)
29415 + movq %r13, 0x8*7(%rdi)
29416
29417 leaq 64 (%rsi), %rsi
29418 leaq 64 (%rdi), %rdi
29419 @@ -68,7 +69,7 @@ ENTRY(copy_page)
29420 movq 0x8*4(%rsi), %r9
29421 movq 0x8*5(%rsi), %r10
29422 movq 0x8*6(%rsi), %r11
29423 - movq 0x8*7(%rsi), %r12
29424 + movq 0x8*7(%rsi), %r13
29425
29426 movq %rax, 0x8*0(%rdi)
29427 movq %rbx, 0x8*1(%rdi)
29428 @@ -77,7 +78,7 @@ ENTRY(copy_page)
29429 movq %r9, 0x8*4(%rdi)
29430 movq %r10, 0x8*5(%rdi)
29431 movq %r11, 0x8*6(%rdi)
29432 - movq %r12, 0x8*7(%rdi)
29433 + movq %r13, 0x8*7(%rdi)
29434
29435 leaq 64(%rdi), %rdi
29436 leaq 64(%rsi), %rsi
29437 @@ -85,10 +86,11 @@ ENTRY(copy_page)
29438
29439 movq (%rsp), %rbx
29440 CFI_RESTORE rbx
29441 - movq 1*8(%rsp), %r12
29442 - CFI_RESTORE r12
29443 + movq 1*8(%rsp), %r13
29444 + CFI_RESTORE r13
29445 addq $2*8, %rsp
29446 CFI_ADJUST_CFA_OFFSET -2*8
29447 + pax_force_retaddr
29448 ret
29449 .Lcopy_page_end:
29450 CFI_ENDPROC
29451 @@ -99,7 +101,7 @@ ENDPROC(copy_page)
29452
29453 #include <asm/cpufeature.h>
29454
29455 - .section .altinstr_replacement,"ax"
29456 + .section .altinstr_replacement,"a"
29457 1: .byte 0xeb /* jmp <disp8> */
29458 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29459 2:
29460 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29461 index dee945d..a84067b 100644
29462 --- a/arch/x86/lib/copy_user_64.S
29463 +++ b/arch/x86/lib/copy_user_64.S
29464 @@ -18,31 +18,7 @@
29465 #include <asm/alternative-asm.h>
29466 #include <asm/asm.h>
29467 #include <asm/smap.h>
29468 -
29469 -/*
29470 - * By placing feature2 after feature1 in altinstructions section, we logically
29471 - * implement:
29472 - * If CPU has feature2, jmp to alt2 is used
29473 - * else if CPU has feature1, jmp to alt1 is used
29474 - * else jmp to orig is used.
29475 - */
29476 - .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29477 -0:
29478 - .byte 0xe9 /* 32bit jump */
29479 - .long \orig-1f /* by default jump to orig */
29480 -1:
29481 - .section .altinstr_replacement,"ax"
29482 -2: .byte 0xe9 /* near jump with 32bit immediate */
29483 - .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29484 -3: .byte 0xe9 /* near jump with 32bit immediate */
29485 - .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29486 - .previous
29487 -
29488 - .section .altinstructions,"a"
29489 - altinstruction_entry 0b,2b,\feature1,5,5
29490 - altinstruction_entry 0b,3b,\feature2,5,5
29491 - .previous
29492 - .endm
29493 +#include <asm/pgtable.h>
29494
29495 .macro ALIGN_DESTINATION
29496 #ifdef FIX_ALIGNMENT
29497 @@ -70,52 +46,6 @@
29498 #endif
29499 .endm
29500
29501 -/* Standard copy_to_user with segment limit checking */
29502 -ENTRY(_copy_to_user)
29503 - CFI_STARTPROC
29504 - GET_THREAD_INFO(%rax)
29505 - movq %rdi,%rcx
29506 - addq %rdx,%rcx
29507 - jc bad_to_user
29508 - cmpq TI_addr_limit(%rax),%rcx
29509 - ja bad_to_user
29510 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29511 - copy_user_generic_unrolled,copy_user_generic_string, \
29512 - copy_user_enhanced_fast_string
29513 - CFI_ENDPROC
29514 -ENDPROC(_copy_to_user)
29515 -
29516 -/* Standard copy_from_user with segment limit checking */
29517 -ENTRY(_copy_from_user)
29518 - CFI_STARTPROC
29519 - GET_THREAD_INFO(%rax)
29520 - movq %rsi,%rcx
29521 - addq %rdx,%rcx
29522 - jc bad_from_user
29523 - cmpq TI_addr_limit(%rax),%rcx
29524 - ja bad_from_user
29525 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29526 - copy_user_generic_unrolled,copy_user_generic_string, \
29527 - copy_user_enhanced_fast_string
29528 - CFI_ENDPROC
29529 -ENDPROC(_copy_from_user)
29530 -
29531 - .section .fixup,"ax"
29532 - /* must zero dest */
29533 -ENTRY(bad_from_user)
29534 -bad_from_user:
29535 - CFI_STARTPROC
29536 - movl %edx,%ecx
29537 - xorl %eax,%eax
29538 - rep
29539 - stosb
29540 -bad_to_user:
29541 - movl %edx,%eax
29542 - ret
29543 - CFI_ENDPROC
29544 -ENDPROC(bad_from_user)
29545 - .previous
29546 -
29547 /*
29548 * copy_user_generic_unrolled - memory copy with exception handling.
29549 * This version is for CPUs like P4 that don't have efficient micro
29550 @@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
29551 */
29552 ENTRY(copy_user_generic_unrolled)
29553 CFI_STARTPROC
29554 + ASM_PAX_OPEN_USERLAND
29555 ASM_STAC
29556 cmpl $8,%edx
29557 jb 20f /* less then 8 bytes, go to byte copy loop */
29558 @@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
29559 jnz 21b
29560 23: xor %eax,%eax
29561 ASM_CLAC
29562 + ASM_PAX_CLOSE_USERLAND
29563 + pax_force_retaddr
29564 ret
29565
29566 .section .fixup,"ax"
29567 @@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
29568 */
29569 ENTRY(copy_user_generic_string)
29570 CFI_STARTPROC
29571 + ASM_PAX_OPEN_USERLAND
29572 ASM_STAC
29573 cmpl $8,%edx
29574 jb 2f /* less than 8 bytes, go to byte copy loop */
29575 @@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
29576 movsb
29577 xorl %eax,%eax
29578 ASM_CLAC
29579 + ASM_PAX_CLOSE_USERLAND
29580 + pax_force_retaddr
29581 ret
29582
29583 .section .fixup,"ax"
29584 @@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
29585 */
29586 ENTRY(copy_user_enhanced_fast_string)
29587 CFI_STARTPROC
29588 + ASM_PAX_OPEN_USERLAND
29589 ASM_STAC
29590 movl %edx,%ecx
29591 1: rep
29592 movsb
29593 xorl %eax,%eax
29594 ASM_CLAC
29595 + ASM_PAX_CLOSE_USERLAND
29596 + pax_force_retaddr
29597 ret
29598
29599 .section .fixup,"ax"
29600 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
29601 index 6a4f43c..c70fb52 100644
29602 --- a/arch/x86/lib/copy_user_nocache_64.S
29603 +++ b/arch/x86/lib/copy_user_nocache_64.S
29604 @@ -8,6 +8,7 @@
29605
29606 #include <linux/linkage.h>
29607 #include <asm/dwarf2.h>
29608 +#include <asm/alternative-asm.h>
29609
29610 #define FIX_ALIGNMENT 1
29611
29612 @@ -16,6 +17,7 @@
29613 #include <asm/thread_info.h>
29614 #include <asm/asm.h>
29615 #include <asm/smap.h>
29616 +#include <asm/pgtable.h>
29617
29618 .macro ALIGN_DESTINATION
29619 #ifdef FIX_ALIGNMENT
29620 @@ -49,6 +51,16 @@
29621 */
29622 ENTRY(__copy_user_nocache)
29623 CFI_STARTPROC
29624 +
29625 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29626 + mov pax_user_shadow_base,%rcx
29627 + cmp %rcx,%rsi
29628 + jae 1f
29629 + add %rcx,%rsi
29630 +1:
29631 +#endif
29632 +
29633 + ASM_PAX_OPEN_USERLAND
29634 ASM_STAC
29635 cmpl $8,%edx
29636 jb 20f /* less then 8 bytes, go to byte copy loop */
29637 @@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
29638 jnz 21b
29639 23: xorl %eax,%eax
29640 ASM_CLAC
29641 + ASM_PAX_CLOSE_USERLAND
29642 sfence
29643 + pax_force_retaddr
29644 ret
29645
29646 .section .fixup,"ax"
29647 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
29648 index 2419d5f..fe52d0e 100644
29649 --- a/arch/x86/lib/csum-copy_64.S
29650 +++ b/arch/x86/lib/csum-copy_64.S
29651 @@ -9,6 +9,7 @@
29652 #include <asm/dwarf2.h>
29653 #include <asm/errno.h>
29654 #include <asm/asm.h>
29655 +#include <asm/alternative-asm.h>
29656
29657 /*
29658 * Checksum copy with exception handling.
29659 @@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
29660 CFI_ADJUST_CFA_OFFSET 7*8
29661 movq %rbx, 2*8(%rsp)
29662 CFI_REL_OFFSET rbx, 2*8
29663 - movq %r12, 3*8(%rsp)
29664 - CFI_REL_OFFSET r12, 3*8
29665 + movq %r15, 3*8(%rsp)
29666 + CFI_REL_OFFSET r15, 3*8
29667 movq %r14, 4*8(%rsp)
29668 CFI_REL_OFFSET r14, 4*8
29669 movq %r13, 5*8(%rsp)
29670 @@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
29671 movl %edx, %ecx
29672
29673 xorl %r9d, %r9d
29674 - movq %rcx, %r12
29675 + movq %rcx, %r15
29676
29677 - shrq $6, %r12
29678 + shrq $6, %r15
29679 jz .Lhandle_tail /* < 64 */
29680
29681 clc
29682
29683 /* main loop. clear in 64 byte blocks */
29684 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
29685 - /* r11: temp3, rdx: temp4, r12 loopcnt */
29686 + /* r11: temp3, rdx: temp4, r15 loopcnt */
29687 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
29688 .p2align 4
29689 .Lloop:
29690 @@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
29691 adcq %r14, %rax
29692 adcq %r13, %rax
29693
29694 - decl %r12d
29695 + decl %r15d
29696
29697 dest
29698 movq %rbx, (%rsi)
29699 @@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
29700 .Lende:
29701 movq 2*8(%rsp), %rbx
29702 CFI_RESTORE rbx
29703 - movq 3*8(%rsp), %r12
29704 - CFI_RESTORE r12
29705 + movq 3*8(%rsp), %r15
29706 + CFI_RESTORE r15
29707 movq 4*8(%rsp), %r14
29708 CFI_RESTORE r14
29709 movq 5*8(%rsp), %r13
29710 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
29711 CFI_RESTORE rbp
29712 addq $7*8, %rsp
29713 CFI_ADJUST_CFA_OFFSET -7*8
29714 + pax_force_retaddr
29715 ret
29716 CFI_RESTORE_STATE
29717
29718 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
29719 index 7609e0e..b449b98 100644
29720 --- a/arch/x86/lib/csum-wrappers_64.c
29721 +++ b/arch/x86/lib/csum-wrappers_64.c
29722 @@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
29723 len -= 2;
29724 }
29725 }
29726 + pax_open_userland();
29727 stac();
29728 - isum = csum_partial_copy_generic((__force const void *)src,
29729 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
29730 dst, len, isum, errp, NULL);
29731 clac();
29732 + pax_close_userland();
29733 if (unlikely(*errp))
29734 goto out_err;
29735
29736 @@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
29737 }
29738
29739 *errp = 0;
29740 + pax_open_userland();
29741 stac();
29742 - ret = csum_partial_copy_generic(src, (void __force *)dst,
29743 + ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
29744 len, isum, NULL, errp);
29745 clac();
29746 + pax_close_userland();
29747 return ret;
29748 }
29749 EXPORT_SYMBOL(csum_partial_copy_to_user);
29750 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
29751 index a451235..1daa956 100644
29752 --- a/arch/x86/lib/getuser.S
29753 +++ b/arch/x86/lib/getuser.S
29754 @@ -33,17 +33,40 @@
29755 #include <asm/thread_info.h>
29756 #include <asm/asm.h>
29757 #include <asm/smap.h>
29758 +#include <asm/segment.h>
29759 +#include <asm/pgtable.h>
29760 +#include <asm/alternative-asm.h>
29761 +
29762 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29763 +#define __copyuser_seg gs;
29764 +#else
29765 +#define __copyuser_seg
29766 +#endif
29767
29768 .text
29769 ENTRY(__get_user_1)
29770 CFI_STARTPROC
29771 +
29772 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29773 GET_THREAD_INFO(%_ASM_DX)
29774 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29775 jae bad_get_user
29776 ASM_STAC
29777 -1: movzbl (%_ASM_AX),%edx
29778 +
29779 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29780 + mov pax_user_shadow_base,%_ASM_DX
29781 + cmp %_ASM_DX,%_ASM_AX
29782 + jae 1234f
29783 + add %_ASM_DX,%_ASM_AX
29784 +1234:
29785 +#endif
29786 +
29787 +#endif
29788 +
29789 +1: __copyuser_seg movzbl (%_ASM_AX),%edx
29790 xor %eax,%eax
29791 ASM_CLAC
29792 + pax_force_retaddr
29793 ret
29794 CFI_ENDPROC
29795 ENDPROC(__get_user_1)
29796 @@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
29797 ENTRY(__get_user_2)
29798 CFI_STARTPROC
29799 add $1,%_ASM_AX
29800 +
29801 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29802 jc bad_get_user
29803 GET_THREAD_INFO(%_ASM_DX)
29804 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29805 jae bad_get_user
29806 ASM_STAC
29807 -2: movzwl -1(%_ASM_AX),%edx
29808 +
29809 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29810 + mov pax_user_shadow_base,%_ASM_DX
29811 + cmp %_ASM_DX,%_ASM_AX
29812 + jae 1234f
29813 + add %_ASM_DX,%_ASM_AX
29814 +1234:
29815 +#endif
29816 +
29817 +#endif
29818 +
29819 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
29820 xor %eax,%eax
29821 ASM_CLAC
29822 + pax_force_retaddr
29823 ret
29824 CFI_ENDPROC
29825 ENDPROC(__get_user_2)
29826 @@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
29827 ENTRY(__get_user_4)
29828 CFI_STARTPROC
29829 add $3,%_ASM_AX
29830 +
29831 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29832 jc bad_get_user
29833 GET_THREAD_INFO(%_ASM_DX)
29834 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29835 jae bad_get_user
29836 ASM_STAC
29837 -3: movl -3(%_ASM_AX),%edx
29838 +
29839 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29840 + mov pax_user_shadow_base,%_ASM_DX
29841 + cmp %_ASM_DX,%_ASM_AX
29842 + jae 1234f
29843 + add %_ASM_DX,%_ASM_AX
29844 +1234:
29845 +#endif
29846 +
29847 +#endif
29848 +
29849 +3: __copyuser_seg movl -3(%_ASM_AX),%edx
29850 xor %eax,%eax
29851 ASM_CLAC
29852 + pax_force_retaddr
29853 ret
29854 CFI_ENDPROC
29855 ENDPROC(__get_user_4)
29856 @@ -86,10 +137,20 @@ ENTRY(__get_user_8)
29857 GET_THREAD_INFO(%_ASM_DX)
29858 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29859 jae bad_get_user
29860 +
29861 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29862 + mov pax_user_shadow_base,%_ASM_DX
29863 + cmp %_ASM_DX,%_ASM_AX
29864 + jae 1234f
29865 + add %_ASM_DX,%_ASM_AX
29866 +1234:
29867 +#endif
29868 +
29869 ASM_STAC
29870 4: movq -7(%_ASM_AX),%rdx
29871 xor %eax,%eax
29872 ASM_CLAC
29873 + pax_force_retaddr
29874 ret
29875 #else
29876 add $7,%_ASM_AX
29877 @@ -98,10 +159,11 @@ ENTRY(__get_user_8)
29878 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29879 jae bad_get_user_8
29880 ASM_STAC
29881 -4: movl -7(%_ASM_AX),%edx
29882 -5: movl -3(%_ASM_AX),%ecx
29883 +4: __copyuser_seg movl -7(%_ASM_AX),%edx
29884 +5: __copyuser_seg movl -3(%_ASM_AX),%ecx
29885 xor %eax,%eax
29886 ASM_CLAC
29887 + pax_force_retaddr
29888 ret
29889 #endif
29890 CFI_ENDPROC
29891 @@ -113,6 +175,7 @@ bad_get_user:
29892 xor %edx,%edx
29893 mov $(-EFAULT),%_ASM_AX
29894 ASM_CLAC
29895 + pax_force_retaddr
29896 ret
29897 CFI_ENDPROC
29898 END(bad_get_user)
29899 @@ -124,6 +187,7 @@ bad_get_user_8:
29900 xor %ecx,%ecx
29901 mov $(-EFAULT),%_ASM_AX
29902 ASM_CLAC
29903 + pax_force_retaddr
29904 ret
29905 CFI_ENDPROC
29906 END(bad_get_user_8)
29907 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
29908 index 54fcffe..7be149e 100644
29909 --- a/arch/x86/lib/insn.c
29910 +++ b/arch/x86/lib/insn.c
29911 @@ -20,8 +20,10 @@
29912
29913 #ifdef __KERNEL__
29914 #include <linux/string.h>
29915 +#include <asm/pgtable_types.h>
29916 #else
29917 #include <string.h>
29918 +#define ktla_ktva(addr) addr
29919 #endif
29920 #include <asm/inat.h>
29921 #include <asm/insn.h>
29922 @@ -53,8 +55,8 @@
29923 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
29924 {
29925 memset(insn, 0, sizeof(*insn));
29926 - insn->kaddr = kaddr;
29927 - insn->next_byte = kaddr;
29928 + insn->kaddr = ktla_ktva(kaddr);
29929 + insn->next_byte = ktla_ktva(kaddr);
29930 insn->x86_64 = x86_64 ? 1 : 0;
29931 insn->opnd_bytes = 4;
29932 if (x86_64)
29933 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
29934 index 05a95e7..326f2fa 100644
29935 --- a/arch/x86/lib/iomap_copy_64.S
29936 +++ b/arch/x86/lib/iomap_copy_64.S
29937 @@ -17,6 +17,7 @@
29938
29939 #include <linux/linkage.h>
29940 #include <asm/dwarf2.h>
29941 +#include <asm/alternative-asm.h>
29942
29943 /*
29944 * override generic version in lib/iomap_copy.c
29945 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
29946 CFI_STARTPROC
29947 movl %edx,%ecx
29948 rep movsd
29949 + pax_force_retaddr
29950 ret
29951 CFI_ENDPROC
29952 ENDPROC(__iowrite32_copy)
29953 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
29954 index 56313a3..0db417e 100644
29955 --- a/arch/x86/lib/memcpy_64.S
29956 +++ b/arch/x86/lib/memcpy_64.S
29957 @@ -24,7 +24,7 @@
29958 * This gets patched over the unrolled variant (below) via the
29959 * alternative instructions framework:
29960 */
29961 - .section .altinstr_replacement, "ax", @progbits
29962 + .section .altinstr_replacement, "a", @progbits
29963 .Lmemcpy_c:
29964 movq %rdi, %rax
29965 movq %rdx, %rcx
29966 @@ -33,6 +33,7 @@
29967 rep movsq
29968 movl %edx, %ecx
29969 rep movsb
29970 + pax_force_retaddr
29971 ret
29972 .Lmemcpy_e:
29973 .previous
29974 @@ -44,11 +45,12 @@
29975 * This gets patched over the unrolled variant (below) via the
29976 * alternative instructions framework:
29977 */
29978 - .section .altinstr_replacement, "ax", @progbits
29979 + .section .altinstr_replacement, "a", @progbits
29980 .Lmemcpy_c_e:
29981 movq %rdi, %rax
29982 movq %rdx, %rcx
29983 rep movsb
29984 + pax_force_retaddr
29985 ret
29986 .Lmemcpy_e_e:
29987 .previous
29988 @@ -136,6 +138,7 @@ ENTRY(memcpy)
29989 movq %r9, 1*8(%rdi)
29990 movq %r10, -2*8(%rdi, %rdx)
29991 movq %r11, -1*8(%rdi, %rdx)
29992 + pax_force_retaddr
29993 retq
29994 .p2align 4
29995 .Lless_16bytes:
29996 @@ -148,6 +151,7 @@ ENTRY(memcpy)
29997 movq -1*8(%rsi, %rdx), %r9
29998 movq %r8, 0*8(%rdi)
29999 movq %r9, -1*8(%rdi, %rdx)
30000 + pax_force_retaddr
30001 retq
30002 .p2align 4
30003 .Lless_8bytes:
30004 @@ -161,6 +165,7 @@ ENTRY(memcpy)
30005 movl -4(%rsi, %rdx), %r8d
30006 movl %ecx, (%rdi)
30007 movl %r8d, -4(%rdi, %rdx)
30008 + pax_force_retaddr
30009 retq
30010 .p2align 4
30011 .Lless_3bytes:
30012 @@ -179,6 +184,7 @@ ENTRY(memcpy)
30013 movb %cl, (%rdi)
30014
30015 .Lend:
30016 + pax_force_retaddr
30017 retq
30018 CFI_ENDPROC
30019 ENDPROC(memcpy)
30020 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
30021 index 65268a6..dd1de11 100644
30022 --- a/arch/x86/lib/memmove_64.S
30023 +++ b/arch/x86/lib/memmove_64.S
30024 @@ -202,14 +202,16 @@ ENTRY(memmove)
30025 movb (%rsi), %r11b
30026 movb %r11b, (%rdi)
30027 13:
30028 + pax_force_retaddr
30029 retq
30030 CFI_ENDPROC
30031
30032 - .section .altinstr_replacement,"ax"
30033 + .section .altinstr_replacement,"a"
30034 .Lmemmove_begin_forward_efs:
30035 /* Forward moving data. */
30036 movq %rdx, %rcx
30037 rep movsb
30038 + pax_force_retaddr
30039 retq
30040 .Lmemmove_end_forward_efs:
30041 .previous
30042 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
30043 index 2dcb380..2eb79fe 100644
30044 --- a/arch/x86/lib/memset_64.S
30045 +++ b/arch/x86/lib/memset_64.S
30046 @@ -16,7 +16,7 @@
30047 *
30048 * rax original destination
30049 */
30050 - .section .altinstr_replacement, "ax", @progbits
30051 + .section .altinstr_replacement, "a", @progbits
30052 .Lmemset_c:
30053 movq %rdi,%r9
30054 movq %rdx,%rcx
30055 @@ -30,6 +30,7 @@
30056 movl %edx,%ecx
30057 rep stosb
30058 movq %r9,%rax
30059 + pax_force_retaddr
30060 ret
30061 .Lmemset_e:
30062 .previous
30063 @@ -45,13 +46,14 @@
30064 *
30065 * rax original destination
30066 */
30067 - .section .altinstr_replacement, "ax", @progbits
30068 + .section .altinstr_replacement, "a", @progbits
30069 .Lmemset_c_e:
30070 movq %rdi,%r9
30071 movb %sil,%al
30072 movq %rdx,%rcx
30073 rep stosb
30074 movq %r9,%rax
30075 + pax_force_retaddr
30076 ret
30077 .Lmemset_e_e:
30078 .previous
30079 @@ -118,6 +120,7 @@ ENTRY(__memset)
30080
30081 .Lende:
30082 movq %r10,%rax
30083 + pax_force_retaddr
30084 ret
30085
30086 CFI_RESTORE_STATE
30087 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
30088 index c9f2d9b..e7fd2c0 100644
30089 --- a/arch/x86/lib/mmx_32.c
30090 +++ b/arch/x86/lib/mmx_32.c
30091 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30092 {
30093 void *p;
30094 int i;
30095 + unsigned long cr0;
30096
30097 if (unlikely(in_interrupt()))
30098 return __memcpy(to, from, len);
30099 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30100 kernel_fpu_begin();
30101
30102 __asm__ __volatile__ (
30103 - "1: prefetch (%0)\n" /* This set is 28 bytes */
30104 - " prefetch 64(%0)\n"
30105 - " prefetch 128(%0)\n"
30106 - " prefetch 192(%0)\n"
30107 - " prefetch 256(%0)\n"
30108 + "1: prefetch (%1)\n" /* This set is 28 bytes */
30109 + " prefetch 64(%1)\n"
30110 + " prefetch 128(%1)\n"
30111 + " prefetch 192(%1)\n"
30112 + " prefetch 256(%1)\n"
30113 "2: \n"
30114 ".section .fixup, \"ax\"\n"
30115 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30116 + "3: \n"
30117 +
30118 +#ifdef CONFIG_PAX_KERNEXEC
30119 + " movl %%cr0, %0\n"
30120 + " movl %0, %%eax\n"
30121 + " andl $0xFFFEFFFF, %%eax\n"
30122 + " movl %%eax, %%cr0\n"
30123 +#endif
30124 +
30125 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30126 +
30127 +#ifdef CONFIG_PAX_KERNEXEC
30128 + " movl %0, %%cr0\n"
30129 +#endif
30130 +
30131 " jmp 2b\n"
30132 ".previous\n"
30133 _ASM_EXTABLE(1b, 3b)
30134 - : : "r" (from));
30135 + : "=&r" (cr0) : "r" (from) : "ax");
30136
30137 for ( ; i > 5; i--) {
30138 __asm__ __volatile__ (
30139 - "1: prefetch 320(%0)\n"
30140 - "2: movq (%0), %%mm0\n"
30141 - " movq 8(%0), %%mm1\n"
30142 - " movq 16(%0), %%mm2\n"
30143 - " movq 24(%0), %%mm3\n"
30144 - " movq %%mm0, (%1)\n"
30145 - " movq %%mm1, 8(%1)\n"
30146 - " movq %%mm2, 16(%1)\n"
30147 - " movq %%mm3, 24(%1)\n"
30148 - " movq 32(%0), %%mm0\n"
30149 - " movq 40(%0), %%mm1\n"
30150 - " movq 48(%0), %%mm2\n"
30151 - " movq 56(%0), %%mm3\n"
30152 - " movq %%mm0, 32(%1)\n"
30153 - " movq %%mm1, 40(%1)\n"
30154 - " movq %%mm2, 48(%1)\n"
30155 - " movq %%mm3, 56(%1)\n"
30156 + "1: prefetch 320(%1)\n"
30157 + "2: movq (%1), %%mm0\n"
30158 + " movq 8(%1), %%mm1\n"
30159 + " movq 16(%1), %%mm2\n"
30160 + " movq 24(%1), %%mm3\n"
30161 + " movq %%mm0, (%2)\n"
30162 + " movq %%mm1, 8(%2)\n"
30163 + " movq %%mm2, 16(%2)\n"
30164 + " movq %%mm3, 24(%2)\n"
30165 + " movq 32(%1), %%mm0\n"
30166 + " movq 40(%1), %%mm1\n"
30167 + " movq 48(%1), %%mm2\n"
30168 + " movq 56(%1), %%mm3\n"
30169 + " movq %%mm0, 32(%2)\n"
30170 + " movq %%mm1, 40(%2)\n"
30171 + " movq %%mm2, 48(%2)\n"
30172 + " movq %%mm3, 56(%2)\n"
30173 ".section .fixup, \"ax\"\n"
30174 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30175 + "3:\n"
30176 +
30177 +#ifdef CONFIG_PAX_KERNEXEC
30178 + " movl %%cr0, %0\n"
30179 + " movl %0, %%eax\n"
30180 + " andl $0xFFFEFFFF, %%eax\n"
30181 + " movl %%eax, %%cr0\n"
30182 +#endif
30183 +
30184 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30185 +
30186 +#ifdef CONFIG_PAX_KERNEXEC
30187 + " movl %0, %%cr0\n"
30188 +#endif
30189 +
30190 " jmp 2b\n"
30191 ".previous\n"
30192 _ASM_EXTABLE(1b, 3b)
30193 - : : "r" (from), "r" (to) : "memory");
30194 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30195
30196 from += 64;
30197 to += 64;
30198 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
30199 static void fast_copy_page(void *to, void *from)
30200 {
30201 int i;
30202 + unsigned long cr0;
30203
30204 kernel_fpu_begin();
30205
30206 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
30207 * but that is for later. -AV
30208 */
30209 __asm__ __volatile__(
30210 - "1: prefetch (%0)\n"
30211 - " prefetch 64(%0)\n"
30212 - " prefetch 128(%0)\n"
30213 - " prefetch 192(%0)\n"
30214 - " prefetch 256(%0)\n"
30215 + "1: prefetch (%1)\n"
30216 + " prefetch 64(%1)\n"
30217 + " prefetch 128(%1)\n"
30218 + " prefetch 192(%1)\n"
30219 + " prefetch 256(%1)\n"
30220 "2: \n"
30221 ".section .fixup, \"ax\"\n"
30222 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 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 $0x1AEB, 1b\n" /* jmp on 26 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));
30241 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30242
30243 for (i = 0; i < (4096-320)/64; i++) {
30244 __asm__ __volatile__ (
30245 - "1: prefetch 320(%0)\n"
30246 - "2: movq (%0), %%mm0\n"
30247 - " movntq %%mm0, (%1)\n"
30248 - " movq 8(%0), %%mm1\n"
30249 - " movntq %%mm1, 8(%1)\n"
30250 - " movq 16(%0), %%mm2\n"
30251 - " movntq %%mm2, 16(%1)\n"
30252 - " movq 24(%0), %%mm3\n"
30253 - " movntq %%mm3, 24(%1)\n"
30254 - " movq 32(%0), %%mm4\n"
30255 - " movntq %%mm4, 32(%1)\n"
30256 - " movq 40(%0), %%mm5\n"
30257 - " movntq %%mm5, 40(%1)\n"
30258 - " movq 48(%0), %%mm6\n"
30259 - " movntq %%mm6, 48(%1)\n"
30260 - " movq 56(%0), %%mm7\n"
30261 - " movntq %%mm7, 56(%1)\n"
30262 + "1: prefetch 320(%1)\n"
30263 + "2: movq (%1), %%mm0\n"
30264 + " movntq %%mm0, (%2)\n"
30265 + " movq 8(%1), %%mm1\n"
30266 + " movntq %%mm1, 8(%2)\n"
30267 + " movq 16(%1), %%mm2\n"
30268 + " movntq %%mm2, 16(%2)\n"
30269 + " movq 24(%1), %%mm3\n"
30270 + " movntq %%mm3, 24(%2)\n"
30271 + " movq 32(%1), %%mm4\n"
30272 + " movntq %%mm4, 32(%2)\n"
30273 + " movq 40(%1), %%mm5\n"
30274 + " movntq %%mm5, 40(%2)\n"
30275 + " movq 48(%1), %%mm6\n"
30276 + " movntq %%mm6, 48(%2)\n"
30277 + " movq 56(%1), %%mm7\n"
30278 + " movntq %%mm7, 56(%2)\n"
30279 ".section .fixup, \"ax\"\n"
30280 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30281 + "3:\n"
30282 +
30283 +#ifdef CONFIG_PAX_KERNEXEC
30284 + " movl %%cr0, %0\n"
30285 + " movl %0, %%eax\n"
30286 + " andl $0xFFFEFFFF, %%eax\n"
30287 + " movl %%eax, %%cr0\n"
30288 +#endif
30289 +
30290 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30291 +
30292 +#ifdef CONFIG_PAX_KERNEXEC
30293 + " movl %0, %%cr0\n"
30294 +#endif
30295 +
30296 " jmp 2b\n"
30297 ".previous\n"
30298 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30299 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30300
30301 from += 64;
30302 to += 64;
30303 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30304 static void fast_copy_page(void *to, void *from)
30305 {
30306 int i;
30307 + unsigned long cr0;
30308
30309 kernel_fpu_begin();
30310
30311 __asm__ __volatile__ (
30312 - "1: prefetch (%0)\n"
30313 - " prefetch 64(%0)\n"
30314 - " prefetch 128(%0)\n"
30315 - " prefetch 192(%0)\n"
30316 - " prefetch 256(%0)\n"
30317 + "1: prefetch (%1)\n"
30318 + " prefetch 64(%1)\n"
30319 + " prefetch 128(%1)\n"
30320 + " prefetch 192(%1)\n"
30321 + " prefetch 256(%1)\n"
30322 "2: \n"
30323 ".section .fixup, \"ax\"\n"
30324 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 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 $0x1AEB, 1b\n" /* jmp on 26 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) : : "r" (from));
30343 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30344
30345 for (i = 0; i < 4096/64; i++) {
30346 __asm__ __volatile__ (
30347 - "1: prefetch 320(%0)\n"
30348 - "2: movq (%0), %%mm0\n"
30349 - " movq 8(%0), %%mm1\n"
30350 - " movq 16(%0), %%mm2\n"
30351 - " movq 24(%0), %%mm3\n"
30352 - " movq %%mm0, (%1)\n"
30353 - " movq %%mm1, 8(%1)\n"
30354 - " movq %%mm2, 16(%1)\n"
30355 - " movq %%mm3, 24(%1)\n"
30356 - " movq 32(%0), %%mm0\n"
30357 - " movq 40(%0), %%mm1\n"
30358 - " movq 48(%0), %%mm2\n"
30359 - " movq 56(%0), %%mm3\n"
30360 - " movq %%mm0, 32(%1)\n"
30361 - " movq %%mm1, 40(%1)\n"
30362 - " movq %%mm2, 48(%1)\n"
30363 - " movq %%mm3, 56(%1)\n"
30364 + "1: prefetch 320(%1)\n"
30365 + "2: movq (%1), %%mm0\n"
30366 + " movq 8(%1), %%mm1\n"
30367 + " movq 16(%1), %%mm2\n"
30368 + " movq 24(%1), %%mm3\n"
30369 + " movq %%mm0, (%2)\n"
30370 + " movq %%mm1, 8(%2)\n"
30371 + " movq %%mm2, 16(%2)\n"
30372 + " movq %%mm3, 24(%2)\n"
30373 + " movq 32(%1), %%mm0\n"
30374 + " movq 40(%1), %%mm1\n"
30375 + " movq 48(%1), %%mm2\n"
30376 + " movq 56(%1), %%mm3\n"
30377 + " movq %%mm0, 32(%2)\n"
30378 + " movq %%mm1, 40(%2)\n"
30379 + " movq %%mm2, 48(%2)\n"
30380 + " movq %%mm3, 56(%2)\n"
30381 ".section .fixup, \"ax\"\n"
30382 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30383 + "3:\n"
30384 +
30385 +#ifdef CONFIG_PAX_KERNEXEC
30386 + " movl %%cr0, %0\n"
30387 + " movl %0, %%eax\n"
30388 + " andl $0xFFFEFFFF, %%eax\n"
30389 + " movl %%eax, %%cr0\n"
30390 +#endif
30391 +
30392 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30393 +
30394 +#ifdef CONFIG_PAX_KERNEXEC
30395 + " movl %0, %%cr0\n"
30396 +#endif
30397 +
30398 " jmp 2b\n"
30399 ".previous\n"
30400 _ASM_EXTABLE(1b, 3b)
30401 - : : "r" (from), "r" (to) : "memory");
30402 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30403
30404 from += 64;
30405 to += 64;
30406 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30407 index f6d13ee..d789440 100644
30408 --- a/arch/x86/lib/msr-reg.S
30409 +++ b/arch/x86/lib/msr-reg.S
30410 @@ -3,6 +3,7 @@
30411 #include <asm/dwarf2.h>
30412 #include <asm/asm.h>
30413 #include <asm/msr.h>
30414 +#include <asm/alternative-asm.h>
30415
30416 #ifdef CONFIG_X86_64
30417 /*
30418 @@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30419 movl %edi, 28(%r10)
30420 popq_cfi %rbp
30421 popq_cfi %rbx
30422 + pax_force_retaddr
30423 ret
30424 3:
30425 CFI_RESTORE_STATE
30426 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30427 index fc6ba17..d4d989d 100644
30428 --- a/arch/x86/lib/putuser.S
30429 +++ b/arch/x86/lib/putuser.S
30430 @@ -16,7 +16,9 @@
30431 #include <asm/errno.h>
30432 #include <asm/asm.h>
30433 #include <asm/smap.h>
30434 -
30435 +#include <asm/segment.h>
30436 +#include <asm/pgtable.h>
30437 +#include <asm/alternative-asm.h>
30438
30439 /*
30440 * __put_user_X
30441 @@ -30,57 +32,125 @@
30442 * as they get called from within inline assembly.
30443 */
30444
30445 -#define ENTER CFI_STARTPROC ; \
30446 - GET_THREAD_INFO(%_ASM_BX)
30447 -#define EXIT ASM_CLAC ; \
30448 - ret ; \
30449 +#define ENTER CFI_STARTPROC
30450 +#define EXIT ASM_CLAC ; \
30451 + pax_force_retaddr ; \
30452 + ret ; \
30453 CFI_ENDPROC
30454
30455 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30456 +#define _DEST %_ASM_CX,%_ASM_BX
30457 +#else
30458 +#define _DEST %_ASM_CX
30459 +#endif
30460 +
30461 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30462 +#define __copyuser_seg gs;
30463 +#else
30464 +#define __copyuser_seg
30465 +#endif
30466 +
30467 .text
30468 ENTRY(__put_user_1)
30469 ENTER
30470 +
30471 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30472 + GET_THREAD_INFO(%_ASM_BX)
30473 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30474 jae bad_put_user
30475 ASM_STAC
30476 -1: movb %al,(%_ASM_CX)
30477 +
30478 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30479 + mov pax_user_shadow_base,%_ASM_BX
30480 + cmp %_ASM_BX,%_ASM_CX
30481 + jb 1234f
30482 + xor %ebx,%ebx
30483 +1234:
30484 +#endif
30485 +
30486 +#endif
30487 +
30488 +1: __copyuser_seg movb %al,(_DEST)
30489 xor %eax,%eax
30490 EXIT
30491 ENDPROC(__put_user_1)
30492
30493 ENTRY(__put_user_2)
30494 ENTER
30495 +
30496 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30497 + GET_THREAD_INFO(%_ASM_BX)
30498 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30499 sub $1,%_ASM_BX
30500 cmp %_ASM_BX,%_ASM_CX
30501 jae bad_put_user
30502 ASM_STAC
30503 -2: movw %ax,(%_ASM_CX)
30504 +
30505 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30506 + mov pax_user_shadow_base,%_ASM_BX
30507 + cmp %_ASM_BX,%_ASM_CX
30508 + jb 1234f
30509 + xor %ebx,%ebx
30510 +1234:
30511 +#endif
30512 +
30513 +#endif
30514 +
30515 +2: __copyuser_seg movw %ax,(_DEST)
30516 xor %eax,%eax
30517 EXIT
30518 ENDPROC(__put_user_2)
30519
30520 ENTRY(__put_user_4)
30521 ENTER
30522 +
30523 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30524 + GET_THREAD_INFO(%_ASM_BX)
30525 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30526 sub $3,%_ASM_BX
30527 cmp %_ASM_BX,%_ASM_CX
30528 jae bad_put_user
30529 ASM_STAC
30530 -3: movl %eax,(%_ASM_CX)
30531 +
30532 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30533 + mov pax_user_shadow_base,%_ASM_BX
30534 + cmp %_ASM_BX,%_ASM_CX
30535 + jb 1234f
30536 + xor %ebx,%ebx
30537 +1234:
30538 +#endif
30539 +
30540 +#endif
30541 +
30542 +3: __copyuser_seg movl %eax,(_DEST)
30543 xor %eax,%eax
30544 EXIT
30545 ENDPROC(__put_user_4)
30546
30547 ENTRY(__put_user_8)
30548 ENTER
30549 +
30550 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30551 + GET_THREAD_INFO(%_ASM_BX)
30552 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30553 sub $7,%_ASM_BX
30554 cmp %_ASM_BX,%_ASM_CX
30555 jae bad_put_user
30556 ASM_STAC
30557 -4: mov %_ASM_AX,(%_ASM_CX)
30558 +
30559 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30560 + mov pax_user_shadow_base,%_ASM_BX
30561 + cmp %_ASM_BX,%_ASM_CX
30562 + jb 1234f
30563 + xor %ebx,%ebx
30564 +1234:
30565 +#endif
30566 +
30567 +#endif
30568 +
30569 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
30570 #ifdef CONFIG_X86_32
30571 -5: movl %edx,4(%_ASM_CX)
30572 +5: __copyuser_seg movl %edx,4(_DEST)
30573 #endif
30574 xor %eax,%eax
30575 EXIT
30576 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
30577 index 1cad221..de671ee 100644
30578 --- a/arch/x86/lib/rwlock.S
30579 +++ b/arch/x86/lib/rwlock.S
30580 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
30581 FRAME
30582 0: LOCK_PREFIX
30583 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30584 +
30585 +#ifdef CONFIG_PAX_REFCOUNT
30586 + jno 1234f
30587 + LOCK_PREFIX
30588 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30589 + int $4
30590 +1234:
30591 + _ASM_EXTABLE(1234b, 1234b)
30592 +#endif
30593 +
30594 1: rep; nop
30595 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
30596 jne 1b
30597 LOCK_PREFIX
30598 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30599 +
30600 +#ifdef CONFIG_PAX_REFCOUNT
30601 + jno 1234f
30602 + LOCK_PREFIX
30603 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30604 + int $4
30605 +1234:
30606 + _ASM_EXTABLE(1234b, 1234b)
30607 +#endif
30608 +
30609 jnz 0b
30610 ENDFRAME
30611 + pax_force_retaddr
30612 ret
30613 CFI_ENDPROC
30614 END(__write_lock_failed)
30615 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
30616 FRAME
30617 0: LOCK_PREFIX
30618 READ_LOCK_SIZE(inc) (%__lock_ptr)
30619 +
30620 +#ifdef CONFIG_PAX_REFCOUNT
30621 + jno 1234f
30622 + LOCK_PREFIX
30623 + READ_LOCK_SIZE(dec) (%__lock_ptr)
30624 + int $4
30625 +1234:
30626 + _ASM_EXTABLE(1234b, 1234b)
30627 +#endif
30628 +
30629 1: rep; nop
30630 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
30631 js 1b
30632 LOCK_PREFIX
30633 READ_LOCK_SIZE(dec) (%__lock_ptr)
30634 +
30635 +#ifdef CONFIG_PAX_REFCOUNT
30636 + jno 1234f
30637 + LOCK_PREFIX
30638 + READ_LOCK_SIZE(inc) (%__lock_ptr)
30639 + int $4
30640 +1234:
30641 + _ASM_EXTABLE(1234b, 1234b)
30642 +#endif
30643 +
30644 js 0b
30645 ENDFRAME
30646 + pax_force_retaddr
30647 ret
30648 CFI_ENDPROC
30649 END(__read_lock_failed)
30650 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
30651 index 5dff5f0..cadebf4 100644
30652 --- a/arch/x86/lib/rwsem.S
30653 +++ b/arch/x86/lib/rwsem.S
30654 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
30655 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30656 CFI_RESTORE __ASM_REG(dx)
30657 restore_common_regs
30658 + pax_force_retaddr
30659 ret
30660 CFI_ENDPROC
30661 ENDPROC(call_rwsem_down_read_failed)
30662 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
30663 movq %rax,%rdi
30664 call rwsem_down_write_failed
30665 restore_common_regs
30666 + pax_force_retaddr
30667 ret
30668 CFI_ENDPROC
30669 ENDPROC(call_rwsem_down_write_failed)
30670 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
30671 movq %rax,%rdi
30672 call rwsem_wake
30673 restore_common_regs
30674 -1: ret
30675 +1: pax_force_retaddr
30676 + ret
30677 CFI_ENDPROC
30678 ENDPROC(call_rwsem_wake)
30679
30680 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
30681 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30682 CFI_RESTORE __ASM_REG(dx)
30683 restore_common_regs
30684 + pax_force_retaddr
30685 ret
30686 CFI_ENDPROC
30687 ENDPROC(call_rwsem_downgrade_wake)
30688 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
30689 index a63efd6..8149fbe 100644
30690 --- a/arch/x86/lib/thunk_64.S
30691 +++ b/arch/x86/lib/thunk_64.S
30692 @@ -8,6 +8,7 @@
30693 #include <linux/linkage.h>
30694 #include <asm/dwarf2.h>
30695 #include <asm/calling.h>
30696 +#include <asm/alternative-asm.h>
30697
30698 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
30699 .macro THUNK name, func, put_ret_addr_in_rdi=0
30700 @@ -15,11 +16,11 @@
30701 \name:
30702 CFI_STARTPROC
30703
30704 - /* this one pushes 9 elems, the next one would be %rIP */
30705 - SAVE_ARGS
30706 + /* this one pushes 15+1 elems, the next one would be %rIP */
30707 + SAVE_ARGS 8
30708
30709 .if \put_ret_addr_in_rdi
30710 - movq_cfi_restore 9*8, rdi
30711 + movq_cfi_restore RIP, rdi
30712 .endif
30713
30714 call \func
30715 @@ -38,8 +39,9 @@
30716
30717 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
30718 CFI_STARTPROC
30719 - SAVE_ARGS
30720 + SAVE_ARGS 8
30721 restore:
30722 - RESTORE_ARGS
30723 + RESTORE_ARGS 1,8
30724 + pax_force_retaddr
30725 ret
30726 CFI_ENDPROC
30727 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
30728 index e2f5e21..4b22130 100644
30729 --- a/arch/x86/lib/usercopy_32.c
30730 +++ b/arch/x86/lib/usercopy_32.c
30731 @@ -42,11 +42,13 @@ do { \
30732 int __d0; \
30733 might_fault(); \
30734 __asm__ __volatile__( \
30735 + __COPYUSER_SET_ES \
30736 ASM_STAC "\n" \
30737 "0: rep; stosl\n" \
30738 " movl %2,%0\n" \
30739 "1: rep; stosb\n" \
30740 "2: " ASM_CLAC "\n" \
30741 + __COPYUSER_RESTORE_ES \
30742 ".section .fixup,\"ax\"\n" \
30743 "3: lea 0(%2,%0,4),%0\n" \
30744 " jmp 2b\n" \
30745 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
30746
30747 #ifdef CONFIG_X86_INTEL_USERCOPY
30748 static unsigned long
30749 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
30750 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
30751 {
30752 int d0, d1;
30753 __asm__ __volatile__(
30754 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30755 " .align 2,0x90\n"
30756 "3: movl 0(%4), %%eax\n"
30757 "4: movl 4(%4), %%edx\n"
30758 - "5: movl %%eax, 0(%3)\n"
30759 - "6: movl %%edx, 4(%3)\n"
30760 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
30761 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
30762 "7: movl 8(%4), %%eax\n"
30763 "8: movl 12(%4),%%edx\n"
30764 - "9: movl %%eax, 8(%3)\n"
30765 - "10: movl %%edx, 12(%3)\n"
30766 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
30767 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
30768 "11: movl 16(%4), %%eax\n"
30769 "12: movl 20(%4), %%edx\n"
30770 - "13: movl %%eax, 16(%3)\n"
30771 - "14: movl %%edx, 20(%3)\n"
30772 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
30773 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
30774 "15: movl 24(%4), %%eax\n"
30775 "16: movl 28(%4), %%edx\n"
30776 - "17: movl %%eax, 24(%3)\n"
30777 - "18: movl %%edx, 28(%3)\n"
30778 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
30779 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
30780 "19: movl 32(%4), %%eax\n"
30781 "20: movl 36(%4), %%edx\n"
30782 - "21: movl %%eax, 32(%3)\n"
30783 - "22: movl %%edx, 36(%3)\n"
30784 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
30785 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
30786 "23: movl 40(%4), %%eax\n"
30787 "24: movl 44(%4), %%edx\n"
30788 - "25: movl %%eax, 40(%3)\n"
30789 - "26: movl %%edx, 44(%3)\n"
30790 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
30791 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
30792 "27: movl 48(%4), %%eax\n"
30793 "28: movl 52(%4), %%edx\n"
30794 - "29: movl %%eax, 48(%3)\n"
30795 - "30: movl %%edx, 52(%3)\n"
30796 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
30797 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
30798 "31: movl 56(%4), %%eax\n"
30799 "32: movl 60(%4), %%edx\n"
30800 - "33: movl %%eax, 56(%3)\n"
30801 - "34: movl %%edx, 60(%3)\n"
30802 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
30803 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
30804 " addl $-64, %0\n"
30805 " addl $64, %4\n"
30806 " addl $64, %3\n"
30807 @@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30808 " shrl $2, %0\n"
30809 " andl $3, %%eax\n"
30810 " cld\n"
30811 + __COPYUSER_SET_ES
30812 "99: rep; movsl\n"
30813 "36: movl %%eax, %0\n"
30814 "37: rep; movsb\n"
30815 "100:\n"
30816 + __COPYUSER_RESTORE_ES
30817 + ".section .fixup,\"ax\"\n"
30818 + "101: lea 0(%%eax,%0,4),%0\n"
30819 + " jmp 100b\n"
30820 + ".previous\n"
30821 + _ASM_EXTABLE(1b,100b)
30822 + _ASM_EXTABLE(2b,100b)
30823 + _ASM_EXTABLE(3b,100b)
30824 + _ASM_EXTABLE(4b,100b)
30825 + _ASM_EXTABLE(5b,100b)
30826 + _ASM_EXTABLE(6b,100b)
30827 + _ASM_EXTABLE(7b,100b)
30828 + _ASM_EXTABLE(8b,100b)
30829 + _ASM_EXTABLE(9b,100b)
30830 + _ASM_EXTABLE(10b,100b)
30831 + _ASM_EXTABLE(11b,100b)
30832 + _ASM_EXTABLE(12b,100b)
30833 + _ASM_EXTABLE(13b,100b)
30834 + _ASM_EXTABLE(14b,100b)
30835 + _ASM_EXTABLE(15b,100b)
30836 + _ASM_EXTABLE(16b,100b)
30837 + _ASM_EXTABLE(17b,100b)
30838 + _ASM_EXTABLE(18b,100b)
30839 + _ASM_EXTABLE(19b,100b)
30840 + _ASM_EXTABLE(20b,100b)
30841 + _ASM_EXTABLE(21b,100b)
30842 + _ASM_EXTABLE(22b,100b)
30843 + _ASM_EXTABLE(23b,100b)
30844 + _ASM_EXTABLE(24b,100b)
30845 + _ASM_EXTABLE(25b,100b)
30846 + _ASM_EXTABLE(26b,100b)
30847 + _ASM_EXTABLE(27b,100b)
30848 + _ASM_EXTABLE(28b,100b)
30849 + _ASM_EXTABLE(29b,100b)
30850 + _ASM_EXTABLE(30b,100b)
30851 + _ASM_EXTABLE(31b,100b)
30852 + _ASM_EXTABLE(32b,100b)
30853 + _ASM_EXTABLE(33b,100b)
30854 + _ASM_EXTABLE(34b,100b)
30855 + _ASM_EXTABLE(35b,100b)
30856 + _ASM_EXTABLE(36b,100b)
30857 + _ASM_EXTABLE(37b,100b)
30858 + _ASM_EXTABLE(99b,101b)
30859 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
30860 + : "1"(to), "2"(from), "0"(size)
30861 + : "eax", "edx", "memory");
30862 + return size;
30863 +}
30864 +
30865 +static unsigned long
30866 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
30867 +{
30868 + int d0, d1;
30869 + __asm__ __volatile__(
30870 + " .align 2,0x90\n"
30871 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
30872 + " cmpl $67, %0\n"
30873 + " jbe 3f\n"
30874 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
30875 + " .align 2,0x90\n"
30876 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
30877 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
30878 + "5: movl %%eax, 0(%3)\n"
30879 + "6: movl %%edx, 4(%3)\n"
30880 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
30881 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
30882 + "9: movl %%eax, 8(%3)\n"
30883 + "10: movl %%edx, 12(%3)\n"
30884 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
30885 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
30886 + "13: movl %%eax, 16(%3)\n"
30887 + "14: movl %%edx, 20(%3)\n"
30888 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
30889 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
30890 + "17: movl %%eax, 24(%3)\n"
30891 + "18: movl %%edx, 28(%3)\n"
30892 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
30893 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
30894 + "21: movl %%eax, 32(%3)\n"
30895 + "22: movl %%edx, 36(%3)\n"
30896 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
30897 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
30898 + "25: movl %%eax, 40(%3)\n"
30899 + "26: movl %%edx, 44(%3)\n"
30900 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
30901 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
30902 + "29: movl %%eax, 48(%3)\n"
30903 + "30: movl %%edx, 52(%3)\n"
30904 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
30905 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
30906 + "33: movl %%eax, 56(%3)\n"
30907 + "34: movl %%edx, 60(%3)\n"
30908 + " addl $-64, %0\n"
30909 + " addl $64, %4\n"
30910 + " addl $64, %3\n"
30911 + " cmpl $63, %0\n"
30912 + " ja 1b\n"
30913 + "35: movl %0, %%eax\n"
30914 + " shrl $2, %0\n"
30915 + " andl $3, %%eax\n"
30916 + " cld\n"
30917 + "99: rep; "__copyuser_seg" movsl\n"
30918 + "36: movl %%eax, %0\n"
30919 + "37: rep; "__copyuser_seg" movsb\n"
30920 + "100:\n"
30921 ".section .fixup,\"ax\"\n"
30922 "101: lea 0(%%eax,%0,4),%0\n"
30923 " jmp 100b\n"
30924 @@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30925 int d0, d1;
30926 __asm__ __volatile__(
30927 " .align 2,0x90\n"
30928 - "0: movl 32(%4), %%eax\n"
30929 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30930 " cmpl $67, %0\n"
30931 " jbe 2f\n"
30932 - "1: movl 64(%4), %%eax\n"
30933 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30934 " .align 2,0x90\n"
30935 - "2: movl 0(%4), %%eax\n"
30936 - "21: movl 4(%4), %%edx\n"
30937 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30938 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30939 " movl %%eax, 0(%3)\n"
30940 " movl %%edx, 4(%3)\n"
30941 - "3: movl 8(%4), %%eax\n"
30942 - "31: movl 12(%4),%%edx\n"
30943 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30944 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30945 " movl %%eax, 8(%3)\n"
30946 " movl %%edx, 12(%3)\n"
30947 - "4: movl 16(%4), %%eax\n"
30948 - "41: movl 20(%4), %%edx\n"
30949 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30950 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30951 " movl %%eax, 16(%3)\n"
30952 " movl %%edx, 20(%3)\n"
30953 - "10: movl 24(%4), %%eax\n"
30954 - "51: movl 28(%4), %%edx\n"
30955 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30956 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30957 " movl %%eax, 24(%3)\n"
30958 " movl %%edx, 28(%3)\n"
30959 - "11: movl 32(%4), %%eax\n"
30960 - "61: movl 36(%4), %%edx\n"
30961 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30962 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30963 " movl %%eax, 32(%3)\n"
30964 " movl %%edx, 36(%3)\n"
30965 - "12: movl 40(%4), %%eax\n"
30966 - "71: movl 44(%4), %%edx\n"
30967 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30968 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30969 " movl %%eax, 40(%3)\n"
30970 " movl %%edx, 44(%3)\n"
30971 - "13: movl 48(%4), %%eax\n"
30972 - "81: movl 52(%4), %%edx\n"
30973 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30974 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30975 " movl %%eax, 48(%3)\n"
30976 " movl %%edx, 52(%3)\n"
30977 - "14: movl 56(%4), %%eax\n"
30978 - "91: movl 60(%4), %%edx\n"
30979 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30980 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30981 " movl %%eax, 56(%3)\n"
30982 " movl %%edx, 60(%3)\n"
30983 " addl $-64, %0\n"
30984 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30985 " shrl $2, %0\n"
30986 " andl $3, %%eax\n"
30987 " cld\n"
30988 - "6: rep; movsl\n"
30989 + "6: rep; "__copyuser_seg" movsl\n"
30990 " movl %%eax,%0\n"
30991 - "7: rep; movsb\n"
30992 + "7: rep; "__copyuser_seg" movsb\n"
30993 "8:\n"
30994 ".section .fixup,\"ax\"\n"
30995 "9: lea 0(%%eax,%0,4),%0\n"
30996 @@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30997
30998 __asm__ __volatile__(
30999 " .align 2,0x90\n"
31000 - "0: movl 32(%4), %%eax\n"
31001 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31002 " cmpl $67, %0\n"
31003 " jbe 2f\n"
31004 - "1: movl 64(%4), %%eax\n"
31005 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31006 " .align 2,0x90\n"
31007 - "2: movl 0(%4), %%eax\n"
31008 - "21: movl 4(%4), %%edx\n"
31009 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31010 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31011 " movnti %%eax, 0(%3)\n"
31012 " movnti %%edx, 4(%3)\n"
31013 - "3: movl 8(%4), %%eax\n"
31014 - "31: movl 12(%4),%%edx\n"
31015 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31016 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31017 " movnti %%eax, 8(%3)\n"
31018 " movnti %%edx, 12(%3)\n"
31019 - "4: movl 16(%4), %%eax\n"
31020 - "41: movl 20(%4), %%edx\n"
31021 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31022 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31023 " movnti %%eax, 16(%3)\n"
31024 " movnti %%edx, 20(%3)\n"
31025 - "10: movl 24(%4), %%eax\n"
31026 - "51: movl 28(%4), %%edx\n"
31027 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31028 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31029 " movnti %%eax, 24(%3)\n"
31030 " movnti %%edx, 28(%3)\n"
31031 - "11: movl 32(%4), %%eax\n"
31032 - "61: movl 36(%4), %%edx\n"
31033 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31034 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31035 " movnti %%eax, 32(%3)\n"
31036 " movnti %%edx, 36(%3)\n"
31037 - "12: movl 40(%4), %%eax\n"
31038 - "71: movl 44(%4), %%edx\n"
31039 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31040 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31041 " movnti %%eax, 40(%3)\n"
31042 " movnti %%edx, 44(%3)\n"
31043 - "13: movl 48(%4), %%eax\n"
31044 - "81: movl 52(%4), %%edx\n"
31045 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31046 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31047 " movnti %%eax, 48(%3)\n"
31048 " movnti %%edx, 52(%3)\n"
31049 - "14: movl 56(%4), %%eax\n"
31050 - "91: movl 60(%4), %%edx\n"
31051 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31052 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31053 " movnti %%eax, 56(%3)\n"
31054 " movnti %%edx, 60(%3)\n"
31055 " addl $-64, %0\n"
31056 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31057 " shrl $2, %0\n"
31058 " andl $3, %%eax\n"
31059 " cld\n"
31060 - "6: rep; movsl\n"
31061 + "6: rep; "__copyuser_seg" movsl\n"
31062 " movl %%eax,%0\n"
31063 - "7: rep; movsb\n"
31064 + "7: rep; "__copyuser_seg" movsb\n"
31065 "8:\n"
31066 ".section .fixup,\"ax\"\n"
31067 "9: lea 0(%%eax,%0,4),%0\n"
31068 @@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
31069
31070 __asm__ __volatile__(
31071 " .align 2,0x90\n"
31072 - "0: movl 32(%4), %%eax\n"
31073 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31074 " cmpl $67, %0\n"
31075 " jbe 2f\n"
31076 - "1: movl 64(%4), %%eax\n"
31077 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31078 " .align 2,0x90\n"
31079 - "2: movl 0(%4), %%eax\n"
31080 - "21: movl 4(%4), %%edx\n"
31081 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31082 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31083 " movnti %%eax, 0(%3)\n"
31084 " movnti %%edx, 4(%3)\n"
31085 - "3: movl 8(%4), %%eax\n"
31086 - "31: movl 12(%4),%%edx\n"
31087 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31088 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31089 " movnti %%eax, 8(%3)\n"
31090 " movnti %%edx, 12(%3)\n"
31091 - "4: movl 16(%4), %%eax\n"
31092 - "41: movl 20(%4), %%edx\n"
31093 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31094 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31095 " movnti %%eax, 16(%3)\n"
31096 " movnti %%edx, 20(%3)\n"
31097 - "10: movl 24(%4), %%eax\n"
31098 - "51: movl 28(%4), %%edx\n"
31099 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31100 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31101 " movnti %%eax, 24(%3)\n"
31102 " movnti %%edx, 28(%3)\n"
31103 - "11: movl 32(%4), %%eax\n"
31104 - "61: movl 36(%4), %%edx\n"
31105 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31106 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31107 " movnti %%eax, 32(%3)\n"
31108 " movnti %%edx, 36(%3)\n"
31109 - "12: movl 40(%4), %%eax\n"
31110 - "71: movl 44(%4), %%edx\n"
31111 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31112 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31113 " movnti %%eax, 40(%3)\n"
31114 " movnti %%edx, 44(%3)\n"
31115 - "13: movl 48(%4), %%eax\n"
31116 - "81: movl 52(%4), %%edx\n"
31117 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31118 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31119 " movnti %%eax, 48(%3)\n"
31120 " movnti %%edx, 52(%3)\n"
31121 - "14: movl 56(%4), %%eax\n"
31122 - "91: movl 60(%4), %%edx\n"
31123 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31124 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31125 " movnti %%eax, 56(%3)\n"
31126 " movnti %%edx, 60(%3)\n"
31127 " addl $-64, %0\n"
31128 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
31129 " shrl $2, %0\n"
31130 " andl $3, %%eax\n"
31131 " cld\n"
31132 - "6: rep; movsl\n"
31133 + "6: rep; "__copyuser_seg" movsl\n"
31134 " movl %%eax,%0\n"
31135 - "7: rep; movsb\n"
31136 + "7: rep; "__copyuser_seg" movsb\n"
31137 "8:\n"
31138 ".section .fixup,\"ax\"\n"
31139 "9: lea 0(%%eax,%0,4),%0\n"
31140 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
31141 */
31142 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
31143 unsigned long size);
31144 -unsigned long __copy_user_intel(void __user *to, const void *from,
31145 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
31146 + unsigned long size);
31147 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
31148 unsigned long size);
31149 unsigned long __copy_user_zeroing_intel_nocache(void *to,
31150 const void __user *from, unsigned long size);
31151 #endif /* CONFIG_X86_INTEL_USERCOPY */
31152
31153 /* Generic arbitrary sized copy. */
31154 -#define __copy_user(to, from, size) \
31155 +#define __copy_user(to, from, size, prefix, set, restore) \
31156 do { \
31157 int __d0, __d1, __d2; \
31158 __asm__ __volatile__( \
31159 + set \
31160 " cmp $7,%0\n" \
31161 " jbe 1f\n" \
31162 " movl %1,%0\n" \
31163 " negl %0\n" \
31164 " andl $7,%0\n" \
31165 " subl %0,%3\n" \
31166 - "4: rep; movsb\n" \
31167 + "4: rep; "prefix"movsb\n" \
31168 " movl %3,%0\n" \
31169 " shrl $2,%0\n" \
31170 " andl $3,%3\n" \
31171 " .align 2,0x90\n" \
31172 - "0: rep; movsl\n" \
31173 + "0: rep; "prefix"movsl\n" \
31174 " movl %3,%0\n" \
31175 - "1: rep; movsb\n" \
31176 + "1: rep; "prefix"movsb\n" \
31177 "2:\n" \
31178 + restore \
31179 ".section .fixup,\"ax\"\n" \
31180 "5: addl %3,%0\n" \
31181 " jmp 2b\n" \
31182 @@ -538,14 +650,14 @@ do { \
31183 " negl %0\n" \
31184 " andl $7,%0\n" \
31185 " subl %0,%3\n" \
31186 - "4: rep; movsb\n" \
31187 + "4: rep; "__copyuser_seg"movsb\n" \
31188 " movl %3,%0\n" \
31189 " shrl $2,%0\n" \
31190 " andl $3,%3\n" \
31191 " .align 2,0x90\n" \
31192 - "0: rep; movsl\n" \
31193 + "0: rep; "__copyuser_seg"movsl\n" \
31194 " movl %3,%0\n" \
31195 - "1: rep; movsb\n" \
31196 + "1: rep; "__copyuser_seg"movsb\n" \
31197 "2:\n" \
31198 ".section .fixup,\"ax\"\n" \
31199 "5: addl %3,%0\n" \
31200 @@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
31201 {
31202 stac();
31203 if (movsl_is_ok(to, from, n))
31204 - __copy_user(to, from, n);
31205 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
31206 else
31207 - n = __copy_user_intel(to, from, n);
31208 + n = __generic_copy_to_user_intel(to, from, n);
31209 clac();
31210 return n;
31211 }
31212 @@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
31213 {
31214 stac();
31215 if (movsl_is_ok(to, from, n))
31216 - __copy_user(to, from, n);
31217 + __copy_user(to, from, n, __copyuser_seg, "", "");
31218 else
31219 - n = __copy_user_intel((void __user *)to,
31220 - (const void *)from, n);
31221 + n = __generic_copy_from_user_intel(to, from, n);
31222 clac();
31223 return n;
31224 }
31225 @@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
31226 if (n > 64 && cpu_has_xmm2)
31227 n = __copy_user_intel_nocache(to, from, n);
31228 else
31229 - __copy_user(to, from, n);
31230 + __copy_user(to, from, n, __copyuser_seg, "", "");
31231 #else
31232 - __copy_user(to, from, n);
31233 + __copy_user(to, from, n, __copyuser_seg, "", "");
31234 #endif
31235 clac();
31236 return n;
31237 }
31238 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
31239
31240 -/**
31241 - * copy_to_user: - Copy a block of data into user space.
31242 - * @to: Destination address, in user space.
31243 - * @from: Source address, in kernel space.
31244 - * @n: Number of bytes to copy.
31245 - *
31246 - * Context: User context only. This function may sleep.
31247 - *
31248 - * Copy data from kernel space to user space.
31249 - *
31250 - * Returns number of bytes that could not be copied.
31251 - * On success, this will be zero.
31252 - */
31253 -unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
31254 +#ifdef CONFIG_PAX_MEMORY_UDEREF
31255 +void __set_fs(mm_segment_t x)
31256 {
31257 - if (access_ok(VERIFY_WRITE, to, n))
31258 - n = __copy_to_user(to, from, n);
31259 - return n;
31260 + switch (x.seg) {
31261 + case 0:
31262 + loadsegment(gs, 0);
31263 + break;
31264 + case TASK_SIZE_MAX:
31265 + loadsegment(gs, __USER_DS);
31266 + break;
31267 + case -1UL:
31268 + loadsegment(gs, __KERNEL_DS);
31269 + break;
31270 + default:
31271 + BUG();
31272 + }
31273 }
31274 -EXPORT_SYMBOL(_copy_to_user);
31275 +EXPORT_SYMBOL(__set_fs);
31276
31277 -/**
31278 - * copy_from_user: - Copy a block of data from user space.
31279 - * @to: Destination address, in kernel space.
31280 - * @from: Source address, in user space.
31281 - * @n: Number of bytes to copy.
31282 - *
31283 - * Context: User context only. This function may sleep.
31284 - *
31285 - * Copy data from user space to kernel space.
31286 - *
31287 - * Returns number of bytes that could not be copied.
31288 - * On success, this will be zero.
31289 - *
31290 - * If some data could not be copied, this function will pad the copied
31291 - * data to the requested size using zero bytes.
31292 - */
31293 -unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31294 +void set_fs(mm_segment_t x)
31295 {
31296 - if (access_ok(VERIFY_READ, from, n))
31297 - n = __copy_from_user(to, from, n);
31298 - else
31299 - memset(to, 0, n);
31300 - return n;
31301 + current_thread_info()->addr_limit = x;
31302 + __set_fs(x);
31303 }
31304 -EXPORT_SYMBOL(_copy_from_user);
31305 +EXPORT_SYMBOL(set_fs);
31306 +#endif
31307 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31308 index c905e89..01ab928 100644
31309 --- a/arch/x86/lib/usercopy_64.c
31310 +++ b/arch/x86/lib/usercopy_64.c
31311 @@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31312 might_fault();
31313 /* no memory constraint because it doesn't change any memory gcc knows
31314 about */
31315 + pax_open_userland();
31316 stac();
31317 asm volatile(
31318 " testq %[size8],%[size8]\n"
31319 @@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31320 _ASM_EXTABLE(0b,3b)
31321 _ASM_EXTABLE(1b,2b)
31322 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31323 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31324 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31325 [zero] "r" (0UL), [eight] "r" (8UL));
31326 clac();
31327 + pax_close_userland();
31328 return size;
31329 }
31330 EXPORT_SYMBOL(__clear_user);
31331 @@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31332 }
31333 EXPORT_SYMBOL(clear_user);
31334
31335 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31336 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31337 {
31338 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31339 - return copy_user_generic((__force void *)to, (__force void *)from, len);
31340 - }
31341 - return len;
31342 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31343 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31344 + return len;
31345 }
31346 EXPORT_SYMBOL(copy_in_user);
31347
31348 @@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31349 * it is not necessary to optimize tail handling.
31350 */
31351 __visible unsigned long
31352 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31353 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31354 {
31355 char c;
31356 unsigned zero_len;
31357
31358 + clac();
31359 + pax_close_userland();
31360 for (; len; --len, to++) {
31361 if (__get_user_nocheck(c, from++, sizeof(char)))
31362 break;
31363 @@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31364 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31365 if (__put_user_nocheck(c, to++, sizeof(char)))
31366 break;
31367 - clac();
31368 return len;
31369 }
31370 diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31371 index 6a19ad9..1c48f9a 100644
31372 --- a/arch/x86/mm/Makefile
31373 +++ b/arch/x86/mm/Makefile
31374 @@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31375 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31376
31377 obj-$(CONFIG_MEMTEST) += memtest.o
31378 +
31379 +quote:="
31380 +obj-$(CONFIG_X86_64) += uderef_64.o
31381 +CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31382 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31383 index 903ec1e..c4166b2 100644
31384 --- a/arch/x86/mm/extable.c
31385 +++ b/arch/x86/mm/extable.c
31386 @@ -6,12 +6,24 @@
31387 static inline unsigned long
31388 ex_insn_addr(const struct exception_table_entry *x)
31389 {
31390 - return (unsigned long)&x->insn + x->insn;
31391 + unsigned long reloc = 0;
31392 +
31393 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31394 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31395 +#endif
31396 +
31397 + return (unsigned long)&x->insn + x->insn + reloc;
31398 }
31399 static inline unsigned long
31400 ex_fixup_addr(const struct exception_table_entry *x)
31401 {
31402 - return (unsigned long)&x->fixup + x->fixup;
31403 + unsigned long reloc = 0;
31404 +
31405 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31406 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31407 +#endif
31408 +
31409 + return (unsigned long)&x->fixup + x->fixup + reloc;
31410 }
31411
31412 int fixup_exception(struct pt_regs *regs)
31413 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31414 unsigned long new_ip;
31415
31416 #ifdef CONFIG_PNPBIOS
31417 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31418 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31419 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31420 extern u32 pnp_bios_is_utter_crap;
31421 pnp_bios_is_utter_crap = 1;
31422 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31423 i += 4;
31424 p->fixup -= i;
31425 i += 4;
31426 +
31427 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31428 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31429 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31430 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31431 +#endif
31432 +
31433 }
31434 }
31435
31436 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31437 index 8e57229..31cce89 100644
31438 --- a/arch/x86/mm/fault.c
31439 +++ b/arch/x86/mm/fault.c
31440 @@ -14,11 +14,18 @@
31441 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31442 #include <linux/prefetch.h> /* prefetchw */
31443 #include <linux/context_tracking.h> /* exception_enter(), ... */
31444 +#include <linux/unistd.h>
31445 +#include <linux/compiler.h>
31446
31447 #include <asm/traps.h> /* dotraplinkage, ... */
31448 #include <asm/pgalloc.h> /* pgd_*(), ... */
31449 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31450 #include <asm/fixmap.h> /* VSYSCALL_START */
31451 +#include <asm/tlbflush.h>
31452 +
31453 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31454 +#include <asm/stacktrace.h>
31455 +#endif
31456
31457 #define CREATE_TRACE_POINTS
31458 #include <asm/trace/exceptions.h>
31459 @@ -59,7 +66,7 @@ static inline int __kprobes kprobes_fault(struct pt_regs *regs)
31460 int ret = 0;
31461
31462 /* kprobe_running() needs smp_processor_id() */
31463 - if (kprobes_built_in() && !user_mode_vm(regs)) {
31464 + if (kprobes_built_in() && !user_mode(regs)) {
31465 preempt_disable();
31466 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31467 ret = 1;
31468 @@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31469 return !instr_lo || (instr_lo>>1) == 1;
31470 case 0x00:
31471 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31472 - if (probe_kernel_address(instr, opcode))
31473 + if (user_mode(regs)) {
31474 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31475 + return 0;
31476 + } else if (probe_kernel_address(instr, opcode))
31477 return 0;
31478
31479 *prefetch = (instr_lo == 0xF) &&
31480 @@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31481 while (instr < max_instr) {
31482 unsigned char opcode;
31483
31484 - if (probe_kernel_address(instr, opcode))
31485 + if (user_mode(regs)) {
31486 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31487 + break;
31488 + } else if (probe_kernel_address(instr, opcode))
31489 break;
31490
31491 instr++;
31492 @@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31493 force_sig_info(si_signo, &info, tsk);
31494 }
31495
31496 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31497 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31498 +#endif
31499 +
31500 +#ifdef CONFIG_PAX_EMUTRAMP
31501 +static int pax_handle_fetch_fault(struct pt_regs *regs);
31502 +#endif
31503 +
31504 +#ifdef CONFIG_PAX_PAGEEXEC
31505 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31506 +{
31507 + pgd_t *pgd;
31508 + pud_t *pud;
31509 + pmd_t *pmd;
31510 +
31511 + pgd = pgd_offset(mm, address);
31512 + if (!pgd_present(*pgd))
31513 + return NULL;
31514 + pud = pud_offset(pgd, address);
31515 + if (!pud_present(*pud))
31516 + return NULL;
31517 + pmd = pmd_offset(pud, address);
31518 + if (!pmd_present(*pmd))
31519 + return NULL;
31520 + return pmd;
31521 +}
31522 +#endif
31523 +
31524 DEFINE_SPINLOCK(pgd_lock);
31525 LIST_HEAD(pgd_list);
31526
31527 @@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
31528 for (address = VMALLOC_START & PMD_MASK;
31529 address >= TASK_SIZE && address < FIXADDR_TOP;
31530 address += PMD_SIZE) {
31531 +
31532 +#ifdef CONFIG_PAX_PER_CPU_PGD
31533 + unsigned long cpu;
31534 +#else
31535 struct page *page;
31536 +#endif
31537
31538 spin_lock(&pgd_lock);
31539 +
31540 +#ifdef CONFIG_PAX_PER_CPU_PGD
31541 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31542 + pgd_t *pgd = get_cpu_pgd(cpu, user);
31543 + pmd_t *ret;
31544 +
31545 + ret = vmalloc_sync_one(pgd, address);
31546 + if (!ret)
31547 + break;
31548 + pgd = get_cpu_pgd(cpu, kernel);
31549 +#else
31550 list_for_each_entry(page, &pgd_list, lru) {
31551 + pgd_t *pgd;
31552 spinlock_t *pgt_lock;
31553 pmd_t *ret;
31554
31555 @@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
31556 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31557
31558 spin_lock(pgt_lock);
31559 - ret = vmalloc_sync_one(page_address(page), address);
31560 + pgd = page_address(page);
31561 +#endif
31562 +
31563 + ret = vmalloc_sync_one(pgd, address);
31564 +
31565 +#ifndef CONFIG_PAX_PER_CPU_PGD
31566 spin_unlock(pgt_lock);
31567 +#endif
31568
31569 if (!ret)
31570 break;
31571 @@ -281,6 +345,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31572 * an interrupt in the middle of a task switch..
31573 */
31574 pgd_paddr = read_cr3();
31575 +
31576 +#ifdef CONFIG_PAX_PER_CPU_PGD
31577 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
31578 + vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
31579 +#endif
31580 +
31581 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
31582 if (!pmd_k)
31583 return -1;
31584 @@ -376,11 +446,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31585 * happen within a race in page table update. In the later
31586 * case just flush:
31587 */
31588 - pgd = pgd_offset(current->active_mm, address);
31589 +
31590 pgd_ref = pgd_offset_k(address);
31591 if (pgd_none(*pgd_ref))
31592 return -1;
31593
31594 +#ifdef CONFIG_PAX_PER_CPU_PGD
31595 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
31596 + pgd = pgd_offset_cpu(smp_processor_id(), user, address);
31597 + if (pgd_none(*pgd)) {
31598 + set_pgd(pgd, *pgd_ref);
31599 + arch_flush_lazy_mmu_mode();
31600 + } else {
31601 + BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
31602 + }
31603 + pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
31604 +#else
31605 + pgd = pgd_offset(current->active_mm, address);
31606 +#endif
31607 +
31608 if (pgd_none(*pgd)) {
31609 set_pgd(pgd, *pgd_ref);
31610 arch_flush_lazy_mmu_mode();
31611 @@ -546,7 +630,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
31612 static int is_errata100(struct pt_regs *regs, unsigned long address)
31613 {
31614 #ifdef CONFIG_X86_64
31615 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
31616 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
31617 return 1;
31618 #endif
31619 return 0;
31620 @@ -573,7 +657,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
31621 }
31622
31623 static const char nx_warning[] = KERN_CRIT
31624 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
31625 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
31626
31627 static void
31628 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31629 @@ -582,7 +666,7 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31630 if (!oops_may_print())
31631 return;
31632
31633 - if (error_code & PF_INSTR) {
31634 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
31635 unsigned int level;
31636 pgd_t *pgd;
31637 pte_t *pte;
31638 @@ -593,9 +677,21 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31639 pte = lookup_address_in_pgd(pgd, address, &level);
31640
31641 if (pte && pte_present(*pte) && !pte_exec(*pte))
31642 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
31643 + printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31644 }
31645
31646 +#ifdef CONFIG_PAX_KERNEXEC
31647 + if (init_mm.start_code <= address && address < init_mm.end_code) {
31648 + if (current->signal->curr_ip)
31649 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
31650 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
31651 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31652 + else
31653 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
31654 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31655 + }
31656 +#endif
31657 +
31658 printk(KERN_ALERT "BUG: unable to handle kernel ");
31659 if (address < PAGE_SIZE)
31660 printk(KERN_CONT "NULL pointer dereference");
31661 @@ -776,6 +872,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
31662 return;
31663 }
31664 #endif
31665 +
31666 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31667 + if (pax_is_fetch_fault(regs, error_code, address)) {
31668 +
31669 +#ifdef CONFIG_PAX_EMUTRAMP
31670 + switch (pax_handle_fetch_fault(regs)) {
31671 + case 2:
31672 + return;
31673 + }
31674 +#endif
31675 +
31676 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31677 + do_group_exit(SIGKILL);
31678 + }
31679 +#endif
31680 +
31681 /* Kernel addresses are always protection faults: */
31682 if (address >= TASK_SIZE)
31683 error_code |= PF_PROT;
31684 @@ -861,7 +973,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
31685 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
31686 printk(KERN_ERR
31687 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
31688 - tsk->comm, tsk->pid, address);
31689 + tsk->comm, task_pid_nr(tsk), address);
31690 code = BUS_MCEERR_AR;
31691 }
31692 #endif
31693 @@ -915,6 +1027,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
31694 return 1;
31695 }
31696
31697 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31698 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
31699 +{
31700 + pte_t *pte;
31701 + pmd_t *pmd;
31702 + spinlock_t *ptl;
31703 + unsigned char pte_mask;
31704 +
31705 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
31706 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
31707 + return 0;
31708 +
31709 + /* PaX: it's our fault, let's handle it if we can */
31710 +
31711 + /* PaX: take a look at read faults before acquiring any locks */
31712 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
31713 + /* instruction fetch attempt from a protected page in user mode */
31714 + up_read(&mm->mmap_sem);
31715 +
31716 +#ifdef CONFIG_PAX_EMUTRAMP
31717 + switch (pax_handle_fetch_fault(regs)) {
31718 + case 2:
31719 + return 1;
31720 + }
31721 +#endif
31722 +
31723 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31724 + do_group_exit(SIGKILL);
31725 + }
31726 +
31727 + pmd = pax_get_pmd(mm, address);
31728 + if (unlikely(!pmd))
31729 + return 0;
31730 +
31731 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
31732 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
31733 + pte_unmap_unlock(pte, ptl);
31734 + return 0;
31735 + }
31736 +
31737 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
31738 + /* write attempt to a protected page in user mode */
31739 + pte_unmap_unlock(pte, ptl);
31740 + return 0;
31741 + }
31742 +
31743 +#ifdef CONFIG_SMP
31744 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
31745 +#else
31746 + if (likely(address > get_limit(regs->cs)))
31747 +#endif
31748 + {
31749 + set_pte(pte, pte_mkread(*pte));
31750 + __flush_tlb_one(address);
31751 + pte_unmap_unlock(pte, ptl);
31752 + up_read(&mm->mmap_sem);
31753 + return 1;
31754 + }
31755 +
31756 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
31757 +
31758 + /*
31759 + * PaX: fill DTLB with user rights and retry
31760 + */
31761 + __asm__ __volatile__ (
31762 + "orb %2,(%1)\n"
31763 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
31764 +/*
31765 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
31766 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
31767 + * page fault when examined during a TLB load attempt. this is true not only
31768 + * for PTEs holding a non-present entry but also present entries that will
31769 + * raise a page fault (such as those set up by PaX, or the copy-on-write
31770 + * mechanism). in effect it means that we do *not* need to flush the TLBs
31771 + * for our target pages since their PTEs are simply not in the TLBs at all.
31772 +
31773 + * the best thing in omitting it is that we gain around 15-20% speed in the
31774 + * fast path of the page fault handler and can get rid of tracing since we
31775 + * can no longer flush unintended entries.
31776 + */
31777 + "invlpg (%0)\n"
31778 +#endif
31779 + __copyuser_seg"testb $0,(%0)\n"
31780 + "xorb %3,(%1)\n"
31781 + :
31782 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
31783 + : "memory", "cc");
31784 + pte_unmap_unlock(pte, ptl);
31785 + up_read(&mm->mmap_sem);
31786 + return 1;
31787 +}
31788 +#endif
31789 +
31790 /*
31791 * Handle a spurious fault caused by a stale TLB entry.
31792 *
31793 @@ -981,6 +1186,9 @@ int show_unhandled_signals = 1;
31794 static inline int
31795 access_error(unsigned long error_code, struct vm_area_struct *vma)
31796 {
31797 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
31798 + return 1;
31799 +
31800 if (error_code & PF_WRITE) {
31801 /* write, present and write, not present: */
31802 if (unlikely(!(vma->vm_flags & VM_WRITE)))
31803 @@ -1015,7 +1223,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
31804 if (error_code & PF_USER)
31805 return false;
31806
31807 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
31808 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
31809 return false;
31810
31811 return true;
31812 @@ -1043,6 +1251,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
31813 tsk = current;
31814 mm = tsk->mm;
31815
31816 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31817 + if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
31818 + if (!search_exception_tables(regs->ip)) {
31819 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31820 + bad_area_nosemaphore(regs, error_code, address);
31821 + return;
31822 + }
31823 + if (address < pax_user_shadow_base) {
31824 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31825 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
31826 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
31827 + } else
31828 + address -= pax_user_shadow_base;
31829 + }
31830 +#endif
31831 +
31832 /*
31833 * Detect and handle instructions that would cause a page fault for
31834 * both a tracked kernel page and a userspace page.
31835 @@ -1120,7 +1344,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
31836 * User-mode registers count as a user access even for any
31837 * potential system fault or CPU buglet:
31838 */
31839 - if (user_mode_vm(regs)) {
31840 + if (user_mode(regs)) {
31841 local_irq_enable();
31842 error_code |= PF_USER;
31843 flags |= FAULT_FLAG_USER;
31844 @@ -1167,6 +1391,11 @@ retry:
31845 might_sleep();
31846 }
31847
31848 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31849 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
31850 + return;
31851 +#endif
31852 +
31853 vma = find_vma(mm, address);
31854 if (unlikely(!vma)) {
31855 bad_area(regs, error_code, address);
31856 @@ -1178,18 +1407,24 @@ retry:
31857 bad_area(regs, error_code, address);
31858 return;
31859 }
31860 - if (error_code & PF_USER) {
31861 - /*
31862 - * Accessing the stack below %sp is always a bug.
31863 - * The large cushion allows instructions like enter
31864 - * and pusha to work. ("enter $65535, $31" pushes
31865 - * 32 pointers and then decrements %sp by 65535.)
31866 - */
31867 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
31868 - bad_area(regs, error_code, address);
31869 - return;
31870 - }
31871 + /*
31872 + * Accessing the stack below %sp is always a bug.
31873 + * The large cushion allows instructions like enter
31874 + * and pusha to work. ("enter $65535, $31" pushes
31875 + * 32 pointers and then decrements %sp by 65535.)
31876 + */
31877 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
31878 + bad_area(regs, error_code, address);
31879 + return;
31880 }
31881 +
31882 +#ifdef CONFIG_PAX_SEGMEXEC
31883 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
31884 + bad_area(regs, error_code, address);
31885 + return;
31886 + }
31887 +#endif
31888 +
31889 if (unlikely(expand_stack(vma, address))) {
31890 bad_area(regs, error_code, address);
31891 return;
31892 @@ -1301,3 +1536,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
31893 exception_exit(prev_state);
31894 }
31895 #endif /* CONFIG_TRACING */
31896 +
31897 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31898 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
31899 +{
31900 + struct mm_struct *mm = current->mm;
31901 + unsigned long ip = regs->ip;
31902 +
31903 + if (v8086_mode(regs))
31904 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
31905 +
31906 +#ifdef CONFIG_PAX_PAGEEXEC
31907 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
31908 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
31909 + return true;
31910 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
31911 + return true;
31912 + return false;
31913 + }
31914 +#endif
31915 +
31916 +#ifdef CONFIG_PAX_SEGMEXEC
31917 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
31918 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
31919 + return true;
31920 + return false;
31921 + }
31922 +#endif
31923 +
31924 + return false;
31925 +}
31926 +#endif
31927 +
31928 +#ifdef CONFIG_PAX_EMUTRAMP
31929 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
31930 +{
31931 + int err;
31932 +
31933 + do { /* PaX: libffi trampoline emulation */
31934 + unsigned char mov, jmp;
31935 + unsigned int addr1, addr2;
31936 +
31937 +#ifdef CONFIG_X86_64
31938 + if ((regs->ip + 9) >> 32)
31939 + break;
31940 +#endif
31941 +
31942 + err = get_user(mov, (unsigned char __user *)regs->ip);
31943 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31944 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31945 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31946 +
31947 + if (err)
31948 + break;
31949 +
31950 + if (mov == 0xB8 && jmp == 0xE9) {
31951 + regs->ax = addr1;
31952 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31953 + return 2;
31954 + }
31955 + } while (0);
31956 +
31957 + do { /* PaX: gcc trampoline emulation #1 */
31958 + unsigned char mov1, mov2;
31959 + unsigned short jmp;
31960 + unsigned int addr1, addr2;
31961 +
31962 +#ifdef CONFIG_X86_64
31963 + if ((regs->ip + 11) >> 32)
31964 + break;
31965 +#endif
31966 +
31967 + err = get_user(mov1, (unsigned char __user *)regs->ip);
31968 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31969 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
31970 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31971 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
31972 +
31973 + if (err)
31974 + break;
31975 +
31976 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
31977 + regs->cx = addr1;
31978 + regs->ax = addr2;
31979 + regs->ip = addr2;
31980 + return 2;
31981 + }
31982 + } while (0);
31983 +
31984 + do { /* PaX: gcc trampoline emulation #2 */
31985 + unsigned char mov, jmp;
31986 + unsigned int addr1, addr2;
31987 +
31988 +#ifdef CONFIG_X86_64
31989 + if ((regs->ip + 9) >> 32)
31990 + break;
31991 +#endif
31992 +
31993 + err = get_user(mov, (unsigned char __user *)regs->ip);
31994 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31995 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31996 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31997 +
31998 + if (err)
31999 + break;
32000 +
32001 + if (mov == 0xB9 && jmp == 0xE9) {
32002 + regs->cx = addr1;
32003 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32004 + return 2;
32005 + }
32006 + } while (0);
32007 +
32008 + return 1; /* PaX in action */
32009 +}
32010 +
32011 +#ifdef CONFIG_X86_64
32012 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
32013 +{
32014 + int err;
32015 +
32016 + do { /* PaX: libffi trampoline emulation */
32017 + unsigned short mov1, mov2, jmp1;
32018 + unsigned char stcclc, jmp2;
32019 + unsigned long addr1, addr2;
32020 +
32021 + err = get_user(mov1, (unsigned short __user *)regs->ip);
32022 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32023 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32024 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32025 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
32026 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
32027 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
32028 +
32029 + if (err)
32030 + break;
32031 +
32032 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32033 + regs->r11 = addr1;
32034 + regs->r10 = addr2;
32035 + if (stcclc == 0xF8)
32036 + regs->flags &= ~X86_EFLAGS_CF;
32037 + else
32038 + regs->flags |= X86_EFLAGS_CF;
32039 + regs->ip = addr1;
32040 + return 2;
32041 + }
32042 + } while (0);
32043 +
32044 + do { /* PaX: gcc trampoline emulation #1 */
32045 + unsigned short mov1, mov2, jmp1;
32046 + unsigned char jmp2;
32047 + unsigned int addr1;
32048 + unsigned long addr2;
32049 +
32050 + err = get_user(mov1, (unsigned short __user *)regs->ip);
32051 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
32052 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
32053 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
32054 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
32055 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
32056 +
32057 + if (err)
32058 + break;
32059 +
32060 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32061 + regs->r11 = addr1;
32062 + regs->r10 = addr2;
32063 + regs->ip = addr1;
32064 + return 2;
32065 + }
32066 + } while (0);
32067 +
32068 + do { /* PaX: gcc trampoline emulation #2 */
32069 + unsigned short mov1, mov2, jmp1;
32070 + unsigned char jmp2;
32071 + unsigned long addr1, addr2;
32072 +
32073 + err = get_user(mov1, (unsigned short __user *)regs->ip);
32074 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32075 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32076 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32077 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
32078 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
32079 +
32080 + if (err)
32081 + break;
32082 +
32083 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32084 + regs->r11 = addr1;
32085 + regs->r10 = addr2;
32086 + regs->ip = addr1;
32087 + return 2;
32088 + }
32089 + } while (0);
32090 +
32091 + return 1; /* PaX in action */
32092 +}
32093 +#endif
32094 +
32095 +/*
32096 + * PaX: decide what to do with offenders (regs->ip = fault address)
32097 + *
32098 + * returns 1 when task should be killed
32099 + * 2 when gcc trampoline was detected
32100 + */
32101 +static int pax_handle_fetch_fault(struct pt_regs *regs)
32102 +{
32103 + if (v8086_mode(regs))
32104 + return 1;
32105 +
32106 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
32107 + return 1;
32108 +
32109 +#ifdef CONFIG_X86_32
32110 + return pax_handle_fetch_fault_32(regs);
32111 +#else
32112 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
32113 + return pax_handle_fetch_fault_32(regs);
32114 + else
32115 + return pax_handle_fetch_fault_64(regs);
32116 +#endif
32117 +}
32118 +#endif
32119 +
32120 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32121 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
32122 +{
32123 + long i;
32124 +
32125 + printk(KERN_ERR "PAX: bytes at PC: ");
32126 + for (i = 0; i < 20; i++) {
32127 + unsigned char c;
32128 + if (get_user(c, (unsigned char __force_user *)pc+i))
32129 + printk(KERN_CONT "?? ");
32130 + else
32131 + printk(KERN_CONT "%02x ", c);
32132 + }
32133 + printk("\n");
32134 +
32135 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
32136 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
32137 + unsigned long c;
32138 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
32139 +#ifdef CONFIG_X86_32
32140 + printk(KERN_CONT "???????? ");
32141 +#else
32142 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
32143 + printk(KERN_CONT "???????? ???????? ");
32144 + else
32145 + printk(KERN_CONT "???????????????? ");
32146 +#endif
32147 + } else {
32148 +#ifdef CONFIG_X86_64
32149 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
32150 + printk(KERN_CONT "%08x ", (unsigned int)c);
32151 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
32152 + } else
32153 +#endif
32154 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
32155 + }
32156 + }
32157 + printk("\n");
32158 +}
32159 +#endif
32160 +
32161 +/**
32162 + * probe_kernel_write(): safely attempt to write to a location
32163 + * @dst: address to write to
32164 + * @src: pointer to the data that shall be written
32165 + * @size: size of the data chunk
32166 + *
32167 + * Safely write to address @dst from the buffer at @src. If a kernel fault
32168 + * happens, handle that and return -EFAULT.
32169 + */
32170 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
32171 +{
32172 + long ret;
32173 + mm_segment_t old_fs = get_fs();
32174 +
32175 + set_fs(KERNEL_DS);
32176 + pagefault_disable();
32177 + pax_open_kernel();
32178 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
32179 + pax_close_kernel();
32180 + pagefault_enable();
32181 + set_fs(old_fs);
32182 +
32183 + return ret ? -EFAULT : 0;
32184 +}
32185 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
32186 index 207d9aef..69030980 100644
32187 --- a/arch/x86/mm/gup.c
32188 +++ b/arch/x86/mm/gup.c
32189 @@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
32190 addr = start;
32191 len = (unsigned long) nr_pages << PAGE_SHIFT;
32192 end = start + len;
32193 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
32194 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32195 (void __user *)start, len)))
32196 return 0;
32197
32198 @@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
32199 goto slow_irqon;
32200 #endif
32201
32202 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32203 + (void __user *)start, len)))
32204 + return 0;
32205 +
32206 /*
32207 * XXX: batch / limit 'nr', to avoid large irq off latency
32208 * needs some instrumenting to determine the common sizes used by
32209 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
32210 index 4500142..53a363c 100644
32211 --- a/arch/x86/mm/highmem_32.c
32212 +++ b/arch/x86/mm/highmem_32.c
32213 @@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
32214 idx = type + KM_TYPE_NR*smp_processor_id();
32215 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32216 BUG_ON(!pte_none(*(kmap_pte-idx)));
32217 +
32218 + pax_open_kernel();
32219 set_pte(kmap_pte-idx, mk_pte(page, prot));
32220 + pax_close_kernel();
32221 +
32222 arch_flush_lazy_mmu_mode();
32223
32224 return (void *)vaddr;
32225 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
32226 index 8b977eb..4732c33 100644
32227 --- a/arch/x86/mm/hugetlbpage.c
32228 +++ b/arch/x86/mm/hugetlbpage.c
32229 @@ -80,23 +80,24 @@ int pud_huge(pud_t pud)
32230 #ifdef CONFIG_HUGETLB_PAGE
32231 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
32232 unsigned long addr, unsigned long len,
32233 - unsigned long pgoff, unsigned long flags)
32234 + unsigned long pgoff, unsigned long flags, unsigned long offset)
32235 {
32236 struct hstate *h = hstate_file(file);
32237 struct vm_unmapped_area_info info;
32238 -
32239 +
32240 info.flags = 0;
32241 info.length = len;
32242 info.low_limit = current->mm->mmap_legacy_base;
32243 info.high_limit = TASK_SIZE;
32244 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32245 info.align_offset = 0;
32246 + info.threadstack_offset = offset;
32247 return vm_unmapped_area(&info);
32248 }
32249
32250 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32251 unsigned long addr0, unsigned long len,
32252 - unsigned long pgoff, unsigned long flags)
32253 + unsigned long pgoff, unsigned long flags, unsigned long offset)
32254 {
32255 struct hstate *h = hstate_file(file);
32256 struct vm_unmapped_area_info info;
32257 @@ -108,6 +109,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32258 info.high_limit = current->mm->mmap_base;
32259 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32260 info.align_offset = 0;
32261 + info.threadstack_offset = offset;
32262 addr = vm_unmapped_area(&info);
32263
32264 /*
32265 @@ -120,6 +122,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32266 VM_BUG_ON(addr != -ENOMEM);
32267 info.flags = 0;
32268 info.low_limit = TASK_UNMAPPED_BASE;
32269 +
32270 +#ifdef CONFIG_PAX_RANDMMAP
32271 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32272 + info.low_limit += current->mm->delta_mmap;
32273 +#endif
32274 +
32275 info.high_limit = TASK_SIZE;
32276 addr = vm_unmapped_area(&info);
32277 }
32278 @@ -134,10 +142,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32279 struct hstate *h = hstate_file(file);
32280 struct mm_struct *mm = current->mm;
32281 struct vm_area_struct *vma;
32282 + unsigned long pax_task_size = TASK_SIZE;
32283 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32284
32285 if (len & ~huge_page_mask(h))
32286 return -EINVAL;
32287 - if (len > TASK_SIZE)
32288 +
32289 +#ifdef CONFIG_PAX_SEGMEXEC
32290 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32291 + pax_task_size = SEGMEXEC_TASK_SIZE;
32292 +#endif
32293 +
32294 + pax_task_size -= PAGE_SIZE;
32295 +
32296 + if (len > pax_task_size)
32297 return -ENOMEM;
32298
32299 if (flags & MAP_FIXED) {
32300 @@ -146,19 +164,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32301 return addr;
32302 }
32303
32304 +#ifdef CONFIG_PAX_RANDMMAP
32305 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32306 +#endif
32307 +
32308 if (addr) {
32309 addr = ALIGN(addr, huge_page_size(h));
32310 vma = find_vma(mm, addr);
32311 - if (TASK_SIZE - len >= addr &&
32312 - (!vma || addr + len <= vma->vm_start))
32313 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32314 return addr;
32315 }
32316 if (mm->get_unmapped_area == arch_get_unmapped_area)
32317 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32318 - pgoff, flags);
32319 + pgoff, flags, offset);
32320 else
32321 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32322 - pgoff, flags);
32323 + pgoff, flags, offset);
32324 }
32325 #endif /* CONFIG_HUGETLB_PAGE */
32326
32327 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32328 index f971306..e83e0f6 100644
32329 --- a/arch/x86/mm/init.c
32330 +++ b/arch/x86/mm/init.c
32331 @@ -4,6 +4,7 @@
32332 #include <linux/swap.h>
32333 #include <linux/memblock.h>
32334 #include <linux/bootmem.h> /* for max_low_pfn */
32335 +#include <linux/tboot.h>
32336
32337 #include <asm/cacheflush.h>
32338 #include <asm/e820.h>
32339 @@ -17,6 +18,8 @@
32340 #include <asm/proto.h>
32341 #include <asm/dma.h> /* for MAX_DMA_PFN */
32342 #include <asm/microcode.h>
32343 +#include <asm/desc.h>
32344 +#include <asm/bios_ebda.h>
32345
32346 #include "mm_internal.h"
32347
32348 @@ -563,7 +566,18 @@ void __init init_mem_mapping(void)
32349 early_ioremap_page_table_range_init();
32350 #endif
32351
32352 +#ifdef CONFIG_PAX_PER_CPU_PGD
32353 + clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32354 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32355 + KERNEL_PGD_PTRS);
32356 + clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32357 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32358 + KERNEL_PGD_PTRS);
32359 + load_cr3(get_cpu_pgd(0, kernel));
32360 +#else
32361 load_cr3(swapper_pg_dir);
32362 +#endif
32363 +
32364 __flush_tlb_all();
32365
32366 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32367 @@ -579,10 +593,40 @@ void __init init_mem_mapping(void)
32368 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32369 * mmio resources as well as potential bios/acpi data regions.
32370 */
32371 +
32372 +#ifdef CONFIG_GRKERNSEC_KMEM
32373 +static unsigned int ebda_start __read_only;
32374 +static unsigned int ebda_end __read_only;
32375 +#endif
32376 +
32377 int devmem_is_allowed(unsigned long pagenr)
32378 {
32379 - if (pagenr < 256)
32380 +#ifdef CONFIG_GRKERNSEC_KMEM
32381 + /* allow BDA */
32382 + if (!pagenr)
32383 return 1;
32384 + /* allow EBDA */
32385 + if (pagenr >= ebda_start && pagenr < ebda_end)
32386 + return 1;
32387 + /* if tboot is in use, allow access to its hardcoded serial log range */
32388 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32389 + return 1;
32390 +#else
32391 + if (!pagenr)
32392 + return 1;
32393 +#ifdef CONFIG_VM86
32394 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32395 + return 1;
32396 +#endif
32397 +#endif
32398 +
32399 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32400 + return 1;
32401 +#ifdef CONFIG_GRKERNSEC_KMEM
32402 + /* throw out everything else below 1MB */
32403 + if (pagenr <= 256)
32404 + return 0;
32405 +#endif
32406 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32407 return 0;
32408 if (!page_is_ram(pagenr))
32409 @@ -628,8 +672,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32410 #endif
32411 }
32412
32413 +#ifdef CONFIG_GRKERNSEC_KMEM
32414 +static inline void gr_init_ebda(void)
32415 +{
32416 + unsigned int ebda_addr;
32417 + unsigned int ebda_size = 0;
32418 +
32419 + ebda_addr = get_bios_ebda();
32420 + if (ebda_addr) {
32421 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32422 + ebda_size <<= 10;
32423 + }
32424 + if (ebda_addr && ebda_size) {
32425 + ebda_start = ebda_addr >> PAGE_SHIFT;
32426 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32427 + } else {
32428 + ebda_start = 0x9f000 >> PAGE_SHIFT;
32429 + ebda_end = 0xa0000 >> PAGE_SHIFT;
32430 + }
32431 +}
32432 +#else
32433 +static inline void gr_init_ebda(void) { }
32434 +#endif
32435 +
32436 void free_initmem(void)
32437 {
32438 +#ifdef CONFIG_PAX_KERNEXEC
32439 +#ifdef CONFIG_X86_32
32440 + /* PaX: limit KERNEL_CS to actual size */
32441 + unsigned long addr, limit;
32442 + struct desc_struct d;
32443 + int cpu;
32444 +#else
32445 + pgd_t *pgd;
32446 + pud_t *pud;
32447 + pmd_t *pmd;
32448 + unsigned long addr, end;
32449 +#endif
32450 +#endif
32451 +
32452 + gr_init_ebda();
32453 +
32454 +#ifdef CONFIG_PAX_KERNEXEC
32455 +#ifdef CONFIG_X86_32
32456 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32457 + limit = (limit - 1UL) >> PAGE_SHIFT;
32458 +
32459 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32460 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32461 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32462 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32463 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32464 + }
32465 +
32466 + /* PaX: make KERNEL_CS read-only */
32467 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32468 + if (!paravirt_enabled())
32469 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32470 +/*
32471 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32472 + pgd = pgd_offset_k(addr);
32473 + pud = pud_offset(pgd, addr);
32474 + pmd = pmd_offset(pud, addr);
32475 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32476 + }
32477 +*/
32478 +#ifdef CONFIG_X86_PAE
32479 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32480 +/*
32481 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32482 + pgd = pgd_offset_k(addr);
32483 + pud = pud_offset(pgd, addr);
32484 + pmd = pmd_offset(pud, addr);
32485 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32486 + }
32487 +*/
32488 +#endif
32489 +
32490 +#ifdef CONFIG_MODULES
32491 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32492 +#endif
32493 +
32494 +#else
32495 + /* PaX: make kernel code/rodata read-only, rest non-executable */
32496 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32497 + pgd = pgd_offset_k(addr);
32498 + pud = pud_offset(pgd, addr);
32499 + pmd = pmd_offset(pud, addr);
32500 + if (!pmd_present(*pmd))
32501 + continue;
32502 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32503 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32504 + else
32505 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32506 + }
32507 +
32508 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32509 + end = addr + KERNEL_IMAGE_SIZE;
32510 + for (; addr < end; addr += PMD_SIZE) {
32511 + pgd = pgd_offset_k(addr);
32512 + pud = pud_offset(pgd, addr);
32513 + pmd = pmd_offset(pud, addr);
32514 + if (!pmd_present(*pmd))
32515 + continue;
32516 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32517 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32518 + }
32519 +#endif
32520 +
32521 + flush_tlb_all();
32522 +#endif
32523 +
32524 free_init_pages("unused kernel",
32525 (unsigned long)(&__init_begin),
32526 (unsigned long)(&__init_end));
32527 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32528 index e395048..cd38278 100644
32529 --- a/arch/x86/mm/init_32.c
32530 +++ b/arch/x86/mm/init_32.c
32531 @@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32532 bool __read_mostly __vmalloc_start_set = false;
32533
32534 /*
32535 - * Creates a middle page table and puts a pointer to it in the
32536 - * given global directory entry. This only returns the gd entry
32537 - * in non-PAE compilation mode, since the middle layer is folded.
32538 - */
32539 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
32540 -{
32541 - pud_t *pud;
32542 - pmd_t *pmd_table;
32543 -
32544 -#ifdef CONFIG_X86_PAE
32545 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
32546 - pmd_table = (pmd_t *)alloc_low_page();
32547 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
32548 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
32549 - pud = pud_offset(pgd, 0);
32550 - BUG_ON(pmd_table != pmd_offset(pud, 0));
32551 -
32552 - return pmd_table;
32553 - }
32554 -#endif
32555 - pud = pud_offset(pgd, 0);
32556 - pmd_table = pmd_offset(pud, 0);
32557 -
32558 - return pmd_table;
32559 -}
32560 -
32561 -/*
32562 * Create a page table and place a pointer to it in a middle page
32563 * directory entry:
32564 */
32565 @@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
32566 pte_t *page_table = (pte_t *)alloc_low_page();
32567
32568 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
32569 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32570 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
32571 +#else
32572 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
32573 +#endif
32574 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
32575 }
32576
32577 return pte_offset_kernel(pmd, 0);
32578 }
32579
32580 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
32581 +{
32582 + pud_t *pud;
32583 + pmd_t *pmd_table;
32584 +
32585 + pud = pud_offset(pgd, 0);
32586 + pmd_table = pmd_offset(pud, 0);
32587 +
32588 + return pmd_table;
32589 +}
32590 +
32591 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
32592 {
32593 int pgd_idx = pgd_index(vaddr);
32594 @@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32595 int pgd_idx, pmd_idx;
32596 unsigned long vaddr;
32597 pgd_t *pgd;
32598 + pud_t *pud;
32599 pmd_t *pmd;
32600 pte_t *pte = NULL;
32601 unsigned long count = page_table_range_init_count(start, end);
32602 @@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32603 pgd = pgd_base + pgd_idx;
32604
32605 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
32606 - pmd = one_md_table_init(pgd);
32607 - pmd = pmd + pmd_index(vaddr);
32608 + pud = pud_offset(pgd, vaddr);
32609 + pmd = pmd_offset(pud, vaddr);
32610 +
32611 +#ifdef CONFIG_X86_PAE
32612 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32613 +#endif
32614 +
32615 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
32616 pmd++, pmd_idx++) {
32617 pte = page_table_kmap_check(one_page_table_init(pmd),
32618 @@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32619 }
32620 }
32621
32622 -static inline int is_kernel_text(unsigned long addr)
32623 +static inline int is_kernel_text(unsigned long start, unsigned long end)
32624 {
32625 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
32626 - return 1;
32627 - return 0;
32628 + if ((start >= ktla_ktva((unsigned long)_etext) ||
32629 + end <= ktla_ktva((unsigned long)_stext)) &&
32630 + (start >= ktla_ktva((unsigned long)_einittext) ||
32631 + end <= ktla_ktva((unsigned long)_sinittext)) &&
32632 +
32633 +#ifdef CONFIG_ACPI_SLEEP
32634 + (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
32635 +#endif
32636 +
32637 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
32638 + return 0;
32639 + return 1;
32640 }
32641
32642 /*
32643 @@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
32644 unsigned long last_map_addr = end;
32645 unsigned long start_pfn, end_pfn;
32646 pgd_t *pgd_base = swapper_pg_dir;
32647 - int pgd_idx, pmd_idx, pte_ofs;
32648 + unsigned int pgd_idx, pmd_idx, pte_ofs;
32649 unsigned long pfn;
32650 pgd_t *pgd;
32651 + pud_t *pud;
32652 pmd_t *pmd;
32653 pte_t *pte;
32654 unsigned pages_2m, pages_4k;
32655 @@ -291,8 +295,13 @@ repeat:
32656 pfn = start_pfn;
32657 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32658 pgd = pgd_base + pgd_idx;
32659 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
32660 - pmd = one_md_table_init(pgd);
32661 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
32662 + pud = pud_offset(pgd, 0);
32663 + pmd = pmd_offset(pud, 0);
32664 +
32665 +#ifdef CONFIG_X86_PAE
32666 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32667 +#endif
32668
32669 if (pfn >= end_pfn)
32670 continue;
32671 @@ -304,14 +313,13 @@ repeat:
32672 #endif
32673 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
32674 pmd++, pmd_idx++) {
32675 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
32676 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
32677
32678 /*
32679 * Map with big pages if possible, otherwise
32680 * create normal page tables:
32681 */
32682 if (use_pse) {
32683 - unsigned int addr2;
32684 pgprot_t prot = PAGE_KERNEL_LARGE;
32685 /*
32686 * first pass will use the same initial
32687 @@ -322,11 +330,7 @@ repeat:
32688 _PAGE_PSE);
32689
32690 pfn &= PMD_MASK >> PAGE_SHIFT;
32691 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
32692 - PAGE_OFFSET + PAGE_SIZE-1;
32693 -
32694 - if (is_kernel_text(addr) ||
32695 - is_kernel_text(addr2))
32696 + if (is_kernel_text(address, address + PMD_SIZE))
32697 prot = PAGE_KERNEL_LARGE_EXEC;
32698
32699 pages_2m++;
32700 @@ -343,7 +347,7 @@ repeat:
32701 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32702 pte += pte_ofs;
32703 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
32704 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
32705 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
32706 pgprot_t prot = PAGE_KERNEL;
32707 /*
32708 * first pass will use the same initial
32709 @@ -351,7 +355,7 @@ repeat:
32710 */
32711 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
32712
32713 - if (is_kernel_text(addr))
32714 + if (is_kernel_text(address, address + PAGE_SIZE))
32715 prot = PAGE_KERNEL_EXEC;
32716
32717 pages_4k++;
32718 @@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
32719
32720 pud = pud_offset(pgd, va);
32721 pmd = pmd_offset(pud, va);
32722 - if (!pmd_present(*pmd))
32723 + if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
32724 break;
32725
32726 /* should not be large page here */
32727 @@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
32728
32729 static void __init pagetable_init(void)
32730 {
32731 - pgd_t *pgd_base = swapper_pg_dir;
32732 -
32733 - permanent_kmaps_init(pgd_base);
32734 + permanent_kmaps_init(swapper_pg_dir);
32735 }
32736
32737 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32738 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32739 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32740
32741 /* user-defined highmem size */
32742 @@ -787,10 +789,10 @@ void __init mem_init(void)
32743 ((unsigned long)&__init_end -
32744 (unsigned long)&__init_begin) >> 10,
32745
32746 - (unsigned long)&_etext, (unsigned long)&_edata,
32747 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
32748 + (unsigned long)&_sdata, (unsigned long)&_edata,
32749 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
32750
32751 - (unsigned long)&_text, (unsigned long)&_etext,
32752 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
32753 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
32754
32755 /*
32756 @@ -883,6 +885,7 @@ void set_kernel_text_rw(void)
32757 if (!kernel_set_to_readonly)
32758 return;
32759
32760 + start = ktla_ktva(start);
32761 pr_debug("Set kernel text: %lx - %lx for read write\n",
32762 start, start+size);
32763
32764 @@ -897,6 +900,7 @@ void set_kernel_text_ro(void)
32765 if (!kernel_set_to_readonly)
32766 return;
32767
32768 + start = ktla_ktva(start);
32769 pr_debug("Set kernel text: %lx - %lx for read only\n",
32770 start, start+size);
32771
32772 @@ -925,6 +929,7 @@ void mark_rodata_ro(void)
32773 unsigned long start = PFN_ALIGN(_text);
32774 unsigned long size = PFN_ALIGN(_etext) - start;
32775
32776 + start = ktla_ktva(start);
32777 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
32778 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
32779 size >> 10);
32780 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
32781 index f35c66c..84b95ef 100644
32782 --- a/arch/x86/mm/init_64.c
32783 +++ b/arch/x86/mm/init_64.c
32784 @@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
32785 * around without checking the pgd every time.
32786 */
32787
32788 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
32789 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
32790 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32791
32792 int force_personality32;
32793 @@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32794
32795 for (address = start; address <= end; address += PGDIR_SIZE) {
32796 const pgd_t *pgd_ref = pgd_offset_k(address);
32797 +
32798 +#ifdef CONFIG_PAX_PER_CPU_PGD
32799 + unsigned long cpu;
32800 +#else
32801 struct page *page;
32802 +#endif
32803
32804 if (pgd_none(*pgd_ref))
32805 continue;
32806
32807 spin_lock(&pgd_lock);
32808 +
32809 +#ifdef CONFIG_PAX_PER_CPU_PGD
32810 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32811 + pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
32812 +
32813 + if (pgd_none(*pgd))
32814 + set_pgd(pgd, *pgd_ref);
32815 + else
32816 + BUG_ON(pgd_page_vaddr(*pgd)
32817 + != pgd_page_vaddr(*pgd_ref));
32818 + pgd = pgd_offset_cpu(cpu, kernel, address);
32819 +#else
32820 list_for_each_entry(page, &pgd_list, lru) {
32821 pgd_t *pgd;
32822 spinlock_t *pgt_lock;
32823 @@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32824 /* the pgt_lock only for Xen */
32825 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32826 spin_lock(pgt_lock);
32827 +#endif
32828
32829 if (pgd_none(*pgd))
32830 set_pgd(pgd, *pgd_ref);
32831 @@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32832 BUG_ON(pgd_page_vaddr(*pgd)
32833 != pgd_page_vaddr(*pgd_ref));
32834
32835 +#ifndef CONFIG_PAX_PER_CPU_PGD
32836 spin_unlock(pgt_lock);
32837 +#endif
32838 +
32839 }
32840 spin_unlock(&pgd_lock);
32841 }
32842 @@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
32843 {
32844 if (pgd_none(*pgd)) {
32845 pud_t *pud = (pud_t *)spp_getpage();
32846 - pgd_populate(&init_mm, pgd, pud);
32847 + pgd_populate_kernel(&init_mm, pgd, pud);
32848 if (pud != pud_offset(pgd, 0))
32849 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
32850 pud, pud_offset(pgd, 0));
32851 @@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
32852 {
32853 if (pud_none(*pud)) {
32854 pmd_t *pmd = (pmd_t *) spp_getpage();
32855 - pud_populate(&init_mm, pud, pmd);
32856 + pud_populate_kernel(&init_mm, pud, pmd);
32857 if (pmd != pmd_offset(pud, 0))
32858 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
32859 pmd, pmd_offset(pud, 0));
32860 @@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
32861 pmd = fill_pmd(pud, vaddr);
32862 pte = fill_pte(pmd, vaddr);
32863
32864 + pax_open_kernel();
32865 set_pte(pte, new_pte);
32866 + pax_close_kernel();
32867
32868 /*
32869 * It's enough to flush this one mapping.
32870 @@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
32871 pgd = pgd_offset_k((unsigned long)__va(phys));
32872 if (pgd_none(*pgd)) {
32873 pud = (pud_t *) spp_getpage();
32874 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
32875 - _PAGE_USER));
32876 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
32877 }
32878 pud = pud_offset(pgd, (unsigned long)__va(phys));
32879 if (pud_none(*pud)) {
32880 pmd = (pmd_t *) spp_getpage();
32881 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
32882 - _PAGE_USER));
32883 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
32884 }
32885 pmd = pmd_offset(pud, phys);
32886 BUG_ON(!pmd_none(*pmd));
32887 @@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
32888 prot);
32889
32890 spin_lock(&init_mm.page_table_lock);
32891 - pud_populate(&init_mm, pud, pmd);
32892 + pud_populate_kernel(&init_mm, pud, pmd);
32893 spin_unlock(&init_mm.page_table_lock);
32894 }
32895 __flush_tlb_all();
32896 @@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
32897 page_size_mask);
32898
32899 spin_lock(&init_mm.page_table_lock);
32900 - pgd_populate(&init_mm, pgd, pud);
32901 + pgd_populate_kernel(&init_mm, pgd, pud);
32902 spin_unlock(&init_mm.page_table_lock);
32903 pgd_changed = true;
32904 }
32905 @@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
32906 static struct vm_area_struct gate_vma = {
32907 .vm_start = VSYSCALL_START,
32908 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
32909 - .vm_page_prot = PAGE_READONLY_EXEC,
32910 - .vm_flags = VM_READ | VM_EXEC
32911 + .vm_page_prot = PAGE_READONLY,
32912 + .vm_flags = VM_READ
32913 };
32914
32915 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
32916 @@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
32917
32918 const char *arch_vma_name(struct vm_area_struct *vma)
32919 {
32920 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
32921 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
32922 return "[vdso]";
32923 if (vma == &gate_vma)
32924 return "[vsyscall]";
32925 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
32926 index 7b179b4..6bd17777 100644
32927 --- a/arch/x86/mm/iomap_32.c
32928 +++ b/arch/x86/mm/iomap_32.c
32929 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
32930 type = kmap_atomic_idx_push();
32931 idx = type + KM_TYPE_NR * smp_processor_id();
32932 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32933 +
32934 + pax_open_kernel();
32935 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
32936 + pax_close_kernel();
32937 +
32938 arch_flush_lazy_mmu_mode();
32939
32940 return (void *)vaddr;
32941 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
32942 index bc7527e..5e2c495 100644
32943 --- a/arch/x86/mm/ioremap.c
32944 +++ b/arch/x86/mm/ioremap.c
32945 @@ -56,8 +56,8 @@ static int __ioremap_check_ram(unsigned long start_pfn, unsigned long nr_pages,
32946 unsigned long i;
32947
32948 for (i = 0; i < nr_pages; ++i)
32949 - if (pfn_valid(start_pfn + i) &&
32950 - !PageReserved(pfn_to_page(start_pfn + i)))
32951 + if (pfn_valid(start_pfn + i) && (start_pfn + i >= 0x100 ||
32952 + !PageReserved(pfn_to_page(start_pfn + i))))
32953 return 1;
32954
32955 WARN_ONCE(1, "ioremap on RAM pfn 0x%lx\n", start_pfn);
32956 @@ -268,7 +268,7 @@ EXPORT_SYMBOL(ioremap_prot);
32957 *
32958 * Caller must ensure there is only one unmapping for the same pointer.
32959 */
32960 -void iounmap(volatile void __iomem *addr)
32961 +void iounmap(const volatile void __iomem *addr)
32962 {
32963 struct vm_struct *p, *o;
32964
32965 @@ -322,6 +322,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32966
32967 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
32968 if (page_is_ram(start >> PAGE_SHIFT))
32969 +#ifdef CONFIG_HIGHMEM
32970 + if ((start >> PAGE_SHIFT) < max_low_pfn)
32971 +#endif
32972 return __va(phys);
32973
32974 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
32975 @@ -334,13 +337,16 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32976 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
32977 {
32978 if (page_is_ram(phys >> PAGE_SHIFT))
32979 +#ifdef CONFIG_HIGHMEM
32980 + if ((phys >> PAGE_SHIFT) < max_low_pfn)
32981 +#endif
32982 return;
32983
32984 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
32985 return;
32986 }
32987
32988 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
32989 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
32990
32991 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
32992 {
32993 @@ -370,8 +376,7 @@ void __init early_ioremap_init(void)
32994 early_ioremap_setup();
32995
32996 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
32997 - memset(bm_pte, 0, sizeof(bm_pte));
32998 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
32999 + pmd_populate_user(&init_mm, pmd, bm_pte);
33000
33001 /*
33002 * The boot-ioremap range spans multiple pmds, for which
33003 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
33004 index dd89a13..d77bdcc 100644
33005 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
33006 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
33007 @@ -628,9 +628,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
33008 * memory (e.g. tracked pages)? For now, we need this to avoid
33009 * invoking kmemcheck for PnP BIOS calls.
33010 */
33011 - if (regs->flags & X86_VM_MASK)
33012 + if (v8086_mode(regs))
33013 return false;
33014 - if (regs->cs != __KERNEL_CS)
33015 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
33016 return false;
33017
33018 pte = kmemcheck_pte_lookup(address);
33019 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
33020 index 25e7e13..1964579 100644
33021 --- a/arch/x86/mm/mmap.c
33022 +++ b/arch/x86/mm/mmap.c
33023 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
33024 * Leave an at least ~128 MB hole with possible stack randomization.
33025 */
33026 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
33027 -#define MAX_GAP (TASK_SIZE/6*5)
33028 +#define MAX_GAP (pax_task_size/6*5)
33029
33030 static int mmap_is_legacy(void)
33031 {
33032 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
33033 return rnd << PAGE_SHIFT;
33034 }
33035
33036 -static unsigned long mmap_base(void)
33037 +static unsigned long mmap_base(struct mm_struct *mm)
33038 {
33039 unsigned long gap = rlimit(RLIMIT_STACK);
33040 + unsigned long pax_task_size = TASK_SIZE;
33041 +
33042 +#ifdef CONFIG_PAX_SEGMEXEC
33043 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
33044 + pax_task_size = SEGMEXEC_TASK_SIZE;
33045 +#endif
33046
33047 if (gap < MIN_GAP)
33048 gap = MIN_GAP;
33049 else if (gap > MAX_GAP)
33050 gap = MAX_GAP;
33051
33052 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
33053 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
33054 }
33055
33056 /*
33057 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
33058 * does, but not when emulating X86_32
33059 */
33060 -static unsigned long mmap_legacy_base(void)
33061 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
33062 {
33063 - if (mmap_is_ia32())
33064 + if (mmap_is_ia32()) {
33065 +
33066 +#ifdef CONFIG_PAX_SEGMEXEC
33067 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
33068 + return SEGMEXEC_TASK_UNMAPPED_BASE;
33069 + else
33070 +#endif
33071 +
33072 return TASK_UNMAPPED_BASE;
33073 - else
33074 + } else
33075 return TASK_UNMAPPED_BASE + mmap_rnd();
33076 }
33077
33078 @@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
33079 */
33080 void arch_pick_mmap_layout(struct mm_struct *mm)
33081 {
33082 - mm->mmap_legacy_base = mmap_legacy_base();
33083 - mm->mmap_base = mmap_base();
33084 + mm->mmap_legacy_base = mmap_legacy_base(mm);
33085 + mm->mmap_base = mmap_base(mm);
33086 +
33087 +#ifdef CONFIG_PAX_RANDMMAP
33088 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
33089 + mm->mmap_legacy_base += mm->delta_mmap;
33090 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
33091 + }
33092 +#endif
33093
33094 if (mmap_is_legacy()) {
33095 mm->mmap_base = mm->mmap_legacy_base;
33096 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
33097 index 0057a7a..95c7edd 100644
33098 --- a/arch/x86/mm/mmio-mod.c
33099 +++ b/arch/x86/mm/mmio-mod.c
33100 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
33101 break;
33102 default:
33103 {
33104 - unsigned char *ip = (unsigned char *)instptr;
33105 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
33106 my_trace->opcode = MMIO_UNKNOWN_OP;
33107 my_trace->width = 0;
33108 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
33109 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
33110 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33111 void __iomem *addr)
33112 {
33113 - static atomic_t next_id;
33114 + static atomic_unchecked_t next_id;
33115 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
33116 /* These are page-unaligned. */
33117 struct mmiotrace_map map = {
33118 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33119 .private = trace
33120 },
33121 .phys = offset,
33122 - .id = atomic_inc_return(&next_id)
33123 + .id = atomic_inc_return_unchecked(&next_id)
33124 };
33125 map.map_id = trace->id;
33126
33127 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
33128 ioremap_trace_core(offset, size, addr);
33129 }
33130
33131 -static void iounmap_trace_core(volatile void __iomem *addr)
33132 +static void iounmap_trace_core(const volatile void __iomem *addr)
33133 {
33134 struct mmiotrace_map map = {
33135 .phys = 0,
33136 @@ -328,7 +328,7 @@ not_enabled:
33137 }
33138 }
33139
33140 -void mmiotrace_iounmap(volatile void __iomem *addr)
33141 +void mmiotrace_iounmap(const volatile void __iomem *addr)
33142 {
33143 might_sleep();
33144 if (is_enabled()) /* recheck and proper locking in *_core() */
33145 diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
33146 index 1d045f9..3a00249 100644
33147 --- a/arch/x86/mm/numa.c
33148 +++ b/arch/x86/mm/numa.c
33149 @@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
33150 return true;
33151 }
33152
33153 -static int __init numa_register_memblks(struct numa_meminfo *mi)
33154 +static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
33155 {
33156 unsigned long uninitialized_var(pfn_align);
33157 int i, nid;
33158 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
33159 index 461bc82..4e091a3 100644
33160 --- a/arch/x86/mm/pageattr-test.c
33161 +++ b/arch/x86/mm/pageattr-test.c
33162 @@ -35,7 +35,7 @@ enum {
33163
33164 static int pte_testbit(pte_t pte)
33165 {
33166 - return pte_flags(pte) & _PAGE_UNUSED1;
33167 + return pte_flags(pte) & _PAGE_CPA_TEST;
33168 }
33169
33170 struct split_state {
33171 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
33172 index ae242a7..1c7998f 100644
33173 --- a/arch/x86/mm/pageattr.c
33174 +++ b/arch/x86/mm/pageattr.c
33175 @@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33176 */
33177 #ifdef CONFIG_PCI_BIOS
33178 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
33179 - pgprot_val(forbidden) |= _PAGE_NX;
33180 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33181 #endif
33182
33183 /*
33184 @@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33185 * Does not cover __inittext since that is gone later on. On
33186 * 64bit we do not enforce !NX on the low mapping
33187 */
33188 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
33189 - pgprot_val(forbidden) |= _PAGE_NX;
33190 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
33191 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33192
33193 +#ifdef CONFIG_DEBUG_RODATA
33194 /*
33195 * The .rodata section needs to be read-only. Using the pfn
33196 * catches all aliases.
33197 @@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33198 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
33199 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
33200 pgprot_val(forbidden) |= _PAGE_RW;
33201 +#endif
33202
33203 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
33204 /*
33205 @@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33206 }
33207 #endif
33208
33209 +#ifdef CONFIG_PAX_KERNEXEC
33210 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
33211 + pgprot_val(forbidden) |= _PAGE_RW;
33212 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33213 + }
33214 +#endif
33215 +
33216 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
33217
33218 return prot;
33219 @@ -420,23 +429,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
33220 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
33221 {
33222 /* change init_mm */
33223 + pax_open_kernel();
33224 set_pte_atomic(kpte, pte);
33225 +
33226 #ifdef CONFIG_X86_32
33227 if (!SHARED_KERNEL_PMD) {
33228 +
33229 +#ifdef CONFIG_PAX_PER_CPU_PGD
33230 + unsigned long cpu;
33231 +#else
33232 struct page *page;
33233 +#endif
33234
33235 +#ifdef CONFIG_PAX_PER_CPU_PGD
33236 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33237 + pgd_t *pgd = get_cpu_pgd(cpu, kernel);
33238 +#else
33239 list_for_each_entry(page, &pgd_list, lru) {
33240 - pgd_t *pgd;
33241 + pgd_t *pgd = (pgd_t *)page_address(page);
33242 +#endif
33243 +
33244 pud_t *pud;
33245 pmd_t *pmd;
33246
33247 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
33248 + pgd += pgd_index(address);
33249 pud = pud_offset(pgd, address);
33250 pmd = pmd_offset(pud, address);
33251 set_pte_atomic((pte_t *)pmd, pte);
33252 }
33253 }
33254 #endif
33255 + pax_close_kernel();
33256 }
33257
33258 static int
33259 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
33260 index 6574388..87e9bef 100644
33261 --- a/arch/x86/mm/pat.c
33262 +++ b/arch/x86/mm/pat.c
33263 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
33264
33265 if (!entry) {
33266 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
33267 - current->comm, current->pid, start, end - 1);
33268 + current->comm, task_pid_nr(current), start, end - 1);
33269 return -EINVAL;
33270 }
33271
33272 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33273
33274 while (cursor < to) {
33275 if (!devmem_is_allowed(pfn)) {
33276 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33277 - current->comm, from, to - 1);
33278 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33279 + current->comm, from, to - 1, cursor);
33280 return 0;
33281 }
33282 cursor += PAGE_SIZE;
33283 @@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33284 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33285 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33286 "for [mem %#010Lx-%#010Lx]\n",
33287 - current->comm, current->pid,
33288 + current->comm, task_pid_nr(current),
33289 cattr_name(flags),
33290 base, (unsigned long long)(base + size-1));
33291 return -EINVAL;
33292 @@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33293 flags = lookup_memtype(paddr);
33294 if (want_flags != flags) {
33295 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33296 - current->comm, current->pid,
33297 + current->comm, task_pid_nr(current),
33298 cattr_name(want_flags),
33299 (unsigned long long)paddr,
33300 (unsigned long long)(paddr + size - 1),
33301 @@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33302 free_memtype(paddr, paddr + size);
33303 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33304 " for [mem %#010Lx-%#010Lx], got %s\n",
33305 - current->comm, current->pid,
33306 + current->comm, task_pid_nr(current),
33307 cattr_name(want_flags),
33308 (unsigned long long)paddr,
33309 (unsigned long long)(paddr + size - 1),
33310 diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33311 index 415f6c4..d319983 100644
33312 --- a/arch/x86/mm/pat_rbtree.c
33313 +++ b/arch/x86/mm/pat_rbtree.c
33314 @@ -160,7 +160,7 @@ success:
33315
33316 failure:
33317 printk(KERN_INFO "%s:%d conflicting memory types "
33318 - "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33319 + "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33320 end, cattr_name(found_type), cattr_name(match->type));
33321 return -EBUSY;
33322 }
33323 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33324 index 9f0614d..92ae64a 100644
33325 --- a/arch/x86/mm/pf_in.c
33326 +++ b/arch/x86/mm/pf_in.c
33327 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33328 int i;
33329 enum reason_type rv = OTHERS;
33330
33331 - p = (unsigned char *)ins_addr;
33332 + p = (unsigned char *)ktla_ktva(ins_addr);
33333 p += skip_prefix(p, &prf);
33334 p += get_opcode(p, &opcode);
33335
33336 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33337 struct prefix_bits prf;
33338 int i;
33339
33340 - p = (unsigned char *)ins_addr;
33341 + p = (unsigned char *)ktla_ktva(ins_addr);
33342 p += skip_prefix(p, &prf);
33343 p += get_opcode(p, &opcode);
33344
33345 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33346 struct prefix_bits prf;
33347 int i;
33348
33349 - p = (unsigned char *)ins_addr;
33350 + p = (unsigned char *)ktla_ktva(ins_addr);
33351 p += skip_prefix(p, &prf);
33352 p += get_opcode(p, &opcode);
33353
33354 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33355 struct prefix_bits prf;
33356 int i;
33357
33358 - p = (unsigned char *)ins_addr;
33359 + p = (unsigned char *)ktla_ktva(ins_addr);
33360 p += skip_prefix(p, &prf);
33361 p += get_opcode(p, &opcode);
33362 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33363 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33364 struct prefix_bits prf;
33365 int i;
33366
33367 - p = (unsigned char *)ins_addr;
33368 + p = (unsigned char *)ktla_ktva(ins_addr);
33369 p += skip_prefix(p, &prf);
33370 p += get_opcode(p, &opcode);
33371 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33372 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33373 index c96314a..433b127 100644
33374 --- a/arch/x86/mm/pgtable.c
33375 +++ b/arch/x86/mm/pgtable.c
33376 @@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33377 list_del(&page->lru);
33378 }
33379
33380 -#define UNSHARED_PTRS_PER_PGD \
33381 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33382 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33383 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33384
33385 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33386 +{
33387 + unsigned int count = USER_PGD_PTRS;
33388
33389 + if (!pax_user_shadow_base)
33390 + return;
33391 +
33392 + while (count--)
33393 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33394 +}
33395 +#endif
33396 +
33397 +#ifdef CONFIG_PAX_PER_CPU_PGD
33398 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33399 +{
33400 + unsigned int count = USER_PGD_PTRS;
33401 +
33402 + while (count--) {
33403 + pgd_t pgd;
33404 +
33405 +#ifdef CONFIG_X86_64
33406 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33407 +#else
33408 + pgd = *src++;
33409 +#endif
33410 +
33411 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33412 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33413 +#endif
33414 +
33415 + *dst++ = pgd;
33416 + }
33417 +
33418 +}
33419 +#endif
33420 +
33421 +#ifdef CONFIG_X86_64
33422 +#define pxd_t pud_t
33423 +#define pyd_t pgd_t
33424 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33425 +#define pgtable_pxd_page_ctor(page) true
33426 +#define pgtable_pxd_page_dtor(page)
33427 +#define pxd_free(mm, pud) pud_free((mm), (pud))
33428 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33429 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
33430 +#define PYD_SIZE PGDIR_SIZE
33431 +#else
33432 +#define pxd_t pmd_t
33433 +#define pyd_t pud_t
33434 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33435 +#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33436 +#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33437 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
33438 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33439 +#define pyd_offset(mm, address) pud_offset((mm), (address))
33440 +#define PYD_SIZE PUD_SIZE
33441 +#endif
33442 +
33443 +#ifdef CONFIG_PAX_PER_CPU_PGD
33444 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33445 +static inline void pgd_dtor(pgd_t *pgd) {}
33446 +#else
33447 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33448 {
33449 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33450 @@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33451 pgd_list_del(pgd);
33452 spin_unlock(&pgd_lock);
33453 }
33454 +#endif
33455
33456 /*
33457 * List of all pgd's needed for non-PAE so it can invalidate entries
33458 @@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33459 * -- nyc
33460 */
33461
33462 -#ifdef CONFIG_X86_PAE
33463 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33464 /*
33465 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33466 * updating the top-level pagetable entries to guarantee the
33467 @@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33468 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33469 * and initialize the kernel pmds here.
33470 */
33471 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33472 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33473
33474 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33475 {
33476 @@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33477 */
33478 flush_tlb_mm(mm);
33479 }
33480 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33481 +#define PREALLOCATED_PXDS USER_PGD_PTRS
33482 #else /* !CONFIG_X86_PAE */
33483
33484 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33485 -#define PREALLOCATED_PMDS 0
33486 +#define PREALLOCATED_PXDS 0
33487
33488 #endif /* CONFIG_X86_PAE */
33489
33490 -static void free_pmds(pmd_t *pmds[])
33491 +static void free_pxds(pxd_t *pxds[])
33492 {
33493 int i;
33494
33495 - for(i = 0; i < PREALLOCATED_PMDS; i++)
33496 - if (pmds[i]) {
33497 - pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33498 - free_page((unsigned long)pmds[i]);
33499 + for(i = 0; i < PREALLOCATED_PXDS; i++)
33500 + if (pxds[i]) {
33501 + pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33502 + free_page((unsigned long)pxds[i]);
33503 }
33504 }
33505
33506 -static int preallocate_pmds(pmd_t *pmds[])
33507 +static int preallocate_pxds(pxd_t *pxds[])
33508 {
33509 int i;
33510 bool failed = false;
33511
33512 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33513 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33514 - if (!pmd)
33515 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33516 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33517 + if (!pxd)
33518 failed = true;
33519 - if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33520 - free_page((unsigned long)pmd);
33521 - pmd = NULL;
33522 + if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33523 + free_page((unsigned long)pxd);
33524 + pxd = NULL;
33525 failed = true;
33526 }
33527 - pmds[i] = pmd;
33528 + pxds[i] = pxd;
33529 }
33530
33531 if (failed) {
33532 - free_pmds(pmds);
33533 + free_pxds(pxds);
33534 return -ENOMEM;
33535 }
33536
33537 @@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33538 * preallocate which never got a corresponding vma will need to be
33539 * freed manually.
33540 */
33541 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33542 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33543 {
33544 int i;
33545
33546 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33547 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33548 pgd_t pgd = pgdp[i];
33549
33550 if (pgd_val(pgd) != 0) {
33551 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33552 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33553
33554 - pgdp[i] = native_make_pgd(0);
33555 + set_pgd(pgdp + i, native_make_pgd(0));
33556
33557 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33558 - pmd_free(mm, pmd);
33559 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33560 + pxd_free(mm, pxd);
33561 }
33562 }
33563 }
33564
33565 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
33566 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
33567 {
33568 - pud_t *pud;
33569 + pyd_t *pyd;
33570 int i;
33571
33572 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
33573 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
33574 return;
33575
33576 - pud = pud_offset(pgd, 0);
33577 -
33578 - for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
33579 - pmd_t *pmd = pmds[i];
33580 +#ifdef CONFIG_X86_64
33581 + pyd = pyd_offset(mm, 0L);
33582 +#else
33583 + pyd = pyd_offset(pgd, 0L);
33584 +#endif
33585
33586 + for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
33587 + pxd_t *pxd = pxds[i];
33588 if (i >= KERNEL_PGD_BOUNDARY)
33589 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33590 - sizeof(pmd_t) * PTRS_PER_PMD);
33591 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33592 + sizeof(pxd_t) * PTRS_PER_PMD);
33593
33594 - pud_populate(mm, pud, pmd);
33595 + pyd_populate(mm, pyd, pxd);
33596 }
33597 }
33598
33599 pgd_t *pgd_alloc(struct mm_struct *mm)
33600 {
33601 pgd_t *pgd;
33602 - pmd_t *pmds[PREALLOCATED_PMDS];
33603 + pxd_t *pxds[PREALLOCATED_PXDS];
33604
33605 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
33606
33607 @@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33608
33609 mm->pgd = pgd;
33610
33611 - if (preallocate_pmds(pmds) != 0)
33612 + if (preallocate_pxds(pxds) != 0)
33613 goto out_free_pgd;
33614
33615 if (paravirt_pgd_alloc(mm) != 0)
33616 - goto out_free_pmds;
33617 + goto out_free_pxds;
33618
33619 /*
33620 * Make sure that pre-populating the pmds is atomic with
33621 @@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33622 spin_lock(&pgd_lock);
33623
33624 pgd_ctor(mm, pgd);
33625 - pgd_prepopulate_pmd(mm, pgd, pmds);
33626 + pgd_prepopulate_pxd(mm, pgd, pxds);
33627
33628 spin_unlock(&pgd_lock);
33629
33630 return pgd;
33631
33632 -out_free_pmds:
33633 - free_pmds(pmds);
33634 +out_free_pxds:
33635 + free_pxds(pxds);
33636 out_free_pgd:
33637 free_page((unsigned long)pgd);
33638 out:
33639 @@ -313,7 +380,7 @@ out:
33640
33641 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
33642 {
33643 - pgd_mop_up_pmds(mm, pgd);
33644 + pgd_mop_up_pxds(mm, pgd);
33645 pgd_dtor(pgd);
33646 paravirt_pgd_free(mm, pgd);
33647 free_page((unsigned long)pgd);
33648 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
33649 index 4dd8cf6..f9d143e 100644
33650 --- a/arch/x86/mm/pgtable_32.c
33651 +++ b/arch/x86/mm/pgtable_32.c
33652 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
33653 return;
33654 }
33655 pte = pte_offset_kernel(pmd, vaddr);
33656 +
33657 + pax_open_kernel();
33658 if (pte_val(pteval))
33659 set_pte_at(&init_mm, vaddr, pte, pteval);
33660 else
33661 pte_clear(&init_mm, vaddr, pte);
33662 + pax_close_kernel();
33663
33664 /*
33665 * It's enough to flush this one mapping.
33666 diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
33667 index e666cbb..61788c45 100644
33668 --- a/arch/x86/mm/physaddr.c
33669 +++ b/arch/x86/mm/physaddr.c
33670 @@ -10,7 +10,7 @@
33671 #ifdef CONFIG_X86_64
33672
33673 #ifdef CONFIG_DEBUG_VIRTUAL
33674 -unsigned long __phys_addr(unsigned long x)
33675 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33676 {
33677 unsigned long y = x - __START_KERNEL_map;
33678
33679 @@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
33680 #else
33681
33682 #ifdef CONFIG_DEBUG_VIRTUAL
33683 -unsigned long __phys_addr(unsigned long x)
33684 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33685 {
33686 unsigned long phys_addr = x - PAGE_OFFSET;
33687 /* VMALLOC_* aren't constants */
33688 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
33689 index 90555bf..f5f1828 100644
33690 --- a/arch/x86/mm/setup_nx.c
33691 +++ b/arch/x86/mm/setup_nx.c
33692 @@ -5,8 +5,10 @@
33693 #include <asm/pgtable.h>
33694 #include <asm/proto.h>
33695
33696 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33697 static int disable_nx;
33698
33699 +#ifndef CONFIG_PAX_PAGEEXEC
33700 /*
33701 * noexec = on|off
33702 *
33703 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
33704 return 0;
33705 }
33706 early_param("noexec", noexec_setup);
33707 +#endif
33708 +
33709 +#endif
33710
33711 void x86_configure_nx(void)
33712 {
33713 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33714 if (cpu_has_nx && !disable_nx)
33715 __supported_pte_mask |= _PAGE_NX;
33716 else
33717 +#endif
33718 __supported_pte_mask &= ~_PAGE_NX;
33719 }
33720
33721 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
33722 index dd8dda1..9e9b0f6 100644
33723 --- a/arch/x86/mm/tlb.c
33724 +++ b/arch/x86/mm/tlb.c
33725 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
33726 BUG();
33727 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
33728 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
33729 +
33730 +#ifndef CONFIG_PAX_PER_CPU_PGD
33731 load_cr3(swapper_pg_dir);
33732 +#endif
33733 +
33734 }
33735 }
33736 EXPORT_SYMBOL_GPL(leave_mm);
33737 diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
33738 new file mode 100644
33739 index 0000000..dace51c
33740 --- /dev/null
33741 +++ b/arch/x86/mm/uderef_64.c
33742 @@ -0,0 +1,37 @@
33743 +#include <linux/mm.h>
33744 +#include <asm/pgtable.h>
33745 +#include <asm/uaccess.h>
33746 +
33747 +#ifdef CONFIG_PAX_MEMORY_UDEREF
33748 +/* PaX: due to the special call convention these functions must
33749 + * - remain leaf functions under all configurations,
33750 + * - never be called directly, only dereferenced from the wrappers.
33751 + */
33752 +void __pax_open_userland(void)
33753 +{
33754 + unsigned int cpu;
33755 +
33756 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
33757 + return;
33758 +
33759 + cpu = raw_get_cpu();
33760 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
33761 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
33762 + raw_put_cpu_no_resched();
33763 +}
33764 +EXPORT_SYMBOL(__pax_open_userland);
33765 +
33766 +void __pax_close_userland(void)
33767 +{
33768 + unsigned int cpu;
33769 +
33770 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
33771 + return;
33772 +
33773 + cpu = raw_get_cpu();
33774 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
33775 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
33776 + raw_put_cpu_no_resched();
33777 +}
33778 +EXPORT_SYMBOL(__pax_close_userland);
33779 +#endif
33780 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
33781 index 0149575..f746de8 100644
33782 --- a/arch/x86/net/bpf_jit.S
33783 +++ b/arch/x86/net/bpf_jit.S
33784 @@ -9,6 +9,7 @@
33785 */
33786 #include <linux/linkage.h>
33787 #include <asm/dwarf2.h>
33788 +#include <asm/alternative-asm.h>
33789
33790 /*
33791 * Calling convention :
33792 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
33793 jle bpf_slow_path_word
33794 mov (SKBDATA,%rsi),%eax
33795 bswap %eax /* ntohl() */
33796 + pax_force_retaddr
33797 ret
33798
33799 sk_load_half:
33800 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
33801 jle bpf_slow_path_half
33802 movzwl (SKBDATA,%rsi),%eax
33803 rol $8,%ax # ntohs()
33804 + pax_force_retaddr
33805 ret
33806
33807 sk_load_byte:
33808 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
33809 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
33810 jle bpf_slow_path_byte
33811 movzbl (SKBDATA,%rsi),%eax
33812 + pax_force_retaddr
33813 ret
33814
33815 /**
33816 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
33817 movzbl (SKBDATA,%rsi),%ebx
33818 and $15,%bl
33819 shl $2,%bl
33820 + pax_force_retaddr
33821 ret
33822
33823 /* rsi contains offset and can be scratched */
33824 @@ -109,6 +114,7 @@ bpf_slow_path_word:
33825 js bpf_error
33826 mov -12(%rbp),%eax
33827 bswap %eax
33828 + pax_force_retaddr
33829 ret
33830
33831 bpf_slow_path_half:
33832 @@ -117,12 +123,14 @@ bpf_slow_path_half:
33833 mov -12(%rbp),%ax
33834 rol $8,%ax
33835 movzwl %ax,%eax
33836 + pax_force_retaddr
33837 ret
33838
33839 bpf_slow_path_byte:
33840 bpf_slow_path_common(1)
33841 js bpf_error
33842 movzbl -12(%rbp),%eax
33843 + pax_force_retaddr
33844 ret
33845
33846 bpf_slow_path_byte_msh:
33847 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
33848 and $15,%al
33849 shl $2,%al
33850 xchg %eax,%ebx
33851 + pax_force_retaddr
33852 ret
33853
33854 #define sk_negative_common(SIZE) \
33855 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
33856 sk_negative_common(4)
33857 mov (%rax), %eax
33858 bswap %eax
33859 + pax_force_retaddr
33860 ret
33861
33862 bpf_slow_path_half_neg:
33863 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
33864 mov (%rax),%ax
33865 rol $8,%ax
33866 movzwl %ax,%eax
33867 + pax_force_retaddr
33868 ret
33869
33870 bpf_slow_path_byte_neg:
33871 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
33872 .globl sk_load_byte_negative_offset
33873 sk_negative_common(1)
33874 movzbl (%rax), %eax
33875 + pax_force_retaddr
33876 ret
33877
33878 bpf_slow_path_byte_msh_neg:
33879 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
33880 and $15,%al
33881 shl $2,%al
33882 xchg %eax,%ebx
33883 + pax_force_retaddr
33884 ret
33885
33886 bpf_error:
33887 @@ -197,4 +210,5 @@ bpf_error:
33888 xor %eax,%eax
33889 mov -8(%rbp),%rbx
33890 leaveq
33891 + pax_force_retaddr
33892 ret
33893 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
33894 index 6d5663a..f1ec380 100644
33895 --- a/arch/x86/net/bpf_jit_comp.c
33896 +++ b/arch/x86/net/bpf_jit_comp.c
33897 @@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
33898 return ptr + len;
33899 }
33900
33901 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33902 +#define MAX_INSTR_CODE_SIZE 96
33903 +#else
33904 +#define MAX_INSTR_CODE_SIZE 64
33905 +#endif
33906 +
33907 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
33908
33909 #define EMIT1(b1) EMIT(b1, 1)
33910 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
33911 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
33912 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
33913 +
33914 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33915 +/* original constant will appear in ecx */
33916 +#define DILUTE_CONST_SEQUENCE(_off, _key) \
33917 +do { \
33918 + /* mov ecx, randkey */ \
33919 + EMIT1(0xb9); \
33920 + EMIT(_key, 4); \
33921 + /* xor ecx, randkey ^ off */ \
33922 + EMIT2(0x81, 0xf1); \
33923 + EMIT((_key) ^ (_off), 4); \
33924 +} while (0)
33925 +
33926 +#define EMIT1_off32(b1, _off) \
33927 +do { \
33928 + switch (b1) { \
33929 + case 0x05: /* add eax, imm32 */ \
33930 + case 0x2d: /* sub eax, imm32 */ \
33931 + case 0x25: /* and eax, imm32 */ \
33932 + case 0x0d: /* or eax, imm32 */ \
33933 + case 0xb8: /* mov eax, imm32 */ \
33934 + case 0x35: /* xor eax, imm32 */ \
33935 + case 0x3d: /* cmp eax, imm32 */ \
33936 + case 0xa9: /* test eax, imm32 */ \
33937 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33938 + EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
33939 + break; \
33940 + case 0xbb: /* mov ebx, imm32 */ \
33941 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33942 + /* mov ebx, ecx */ \
33943 + EMIT2(0x89, 0xcb); \
33944 + break; \
33945 + case 0xbe: /* mov esi, imm32 */ \
33946 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33947 + /* mov esi, ecx */ \
33948 + EMIT2(0x89, 0xce); \
33949 + break; \
33950 + case 0xe8: /* call rel imm32, always to known funcs */ \
33951 + EMIT1(b1); \
33952 + EMIT(_off, 4); \
33953 + break; \
33954 + case 0xe9: /* jmp rel imm32 */ \
33955 + EMIT1(b1); \
33956 + EMIT(_off, 4); \
33957 + /* prevent fall-through, we're not called if off = 0 */ \
33958 + EMIT(0xcccccccc, 4); \
33959 + EMIT(0xcccccccc, 4); \
33960 + break; \
33961 + default: \
33962 + BUILD_BUG(); \
33963 + } \
33964 +} while (0)
33965 +
33966 +#define EMIT2_off32(b1, b2, _off) \
33967 +do { \
33968 + if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
33969 + EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
33970 + EMIT(randkey, 4); \
33971 + EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
33972 + EMIT((_off) - randkey, 4); \
33973 + } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
33974 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33975 + /* imul eax, ecx */ \
33976 + EMIT3(0x0f, 0xaf, 0xc1); \
33977 + } else { \
33978 + BUILD_BUG(); \
33979 + } \
33980 +} while (0)
33981 +#else
33982 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
33983 +#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
33984 +#endif
33985
33986 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
33987 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
33988 @@ -91,6 +168,24 @@ do { \
33989 #define X86_JBE 0x76
33990 #define X86_JA 0x77
33991
33992 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33993 +#define APPEND_FLOW_VERIFY() \
33994 +do { \
33995 + /* mov ecx, randkey */ \
33996 + EMIT1(0xb9); \
33997 + EMIT(randkey, 4); \
33998 + /* cmp ecx, randkey */ \
33999 + EMIT2(0x81, 0xf9); \
34000 + EMIT(randkey, 4); \
34001 + /* jz after 8 int 3s */ \
34002 + EMIT2(0x74, 0x08); \
34003 + EMIT(0xcccccccc, 4); \
34004 + EMIT(0xcccccccc, 4); \
34005 +} while (0)
34006 +#else
34007 +#define APPEND_FLOW_VERIFY() do { } while (0)
34008 +#endif
34009 +
34010 #define EMIT_COND_JMP(op, offset) \
34011 do { \
34012 if (is_near(offset)) \
34013 @@ -98,6 +193,7 @@ do { \
34014 else { \
34015 EMIT2(0x0f, op + 0x10); \
34016 EMIT(offset, 4); /* jxx .+off32 */ \
34017 + APPEND_FLOW_VERIFY(); \
34018 } \
34019 } while (0)
34020
34021 @@ -145,55 +241,54 @@ static int pkt_type_offset(void)
34022 return -1;
34023 }
34024
34025 -struct bpf_binary_header {
34026 - unsigned int pages;
34027 - /* Note : for security reasons, bpf code will follow a randomly
34028 - * sized amount of int3 instructions
34029 - */
34030 - u8 image[];
34031 -};
34032 -
34033 -static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
34034 +/* Note : for security reasons, bpf code will follow a randomly
34035 + * sized amount of int3 instructions
34036 + */
34037 +static u8 *bpf_alloc_binary(unsigned int proglen,
34038 u8 **image_ptr)
34039 {
34040 unsigned int sz, hole;
34041 - struct bpf_binary_header *header;
34042 + u8 *header;
34043
34044 /* Most of BPF filters are really small,
34045 * but if some of them fill a page, allow at least
34046 * 128 extra bytes to insert a random section of int3
34047 */
34048 - sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
34049 - header = module_alloc(sz);
34050 + sz = round_up(proglen + 128, PAGE_SIZE);
34051 + header = module_alloc_exec(sz);
34052 if (!header)
34053 return NULL;
34054
34055 + pax_open_kernel();
34056 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
34057 + pax_close_kernel();
34058
34059 - header->pages = sz / PAGE_SIZE;
34060 - hole = min(sz - (proglen + sizeof(*header)), PAGE_SIZE - sizeof(*header));
34061 + hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
34062
34063 /* insert a random number of int3 instructions before BPF code */
34064 - *image_ptr = &header->image[prandom_u32() % hole];
34065 + *image_ptr = &header[prandom_u32() % hole];
34066 return header;
34067 }
34068
34069 void bpf_jit_compile(struct sk_filter *fp)
34070 {
34071 - u8 temp[64];
34072 + u8 temp[MAX_INSTR_CODE_SIZE];
34073 u8 *prog;
34074 unsigned int proglen, oldproglen = 0;
34075 int ilen, i;
34076 int t_offset, f_offset;
34077 u8 t_op, f_op, seen = 0, pass;
34078 u8 *image = NULL;
34079 - struct bpf_binary_header *header = NULL;
34080 + u8 *header = NULL;
34081 u8 *func;
34082 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
34083 unsigned int cleanup_addr; /* epilogue code offset */
34084 unsigned int *addrs;
34085 const struct sock_filter *filter = fp->insns;
34086 int flen = fp->len;
34087 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34088 + unsigned int randkey;
34089 +#endif
34090
34091 if (!bpf_jit_enable)
34092 return;
34093 @@ -203,10 +298,10 @@ void bpf_jit_compile(struct sk_filter *fp)
34094 return;
34095
34096 /* Before first pass, make a rough estimation of addrs[]
34097 - * each bpf instruction is translated to less than 64 bytes
34098 + * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
34099 */
34100 for (proglen = 0, i = 0; i < flen; i++) {
34101 - proglen += 64;
34102 + proglen += MAX_INSTR_CODE_SIZE;
34103 addrs[i] = proglen;
34104 }
34105 cleanup_addr = proglen; /* epilogue address */
34106 @@ -285,6 +380,10 @@ void bpf_jit_compile(struct sk_filter *fp)
34107 for (i = 0; i < flen; i++) {
34108 unsigned int K = filter[i].k;
34109
34110 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34111 + randkey = prandom_u32();
34112 +#endif
34113 +
34114 switch (filter[i].code) {
34115 case BPF_S_ALU_ADD_X: /* A += X; */
34116 seen |= SEEN_XREG;
34117 @@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
34118 case BPF_S_ALU_MUL_K: /* A *= K */
34119 if (is_imm8(K))
34120 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
34121 - else {
34122 - EMIT2(0x69, 0xc0); /* imul imm32,%eax */
34123 - EMIT(K, 4);
34124 - }
34125 + else
34126 + EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
34127 break;
34128 case BPF_S_ALU_DIV_X: /* A /= X; */
34129 seen |= SEEN_XREG;
34130 @@ -364,7 +461,11 @@ void bpf_jit_compile(struct sk_filter *fp)
34131 break;
34132 }
34133 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
34134 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34135 + DILUTE_CONST_SEQUENCE(K, randkey);
34136 +#else
34137 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
34138 +#endif
34139 EMIT2(0xf7, 0xf1); /* div %ecx */
34140 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
34141 break;
34142 @@ -372,7 +473,11 @@ void bpf_jit_compile(struct sk_filter *fp)
34143 if (K == 1)
34144 break;
34145 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
34146 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34147 + DILUTE_CONST_SEQUENCE(K, randkey);
34148 +#else
34149 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
34150 +#endif
34151 EMIT2(0xf7, 0xf1); /* div %ecx */
34152 break;
34153 case BPF_S_ALU_AND_X:
34154 @@ -643,8 +748,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
34155 if (is_imm8(K)) {
34156 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
34157 } else {
34158 - EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
34159 - EMIT(K, 4);
34160 + EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
34161 }
34162 } else {
34163 EMIT2(0x89,0xde); /* mov %ebx,%esi */
34164 @@ -734,10 +838,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
34165 if (unlikely(proglen + ilen > oldproglen)) {
34166 pr_err("bpb_jit_compile fatal error\n");
34167 kfree(addrs);
34168 - module_free(NULL, header);
34169 + module_free_exec(NULL, image);
34170 return;
34171 }
34172 + pax_open_kernel();
34173 memcpy(image + proglen, temp, ilen);
34174 + pax_close_kernel();
34175 }
34176 proglen += ilen;
34177 addrs[i] = proglen;
34178 @@ -770,7 +876,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
34179
34180 if (image) {
34181 bpf_flush_icache(header, image + proglen);
34182 - set_memory_ro((unsigned long)header, header->pages);
34183 fp->bpf_func = (void *)image;
34184 fp->jited = 1;
34185 }
34186 @@ -783,10 +888,9 @@ static void bpf_jit_free_deferred(struct work_struct *work)
34187 {
34188 struct sk_filter *fp = container_of(work, struct sk_filter, work);
34189 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
34190 - struct bpf_binary_header *header = (void *)addr;
34191
34192 - set_memory_rw(addr, header->pages);
34193 - module_free(NULL, header);
34194 + set_memory_rw(addr, 1);
34195 + module_free_exec(NULL, (void *)addr);
34196 kfree(fp);
34197 }
34198
34199 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
34200 index 5d04be5..2beeaa2 100644
34201 --- a/arch/x86/oprofile/backtrace.c
34202 +++ b/arch/x86/oprofile/backtrace.c
34203 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
34204 struct stack_frame_ia32 *fp;
34205 unsigned long bytes;
34206
34207 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34208 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34209 if (bytes != 0)
34210 return NULL;
34211
34212 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
34213 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
34214
34215 oprofile_add_trace(bufhead[0].return_address);
34216
34217 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
34218 struct stack_frame bufhead[2];
34219 unsigned long bytes;
34220
34221 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34222 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34223 if (bytes != 0)
34224 return NULL;
34225
34226 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
34227 {
34228 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
34229
34230 - if (!user_mode_vm(regs)) {
34231 + if (!user_mode(regs)) {
34232 unsigned long stack = kernel_stack_pointer(regs);
34233 if (depth)
34234 dump_trace(NULL, regs, (unsigned long *)stack, 0,
34235 diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
34236 index 379e8bd..6386e09 100644
34237 --- a/arch/x86/oprofile/nmi_int.c
34238 +++ b/arch/x86/oprofile/nmi_int.c
34239 @@ -23,6 +23,7 @@
34240 #include <asm/nmi.h>
34241 #include <asm/msr.h>
34242 #include <asm/apic.h>
34243 +#include <asm/pgtable.h>
34244
34245 #include "op_counter.h"
34246 #include "op_x86_model.h"
34247 @@ -785,8 +786,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
34248 if (ret)
34249 return ret;
34250
34251 - if (!model->num_virt_counters)
34252 - model->num_virt_counters = model->num_counters;
34253 + if (!model->num_virt_counters) {
34254 + pax_open_kernel();
34255 + *(unsigned int *)&model->num_virt_counters = model->num_counters;
34256 + pax_close_kernel();
34257 + }
34258
34259 mux_init(ops);
34260
34261 diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
34262 index 50d86c0..7985318 100644
34263 --- a/arch/x86/oprofile/op_model_amd.c
34264 +++ b/arch/x86/oprofile/op_model_amd.c
34265 @@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
34266 num_counters = AMD64_NUM_COUNTERS;
34267 }
34268
34269 - op_amd_spec.num_counters = num_counters;
34270 - op_amd_spec.num_controls = num_counters;
34271 - op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34272 + pax_open_kernel();
34273 + *(unsigned int *)&op_amd_spec.num_counters = num_counters;
34274 + *(unsigned int *)&op_amd_spec.num_controls = num_counters;
34275 + *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34276 + pax_close_kernel();
34277
34278 return 0;
34279 }
34280 diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
34281 index d90528e..0127e2b 100644
34282 --- a/arch/x86/oprofile/op_model_ppro.c
34283 +++ b/arch/x86/oprofile/op_model_ppro.c
34284 @@ -19,6 +19,7 @@
34285 #include <asm/msr.h>
34286 #include <asm/apic.h>
34287 #include <asm/nmi.h>
34288 +#include <asm/pgtable.h>
34289
34290 #include "op_x86_model.h"
34291 #include "op_counter.h"
34292 @@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
34293
34294 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
34295
34296 - op_arch_perfmon_spec.num_counters = num_counters;
34297 - op_arch_perfmon_spec.num_controls = num_counters;
34298 + pax_open_kernel();
34299 + *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
34300 + *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
34301 + pax_close_kernel();
34302 }
34303
34304 static int arch_perfmon_init(struct oprofile_operations *ignore)
34305 diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
34306 index 71e8a67..6a313bb 100644
34307 --- a/arch/x86/oprofile/op_x86_model.h
34308 +++ b/arch/x86/oprofile/op_x86_model.h
34309 @@ -52,7 +52,7 @@ struct op_x86_model_spec {
34310 void (*switch_ctrl)(struct op_x86_model_spec const *model,
34311 struct op_msrs const * const msrs);
34312 #endif
34313 -};
34314 +} __do_const;
34315
34316 struct op_counter_config;
34317
34318 diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
34319 index 84b9d67..260e5ff 100644
34320 --- a/arch/x86/pci/intel_mid_pci.c
34321 +++ b/arch/x86/pci/intel_mid_pci.c
34322 @@ -245,7 +245,7 @@ int __init intel_mid_pci_init(void)
34323 pr_info("Intel MID platform detected, using MID PCI ops\n");
34324 pci_mmcfg_late_init();
34325 pcibios_enable_irq = intel_mid_pci_irq_enable;
34326 - pci_root_ops = intel_mid_pci_ops;
34327 + memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
34328 pci_soc_mode = 1;
34329 /* Continue with standard init */
34330 return 1;
34331 diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
34332 index 84112f5..6334d60 100644
34333 --- a/arch/x86/pci/irq.c
34334 +++ b/arch/x86/pci/irq.c
34335 @@ -50,7 +50,7 @@ struct irq_router {
34336 struct irq_router_handler {
34337 u16 vendor;
34338 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
34339 -};
34340 +} __do_const;
34341
34342 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
34343 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
34344 @@ -790,7 +790,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
34345 return 0;
34346 }
34347
34348 -static __initdata struct irq_router_handler pirq_routers[] = {
34349 +static __initconst const struct irq_router_handler pirq_routers[] = {
34350 { PCI_VENDOR_ID_INTEL, intel_router_probe },
34351 { PCI_VENDOR_ID_AL, ali_router_probe },
34352 { PCI_VENDOR_ID_ITE, ite_router_probe },
34353 @@ -817,7 +817,7 @@ static struct pci_dev *pirq_router_dev;
34354 static void __init pirq_find_router(struct irq_router *r)
34355 {
34356 struct irq_routing_table *rt = pirq_table;
34357 - struct irq_router_handler *h;
34358 + const struct irq_router_handler *h;
34359
34360 #ifdef CONFIG_PCI_BIOS
34361 if (!rt->signature) {
34362 @@ -1090,7 +1090,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
34363 return 0;
34364 }
34365
34366 -static struct dmi_system_id __initdata pciirq_dmi_table[] = {
34367 +static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
34368 {
34369 .callback = fix_broken_hp_bios_irq9,
34370 .ident = "HP Pavilion N5400 Series Laptop",
34371 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
34372 index c77b24a..c979855 100644
34373 --- a/arch/x86/pci/pcbios.c
34374 +++ b/arch/x86/pci/pcbios.c
34375 @@ -79,7 +79,7 @@ union bios32 {
34376 static struct {
34377 unsigned long address;
34378 unsigned short segment;
34379 -} bios32_indirect = { 0, __KERNEL_CS };
34380 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
34381
34382 /*
34383 * Returns the entry point for the given service, NULL on error
34384 @@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
34385 unsigned long length; /* %ecx */
34386 unsigned long entry; /* %edx */
34387 unsigned long flags;
34388 + struct desc_struct d, *gdt;
34389
34390 local_irq_save(flags);
34391 - __asm__("lcall *(%%edi); cld"
34392 +
34393 + gdt = get_cpu_gdt_table(smp_processor_id());
34394 +
34395 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
34396 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34397 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
34398 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34399 +
34400 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
34401 : "=a" (return_code),
34402 "=b" (address),
34403 "=c" (length),
34404 "=d" (entry)
34405 : "0" (service),
34406 "1" (0),
34407 - "D" (&bios32_indirect));
34408 + "D" (&bios32_indirect),
34409 + "r"(__PCIBIOS_DS)
34410 + : "memory");
34411 +
34412 + pax_open_kernel();
34413 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
34414 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
34415 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
34416 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
34417 + pax_close_kernel();
34418 +
34419 local_irq_restore(flags);
34420
34421 switch (return_code) {
34422 - case 0:
34423 - return address + entry;
34424 - case 0x80: /* Not present */
34425 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34426 - return 0;
34427 - default: /* Shouldn't happen */
34428 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34429 - service, return_code);
34430 + case 0: {
34431 + int cpu;
34432 + unsigned char flags;
34433 +
34434 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
34435 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
34436 + printk(KERN_WARNING "bios32_service: not valid\n");
34437 return 0;
34438 + }
34439 + address = address + PAGE_OFFSET;
34440 + length += 16UL; /* some BIOSs underreport this... */
34441 + flags = 4;
34442 + if (length >= 64*1024*1024) {
34443 + length >>= PAGE_SHIFT;
34444 + flags |= 8;
34445 + }
34446 +
34447 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
34448 + gdt = get_cpu_gdt_table(cpu);
34449 + pack_descriptor(&d, address, length, 0x9b, flags);
34450 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34451 + pack_descriptor(&d, address, length, 0x93, flags);
34452 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34453 + }
34454 + return entry;
34455 + }
34456 + case 0x80: /* Not present */
34457 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34458 + return 0;
34459 + default: /* Shouldn't happen */
34460 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34461 + service, return_code);
34462 + return 0;
34463 }
34464 }
34465
34466 static struct {
34467 unsigned long address;
34468 unsigned short segment;
34469 -} pci_indirect = { 0, __KERNEL_CS };
34470 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
34471
34472 -static int pci_bios_present;
34473 +static int pci_bios_present __read_only;
34474
34475 static int check_pcibios(void)
34476 {
34477 @@ -131,11 +174,13 @@ static int check_pcibios(void)
34478 unsigned long flags, pcibios_entry;
34479
34480 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
34481 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
34482 + pci_indirect.address = pcibios_entry;
34483
34484 local_irq_save(flags);
34485 - __asm__(
34486 - "lcall *(%%edi); cld\n\t"
34487 + __asm__("movw %w6, %%ds\n\t"
34488 + "lcall *%%ss:(%%edi); cld\n\t"
34489 + "push %%ss\n\t"
34490 + "pop %%ds\n\t"
34491 "jc 1f\n\t"
34492 "xor %%ah, %%ah\n"
34493 "1:"
34494 @@ -144,7 +189,8 @@ static int check_pcibios(void)
34495 "=b" (ebx),
34496 "=c" (ecx)
34497 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
34498 - "D" (&pci_indirect)
34499 + "D" (&pci_indirect),
34500 + "r" (__PCIBIOS_DS)
34501 : "memory");
34502 local_irq_restore(flags);
34503
34504 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34505
34506 switch (len) {
34507 case 1:
34508 - __asm__("lcall *(%%esi); cld\n\t"
34509 + __asm__("movw %w6, %%ds\n\t"
34510 + "lcall *%%ss:(%%esi); cld\n\t"
34511 + "push %%ss\n\t"
34512 + "pop %%ds\n\t"
34513 "jc 1f\n\t"
34514 "xor %%ah, %%ah\n"
34515 "1:"
34516 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34517 : "1" (PCIBIOS_READ_CONFIG_BYTE),
34518 "b" (bx),
34519 "D" ((long)reg),
34520 - "S" (&pci_indirect));
34521 + "S" (&pci_indirect),
34522 + "r" (__PCIBIOS_DS));
34523 /*
34524 * Zero-extend the result beyond 8 bits, do not trust the
34525 * BIOS having done it:
34526 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34527 *value &= 0xff;
34528 break;
34529 case 2:
34530 - __asm__("lcall *(%%esi); cld\n\t"
34531 + __asm__("movw %w6, %%ds\n\t"
34532 + "lcall *%%ss:(%%esi); cld\n\t"
34533 + "push %%ss\n\t"
34534 + "pop %%ds\n\t"
34535 "jc 1f\n\t"
34536 "xor %%ah, %%ah\n"
34537 "1:"
34538 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34539 : "1" (PCIBIOS_READ_CONFIG_WORD),
34540 "b" (bx),
34541 "D" ((long)reg),
34542 - "S" (&pci_indirect));
34543 + "S" (&pci_indirect),
34544 + "r" (__PCIBIOS_DS));
34545 /*
34546 * Zero-extend the result beyond 16 bits, do not trust the
34547 * BIOS having done it:
34548 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34549 *value &= 0xffff;
34550 break;
34551 case 4:
34552 - __asm__("lcall *(%%esi); cld\n\t"
34553 + __asm__("movw %w6, %%ds\n\t"
34554 + "lcall *%%ss:(%%esi); cld\n\t"
34555 + "push %%ss\n\t"
34556 + "pop %%ds\n\t"
34557 "jc 1f\n\t"
34558 "xor %%ah, %%ah\n"
34559 "1:"
34560 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34561 : "1" (PCIBIOS_READ_CONFIG_DWORD),
34562 "b" (bx),
34563 "D" ((long)reg),
34564 - "S" (&pci_indirect));
34565 + "S" (&pci_indirect),
34566 + "r" (__PCIBIOS_DS));
34567 break;
34568 }
34569
34570 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34571
34572 switch (len) {
34573 case 1:
34574 - __asm__("lcall *(%%esi); cld\n\t"
34575 + __asm__("movw %w6, %%ds\n\t"
34576 + "lcall *%%ss:(%%esi); cld\n\t"
34577 + "push %%ss\n\t"
34578 + "pop %%ds\n\t"
34579 "jc 1f\n\t"
34580 "xor %%ah, %%ah\n"
34581 "1:"
34582 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34583 "c" (value),
34584 "b" (bx),
34585 "D" ((long)reg),
34586 - "S" (&pci_indirect));
34587 + "S" (&pci_indirect),
34588 + "r" (__PCIBIOS_DS));
34589 break;
34590 case 2:
34591 - __asm__("lcall *(%%esi); cld\n\t"
34592 + __asm__("movw %w6, %%ds\n\t"
34593 + "lcall *%%ss:(%%esi); cld\n\t"
34594 + "push %%ss\n\t"
34595 + "pop %%ds\n\t"
34596 "jc 1f\n\t"
34597 "xor %%ah, %%ah\n"
34598 "1:"
34599 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34600 "c" (value),
34601 "b" (bx),
34602 "D" ((long)reg),
34603 - "S" (&pci_indirect));
34604 + "S" (&pci_indirect),
34605 + "r" (__PCIBIOS_DS));
34606 break;
34607 case 4:
34608 - __asm__("lcall *(%%esi); cld\n\t"
34609 + __asm__("movw %w6, %%ds\n\t"
34610 + "lcall *%%ss:(%%esi); cld\n\t"
34611 + "push %%ss\n\t"
34612 + "pop %%ds\n\t"
34613 "jc 1f\n\t"
34614 "xor %%ah, %%ah\n"
34615 "1:"
34616 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34617 "c" (value),
34618 "b" (bx),
34619 "D" ((long)reg),
34620 - "S" (&pci_indirect));
34621 + "S" (&pci_indirect),
34622 + "r" (__PCIBIOS_DS));
34623 break;
34624 }
34625
34626 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34627
34628 DBG("PCI: Fetching IRQ routing table... ");
34629 __asm__("push %%es\n\t"
34630 + "movw %w8, %%ds\n\t"
34631 "push %%ds\n\t"
34632 "pop %%es\n\t"
34633 - "lcall *(%%esi); cld\n\t"
34634 + "lcall *%%ss:(%%esi); cld\n\t"
34635 "pop %%es\n\t"
34636 + "push %%ss\n\t"
34637 + "pop %%ds\n"
34638 "jc 1f\n\t"
34639 "xor %%ah, %%ah\n"
34640 "1:"
34641 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34642 "1" (0),
34643 "D" ((long) &opt),
34644 "S" (&pci_indirect),
34645 - "m" (opt)
34646 + "m" (opt),
34647 + "r" (__PCIBIOS_DS)
34648 : "memory");
34649 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
34650 if (ret & 0xff00)
34651 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34652 {
34653 int ret;
34654
34655 - __asm__("lcall *(%%esi); cld\n\t"
34656 + __asm__("movw %w5, %%ds\n\t"
34657 + "lcall *%%ss:(%%esi); cld\n\t"
34658 + "push %%ss\n\t"
34659 + "pop %%ds\n"
34660 "jc 1f\n\t"
34661 "xor %%ah, %%ah\n"
34662 "1:"
34663 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34664 : "0" (PCIBIOS_SET_PCI_HW_INT),
34665 "b" ((dev->bus->number << 8) | dev->devfn),
34666 "c" ((irq << 8) | (pin + 10)),
34667 - "S" (&pci_indirect));
34668 + "S" (&pci_indirect),
34669 + "r" (__PCIBIOS_DS));
34670 return !(ret & 0xff00);
34671 }
34672 EXPORT_SYMBOL(pcibios_set_irq_routing);
34673 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
34674 index 9ee3491..872192f 100644
34675 --- a/arch/x86/platform/efi/efi_32.c
34676 +++ b/arch/x86/platform/efi/efi_32.c
34677 @@ -59,11 +59,22 @@ void efi_call_phys_prelog(void)
34678 {
34679 struct desc_ptr gdt_descr;
34680
34681 +#ifdef CONFIG_PAX_KERNEXEC
34682 + struct desc_struct d;
34683 +#endif
34684 +
34685 local_irq_save(efi_rt_eflags);
34686
34687 load_cr3(initial_page_table);
34688 __flush_tlb_all();
34689
34690 +#ifdef CONFIG_PAX_KERNEXEC
34691 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
34692 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34693 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
34694 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34695 +#endif
34696 +
34697 gdt_descr.address = __pa(get_cpu_gdt_table(0));
34698 gdt_descr.size = GDT_SIZE - 1;
34699 load_gdt(&gdt_descr);
34700 @@ -73,11 +84,24 @@ void efi_call_phys_epilog(void)
34701 {
34702 struct desc_ptr gdt_descr;
34703
34704 +#ifdef CONFIG_PAX_KERNEXEC
34705 + struct desc_struct d;
34706 +
34707 + memset(&d, 0, sizeof d);
34708 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34709 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34710 +#endif
34711 +
34712 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
34713 gdt_descr.size = GDT_SIZE - 1;
34714 load_gdt(&gdt_descr);
34715
34716 +#ifdef CONFIG_PAX_PER_CPU_PGD
34717 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34718 +#else
34719 load_cr3(swapper_pg_dir);
34720 +#endif
34721 +
34722 __flush_tlb_all();
34723
34724 local_irq_restore(efi_rt_eflags);
34725 diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
34726 index 290d397..3906bcd 100644
34727 --- a/arch/x86/platform/efi/efi_64.c
34728 +++ b/arch/x86/platform/efi/efi_64.c
34729 @@ -99,6 +99,11 @@ void __init efi_call_phys_prelog(void)
34730 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
34731 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
34732 }
34733 +
34734 +#ifdef CONFIG_PAX_PER_CPU_PGD
34735 + load_cr3(swapper_pg_dir);
34736 +#endif
34737 +
34738 __flush_tlb_all();
34739 }
34740
34741 @@ -116,6 +121,11 @@ void __init efi_call_phys_epilog(void)
34742 for (pgd = 0; pgd < n_pgds; pgd++)
34743 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
34744 kfree(save_pgd);
34745 +
34746 +#ifdef CONFIG_PAX_PER_CPU_PGD
34747 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34748 +#endif
34749 +
34750 __flush_tlb_all();
34751 local_irq_restore(efi_flags);
34752 early_code_mapping_set_exec(0);
34753 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
34754 index fbe66e6..eae5e38 100644
34755 --- a/arch/x86/platform/efi/efi_stub_32.S
34756 +++ b/arch/x86/platform/efi/efi_stub_32.S
34757 @@ -6,7 +6,9 @@
34758 */
34759
34760 #include <linux/linkage.h>
34761 +#include <linux/init.h>
34762 #include <asm/page_types.h>
34763 +#include <asm/segment.h>
34764
34765 /*
34766 * efi_call_phys(void *, ...) is a function with variable parameters.
34767 @@ -20,7 +22,7 @@
34768 * service functions will comply with gcc calling convention, too.
34769 */
34770
34771 -.text
34772 +__INIT
34773 ENTRY(efi_call_phys)
34774 /*
34775 * 0. The function can only be called in Linux kernel. So CS has been
34776 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
34777 * The mapping of lower virtual memory has been created in prelog and
34778 * epilog.
34779 */
34780 - movl $1f, %edx
34781 - subl $__PAGE_OFFSET, %edx
34782 - jmp *%edx
34783 +#ifdef CONFIG_PAX_KERNEXEC
34784 + movl $(__KERNEXEC_EFI_DS), %edx
34785 + mov %edx, %ds
34786 + mov %edx, %es
34787 + mov %edx, %ss
34788 + addl $2f,(1f)
34789 + ljmp *(1f)
34790 +
34791 +__INITDATA
34792 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
34793 +.previous
34794 +
34795 +2:
34796 + subl $2b,(1b)
34797 +#else
34798 + jmp 1f-__PAGE_OFFSET
34799 1:
34800 +#endif
34801
34802 /*
34803 * 2. Now on the top of stack is the return
34804 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
34805 * parameter 2, ..., param n. To make things easy, we save the return
34806 * address of efi_call_phys in a global variable.
34807 */
34808 - popl %edx
34809 - movl %edx, saved_return_addr
34810 - /* get the function pointer into ECX*/
34811 - popl %ecx
34812 - movl %ecx, efi_rt_function_ptr
34813 - movl $2f, %edx
34814 - subl $__PAGE_OFFSET, %edx
34815 - pushl %edx
34816 + popl (saved_return_addr)
34817 + popl (efi_rt_function_ptr)
34818
34819 /*
34820 * 3. Clear PG bit in %CR0.
34821 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
34822 /*
34823 * 5. Call the physical function.
34824 */
34825 - jmp *%ecx
34826 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
34827
34828 -2:
34829 /*
34830 * 6. After EFI runtime service returns, control will return to
34831 * following instruction. We'd better readjust stack pointer first.
34832 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
34833 movl %cr0, %edx
34834 orl $0x80000000, %edx
34835 movl %edx, %cr0
34836 - jmp 1f
34837 -1:
34838 +
34839 /*
34840 * 8. Now restore the virtual mode from flat mode by
34841 * adding EIP with PAGE_OFFSET.
34842 */
34843 - movl $1f, %edx
34844 - jmp *%edx
34845 +#ifdef CONFIG_PAX_KERNEXEC
34846 + movl $(__KERNEL_DS), %edx
34847 + mov %edx, %ds
34848 + mov %edx, %es
34849 + mov %edx, %ss
34850 + ljmp $(__KERNEL_CS),$1f
34851 +#else
34852 + jmp 1f+__PAGE_OFFSET
34853 +#endif
34854 1:
34855
34856 /*
34857 * 9. Balance the stack. And because EAX contain the return value,
34858 * we'd better not clobber it.
34859 */
34860 - leal efi_rt_function_ptr, %edx
34861 - movl (%edx), %ecx
34862 - pushl %ecx
34863 + pushl (efi_rt_function_ptr)
34864
34865 /*
34866 - * 10. Push the saved return address onto the stack and return.
34867 + * 10. Return to the saved return address.
34868 */
34869 - leal saved_return_addr, %edx
34870 - movl (%edx), %ecx
34871 - pushl %ecx
34872 - ret
34873 + jmpl *(saved_return_addr)
34874 ENDPROC(efi_call_phys)
34875 .previous
34876
34877 -.data
34878 +__INITDATA
34879 saved_return_addr:
34880 .long 0
34881 efi_rt_function_ptr:
34882 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
34883 index e0984ef..a062dac 100644
34884 --- a/arch/x86/platform/efi/efi_stub_64.S
34885 +++ b/arch/x86/platform/efi/efi_stub_64.S
34886 @@ -11,6 +11,7 @@
34887 #include <asm/msr.h>
34888 #include <asm/processor-flags.h>
34889 #include <asm/page_types.h>
34890 +#include <asm/alternative-asm.h>
34891
34892 #define SAVE_XMM \
34893 mov %rsp, %rax; \
34894 @@ -81,6 +82,7 @@ ENTRY(efi_call0)
34895 RESTORE_PGT
34896 addq $32, %rsp
34897 RESTORE_XMM
34898 + pax_force_retaddr 0, 1
34899 ret
34900 ENDPROC(efi_call0)
34901
34902 @@ -93,6 +95,7 @@ ENTRY(efi_call1)
34903 RESTORE_PGT
34904 addq $32, %rsp
34905 RESTORE_XMM
34906 + pax_force_retaddr 0, 1
34907 ret
34908 ENDPROC(efi_call1)
34909
34910 @@ -105,6 +108,7 @@ ENTRY(efi_call2)
34911 RESTORE_PGT
34912 addq $32, %rsp
34913 RESTORE_XMM
34914 + pax_force_retaddr 0, 1
34915 ret
34916 ENDPROC(efi_call2)
34917
34918 @@ -118,6 +122,7 @@ ENTRY(efi_call3)
34919 RESTORE_PGT
34920 addq $32, %rsp
34921 RESTORE_XMM
34922 + pax_force_retaddr 0, 1
34923 ret
34924 ENDPROC(efi_call3)
34925
34926 @@ -132,6 +137,7 @@ ENTRY(efi_call4)
34927 RESTORE_PGT
34928 addq $32, %rsp
34929 RESTORE_XMM
34930 + pax_force_retaddr 0, 1
34931 ret
34932 ENDPROC(efi_call4)
34933
34934 @@ -147,6 +153,7 @@ ENTRY(efi_call5)
34935 RESTORE_PGT
34936 addq $48, %rsp
34937 RESTORE_XMM
34938 + pax_force_retaddr 0, 1
34939 ret
34940 ENDPROC(efi_call5)
34941
34942 @@ -165,6 +172,7 @@ ENTRY(efi_call6)
34943 RESTORE_PGT
34944 addq $48, %rsp
34945 RESTORE_XMM
34946 + pax_force_retaddr 0, 1
34947 ret
34948 ENDPROC(efi_call6)
34949
34950 diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
34951 index 1bbedc4..eb795b5 100644
34952 --- a/arch/x86/platform/intel-mid/intel-mid.c
34953 +++ b/arch/x86/platform/intel-mid/intel-mid.c
34954 @@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
34955 {
34956 };
34957
34958 -static void intel_mid_reboot(void)
34959 +static void __noreturn intel_mid_reboot(void)
34960 {
34961 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
34962 + BUG();
34963 }
34964
34965 static unsigned long __init intel_mid_calibrate_tsc(void)
34966 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
34967 index d6ee929..3637cb5 100644
34968 --- a/arch/x86/platform/olpc/olpc_dt.c
34969 +++ b/arch/x86/platform/olpc/olpc_dt.c
34970 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
34971 return res;
34972 }
34973
34974 -static struct of_pdt_ops prom_olpc_ops __initdata = {
34975 +static struct of_pdt_ops prom_olpc_ops __initconst = {
34976 .nextprop = olpc_dt_nextprop,
34977 .getproplen = olpc_dt_getproplen,
34978 .getproperty = olpc_dt_getproperty,
34979 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
34980 index 424f4c9..f2a2988 100644
34981 --- a/arch/x86/power/cpu.c
34982 +++ b/arch/x86/power/cpu.c
34983 @@ -137,11 +137,8 @@ static void do_fpu_end(void)
34984 static void fix_processor_context(void)
34985 {
34986 int cpu = smp_processor_id();
34987 - struct tss_struct *t = &per_cpu(init_tss, cpu);
34988 -#ifdef CONFIG_X86_64
34989 - struct desc_struct *desc = get_cpu_gdt_table(cpu);
34990 - tss_desc tss;
34991 -#endif
34992 + struct tss_struct *t = init_tss + cpu;
34993 +
34994 set_tss_desc(cpu, t); /*
34995 * This just modifies memory; should not be
34996 * necessary. But... This is necessary, because
34997 @@ -150,10 +147,6 @@ static void fix_processor_context(void)
34998 */
34999
35000 #ifdef CONFIG_X86_64
35001 - memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
35002 - tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
35003 - write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
35004 -
35005 syscall_init(); /* This sets MSR_*STAR and related */
35006 #endif
35007 load_TR_desc(); /* This does ltr */
35008 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
35009 index bad628a..a102610 100644
35010 --- a/arch/x86/realmode/init.c
35011 +++ b/arch/x86/realmode/init.c
35012 @@ -68,7 +68,13 @@ void __init setup_real_mode(void)
35013 __va(real_mode_header->trampoline_header);
35014
35015 #ifdef CONFIG_X86_32
35016 - trampoline_header->start = __pa_symbol(startup_32_smp);
35017 + trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
35018 +
35019 +#ifdef CONFIG_PAX_KERNEXEC
35020 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
35021 +#endif
35022 +
35023 + trampoline_header->boot_cs = __BOOT_CS;
35024 trampoline_header->gdt_limit = __BOOT_DS + 7;
35025 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
35026 #else
35027 @@ -84,7 +90,7 @@ void __init setup_real_mode(void)
35028 *trampoline_cr4_features = read_cr4();
35029
35030 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
35031 - trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
35032 + trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
35033 trampoline_pgd[511] = init_level4_pgt[511].pgd;
35034 #endif
35035 }
35036 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
35037 index 3497f14..cc73b92 100644
35038 --- a/arch/x86/realmode/rm/Makefile
35039 +++ b/arch/x86/realmode/rm/Makefile
35040 @@ -66,5 +66,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
35041
35042 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
35043 -I$(srctree)/arch/x86/boot
35044 +ifdef CONSTIFY_PLUGIN
35045 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
35046 +endif
35047 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
35048 GCOV_PROFILE := n
35049 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
35050 index a28221d..93c40f1 100644
35051 --- a/arch/x86/realmode/rm/header.S
35052 +++ b/arch/x86/realmode/rm/header.S
35053 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
35054 #endif
35055 /* APM/BIOS reboot */
35056 .long pa_machine_real_restart_asm
35057 -#ifdef CONFIG_X86_64
35058 +#ifdef CONFIG_X86_32
35059 + .long __KERNEL_CS
35060 +#else
35061 .long __KERNEL32_CS
35062 #endif
35063 END(real_mode_header)
35064 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
35065 index 48ddd76..c26749f 100644
35066 --- a/arch/x86/realmode/rm/trampoline_32.S
35067 +++ b/arch/x86/realmode/rm/trampoline_32.S
35068 @@ -24,6 +24,12 @@
35069 #include <asm/page_types.h>
35070 #include "realmode.h"
35071
35072 +#ifdef CONFIG_PAX_KERNEXEC
35073 +#define ta(X) (X)
35074 +#else
35075 +#define ta(X) (pa_ ## X)
35076 +#endif
35077 +
35078 .text
35079 .code16
35080
35081 @@ -38,8 +44,6 @@ ENTRY(trampoline_start)
35082
35083 cli # We should be safe anyway
35084
35085 - movl tr_start, %eax # where we need to go
35086 -
35087 movl $0xA5A5A5A5, trampoline_status
35088 # write marker for master knows we're running
35089
35090 @@ -55,7 +59,7 @@ ENTRY(trampoline_start)
35091 movw $1, %dx # protected mode (PE) bit
35092 lmsw %dx # into protected mode
35093
35094 - ljmpl $__BOOT_CS, $pa_startup_32
35095 + ljmpl *(trampoline_header)
35096
35097 .section ".text32","ax"
35098 .code32
35099 @@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
35100 .balign 8
35101 GLOBAL(trampoline_header)
35102 tr_start: .space 4
35103 - tr_gdt_pad: .space 2
35104 + tr_boot_cs: .space 2
35105 tr_gdt: .space 6
35106 END(trampoline_header)
35107
35108 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
35109 index dac7b20..72dbaca 100644
35110 --- a/arch/x86/realmode/rm/trampoline_64.S
35111 +++ b/arch/x86/realmode/rm/trampoline_64.S
35112 @@ -93,6 +93,7 @@ ENTRY(startup_32)
35113 movl %edx, %gs
35114
35115 movl pa_tr_cr4, %eax
35116 + andl $~X86_CR4_PCIDE, %eax
35117 movl %eax, %cr4 # Enable PAE mode
35118
35119 # Setup trampoline 4 level pagetables
35120 @@ -106,7 +107,7 @@ ENTRY(startup_32)
35121 wrmsr
35122
35123 # Enable paging and in turn activate Long Mode
35124 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
35125 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
35126 movl %eax, %cr0
35127
35128 /*
35129 diff --git a/arch/x86/realmode/rm/wakeup_asm.S b/arch/x86/realmode/rm/wakeup_asm.S
35130 index 9e7e147..25a4158 100644
35131 --- a/arch/x86/realmode/rm/wakeup_asm.S
35132 +++ b/arch/x86/realmode/rm/wakeup_asm.S
35133 @@ -126,11 +126,10 @@ ENTRY(wakeup_start)
35134 lgdtl pmode_gdt
35135
35136 /* This really couldn't... */
35137 - movl pmode_entry, %eax
35138 movl pmode_cr0, %ecx
35139 movl %ecx, %cr0
35140 - ljmpl $__KERNEL_CS, $pa_startup_32
35141 - /* -> jmp *%eax in trampoline_32.S */
35142 +
35143 + ljmpl *pmode_entry
35144 #else
35145 jmp trampoline_start
35146 #endif
35147 diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
35148 index 604a37e..e49702a 100644
35149 --- a/arch/x86/tools/Makefile
35150 +++ b/arch/x86/tools/Makefile
35151 @@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
35152
35153 $(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
35154
35155 -HOST_EXTRACFLAGS += -I$(srctree)/tools/include
35156 +HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
35157 hostprogs-y += relocs
35158 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
35159 PHONY += relocs
35160 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
35161 index bbb1d22..e505211 100644
35162 --- a/arch/x86/tools/relocs.c
35163 +++ b/arch/x86/tools/relocs.c
35164 @@ -1,5 +1,7 @@
35165 /* This is included from relocs_32/64.c */
35166
35167 +#include "../../../include/generated/autoconf.h"
35168 +
35169 #define ElfW(type) _ElfW(ELF_BITS, type)
35170 #define _ElfW(bits, type) __ElfW(bits, type)
35171 #define __ElfW(bits, type) Elf##bits##_##type
35172 @@ -11,6 +13,7 @@
35173 #define Elf_Sym ElfW(Sym)
35174
35175 static Elf_Ehdr ehdr;
35176 +static Elf_Phdr *phdr;
35177
35178 struct relocs {
35179 uint32_t *offset;
35180 @@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
35181 }
35182 }
35183
35184 +static void read_phdrs(FILE *fp)
35185 +{
35186 + unsigned int i;
35187 +
35188 + phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
35189 + if (!phdr) {
35190 + die("Unable to allocate %d program headers\n",
35191 + ehdr.e_phnum);
35192 + }
35193 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
35194 + die("Seek to %d failed: %s\n",
35195 + ehdr.e_phoff, strerror(errno));
35196 + }
35197 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
35198 + die("Cannot read ELF program headers: %s\n",
35199 + strerror(errno));
35200 + }
35201 + for(i = 0; i < ehdr.e_phnum; i++) {
35202 + phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
35203 + phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
35204 + phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
35205 + phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
35206 + phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
35207 + phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
35208 + phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
35209 + phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
35210 + }
35211 +
35212 +}
35213 +
35214 static void read_shdrs(FILE *fp)
35215 {
35216 - int i;
35217 + unsigned int i;
35218 Elf_Shdr shdr;
35219
35220 secs = calloc(ehdr.e_shnum, sizeof(struct section));
35221 @@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
35222
35223 static void read_strtabs(FILE *fp)
35224 {
35225 - int i;
35226 + unsigned int i;
35227 for (i = 0; i < ehdr.e_shnum; i++) {
35228 struct section *sec = &secs[i];
35229 if (sec->shdr.sh_type != SHT_STRTAB) {
35230 @@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
35231
35232 static void read_symtabs(FILE *fp)
35233 {
35234 - int i,j;
35235 + unsigned int i,j;
35236 for (i = 0; i < ehdr.e_shnum; i++) {
35237 struct section *sec = &secs[i];
35238 if (sec->shdr.sh_type != SHT_SYMTAB) {
35239 @@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
35240 }
35241
35242
35243 -static void read_relocs(FILE *fp)
35244 +static void read_relocs(FILE *fp, int use_real_mode)
35245 {
35246 - int i,j;
35247 + unsigned int i,j;
35248 + uint32_t base;
35249 +
35250 for (i = 0; i < ehdr.e_shnum; i++) {
35251 struct section *sec = &secs[i];
35252 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35253 @@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
35254 die("Cannot read symbol table: %s\n",
35255 strerror(errno));
35256 }
35257 + base = 0;
35258 +
35259 +#ifdef CONFIG_X86_32
35260 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
35261 + if (phdr[j].p_type != PT_LOAD )
35262 + continue;
35263 + 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)
35264 + continue;
35265 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
35266 + break;
35267 + }
35268 +#endif
35269 +
35270 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
35271 Elf_Rel *rel = &sec->reltab[j];
35272 - rel->r_offset = elf_addr_to_cpu(rel->r_offset);
35273 + rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
35274 rel->r_info = elf_xword_to_cpu(rel->r_info);
35275 #if (SHT_REL_TYPE == SHT_RELA)
35276 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
35277 @@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
35278
35279 static void print_absolute_symbols(void)
35280 {
35281 - int i;
35282 + unsigned int i;
35283 const char *format;
35284
35285 if (ELF_BITS == 64)
35286 @@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
35287 for (i = 0; i < ehdr.e_shnum; i++) {
35288 struct section *sec = &secs[i];
35289 char *sym_strtab;
35290 - int j;
35291 + unsigned int j;
35292
35293 if (sec->shdr.sh_type != SHT_SYMTAB) {
35294 continue;
35295 @@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
35296
35297 static void print_absolute_relocs(void)
35298 {
35299 - int i, printed = 0;
35300 + unsigned int i, printed = 0;
35301 const char *format;
35302
35303 if (ELF_BITS == 64)
35304 @@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
35305 struct section *sec_applies, *sec_symtab;
35306 char *sym_strtab;
35307 Elf_Sym *sh_symtab;
35308 - int j;
35309 + unsigned int j;
35310 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35311 continue;
35312 }
35313 @@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
35314 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
35315 Elf_Sym *sym, const char *symname))
35316 {
35317 - int i;
35318 + unsigned int i;
35319 /* Walk through the relocations */
35320 for (i = 0; i < ehdr.e_shnum; i++) {
35321 char *sym_strtab;
35322 Elf_Sym *sh_symtab;
35323 struct section *sec_applies, *sec_symtab;
35324 - int j;
35325 + unsigned int j;
35326 struct section *sec = &secs[i];
35327
35328 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35329 @@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35330 {
35331 unsigned r_type = ELF32_R_TYPE(rel->r_info);
35332 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
35333 + char *sym_strtab = sec->link->link->strtab;
35334 +
35335 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
35336 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
35337 + return 0;
35338 +
35339 +#ifdef CONFIG_PAX_KERNEXEC
35340 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
35341 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
35342 + return 0;
35343 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
35344 + return 0;
35345 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
35346 + return 0;
35347 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
35348 + return 0;
35349 +#endif
35350
35351 switch (r_type) {
35352 case R_386_NONE:
35353 @@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
35354
35355 static void emit_relocs(int as_text, int use_real_mode)
35356 {
35357 - int i;
35358 + unsigned int i;
35359 int (*write_reloc)(uint32_t, FILE *) = write32;
35360 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35361 const char *symname);
35362 @@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
35363 {
35364 regex_init(use_real_mode);
35365 read_ehdr(fp);
35366 + read_phdrs(fp);
35367 read_shdrs(fp);
35368 read_strtabs(fp);
35369 read_symtabs(fp);
35370 - read_relocs(fp);
35371 + read_relocs(fp, use_real_mode);
35372 if (ELF_BITS == 64)
35373 percpu_init();
35374 if (show_absolute_syms) {
35375 diff --git a/arch/x86/um/mem_32.c b/arch/x86/um/mem_32.c
35376 index f40281e..92728c9 100644
35377 --- a/arch/x86/um/mem_32.c
35378 +++ b/arch/x86/um/mem_32.c
35379 @@ -21,7 +21,7 @@ static int __init gate_vma_init(void)
35380 gate_vma.vm_start = FIXADDR_USER_START;
35381 gate_vma.vm_end = FIXADDR_USER_END;
35382 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
35383 - gate_vma.vm_page_prot = __P101;
35384 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
35385
35386 return 0;
35387 }
35388 diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
35389 index 80ffa5b..a33bd15 100644
35390 --- a/arch/x86/um/tls_32.c
35391 +++ b/arch/x86/um/tls_32.c
35392 @@ -260,7 +260,7 @@ out:
35393 if (unlikely(task == current &&
35394 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
35395 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
35396 - "without flushed TLS.", current->pid);
35397 + "without flushed TLS.", task_pid_nr(current));
35398 }
35399
35400 return 0;
35401 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
35402 index c580d12..0a0ba35 100644
35403 --- a/arch/x86/vdso/Makefile
35404 +++ b/arch/x86/vdso/Makefile
35405 @@ -196,7 +196,7 @@ quiet_cmd_vdso = VDSO $@
35406 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
35407 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
35408
35409 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
35410 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
35411 $(LTO_CFLAGS)
35412 GCOV_PROFILE := n
35413
35414 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
35415 index 3adf2e6..a0b5576 100644
35416 --- a/arch/x86/vdso/vdso32-setup.c
35417 +++ b/arch/x86/vdso/vdso32-setup.c
35418 @@ -29,6 +29,7 @@
35419 #include <asm/fixmap.h>
35420 #include <asm/hpet.h>
35421 #include <asm/vvar.h>
35422 +#include <asm/mman.h>
35423
35424 #ifdef CONFIG_COMPAT_VDSO
35425 #define VDSO_DEFAULT 0
35426 @@ -98,7 +99,7 @@ void syscall32_cpu_init(void)
35427 void enable_sep_cpu(void)
35428 {
35429 int cpu = get_cpu();
35430 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
35431 + struct tss_struct *tss = init_tss + cpu;
35432
35433 if (!boot_cpu_has(X86_FEATURE_SEP)) {
35434 put_cpu();
35435 @@ -166,7 +167,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35436
35437 down_write(&mm->mmap_sem);
35438
35439 - addr = get_unmapped_area(NULL, 0, vdso32_size + VDSO_OFFSET(VDSO_PREV_PAGES), 0, 0);
35440 + addr = get_unmapped_area(NULL, 0, vdso32_size + VDSO_OFFSET(VDSO_PREV_PAGES), 0, MAP_EXECUTABLE);
35441 if (IS_ERR_VALUE(addr)) {
35442 ret = addr;
35443 goto up_fail;
35444 @@ -174,7 +175,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35445
35446 addr += VDSO_OFFSET(VDSO_PREV_PAGES);
35447
35448 - current->mm->context.vdso = (void *)addr;
35449 + current->mm->context.vdso = addr;
35450
35451 /*
35452 * MAYWRITE to allow gdb to COW and set breakpoints
35453 @@ -223,11 +224,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35454 #endif
35455
35456 current_thread_info()->sysenter_return =
35457 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35458 + (void __force_user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35459
35460 up_fail:
35461 if (ret)
35462 - current->mm->context.vdso = NULL;
35463 + current->mm->context.vdso = 0;
35464
35465 up_write(&mm->mmap_sem);
35466
35467 @@ -274,8 +275,14 @@ __initcall(ia32_binfmt_init);
35468
35469 const char *arch_vma_name(struct vm_area_struct *vma)
35470 {
35471 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
35472 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
35473 return "[vdso]";
35474 +
35475 +#ifdef CONFIG_PAX_SEGMEXEC
35476 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
35477 + return "[vdso]";
35478 +#endif
35479 +
35480 return NULL;
35481 }
35482
35483 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
35484 index 1ad1026..1a08abe 100644
35485 --- a/arch/x86/vdso/vma.c
35486 +++ b/arch/x86/vdso/vma.c
35487 @@ -17,8 +17,6 @@
35488 #include <asm/page.h>
35489
35490 #if defined(CONFIG_X86_64)
35491 -unsigned int __read_mostly vdso_enabled = 1;
35492 -
35493 DECLARE_VDSO_IMAGE(vdso);
35494 extern unsigned short vdso_sync_cpuid;
35495 static unsigned vdso_size;
35496 @@ -144,7 +142,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
35497 * unaligned here as a result of stack start randomization.
35498 */
35499 addr = PAGE_ALIGN(addr);
35500 - addr = align_vdso_addr(addr);
35501
35502 return addr;
35503 }
35504 @@ -157,30 +154,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
35505 unsigned size)
35506 {
35507 struct mm_struct *mm = current->mm;
35508 - unsigned long addr;
35509 + unsigned long addr = 0;
35510 int ret;
35511
35512 - if (!vdso_enabled)
35513 - return 0;
35514 -
35515 down_write(&mm->mmap_sem);
35516 +
35517 +#ifdef CONFIG_PAX_RANDMMAP
35518 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
35519 +#endif
35520 +
35521 addr = vdso_addr(mm->start_stack, size);
35522 + addr = align_vdso_addr(addr);
35523 addr = get_unmapped_area(NULL, addr, size, 0, 0);
35524 if (IS_ERR_VALUE(addr)) {
35525 ret = addr;
35526 goto up_fail;
35527 }
35528
35529 - current->mm->context.vdso = (void *)addr;
35530 + mm->context.vdso = addr;
35531
35532 ret = install_special_mapping(mm, addr, size,
35533 VM_READ|VM_EXEC|
35534 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
35535 pages);
35536 - if (ret) {
35537 - current->mm->context.vdso = NULL;
35538 - goto up_fail;
35539 - }
35540 + if (ret)
35541 + mm->context.vdso = 0;
35542
35543 up_fail:
35544 up_write(&mm->mmap_sem);
35545 @@ -200,11 +198,4 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35546 vdsox32_size);
35547 }
35548 #endif
35549 -
35550 -static __init int vdso_setup(char *s)
35551 -{
35552 - vdso_enabled = simple_strtoul(s, NULL, 0);
35553 - return 0;
35554 -}
35555 -__setup("vdso=", vdso_setup);
35556 #endif
35557 diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
35558 index e88fda8..76ce7ce 100644
35559 --- a/arch/x86/xen/Kconfig
35560 +++ b/arch/x86/xen/Kconfig
35561 @@ -9,6 +9,7 @@ config XEN
35562 select XEN_HAVE_PVMMU
35563 depends on X86_64 || (X86_32 && X86_PAE)
35564 depends on X86_TSC
35565 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
35566 help
35567 This is the Linux Xen port. Enabling this will allow the
35568 kernel to boot in a paravirtualized environment under the
35569 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
35570 index c34bfc4..e599673 100644
35571 --- a/arch/x86/xen/enlighten.c
35572 +++ b/arch/x86/xen/enlighten.c
35573 @@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
35574
35575 struct shared_info xen_dummy_shared_info;
35576
35577 -void *xen_initial_gdt;
35578 -
35579 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
35580 __read_mostly int xen_have_vector_callback;
35581 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
35582 @@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
35583 {
35584 unsigned long va = dtr->address;
35585 unsigned int size = dtr->size + 1;
35586 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35587 - unsigned long frames[pages];
35588 + unsigned long frames[65536 / PAGE_SIZE];
35589 int f;
35590
35591 /*
35592 @@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35593 {
35594 unsigned long va = dtr->address;
35595 unsigned int size = dtr->size + 1;
35596 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35597 - unsigned long frames[pages];
35598 + unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
35599 int f;
35600
35601 /*
35602 @@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35603 * 8-byte entries, or 16 4k pages..
35604 */
35605
35606 - BUG_ON(size > 65536);
35607 + BUG_ON(size > GDT_SIZE);
35608 BUG_ON(va & ~PAGE_MASK);
35609
35610 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
35611 @@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
35612 return 0;
35613 }
35614
35615 -static void set_xen_basic_apic_ops(void)
35616 +static void __init set_xen_basic_apic_ops(void)
35617 {
35618 apic->read = xen_apic_read;
35619 apic->write = xen_apic_write;
35620 @@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
35621 #endif
35622 };
35623
35624 -static void xen_reboot(int reason)
35625 +static __noreturn void xen_reboot(int reason)
35626 {
35627 struct sched_shutdown r = { .reason = reason };
35628
35629 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
35630 - BUG();
35631 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
35632 + BUG();
35633 }
35634
35635 -static void xen_restart(char *msg)
35636 +static __noreturn void xen_restart(char *msg)
35637 {
35638 xen_reboot(SHUTDOWN_reboot);
35639 }
35640
35641 -static void xen_emergency_restart(void)
35642 +static __noreturn void xen_emergency_restart(void)
35643 {
35644 xen_reboot(SHUTDOWN_reboot);
35645 }
35646
35647 -static void xen_machine_halt(void)
35648 +static __noreturn void xen_machine_halt(void)
35649 {
35650 xen_reboot(SHUTDOWN_poweroff);
35651 }
35652
35653 -static void xen_machine_power_off(void)
35654 +static __noreturn void xen_machine_power_off(void)
35655 {
35656 if (pm_power_off)
35657 pm_power_off();
35658 @@ -1564,7 +1560,17 @@ asmlinkage __visible void __init xen_start_kernel(void)
35659 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
35660
35661 /* Work out if we support NX */
35662 - x86_configure_nx();
35663 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
35664 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
35665 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
35666 + unsigned l, h;
35667 +
35668 + __supported_pte_mask |= _PAGE_NX;
35669 + rdmsr(MSR_EFER, l, h);
35670 + l |= EFER_NX;
35671 + wrmsr(MSR_EFER, l, h);
35672 + }
35673 +#endif
35674
35675 /* Get mfn list */
35676 xen_build_dynamic_phys_to_machine();
35677 @@ -1592,13 +1598,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
35678
35679 machine_ops = xen_machine_ops;
35680
35681 - /*
35682 - * The only reliable way to retain the initial address of the
35683 - * percpu gdt_page is to remember it here, so we can go and
35684 - * mark it RW later, when the initial percpu area is freed.
35685 - */
35686 - xen_initial_gdt = &per_cpu(gdt_page, 0);
35687 -
35688 xen_smp_init();
35689
35690 #ifdef CONFIG_ACPI_NUMA
35691 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
35692 index 86e02ea..e3705ca 100644
35693 --- a/arch/x86/xen/mmu.c
35694 +++ b/arch/x86/xen/mmu.c
35695 @@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
35696 return val;
35697 }
35698
35699 -static pteval_t pte_pfn_to_mfn(pteval_t val)
35700 +static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
35701 {
35702 if (val & _PAGE_PRESENT) {
35703 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
35704 @@ -1904,6 +1904,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35705 /* L3_k[510] -> level2_kernel_pgt
35706 * L3_i[511] -> level2_fixmap_pgt */
35707 convert_pfn_mfn(level3_kernel_pgt);
35708 + convert_pfn_mfn(level3_vmalloc_start_pgt);
35709 + convert_pfn_mfn(level3_vmalloc_end_pgt);
35710 + convert_pfn_mfn(level3_vmemmap_pgt);
35711 }
35712 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
35713 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
35714 @@ -1933,8 +1936,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35715 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
35716 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
35717 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
35718 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
35719 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
35720 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
35721 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
35722 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
35723 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
35724 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
35725 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
35726
35727 @@ -2122,6 +2129,7 @@ static void __init xen_post_allocator_init(void)
35728 pv_mmu_ops.set_pud = xen_set_pud;
35729 #if PAGETABLE_LEVELS == 4
35730 pv_mmu_ops.set_pgd = xen_set_pgd;
35731 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
35732 #endif
35733
35734 /* This will work as long as patching hasn't happened yet
35735 @@ -2200,6 +2208,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
35736 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
35737 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
35738 .set_pgd = xen_set_pgd_hyper,
35739 + .set_pgd_batched = xen_set_pgd_hyper,
35740
35741 .alloc_pud = xen_alloc_pmd_init,
35742 .release_pud = xen_release_pmd_init,
35743 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
35744 index 7005974..54fb05f 100644
35745 --- a/arch/x86/xen/smp.c
35746 +++ b/arch/x86/xen/smp.c
35747 @@ -283,17 +283,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
35748
35749 if (xen_pv_domain()) {
35750 if (!xen_feature(XENFEAT_writable_page_tables))
35751 - /* We've switched to the "real" per-cpu gdt, so make
35752 - * sure the old memory can be recycled. */
35753 - make_lowmem_page_readwrite(xen_initial_gdt);
35754 -
35755 #ifdef CONFIG_X86_32
35756 /*
35757 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
35758 * expects __USER_DS
35759 */
35760 - loadsegment(ds, __USER_DS);
35761 - loadsegment(es, __USER_DS);
35762 + loadsegment(ds, __KERNEL_DS);
35763 + loadsegment(es, __KERNEL_DS);
35764 #endif
35765
35766 xen_filter_cpu_maps();
35767 @@ -372,7 +368,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35768 #ifdef CONFIG_X86_32
35769 /* Note: PVH is not yet supported on x86_32. */
35770 ctxt->user_regs.fs = __KERNEL_PERCPU;
35771 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
35772 + savesegment(gs, ctxt->user_regs.gs);
35773 #endif
35774 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
35775
35776 @@ -381,8 +377,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35777 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
35778 ctxt->flags = VGCF_IN_KERNEL;
35779 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
35780 - ctxt->user_regs.ds = __USER_DS;
35781 - ctxt->user_regs.es = __USER_DS;
35782 + ctxt->user_regs.ds = __KERNEL_DS;
35783 + ctxt->user_regs.es = __KERNEL_DS;
35784 ctxt->user_regs.ss = __KERNEL_DS;
35785
35786 xen_copy_trap_info(ctxt->trap_ctxt);
35787 @@ -437,14 +433,13 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
35788 int rc;
35789
35790 per_cpu(current_task, cpu) = idle;
35791 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
35792 #ifdef CONFIG_X86_32
35793 irq_ctx_init(cpu);
35794 #else
35795 clear_tsk_thread_flag(idle, TIF_FORK);
35796 #endif
35797 - per_cpu(kernel_stack, cpu) =
35798 - (unsigned long)task_stack_page(idle) -
35799 - KERNEL_STACK_OFFSET + THREAD_SIZE;
35800 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
35801
35802 xen_setup_runstate_info(cpu);
35803 xen_setup_timer(cpu);
35804 @@ -720,7 +715,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
35805
35806 void __init xen_smp_init(void)
35807 {
35808 - smp_ops = xen_smp_ops;
35809 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
35810 xen_fill_possible_map();
35811 }
35812
35813 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
35814 index fd92a64..1f72641 100644
35815 --- a/arch/x86/xen/xen-asm_32.S
35816 +++ b/arch/x86/xen/xen-asm_32.S
35817 @@ -99,7 +99,7 @@ ENTRY(xen_iret)
35818 pushw %fs
35819 movl $(__KERNEL_PERCPU), %eax
35820 movl %eax, %fs
35821 - movl %fs:xen_vcpu, %eax
35822 + mov PER_CPU_VAR(xen_vcpu), %eax
35823 POP_FS
35824 #else
35825 movl %ss:xen_vcpu, %eax
35826 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
35827 index 485b695..fda3e7c 100644
35828 --- a/arch/x86/xen/xen-head.S
35829 +++ b/arch/x86/xen/xen-head.S
35830 @@ -39,6 +39,17 @@ ENTRY(startup_xen)
35831 #ifdef CONFIG_X86_32
35832 mov %esi,xen_start_info
35833 mov $init_thread_union+THREAD_SIZE,%esp
35834 +#ifdef CONFIG_SMP
35835 + movl $cpu_gdt_table,%edi
35836 + movl $__per_cpu_load,%eax
35837 + movw %ax,__KERNEL_PERCPU + 2(%edi)
35838 + rorl $16,%eax
35839 + movb %al,__KERNEL_PERCPU + 4(%edi)
35840 + movb %ah,__KERNEL_PERCPU + 7(%edi)
35841 + movl $__per_cpu_end - 1,%eax
35842 + subl $__per_cpu_start,%eax
35843 + movw %ax,__KERNEL_PERCPU + 0(%edi)
35844 +#endif
35845 #else
35846 mov %rsi,xen_start_info
35847 mov $init_thread_union+THREAD_SIZE,%rsp
35848 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
35849 index 1cb6f4c..9981524 100644
35850 --- a/arch/x86/xen/xen-ops.h
35851 +++ b/arch/x86/xen/xen-ops.h
35852 @@ -10,8 +10,6 @@
35853 extern const char xen_hypervisor_callback[];
35854 extern const char xen_failsafe_callback[];
35855
35856 -extern void *xen_initial_gdt;
35857 -
35858 struct trap_info;
35859 void xen_copy_trap_info(struct trap_info *traps);
35860
35861 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
35862 index 525bd3d..ef888b1 100644
35863 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
35864 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
35865 @@ -119,9 +119,9 @@
35866 ----------------------------------------------------------------------*/
35867
35868 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
35869 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
35870 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
35871 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
35872 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35873
35874 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
35875 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
35876 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
35877 index 2f33760..835e50a 100644
35878 --- a/arch/xtensa/variants/fsf/include/variant/core.h
35879 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
35880 @@ -11,6 +11,7 @@
35881 #ifndef _XTENSA_CORE_H
35882 #define _XTENSA_CORE_H
35883
35884 +#include <linux/const.h>
35885
35886 /****************************************************************************
35887 Parameters Useful for Any Code, USER or PRIVILEGED
35888 @@ -112,9 +113,9 @@
35889 ----------------------------------------------------------------------*/
35890
35891 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35892 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35893 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35894 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35895 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35896
35897 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
35898 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
35899 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
35900 index af00795..2bb8105 100644
35901 --- a/arch/xtensa/variants/s6000/include/variant/core.h
35902 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
35903 @@ -11,6 +11,7 @@
35904 #ifndef _XTENSA_CORE_CONFIGURATION_H
35905 #define _XTENSA_CORE_CONFIGURATION_H
35906
35907 +#include <linux/const.h>
35908
35909 /****************************************************************************
35910 Parameters Useful for Any Code, USER or PRIVILEGED
35911 @@ -118,9 +119,9 @@
35912 ----------------------------------------------------------------------*/
35913
35914 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35915 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35916 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35917 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35918 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35919
35920 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
35921 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
35922 diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
35923 index f1e3803..05e2d06 100644
35924 --- a/block/blk-cgroup.c
35925 +++ b/block/blk-cgroup.c
35926 @@ -822,7 +822,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
35927 static struct cgroup_subsys_state *
35928 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35929 {
35930 - static atomic64_t id_seq = ATOMIC64_INIT(0);
35931 + static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
35932 struct blkcg *blkcg;
35933
35934 if (!parent_css) {
35935 @@ -836,7 +836,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35936
35937 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
35938 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
35939 - blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
35940 + blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
35941 done:
35942 spin_lock_init(&blkcg->lock);
35943 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
35944 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
35945 index c11d24e..e915d24 100644
35946 --- a/block/blk-iopoll.c
35947 +++ b/block/blk-iopoll.c
35948 @@ -74,7 +74,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
35949 }
35950 EXPORT_SYMBOL(blk_iopoll_complete);
35951
35952 -static void blk_iopoll_softirq(struct softirq_action *h)
35953 +static __latent_entropy void blk_iopoll_softirq(void)
35954 {
35955 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
35956 int rearm = 0, budget = blk_iopoll_budget;
35957 diff --git a/block/blk-map.c b/block/blk-map.c
35958 index f7b22bc..ec2ddf4 100644
35959 --- a/block/blk-map.c
35960 +++ b/block/blk-map.c
35961 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
35962 if (!len || !kbuf)
35963 return -EINVAL;
35964
35965 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
35966 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
35967 if (do_copy)
35968 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
35969 else
35970 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
35971 index 53b1737..08177d2e 100644
35972 --- a/block/blk-softirq.c
35973 +++ b/block/blk-softirq.c
35974 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
35975 * Softirq action handler - move entries to local list and loop over them
35976 * while passing them to the queue registered handler.
35977 */
35978 -static void blk_done_softirq(struct softirq_action *h)
35979 +static __latent_entropy void blk_done_softirq(void)
35980 {
35981 struct list_head *cpu_list, local_list;
35982
35983 diff --git a/block/bsg.c b/block/bsg.c
35984 index 420a5a9..23834aa 100644
35985 --- a/block/bsg.c
35986 +++ b/block/bsg.c
35987 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
35988 struct sg_io_v4 *hdr, struct bsg_device *bd,
35989 fmode_t has_write_perm)
35990 {
35991 + unsigned char tmpcmd[sizeof(rq->__cmd)];
35992 + unsigned char *cmdptr;
35993 +
35994 if (hdr->request_len > BLK_MAX_CDB) {
35995 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
35996 if (!rq->cmd)
35997 return -ENOMEM;
35998 - }
35999 + cmdptr = rq->cmd;
36000 + } else
36001 + cmdptr = tmpcmd;
36002
36003 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
36004 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
36005 hdr->request_len))
36006 return -EFAULT;
36007
36008 + if (cmdptr != rq->cmd)
36009 + memcpy(rq->cmd, cmdptr, hdr->request_len);
36010 +
36011 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
36012 if (blk_verify_command(rq->cmd, has_write_perm))
36013 return -EPERM;
36014 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
36015 index a0926a6..b2b14b2 100644
36016 --- a/block/compat_ioctl.c
36017 +++ b/block/compat_ioctl.c
36018 @@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
36019 cgc = compat_alloc_user_space(sizeof(*cgc));
36020 cgc32 = compat_ptr(arg);
36021
36022 - if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
36023 + if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
36024 get_user(data, &cgc32->buffer) ||
36025 put_user(compat_ptr(data), &cgc->buffer) ||
36026 copy_in_user(&cgc->buflen, &cgc32->buflen,
36027 @@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
36028 err |= __get_user(f->spec1, &uf->spec1);
36029 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
36030 err |= __get_user(name, &uf->name);
36031 - f->name = compat_ptr(name);
36032 + f->name = (void __force_kernel *)compat_ptr(name);
36033 if (err) {
36034 err = -EFAULT;
36035 goto out;
36036 diff --git a/block/genhd.c b/block/genhd.c
36037 index 791f419..89f21c4 100644
36038 --- a/block/genhd.c
36039 +++ b/block/genhd.c
36040 @@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
36041
36042 /*
36043 * Register device numbers dev..(dev+range-1)
36044 - * range must be nonzero
36045 + * Noop if @range is zero.
36046 * The hash chain is sorted on range, so that subranges can override.
36047 */
36048 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
36049 struct kobject *(*probe)(dev_t, int *, void *),
36050 int (*lock)(dev_t, void *), void *data)
36051 {
36052 - kobj_map(bdev_map, devt, range, module, probe, lock, data);
36053 + if (range)
36054 + kobj_map(bdev_map, devt, range, module, probe, lock, data);
36055 }
36056
36057 EXPORT_SYMBOL(blk_register_region);
36058
36059 +/* undo blk_register_region(), noop if @range is zero */
36060 void blk_unregister_region(dev_t devt, unsigned long range)
36061 {
36062 - kobj_unmap(bdev_map, devt, range);
36063 + if (range)
36064 + kobj_unmap(bdev_map, devt, range);
36065 }
36066
36067 EXPORT_SYMBOL(blk_unregister_region);
36068 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
36069 index dc51f46..d5446a8 100644
36070 --- a/block/partitions/efi.c
36071 +++ b/block/partitions/efi.c
36072 @@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
36073 if (!gpt)
36074 return NULL;
36075
36076 + if (!le32_to_cpu(gpt->num_partition_entries))
36077 + return NULL;
36078 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
36079 + if (!pte)
36080 + return NULL;
36081 +
36082 count = le32_to_cpu(gpt->num_partition_entries) *
36083 le32_to_cpu(gpt->sizeof_partition_entry);
36084 - if (!count)
36085 - return NULL;
36086 - pte = kmalloc(count, GFP_KERNEL);
36087 - if (!pte)
36088 - return NULL;
36089 -
36090 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
36091 (u8 *) pte, count) < count) {
36092 kfree(pte);
36093 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
36094 index 2648797..92ed21f 100644
36095 --- a/block/scsi_ioctl.c
36096 +++ b/block/scsi_ioctl.c
36097 @@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
36098 return put_user(0, p);
36099 }
36100
36101 -static int sg_get_timeout(struct request_queue *q)
36102 +static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
36103 {
36104 return jiffies_to_clock_t(q->sg_timeout);
36105 }
36106 @@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
36107 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
36108 struct sg_io_hdr *hdr, fmode_t mode)
36109 {
36110 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
36111 + unsigned char tmpcmd[sizeof(rq->__cmd)];
36112 + unsigned char *cmdptr;
36113 +
36114 + if (rq->cmd != rq->__cmd)
36115 + cmdptr = rq->cmd;
36116 + else
36117 + cmdptr = tmpcmd;
36118 +
36119 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
36120 return -EFAULT;
36121 +
36122 + if (cmdptr != rq->cmd)
36123 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
36124 +
36125 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
36126 return -EPERM;
36127
36128 @@ -417,6 +429,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36129 int err;
36130 unsigned int in_len, out_len, bytes, opcode, cmdlen;
36131 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
36132 + unsigned char tmpcmd[sizeof(rq->__cmd)];
36133 + unsigned char *cmdptr;
36134
36135 if (!sic)
36136 return -EINVAL;
36137 @@ -450,9 +464,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36138 */
36139 err = -EFAULT;
36140 rq->cmd_len = cmdlen;
36141 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
36142 +
36143 + if (rq->cmd != rq->__cmd)
36144 + cmdptr = rq->cmd;
36145 + else
36146 + cmdptr = tmpcmd;
36147 +
36148 + if (copy_from_user(cmdptr, sic->data, cmdlen))
36149 goto error;
36150
36151 + if (rq->cmd != cmdptr)
36152 + memcpy(rq->cmd, cmdptr, cmdlen);
36153 +
36154 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
36155 goto error;
36156
36157 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
36158 index 7bdd61b..afec999 100644
36159 --- a/crypto/cryptd.c
36160 +++ b/crypto/cryptd.c
36161 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
36162
36163 struct cryptd_blkcipher_request_ctx {
36164 crypto_completion_t complete;
36165 -};
36166 +} __no_const;
36167
36168 struct cryptd_hash_ctx {
36169 struct crypto_shash *child;
36170 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
36171
36172 struct cryptd_aead_request_ctx {
36173 crypto_completion_t complete;
36174 -};
36175 +} __no_const;
36176
36177 static void cryptd_queue_worker(struct work_struct *work);
36178
36179 diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
36180 index 309d345..1632720 100644
36181 --- a/crypto/pcrypt.c
36182 +++ b/crypto/pcrypt.c
36183 @@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
36184 int ret;
36185
36186 pinst->kobj.kset = pcrypt_kset;
36187 - ret = kobject_add(&pinst->kobj, NULL, name);
36188 + ret = kobject_add(&pinst->kobj, NULL, "%s", name);
36189 if (!ret)
36190 kobject_uevent(&pinst->kobj, KOBJ_ADD);
36191
36192 diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
36193 index 6921c7f..78e1af7 100644
36194 --- a/drivers/acpi/acpica/hwxfsleep.c
36195 +++ b/drivers/acpi/acpica/hwxfsleep.c
36196 @@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
36197 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
36198
36199 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
36200 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36201 - acpi_hw_extended_sleep},
36202 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36203 - acpi_hw_extended_wake_prep},
36204 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
36205 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36206 + .extended_function = acpi_hw_extended_sleep},
36207 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36208 + .extended_function = acpi_hw_extended_wake_prep},
36209 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
36210 + .extended_function = acpi_hw_extended_wake}
36211 };
36212
36213 /*
36214 diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
36215 index e5bcd91..74f050d 100644
36216 --- a/drivers/acpi/apei/apei-internal.h
36217 +++ b/drivers/acpi/apei/apei-internal.h
36218 @@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
36219 struct apei_exec_ins_type {
36220 u32 flags;
36221 apei_exec_ins_func_t run;
36222 -};
36223 +} __do_const;
36224
36225 struct apei_exec_context {
36226 u32 ip;
36227 diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
36228 index dab7cb7..f0d2994 100644
36229 --- a/drivers/acpi/apei/ghes.c
36230 +++ b/drivers/acpi/apei/ghes.c
36231 @@ -500,7 +500,7 @@ static void __ghes_print_estatus(const char *pfx,
36232 const struct acpi_hest_generic *generic,
36233 const struct acpi_generic_status *estatus)
36234 {
36235 - static atomic_t seqno;
36236 + static atomic_unchecked_t seqno;
36237 unsigned int curr_seqno;
36238 char pfx_seq[64];
36239
36240 @@ -511,7 +511,7 @@ static void __ghes_print_estatus(const char *pfx,
36241 else
36242 pfx = KERN_ERR;
36243 }
36244 - curr_seqno = atomic_inc_return(&seqno);
36245 + curr_seqno = atomic_inc_return_unchecked(&seqno);
36246 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
36247 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
36248 pfx_seq, generic->header.source_id);
36249 diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
36250 index a83e3c6..c3d617f 100644
36251 --- a/drivers/acpi/bgrt.c
36252 +++ b/drivers/acpi/bgrt.c
36253 @@ -86,8 +86,10 @@ static int __init bgrt_init(void)
36254 if (!bgrt_image)
36255 return -ENODEV;
36256
36257 - bin_attr_image.private = bgrt_image;
36258 - bin_attr_image.size = bgrt_image_size;
36259 + pax_open_kernel();
36260 + *(void **)&bin_attr_image.private = bgrt_image;
36261 + *(size_t *)&bin_attr_image.size = bgrt_image_size;
36262 + pax_close_kernel();
36263
36264 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
36265 if (!bgrt_kobj)
36266 diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
36267 index 3d8413d..95f638c 100644
36268 --- a/drivers/acpi/blacklist.c
36269 +++ b/drivers/acpi/blacklist.c
36270 @@ -51,7 +51,7 @@ struct acpi_blacklist_item {
36271 u32 is_critical_error;
36272 };
36273
36274 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
36275 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
36276
36277 /*
36278 * POLICY: If *anything* doesn't work, put it on the blacklist.
36279 @@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
36280 return 0;
36281 }
36282
36283 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
36284 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
36285 {
36286 .callback = dmi_disable_osi_vista,
36287 .ident = "Fujitsu Siemens",
36288 diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
36289 index c68e724..e863008 100644
36290 --- a/drivers/acpi/custom_method.c
36291 +++ b/drivers/acpi/custom_method.c
36292 @@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
36293 struct acpi_table_header table;
36294 acpi_status status;
36295
36296 +#ifdef CONFIG_GRKERNSEC_KMEM
36297 + return -EPERM;
36298 +#endif
36299 +
36300 if (!(*ppos)) {
36301 /* parse the table header to get the table length */
36302 if (count <= sizeof(struct acpi_table_header))
36303 diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
36304 index 3dca36d..abaf070 100644
36305 --- a/drivers/acpi/processor_idle.c
36306 +++ b/drivers/acpi/processor_idle.c
36307 @@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
36308 {
36309 int i, count = CPUIDLE_DRIVER_STATE_START;
36310 struct acpi_processor_cx *cx;
36311 - struct cpuidle_state *state;
36312 + cpuidle_state_no_const *state;
36313 struct cpuidle_driver *drv = &acpi_idle_driver;
36314
36315 if (!pr->flags.power_setup_done)
36316 diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
36317 index 38cb978..352c761 100644
36318 --- a/drivers/acpi/sysfs.c
36319 +++ b/drivers/acpi/sysfs.c
36320 @@ -423,11 +423,11 @@ static u32 num_counters;
36321 static struct attribute **all_attrs;
36322 static u32 acpi_gpe_count;
36323
36324 -static struct attribute_group interrupt_stats_attr_group = {
36325 +static attribute_group_no_const interrupt_stats_attr_group = {
36326 .name = "interrupts",
36327 };
36328
36329 -static struct kobj_attribute *counter_attrs;
36330 +static kobj_attribute_no_const *counter_attrs;
36331
36332 static void delete_gpe_attr_array(void)
36333 {
36334 diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
36335 index b986145..82bddb8 100644
36336 --- a/drivers/ata/libahci.c
36337 +++ b/drivers/ata/libahci.c
36338 @@ -1252,7 +1252,7 @@ int ahci_kick_engine(struct ata_port *ap)
36339 }
36340 EXPORT_SYMBOL_GPL(ahci_kick_engine);
36341
36342 -static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36343 +static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36344 struct ata_taskfile *tf, int is_cmd, u16 flags,
36345 unsigned long timeout_msec)
36346 {
36347 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
36348 index 677c0c1..354b89b 100644
36349 --- a/drivers/ata/libata-core.c
36350 +++ b/drivers/ata/libata-core.c
36351 @@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
36352 static void ata_dev_xfermask(struct ata_device *dev);
36353 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
36354
36355 -atomic_t ata_print_id = ATOMIC_INIT(0);
36356 +atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
36357
36358 struct ata_force_param {
36359 const char *name;
36360 @@ -4863,7 +4863,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
36361 struct ata_port *ap;
36362 unsigned int tag;
36363
36364 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36365 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36366 ap = qc->ap;
36367
36368 qc->flags = 0;
36369 @@ -4879,7 +4879,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
36370 struct ata_port *ap;
36371 struct ata_link *link;
36372
36373 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36374 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36375 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
36376 ap = qc->ap;
36377 link = qc->dev->link;
36378 @@ -5983,6 +5983,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36379 return;
36380
36381 spin_lock(&lock);
36382 + pax_open_kernel();
36383
36384 for (cur = ops->inherits; cur; cur = cur->inherits) {
36385 void **inherit = (void **)cur;
36386 @@ -5996,8 +5997,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36387 if (IS_ERR(*pp))
36388 *pp = NULL;
36389
36390 - ops->inherits = NULL;
36391 + *(struct ata_port_operations **)&ops->inherits = NULL;
36392
36393 + pax_close_kernel();
36394 spin_unlock(&lock);
36395 }
36396
36397 @@ -6193,7 +6195,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
36398
36399 /* give ports names and add SCSI hosts */
36400 for (i = 0; i < host->n_ports; i++) {
36401 - host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
36402 + host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
36403 host->ports[i]->local_port_no = i + 1;
36404 }
36405
36406 diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
36407 index ef8567d..8bdbd03 100644
36408 --- a/drivers/ata/libata-scsi.c
36409 +++ b/drivers/ata/libata-scsi.c
36410 @@ -4147,7 +4147,7 @@ int ata_sas_port_init(struct ata_port *ap)
36411
36412 if (rc)
36413 return rc;
36414 - ap->print_id = atomic_inc_return(&ata_print_id);
36415 + ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
36416 return 0;
36417 }
36418 EXPORT_SYMBOL_GPL(ata_sas_port_init);
36419 diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
36420 index 45b5ab3..98446b8 100644
36421 --- a/drivers/ata/libata.h
36422 +++ b/drivers/ata/libata.h
36423 @@ -53,7 +53,7 @@ enum {
36424 ATA_DNXFER_QUIET = (1 << 31),
36425 };
36426
36427 -extern atomic_t ata_print_id;
36428 +extern atomic_unchecked_t ata_print_id;
36429 extern int atapi_passthru16;
36430 extern int libata_fua;
36431 extern int libata_noacpi;
36432 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
36433 index 4edb1a8..84e1658 100644
36434 --- a/drivers/ata/pata_arasan_cf.c
36435 +++ b/drivers/ata/pata_arasan_cf.c
36436 @@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
36437 /* Handle platform specific quirks */
36438 if (quirk) {
36439 if (quirk & CF_BROKEN_PIO) {
36440 - ap->ops->set_piomode = NULL;
36441 + pax_open_kernel();
36442 + *(void **)&ap->ops->set_piomode = NULL;
36443 + pax_close_kernel();
36444 ap->pio_mask = 0;
36445 }
36446 if (quirk & CF_BROKEN_MWDMA)
36447 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
36448 index f9b983a..887b9d8 100644
36449 --- a/drivers/atm/adummy.c
36450 +++ b/drivers/atm/adummy.c
36451 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
36452 vcc->pop(vcc, skb);
36453 else
36454 dev_kfree_skb_any(skb);
36455 - atomic_inc(&vcc->stats->tx);
36456 + atomic_inc_unchecked(&vcc->stats->tx);
36457
36458 return 0;
36459 }
36460 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
36461 index f1a9198..f466a4a 100644
36462 --- a/drivers/atm/ambassador.c
36463 +++ b/drivers/atm/ambassador.c
36464 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
36465 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
36466
36467 // VC layer stats
36468 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36469 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36470
36471 // free the descriptor
36472 kfree (tx_descr);
36473 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36474 dump_skb ("<<<", vc, skb);
36475
36476 // VC layer stats
36477 - atomic_inc(&atm_vcc->stats->rx);
36478 + atomic_inc_unchecked(&atm_vcc->stats->rx);
36479 __net_timestamp(skb);
36480 // end of our responsibility
36481 atm_vcc->push (atm_vcc, skb);
36482 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36483 } else {
36484 PRINTK (KERN_INFO, "dropped over-size frame");
36485 // should we count this?
36486 - atomic_inc(&atm_vcc->stats->rx_drop);
36487 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36488 }
36489
36490 } else {
36491 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
36492 }
36493
36494 if (check_area (skb->data, skb->len)) {
36495 - atomic_inc(&atm_vcc->stats->tx_err);
36496 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
36497 return -ENOMEM; // ?
36498 }
36499
36500 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
36501 index 0e3f8f9..765a7a5 100644
36502 --- a/drivers/atm/atmtcp.c
36503 +++ b/drivers/atm/atmtcp.c
36504 @@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36505 if (vcc->pop) vcc->pop(vcc,skb);
36506 else dev_kfree_skb(skb);
36507 if (dev_data) return 0;
36508 - atomic_inc(&vcc->stats->tx_err);
36509 + atomic_inc_unchecked(&vcc->stats->tx_err);
36510 return -ENOLINK;
36511 }
36512 size = skb->len+sizeof(struct atmtcp_hdr);
36513 @@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36514 if (!new_skb) {
36515 if (vcc->pop) vcc->pop(vcc,skb);
36516 else dev_kfree_skb(skb);
36517 - atomic_inc(&vcc->stats->tx_err);
36518 + atomic_inc_unchecked(&vcc->stats->tx_err);
36519 return -ENOBUFS;
36520 }
36521 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
36522 @@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36523 if (vcc->pop) vcc->pop(vcc,skb);
36524 else dev_kfree_skb(skb);
36525 out_vcc->push(out_vcc,new_skb);
36526 - atomic_inc(&vcc->stats->tx);
36527 - atomic_inc(&out_vcc->stats->rx);
36528 + atomic_inc_unchecked(&vcc->stats->tx);
36529 + atomic_inc_unchecked(&out_vcc->stats->rx);
36530 return 0;
36531 }
36532
36533 @@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36534 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
36535 read_unlock(&vcc_sklist_lock);
36536 if (!out_vcc) {
36537 - atomic_inc(&vcc->stats->tx_err);
36538 + atomic_inc_unchecked(&vcc->stats->tx_err);
36539 goto done;
36540 }
36541 skb_pull(skb,sizeof(struct atmtcp_hdr));
36542 @@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36543 __net_timestamp(new_skb);
36544 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
36545 out_vcc->push(out_vcc,new_skb);
36546 - atomic_inc(&vcc->stats->tx);
36547 - atomic_inc(&out_vcc->stats->rx);
36548 + atomic_inc_unchecked(&vcc->stats->tx);
36549 + atomic_inc_unchecked(&out_vcc->stats->rx);
36550 done:
36551 if (vcc->pop) vcc->pop(vcc,skb);
36552 else dev_kfree_skb(skb);
36553 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
36554 index b1955ba..b179940 100644
36555 --- a/drivers/atm/eni.c
36556 +++ b/drivers/atm/eni.c
36557 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
36558 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
36559 vcc->dev->number);
36560 length = 0;
36561 - atomic_inc(&vcc->stats->rx_err);
36562 + atomic_inc_unchecked(&vcc->stats->rx_err);
36563 }
36564 else {
36565 length = ATM_CELL_SIZE-1; /* no HEC */
36566 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36567 size);
36568 }
36569 eff = length = 0;
36570 - atomic_inc(&vcc->stats->rx_err);
36571 + atomic_inc_unchecked(&vcc->stats->rx_err);
36572 }
36573 else {
36574 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
36575 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36576 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
36577 vcc->dev->number,vcc->vci,length,size << 2,descr);
36578 length = eff = 0;
36579 - atomic_inc(&vcc->stats->rx_err);
36580 + atomic_inc_unchecked(&vcc->stats->rx_err);
36581 }
36582 }
36583 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
36584 @@ -767,7 +767,7 @@ rx_dequeued++;
36585 vcc->push(vcc,skb);
36586 pushed++;
36587 }
36588 - atomic_inc(&vcc->stats->rx);
36589 + atomic_inc_unchecked(&vcc->stats->rx);
36590 }
36591 wake_up(&eni_dev->rx_wait);
36592 }
36593 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
36594 PCI_DMA_TODEVICE);
36595 if (vcc->pop) vcc->pop(vcc,skb);
36596 else dev_kfree_skb_irq(skb);
36597 - atomic_inc(&vcc->stats->tx);
36598 + atomic_inc_unchecked(&vcc->stats->tx);
36599 wake_up(&eni_dev->tx_wait);
36600 dma_complete++;
36601 }
36602 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
36603 index 82f2ae0..f205c02 100644
36604 --- a/drivers/atm/firestream.c
36605 +++ b/drivers/atm/firestream.c
36606 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
36607 }
36608 }
36609
36610 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36611 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36612
36613 fs_dprintk (FS_DEBUG_TXMEM, "i");
36614 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
36615 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36616 #endif
36617 skb_put (skb, qe->p1 & 0xffff);
36618 ATM_SKB(skb)->vcc = atm_vcc;
36619 - atomic_inc(&atm_vcc->stats->rx);
36620 + atomic_inc_unchecked(&atm_vcc->stats->rx);
36621 __net_timestamp(skb);
36622 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
36623 atm_vcc->push (atm_vcc, skb);
36624 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36625 kfree (pe);
36626 }
36627 if (atm_vcc)
36628 - atomic_inc(&atm_vcc->stats->rx_drop);
36629 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36630 break;
36631 case 0x1f: /* Reassembly abort: no buffers. */
36632 /* Silently increment error counter. */
36633 if (atm_vcc)
36634 - atomic_inc(&atm_vcc->stats->rx_drop);
36635 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36636 break;
36637 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
36638 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
36639 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
36640 index 204814e..cede831 100644
36641 --- a/drivers/atm/fore200e.c
36642 +++ b/drivers/atm/fore200e.c
36643 @@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
36644 #endif
36645 /* check error condition */
36646 if (*entry->status & STATUS_ERROR)
36647 - atomic_inc(&vcc->stats->tx_err);
36648 + atomic_inc_unchecked(&vcc->stats->tx_err);
36649 else
36650 - atomic_inc(&vcc->stats->tx);
36651 + atomic_inc_unchecked(&vcc->stats->tx);
36652 }
36653 }
36654
36655 @@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36656 if (skb == NULL) {
36657 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
36658
36659 - atomic_inc(&vcc->stats->rx_drop);
36660 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36661 return -ENOMEM;
36662 }
36663
36664 @@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36665
36666 dev_kfree_skb_any(skb);
36667
36668 - atomic_inc(&vcc->stats->rx_drop);
36669 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36670 return -ENOMEM;
36671 }
36672
36673 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36674
36675 vcc->push(vcc, skb);
36676 - atomic_inc(&vcc->stats->rx);
36677 + atomic_inc_unchecked(&vcc->stats->rx);
36678
36679 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36680
36681 @@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
36682 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
36683 fore200e->atm_dev->number,
36684 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
36685 - atomic_inc(&vcc->stats->rx_err);
36686 + atomic_inc_unchecked(&vcc->stats->rx_err);
36687 }
36688 }
36689
36690 @@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
36691 goto retry_here;
36692 }
36693
36694 - atomic_inc(&vcc->stats->tx_err);
36695 + atomic_inc_unchecked(&vcc->stats->tx_err);
36696
36697 fore200e->tx_sat++;
36698 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
36699 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
36700 index aa6be26..f70a785 100644
36701 --- a/drivers/atm/he.c
36702 +++ b/drivers/atm/he.c
36703 @@ -1690,7 +1690,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36704
36705 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
36706 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
36707 - atomic_inc(&vcc->stats->rx_drop);
36708 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36709 goto return_host_buffers;
36710 }
36711
36712 @@ -1717,7 +1717,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36713 RBRQ_LEN_ERR(he_dev->rbrq_head)
36714 ? "LEN_ERR" : "",
36715 vcc->vpi, vcc->vci);
36716 - atomic_inc(&vcc->stats->rx_err);
36717 + atomic_inc_unchecked(&vcc->stats->rx_err);
36718 goto return_host_buffers;
36719 }
36720
36721 @@ -1769,7 +1769,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36722 vcc->push(vcc, skb);
36723 spin_lock(&he_dev->global_lock);
36724
36725 - atomic_inc(&vcc->stats->rx);
36726 + atomic_inc_unchecked(&vcc->stats->rx);
36727
36728 return_host_buffers:
36729 ++pdus_assembled;
36730 @@ -2095,7 +2095,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
36731 tpd->vcc->pop(tpd->vcc, tpd->skb);
36732 else
36733 dev_kfree_skb_any(tpd->skb);
36734 - atomic_inc(&tpd->vcc->stats->tx_err);
36735 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
36736 }
36737 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
36738 return;
36739 @@ -2507,7 +2507,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36740 vcc->pop(vcc, skb);
36741 else
36742 dev_kfree_skb_any(skb);
36743 - atomic_inc(&vcc->stats->tx_err);
36744 + atomic_inc_unchecked(&vcc->stats->tx_err);
36745 return -EINVAL;
36746 }
36747
36748 @@ -2518,7 +2518,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36749 vcc->pop(vcc, skb);
36750 else
36751 dev_kfree_skb_any(skb);
36752 - atomic_inc(&vcc->stats->tx_err);
36753 + atomic_inc_unchecked(&vcc->stats->tx_err);
36754 return -EINVAL;
36755 }
36756 #endif
36757 @@ -2530,7 +2530,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36758 vcc->pop(vcc, skb);
36759 else
36760 dev_kfree_skb_any(skb);
36761 - atomic_inc(&vcc->stats->tx_err);
36762 + atomic_inc_unchecked(&vcc->stats->tx_err);
36763 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36764 return -ENOMEM;
36765 }
36766 @@ -2572,7 +2572,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36767 vcc->pop(vcc, skb);
36768 else
36769 dev_kfree_skb_any(skb);
36770 - atomic_inc(&vcc->stats->tx_err);
36771 + atomic_inc_unchecked(&vcc->stats->tx_err);
36772 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36773 return -ENOMEM;
36774 }
36775 @@ -2603,7 +2603,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36776 __enqueue_tpd(he_dev, tpd, cid);
36777 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36778
36779 - atomic_inc(&vcc->stats->tx);
36780 + atomic_inc_unchecked(&vcc->stats->tx);
36781
36782 return 0;
36783 }
36784 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
36785 index 1dc0519..1aadaf7 100644
36786 --- a/drivers/atm/horizon.c
36787 +++ b/drivers/atm/horizon.c
36788 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
36789 {
36790 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
36791 // VC layer stats
36792 - atomic_inc(&vcc->stats->rx);
36793 + atomic_inc_unchecked(&vcc->stats->rx);
36794 __net_timestamp(skb);
36795 // end of our responsibility
36796 vcc->push (vcc, skb);
36797 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
36798 dev->tx_iovec = NULL;
36799
36800 // VC layer stats
36801 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36802 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36803
36804 // free the skb
36805 hrz_kfree_skb (skb);
36806 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
36807 index 1bdf104..9dc44b1 100644
36808 --- a/drivers/atm/idt77252.c
36809 +++ b/drivers/atm/idt77252.c
36810 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
36811 else
36812 dev_kfree_skb(skb);
36813
36814 - atomic_inc(&vcc->stats->tx);
36815 + atomic_inc_unchecked(&vcc->stats->tx);
36816 }
36817
36818 atomic_dec(&scq->used);
36819 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36820 if ((sb = dev_alloc_skb(64)) == NULL) {
36821 printk("%s: Can't allocate buffers for aal0.\n",
36822 card->name);
36823 - atomic_add(i, &vcc->stats->rx_drop);
36824 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
36825 break;
36826 }
36827 if (!atm_charge(vcc, sb->truesize)) {
36828 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
36829 card->name);
36830 - atomic_add(i - 1, &vcc->stats->rx_drop);
36831 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
36832 dev_kfree_skb(sb);
36833 break;
36834 }
36835 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36836 ATM_SKB(sb)->vcc = vcc;
36837 __net_timestamp(sb);
36838 vcc->push(vcc, sb);
36839 - atomic_inc(&vcc->stats->rx);
36840 + atomic_inc_unchecked(&vcc->stats->rx);
36841
36842 cell += ATM_CELL_PAYLOAD;
36843 }
36844 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36845 "(CDC: %08x)\n",
36846 card->name, len, rpp->len, readl(SAR_REG_CDC));
36847 recycle_rx_pool_skb(card, rpp);
36848 - atomic_inc(&vcc->stats->rx_err);
36849 + atomic_inc_unchecked(&vcc->stats->rx_err);
36850 return;
36851 }
36852 if (stat & SAR_RSQE_CRC) {
36853 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
36854 recycle_rx_pool_skb(card, rpp);
36855 - atomic_inc(&vcc->stats->rx_err);
36856 + atomic_inc_unchecked(&vcc->stats->rx_err);
36857 return;
36858 }
36859 if (skb_queue_len(&rpp->queue) > 1) {
36860 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36861 RXPRINTK("%s: Can't alloc RX skb.\n",
36862 card->name);
36863 recycle_rx_pool_skb(card, rpp);
36864 - atomic_inc(&vcc->stats->rx_err);
36865 + atomic_inc_unchecked(&vcc->stats->rx_err);
36866 return;
36867 }
36868 if (!atm_charge(vcc, skb->truesize)) {
36869 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36870 __net_timestamp(skb);
36871
36872 vcc->push(vcc, skb);
36873 - atomic_inc(&vcc->stats->rx);
36874 + atomic_inc_unchecked(&vcc->stats->rx);
36875
36876 return;
36877 }
36878 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36879 __net_timestamp(skb);
36880
36881 vcc->push(vcc, skb);
36882 - atomic_inc(&vcc->stats->rx);
36883 + atomic_inc_unchecked(&vcc->stats->rx);
36884
36885 if (skb->truesize > SAR_FB_SIZE_3)
36886 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
36887 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
36888 if (vcc->qos.aal != ATM_AAL0) {
36889 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
36890 card->name, vpi, vci);
36891 - atomic_inc(&vcc->stats->rx_drop);
36892 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36893 goto drop;
36894 }
36895
36896 if ((sb = dev_alloc_skb(64)) == NULL) {
36897 printk("%s: Can't allocate buffers for AAL0.\n",
36898 card->name);
36899 - atomic_inc(&vcc->stats->rx_err);
36900 + atomic_inc_unchecked(&vcc->stats->rx_err);
36901 goto drop;
36902 }
36903
36904 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
36905 ATM_SKB(sb)->vcc = vcc;
36906 __net_timestamp(sb);
36907 vcc->push(vcc, sb);
36908 - atomic_inc(&vcc->stats->rx);
36909 + atomic_inc_unchecked(&vcc->stats->rx);
36910
36911 drop:
36912 skb_pull(queue, 64);
36913 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36914
36915 if (vc == NULL) {
36916 printk("%s: NULL connection in send().\n", card->name);
36917 - atomic_inc(&vcc->stats->tx_err);
36918 + atomic_inc_unchecked(&vcc->stats->tx_err);
36919 dev_kfree_skb(skb);
36920 return -EINVAL;
36921 }
36922 if (!test_bit(VCF_TX, &vc->flags)) {
36923 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
36924 - atomic_inc(&vcc->stats->tx_err);
36925 + atomic_inc_unchecked(&vcc->stats->tx_err);
36926 dev_kfree_skb(skb);
36927 return -EINVAL;
36928 }
36929 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36930 break;
36931 default:
36932 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
36933 - atomic_inc(&vcc->stats->tx_err);
36934 + atomic_inc_unchecked(&vcc->stats->tx_err);
36935 dev_kfree_skb(skb);
36936 return -EINVAL;
36937 }
36938
36939 if (skb_shinfo(skb)->nr_frags != 0) {
36940 printk("%s: No scatter-gather yet.\n", card->name);
36941 - atomic_inc(&vcc->stats->tx_err);
36942 + atomic_inc_unchecked(&vcc->stats->tx_err);
36943 dev_kfree_skb(skb);
36944 return -EINVAL;
36945 }
36946 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36947
36948 err = queue_skb(card, vc, skb, oam);
36949 if (err) {
36950 - atomic_inc(&vcc->stats->tx_err);
36951 + atomic_inc_unchecked(&vcc->stats->tx_err);
36952 dev_kfree_skb(skb);
36953 return err;
36954 }
36955 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
36956 skb = dev_alloc_skb(64);
36957 if (!skb) {
36958 printk("%s: Out of memory in send_oam().\n", card->name);
36959 - atomic_inc(&vcc->stats->tx_err);
36960 + atomic_inc_unchecked(&vcc->stats->tx_err);
36961 return -ENOMEM;
36962 }
36963 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
36964 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
36965 index 4217f29..88f547a 100644
36966 --- a/drivers/atm/iphase.c
36967 +++ b/drivers/atm/iphase.c
36968 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
36969 status = (u_short) (buf_desc_ptr->desc_mode);
36970 if (status & (RX_CER | RX_PTE | RX_OFL))
36971 {
36972 - atomic_inc(&vcc->stats->rx_err);
36973 + atomic_inc_unchecked(&vcc->stats->rx_err);
36974 IF_ERR(printk("IA: bad packet, dropping it");)
36975 if (status & RX_CER) {
36976 IF_ERR(printk(" cause: packet CRC error\n");)
36977 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
36978 len = dma_addr - buf_addr;
36979 if (len > iadev->rx_buf_sz) {
36980 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
36981 - atomic_inc(&vcc->stats->rx_err);
36982 + atomic_inc_unchecked(&vcc->stats->rx_err);
36983 goto out_free_desc;
36984 }
36985
36986 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36987 ia_vcc = INPH_IA_VCC(vcc);
36988 if (ia_vcc == NULL)
36989 {
36990 - atomic_inc(&vcc->stats->rx_err);
36991 + atomic_inc_unchecked(&vcc->stats->rx_err);
36992 atm_return(vcc, skb->truesize);
36993 dev_kfree_skb_any(skb);
36994 goto INCR_DLE;
36995 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36996 if ((length > iadev->rx_buf_sz) || (length >
36997 (skb->len - sizeof(struct cpcs_trailer))))
36998 {
36999 - atomic_inc(&vcc->stats->rx_err);
37000 + atomic_inc_unchecked(&vcc->stats->rx_err);
37001 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
37002 length, skb->len);)
37003 atm_return(vcc, skb->truesize);
37004 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37005
37006 IF_RX(printk("rx_dle_intr: skb push");)
37007 vcc->push(vcc,skb);
37008 - atomic_inc(&vcc->stats->rx);
37009 + atomic_inc_unchecked(&vcc->stats->rx);
37010 iadev->rx_pkt_cnt++;
37011 }
37012 INCR_DLE:
37013 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
37014 {
37015 struct k_sonet_stats *stats;
37016 stats = &PRIV(_ia_dev[board])->sonet_stats;
37017 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
37018 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
37019 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
37020 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
37021 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
37022 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
37023 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
37024 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
37025 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
37026 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
37027 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
37028 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
37029 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
37030 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
37031 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
37032 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
37033 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
37034 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
37035 }
37036 ia_cmds.status = 0;
37037 break;
37038 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37039 if ((desc == 0) || (desc > iadev->num_tx_desc))
37040 {
37041 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
37042 - atomic_inc(&vcc->stats->tx);
37043 + atomic_inc_unchecked(&vcc->stats->tx);
37044 if (vcc->pop)
37045 vcc->pop(vcc, skb);
37046 else
37047 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37048 ATM_DESC(skb) = vcc->vci;
37049 skb_queue_tail(&iadev->tx_dma_q, skb);
37050
37051 - atomic_inc(&vcc->stats->tx);
37052 + atomic_inc_unchecked(&vcc->stats->tx);
37053 iadev->tx_pkt_cnt++;
37054 /* Increment transaction counter */
37055 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
37056
37057 #if 0
37058 /* add flow control logic */
37059 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
37060 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
37061 if (iavcc->vc_desc_cnt > 10) {
37062 vcc->tx_quota = vcc->tx_quota * 3 / 4;
37063 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
37064 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
37065 index fa7d7019..1e404c7 100644
37066 --- a/drivers/atm/lanai.c
37067 +++ b/drivers/atm/lanai.c
37068 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
37069 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
37070 lanai_endtx(lanai, lvcc);
37071 lanai_free_skb(lvcc->tx.atmvcc, skb);
37072 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
37073 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
37074 }
37075
37076 /* Try to fill the buffer - don't call unless there is backlog */
37077 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
37078 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
37079 __net_timestamp(skb);
37080 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
37081 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
37082 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
37083 out:
37084 lvcc->rx.buf.ptr = end;
37085 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
37086 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37087 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
37088 "vcc %d\n", lanai->number, (unsigned int) s, vci);
37089 lanai->stats.service_rxnotaal5++;
37090 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37091 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37092 return 0;
37093 }
37094 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
37095 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37096 int bytes;
37097 read_unlock(&vcc_sklist_lock);
37098 DPRINTK("got trashed rx pdu on vci %d\n", vci);
37099 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37100 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37101 lvcc->stats.x.aal5.service_trash++;
37102 bytes = (SERVICE_GET_END(s) * 16) -
37103 (((unsigned long) lvcc->rx.buf.ptr) -
37104 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37105 }
37106 if (s & SERVICE_STREAM) {
37107 read_unlock(&vcc_sklist_lock);
37108 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37109 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37110 lvcc->stats.x.aal5.service_stream++;
37111 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
37112 "PDU on VCI %d!\n", lanai->number, vci);
37113 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37114 return 0;
37115 }
37116 DPRINTK("got rx crc error on vci %d\n", vci);
37117 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37118 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37119 lvcc->stats.x.aal5.service_rxcrc++;
37120 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
37121 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
37122 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
37123 index 9988ac9..7c52585 100644
37124 --- a/drivers/atm/nicstar.c
37125 +++ b/drivers/atm/nicstar.c
37126 @@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37127 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
37128 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
37129 card->index);
37130 - atomic_inc(&vcc->stats->tx_err);
37131 + atomic_inc_unchecked(&vcc->stats->tx_err);
37132 dev_kfree_skb_any(skb);
37133 return -EINVAL;
37134 }
37135 @@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37136 if (!vc->tx) {
37137 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
37138 card->index);
37139 - atomic_inc(&vcc->stats->tx_err);
37140 + atomic_inc_unchecked(&vcc->stats->tx_err);
37141 dev_kfree_skb_any(skb);
37142 return -EINVAL;
37143 }
37144 @@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37145 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
37146 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
37147 card->index);
37148 - atomic_inc(&vcc->stats->tx_err);
37149 + atomic_inc_unchecked(&vcc->stats->tx_err);
37150 dev_kfree_skb_any(skb);
37151 return -EINVAL;
37152 }
37153
37154 if (skb_shinfo(skb)->nr_frags != 0) {
37155 printk("nicstar%d: No scatter-gather yet.\n", card->index);
37156 - atomic_inc(&vcc->stats->tx_err);
37157 + atomic_inc_unchecked(&vcc->stats->tx_err);
37158 dev_kfree_skb_any(skb);
37159 return -EINVAL;
37160 }
37161 @@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37162 }
37163
37164 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
37165 - atomic_inc(&vcc->stats->tx_err);
37166 + atomic_inc_unchecked(&vcc->stats->tx_err);
37167 dev_kfree_skb_any(skb);
37168 return -EIO;
37169 }
37170 - atomic_inc(&vcc->stats->tx);
37171 + atomic_inc_unchecked(&vcc->stats->tx);
37172
37173 return 0;
37174 }
37175 @@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37176 printk
37177 ("nicstar%d: Can't allocate buffers for aal0.\n",
37178 card->index);
37179 - atomic_add(i, &vcc->stats->rx_drop);
37180 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
37181 break;
37182 }
37183 if (!atm_charge(vcc, sb->truesize)) {
37184 RXPRINTK
37185 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
37186 card->index);
37187 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37188 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37189 dev_kfree_skb_any(sb);
37190 break;
37191 }
37192 @@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37193 ATM_SKB(sb)->vcc = vcc;
37194 __net_timestamp(sb);
37195 vcc->push(vcc, sb);
37196 - atomic_inc(&vcc->stats->rx);
37197 + atomic_inc_unchecked(&vcc->stats->rx);
37198 cell += ATM_CELL_PAYLOAD;
37199 }
37200
37201 @@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37202 if (iovb == NULL) {
37203 printk("nicstar%d: Out of iovec buffers.\n",
37204 card->index);
37205 - atomic_inc(&vcc->stats->rx_drop);
37206 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37207 recycle_rx_buf(card, skb);
37208 return;
37209 }
37210 @@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37211 small or large buffer itself. */
37212 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
37213 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
37214 - atomic_inc(&vcc->stats->rx_err);
37215 + atomic_inc_unchecked(&vcc->stats->rx_err);
37216 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37217 NS_MAX_IOVECS);
37218 NS_PRV_IOVCNT(iovb) = 0;
37219 @@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37220 ("nicstar%d: Expected a small buffer, and this is not one.\n",
37221 card->index);
37222 which_list(card, skb);
37223 - atomic_inc(&vcc->stats->rx_err);
37224 + atomic_inc_unchecked(&vcc->stats->rx_err);
37225 recycle_rx_buf(card, skb);
37226 vc->rx_iov = NULL;
37227 recycle_iov_buf(card, iovb);
37228 @@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37229 ("nicstar%d: Expected a large buffer, and this is not one.\n",
37230 card->index);
37231 which_list(card, skb);
37232 - atomic_inc(&vcc->stats->rx_err);
37233 + atomic_inc_unchecked(&vcc->stats->rx_err);
37234 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37235 NS_PRV_IOVCNT(iovb));
37236 vc->rx_iov = NULL;
37237 @@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37238 printk(" - PDU size mismatch.\n");
37239 else
37240 printk(".\n");
37241 - atomic_inc(&vcc->stats->rx_err);
37242 + atomic_inc_unchecked(&vcc->stats->rx_err);
37243 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37244 NS_PRV_IOVCNT(iovb));
37245 vc->rx_iov = NULL;
37246 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37247 /* skb points to a small buffer */
37248 if (!atm_charge(vcc, skb->truesize)) {
37249 push_rxbufs(card, skb);
37250 - atomic_inc(&vcc->stats->rx_drop);
37251 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37252 } else {
37253 skb_put(skb, len);
37254 dequeue_sm_buf(card, skb);
37255 @@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37256 ATM_SKB(skb)->vcc = vcc;
37257 __net_timestamp(skb);
37258 vcc->push(vcc, skb);
37259 - atomic_inc(&vcc->stats->rx);
37260 + atomic_inc_unchecked(&vcc->stats->rx);
37261 }
37262 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
37263 struct sk_buff *sb;
37264 @@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37265 if (len <= NS_SMBUFSIZE) {
37266 if (!atm_charge(vcc, sb->truesize)) {
37267 push_rxbufs(card, sb);
37268 - atomic_inc(&vcc->stats->rx_drop);
37269 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37270 } else {
37271 skb_put(sb, len);
37272 dequeue_sm_buf(card, sb);
37273 @@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37274 ATM_SKB(sb)->vcc = vcc;
37275 __net_timestamp(sb);
37276 vcc->push(vcc, sb);
37277 - atomic_inc(&vcc->stats->rx);
37278 + atomic_inc_unchecked(&vcc->stats->rx);
37279 }
37280
37281 push_rxbufs(card, skb);
37282 @@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37283
37284 if (!atm_charge(vcc, skb->truesize)) {
37285 push_rxbufs(card, skb);
37286 - atomic_inc(&vcc->stats->rx_drop);
37287 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37288 } else {
37289 dequeue_lg_buf(card, skb);
37290 #ifdef NS_USE_DESTRUCTORS
37291 @@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37292 ATM_SKB(skb)->vcc = vcc;
37293 __net_timestamp(skb);
37294 vcc->push(vcc, skb);
37295 - atomic_inc(&vcc->stats->rx);
37296 + atomic_inc_unchecked(&vcc->stats->rx);
37297 }
37298
37299 push_rxbufs(card, sb);
37300 @@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37301 printk
37302 ("nicstar%d: Out of huge buffers.\n",
37303 card->index);
37304 - atomic_inc(&vcc->stats->rx_drop);
37305 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37306 recycle_iovec_rx_bufs(card,
37307 (struct iovec *)
37308 iovb->data,
37309 @@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37310 card->hbpool.count++;
37311 } else
37312 dev_kfree_skb_any(hb);
37313 - atomic_inc(&vcc->stats->rx_drop);
37314 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37315 } else {
37316 /* Copy the small buffer to the huge buffer */
37317 sb = (struct sk_buff *)iov->iov_base;
37318 @@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37319 #endif /* NS_USE_DESTRUCTORS */
37320 __net_timestamp(hb);
37321 vcc->push(vcc, hb);
37322 - atomic_inc(&vcc->stats->rx);
37323 + atomic_inc_unchecked(&vcc->stats->rx);
37324 }
37325 }
37326
37327 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
37328 index 943cf0d..37d15d5 100644
37329 --- a/drivers/atm/solos-pci.c
37330 +++ b/drivers/atm/solos-pci.c
37331 @@ -838,7 +838,7 @@ static void solos_bh(unsigned long card_arg)
37332 }
37333 atm_charge(vcc, skb->truesize);
37334 vcc->push(vcc, skb);
37335 - atomic_inc(&vcc->stats->rx);
37336 + atomic_inc_unchecked(&vcc->stats->rx);
37337 break;
37338
37339 case PKT_STATUS:
37340 @@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
37341 vcc = SKB_CB(oldskb)->vcc;
37342
37343 if (vcc) {
37344 - atomic_inc(&vcc->stats->tx);
37345 + atomic_inc_unchecked(&vcc->stats->tx);
37346 solos_pop(vcc, oldskb);
37347 } else {
37348 dev_kfree_skb_irq(oldskb);
37349 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
37350 index 0215934..ce9f5b1 100644
37351 --- a/drivers/atm/suni.c
37352 +++ b/drivers/atm/suni.c
37353 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
37354
37355
37356 #define ADD_LIMITED(s,v) \
37357 - atomic_add((v),&stats->s); \
37358 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
37359 + atomic_add_unchecked((v),&stats->s); \
37360 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
37361
37362
37363 static void suni_hz(unsigned long from_timer)
37364 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
37365 index 5120a96..e2572bd 100644
37366 --- a/drivers/atm/uPD98402.c
37367 +++ b/drivers/atm/uPD98402.c
37368 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
37369 struct sonet_stats tmp;
37370 int error = 0;
37371
37372 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37373 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37374 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
37375 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
37376 if (zero && !error) {
37377 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
37378
37379
37380 #define ADD_LIMITED(s,v) \
37381 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
37382 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
37383 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37384 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
37385 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
37386 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37387
37388
37389 static void stat_event(struct atm_dev *dev)
37390 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
37391 if (reason & uPD98402_INT_PFM) stat_event(dev);
37392 if (reason & uPD98402_INT_PCO) {
37393 (void) GET(PCOCR); /* clear interrupt cause */
37394 - atomic_add(GET(HECCT),
37395 + atomic_add_unchecked(GET(HECCT),
37396 &PRIV(dev)->sonet_stats.uncorr_hcs);
37397 }
37398 if ((reason & uPD98402_INT_RFO) &&
37399 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
37400 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
37401 uPD98402_INT_LOS),PIMR); /* enable them */
37402 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
37403 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37404 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
37405 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
37406 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37407 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
37408 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
37409 return 0;
37410 }
37411
37412 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
37413 index 969c3c2..9b72956 100644
37414 --- a/drivers/atm/zatm.c
37415 +++ b/drivers/atm/zatm.c
37416 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37417 }
37418 if (!size) {
37419 dev_kfree_skb_irq(skb);
37420 - if (vcc) atomic_inc(&vcc->stats->rx_err);
37421 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
37422 continue;
37423 }
37424 if (!atm_charge(vcc,skb->truesize)) {
37425 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37426 skb->len = size;
37427 ATM_SKB(skb)->vcc = vcc;
37428 vcc->push(vcc,skb);
37429 - atomic_inc(&vcc->stats->rx);
37430 + atomic_inc_unchecked(&vcc->stats->rx);
37431 }
37432 zout(pos & 0xffff,MTA(mbx));
37433 #if 0 /* probably a stupid idea */
37434 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
37435 skb_queue_head(&zatm_vcc->backlog,skb);
37436 break;
37437 }
37438 - atomic_inc(&vcc->stats->tx);
37439 + atomic_inc_unchecked(&vcc->stats->tx);
37440 wake_up(&zatm_vcc->tx_wait);
37441 }
37442
37443 diff --git a/drivers/base/bus.c b/drivers/base/bus.c
37444 index 83e910a..b224a73 100644
37445 --- a/drivers/base/bus.c
37446 +++ b/drivers/base/bus.c
37447 @@ -1124,7 +1124,7 @@ int subsys_interface_register(struct subsys_interface *sif)
37448 return -EINVAL;
37449
37450 mutex_lock(&subsys->p->mutex);
37451 - list_add_tail(&sif->node, &subsys->p->interfaces);
37452 + pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
37453 if (sif->add_dev) {
37454 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37455 while ((dev = subsys_dev_iter_next(&iter)))
37456 @@ -1149,7 +1149,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
37457 subsys = sif->subsys;
37458
37459 mutex_lock(&subsys->p->mutex);
37460 - list_del_init(&sif->node);
37461 + pax_list_del_init((struct list_head *)&sif->node);
37462 if (sif->remove_dev) {
37463 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37464 while ((dev = subsys_dev_iter_next(&iter)))
37465 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
37466 index 25798db..15f130e 100644
37467 --- a/drivers/base/devtmpfs.c
37468 +++ b/drivers/base/devtmpfs.c
37469 @@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
37470 if (!thread)
37471 return 0;
37472
37473 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
37474 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
37475 if (err)
37476 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
37477 else
37478 @@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
37479 *err = sys_unshare(CLONE_NEWNS);
37480 if (*err)
37481 goto out;
37482 - *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
37483 + *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
37484 if (*err)
37485 goto out;
37486 - sys_chdir("/.."); /* will traverse into overmounted root */
37487 - sys_chroot(".");
37488 + sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
37489 + sys_chroot((char __force_user *)".");
37490 complete(&setup_done);
37491 while (1) {
37492 spin_lock(&req_lock);
37493 diff --git a/drivers/base/node.c b/drivers/base/node.c
37494 index 8f7ed99..700dd0c 100644
37495 --- a/drivers/base/node.c
37496 +++ b/drivers/base/node.c
37497 @@ -624,7 +624,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
37498 struct node_attr {
37499 struct device_attribute attr;
37500 enum node_states state;
37501 -};
37502 +} __do_const;
37503
37504 static ssize_t show_node_state(struct device *dev,
37505 struct device_attribute *attr, char *buf)
37506 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
37507 index ae098a2..0999830 100644
37508 --- a/drivers/base/power/domain.c
37509 +++ b/drivers/base/power/domain.c
37510 @@ -1821,9 +1821,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
37511
37512 if (dev->power.subsys_data->domain_data) {
37513 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
37514 - gpd_data->ops = (struct gpd_dev_ops){ NULL };
37515 + memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
37516 if (clear_td)
37517 - gpd_data->td = (struct gpd_timing_data){ 0 };
37518 + memset(&gpd_data->td, 0, sizeof(gpd_data->td));
37519
37520 if (--gpd_data->refcount == 0) {
37521 dev->power.subsys_data->domain_data = NULL;
37522 @@ -1862,7 +1862,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
37523 {
37524 struct cpuidle_driver *cpuidle_drv;
37525 struct gpd_cpu_data *cpu_data;
37526 - struct cpuidle_state *idle_state;
37527 + cpuidle_state_no_const *idle_state;
37528 int ret = 0;
37529
37530 if (IS_ERR_OR_NULL(genpd) || state < 0)
37531 @@ -1930,7 +1930,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
37532 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
37533 {
37534 struct gpd_cpu_data *cpu_data;
37535 - struct cpuidle_state *idle_state;
37536 + cpuidle_state_no_const *idle_state;
37537 int ret = 0;
37538
37539 if (IS_ERR_OR_NULL(genpd))
37540 diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
37541 index 95b181d1..c4f0e19 100644
37542 --- a/drivers/base/power/sysfs.c
37543 +++ b/drivers/base/power/sysfs.c
37544 @@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
37545 return -EIO;
37546 }
37547 }
37548 - return sprintf(buf, p);
37549 + return sprintf(buf, "%s", p);
37550 }
37551
37552 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
37553 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
37554 index 2d56f41..8830f19 100644
37555 --- a/drivers/base/power/wakeup.c
37556 +++ b/drivers/base/power/wakeup.c
37557 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
37558 * They need to be modified together atomically, so it's better to use one
37559 * atomic variable to hold them both.
37560 */
37561 -static atomic_t combined_event_count = ATOMIC_INIT(0);
37562 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
37563
37564 #define IN_PROGRESS_BITS (sizeof(int) * 4)
37565 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
37566
37567 static void split_counters(unsigned int *cnt, unsigned int *inpr)
37568 {
37569 - unsigned int comb = atomic_read(&combined_event_count);
37570 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
37571
37572 *cnt = (comb >> IN_PROGRESS_BITS);
37573 *inpr = comb & MAX_IN_PROGRESS;
37574 @@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
37575 ws->start_prevent_time = ws->last_time;
37576
37577 /* Increment the counter of events in progress. */
37578 - cec = atomic_inc_return(&combined_event_count);
37579 + cec = atomic_inc_return_unchecked(&combined_event_count);
37580
37581 trace_wakeup_source_activate(ws->name, cec);
37582 }
37583 @@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
37584 * Increment the counter of registered wakeup events and decrement the
37585 * couter of wakeup events in progress simultaneously.
37586 */
37587 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
37588 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
37589 trace_wakeup_source_deactivate(ws->name, cec);
37590
37591 split_counters(&cnt, &inpr);
37592 diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
37593 index e8d11b6..7b1b36f 100644
37594 --- a/drivers/base/syscore.c
37595 +++ b/drivers/base/syscore.c
37596 @@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
37597 void register_syscore_ops(struct syscore_ops *ops)
37598 {
37599 mutex_lock(&syscore_ops_lock);
37600 - list_add_tail(&ops->node, &syscore_ops_list);
37601 + pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
37602 mutex_unlock(&syscore_ops_lock);
37603 }
37604 EXPORT_SYMBOL_GPL(register_syscore_ops);
37605 @@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
37606 void unregister_syscore_ops(struct syscore_ops *ops)
37607 {
37608 mutex_lock(&syscore_ops_lock);
37609 - list_del(&ops->node);
37610 + pax_list_del((struct list_head *)&ops->node);
37611 mutex_unlock(&syscore_ops_lock);
37612 }
37613 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
37614 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
37615 index 73894ca..69f64ef 100644
37616 --- a/drivers/block/cciss.c
37617 +++ b/drivers/block/cciss.c
37618 @@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
37619 while (!list_empty(&h->reqQ)) {
37620 c = list_entry(h->reqQ.next, CommandList_struct, list);
37621 /* can't do anything if fifo is full */
37622 - if ((h->access.fifo_full(h))) {
37623 + if ((h->access->fifo_full(h))) {
37624 dev_warn(&h->pdev->dev, "fifo full\n");
37625 break;
37626 }
37627 @@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
37628 h->Qdepth--;
37629
37630 /* Tell the controller execute command */
37631 - h->access.submit_command(h, c);
37632 + h->access->submit_command(h, c);
37633
37634 /* Put job onto the completed Q */
37635 addQ(&h->cmpQ, c);
37636 @@ -3447,17 +3447,17 @@ startio:
37637
37638 static inline unsigned long get_next_completion(ctlr_info_t *h)
37639 {
37640 - return h->access.command_completed(h);
37641 + return h->access->command_completed(h);
37642 }
37643
37644 static inline int interrupt_pending(ctlr_info_t *h)
37645 {
37646 - return h->access.intr_pending(h);
37647 + return h->access->intr_pending(h);
37648 }
37649
37650 static inline long interrupt_not_for_us(ctlr_info_t *h)
37651 {
37652 - return ((h->access.intr_pending(h) == 0) ||
37653 + return ((h->access->intr_pending(h) == 0) ||
37654 (h->interrupts_enabled == 0));
37655 }
37656
37657 @@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
37658 u32 a;
37659
37660 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37661 - return h->access.command_completed(h);
37662 + return h->access->command_completed(h);
37663
37664 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
37665 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
37666 @@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
37667 trans_support & CFGTBL_Trans_use_short_tags);
37668
37669 /* Change the access methods to the performant access methods */
37670 - h->access = SA5_performant_access;
37671 + h->access = &SA5_performant_access;
37672 h->transMethod = CFGTBL_Trans_Performant;
37673
37674 return;
37675 @@ -4325,7 +4325,7 @@ static int cciss_pci_init(ctlr_info_t *h)
37676 if (prod_index < 0)
37677 return -ENODEV;
37678 h->product_name = products[prod_index].product_name;
37679 - h->access = *(products[prod_index].access);
37680 + h->access = products[prod_index].access;
37681
37682 if (cciss_board_disabled(h)) {
37683 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
37684 @@ -5057,7 +5057,7 @@ reinit_after_soft_reset:
37685 }
37686
37687 /* make sure the board interrupts are off */
37688 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37689 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37690 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
37691 if (rc)
37692 goto clean2;
37693 @@ -5107,7 +5107,7 @@ reinit_after_soft_reset:
37694 * fake ones to scoop up any residual completions.
37695 */
37696 spin_lock_irqsave(&h->lock, flags);
37697 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37698 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37699 spin_unlock_irqrestore(&h->lock, flags);
37700 free_irq(h->intr[h->intr_mode], h);
37701 rc = cciss_request_irq(h, cciss_msix_discard_completions,
37702 @@ -5127,9 +5127,9 @@ reinit_after_soft_reset:
37703 dev_info(&h->pdev->dev, "Board READY.\n");
37704 dev_info(&h->pdev->dev,
37705 "Waiting for stale completions to drain.\n");
37706 - h->access.set_intr_mask(h, CCISS_INTR_ON);
37707 + h->access->set_intr_mask(h, CCISS_INTR_ON);
37708 msleep(10000);
37709 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37710 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37711
37712 rc = controller_reset_failed(h->cfgtable);
37713 if (rc)
37714 @@ -5152,7 +5152,7 @@ reinit_after_soft_reset:
37715 cciss_scsi_setup(h);
37716
37717 /* Turn the interrupts on so we can service requests */
37718 - h->access.set_intr_mask(h, CCISS_INTR_ON);
37719 + h->access->set_intr_mask(h, CCISS_INTR_ON);
37720
37721 /* Get the firmware version */
37722 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
37723 @@ -5224,7 +5224,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
37724 kfree(flush_buf);
37725 if (return_code != IO_OK)
37726 dev_warn(&h->pdev->dev, "Error flushing cache\n");
37727 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37728 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37729 free_irq(h->intr[h->intr_mode], h);
37730 }
37731
37732 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
37733 index 7fda30e..2f27946 100644
37734 --- a/drivers/block/cciss.h
37735 +++ b/drivers/block/cciss.h
37736 @@ -101,7 +101,7 @@ struct ctlr_info
37737 /* information about each logical volume */
37738 drive_info_struct *drv[CISS_MAX_LUN];
37739
37740 - struct access_method access;
37741 + struct access_method *access;
37742
37743 /* queue and queue Info */
37744 struct list_head reqQ;
37745 @@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
37746 }
37747
37748 static struct access_method SA5_access = {
37749 - SA5_submit_command,
37750 - SA5_intr_mask,
37751 - SA5_fifo_full,
37752 - SA5_intr_pending,
37753 - SA5_completed,
37754 + .submit_command = SA5_submit_command,
37755 + .set_intr_mask = SA5_intr_mask,
37756 + .fifo_full = SA5_fifo_full,
37757 + .intr_pending = SA5_intr_pending,
37758 + .command_completed = SA5_completed,
37759 };
37760
37761 static struct access_method SA5B_access = {
37762 - SA5_submit_command,
37763 - SA5B_intr_mask,
37764 - SA5_fifo_full,
37765 - SA5B_intr_pending,
37766 - SA5_completed,
37767 + .submit_command = SA5_submit_command,
37768 + .set_intr_mask = SA5B_intr_mask,
37769 + .fifo_full = SA5_fifo_full,
37770 + .intr_pending = SA5B_intr_pending,
37771 + .command_completed = SA5_completed,
37772 };
37773
37774 static struct access_method SA5_performant_access = {
37775 - SA5_submit_command,
37776 - SA5_performant_intr_mask,
37777 - SA5_fifo_full,
37778 - SA5_performant_intr_pending,
37779 - SA5_performant_completed,
37780 + .submit_command = SA5_submit_command,
37781 + .set_intr_mask = SA5_performant_intr_mask,
37782 + .fifo_full = SA5_fifo_full,
37783 + .intr_pending = SA5_performant_intr_pending,
37784 + .command_completed = SA5_performant_completed,
37785 };
37786
37787 struct board_type {
37788 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
37789 index 2b94403..fd6ad1f 100644
37790 --- a/drivers/block/cpqarray.c
37791 +++ b/drivers/block/cpqarray.c
37792 @@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37793 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
37794 goto Enomem4;
37795 }
37796 - hba[i]->access.set_intr_mask(hba[i], 0);
37797 + hba[i]->access->set_intr_mask(hba[i], 0);
37798 if (request_irq(hba[i]->intr, do_ida_intr,
37799 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
37800 {
37801 @@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37802 add_timer(&hba[i]->timer);
37803
37804 /* Enable IRQ now that spinlock and rate limit timer are set up */
37805 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37806 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37807
37808 for(j=0; j<NWD; j++) {
37809 struct gendisk *disk = ida_gendisk[i][j];
37810 @@ -694,7 +694,7 @@ DBGINFO(
37811 for(i=0; i<NR_PRODUCTS; i++) {
37812 if (board_id == products[i].board_id) {
37813 c->product_name = products[i].product_name;
37814 - c->access = *(products[i].access);
37815 + c->access = products[i].access;
37816 break;
37817 }
37818 }
37819 @@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
37820 hba[ctlr]->intr = intr;
37821 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
37822 hba[ctlr]->product_name = products[j].product_name;
37823 - hba[ctlr]->access = *(products[j].access);
37824 + hba[ctlr]->access = products[j].access;
37825 hba[ctlr]->ctlr = ctlr;
37826 hba[ctlr]->board_id = board_id;
37827 hba[ctlr]->pci_dev = NULL; /* not PCI */
37828 @@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
37829
37830 while((c = h->reqQ) != NULL) {
37831 /* Can't do anything if we're busy */
37832 - if (h->access.fifo_full(h) == 0)
37833 + if (h->access->fifo_full(h) == 0)
37834 return;
37835
37836 /* Get the first entry from the request Q */
37837 @@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
37838 h->Qdepth--;
37839
37840 /* Tell the controller to do our bidding */
37841 - h->access.submit_command(h, c);
37842 + h->access->submit_command(h, c);
37843
37844 /* Get onto the completion Q */
37845 addQ(&h->cmpQ, c);
37846 @@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37847 unsigned long flags;
37848 __u32 a,a1;
37849
37850 - istat = h->access.intr_pending(h);
37851 + istat = h->access->intr_pending(h);
37852 /* Is this interrupt for us? */
37853 if (istat == 0)
37854 return IRQ_NONE;
37855 @@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37856 */
37857 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
37858 if (istat & FIFO_NOT_EMPTY) {
37859 - while((a = h->access.command_completed(h))) {
37860 + while((a = h->access->command_completed(h))) {
37861 a1 = a; a &= ~3;
37862 if ((c = h->cmpQ) == NULL)
37863 {
37864 @@ -1448,11 +1448,11 @@ static int sendcmd(
37865 /*
37866 * Disable interrupt
37867 */
37868 - info_p->access.set_intr_mask(info_p, 0);
37869 + info_p->access->set_intr_mask(info_p, 0);
37870 /* Make sure there is room in the command FIFO */
37871 /* Actually it should be completely empty at this time. */
37872 for (i = 200000; i > 0; i--) {
37873 - temp = info_p->access.fifo_full(info_p);
37874 + temp = info_p->access->fifo_full(info_p);
37875 if (temp != 0) {
37876 break;
37877 }
37878 @@ -1465,7 +1465,7 @@ DBG(
37879 /*
37880 * Send the cmd
37881 */
37882 - info_p->access.submit_command(info_p, c);
37883 + info_p->access->submit_command(info_p, c);
37884 complete = pollcomplete(ctlr);
37885
37886 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
37887 @@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
37888 * we check the new geometry. Then turn interrupts back on when
37889 * we're done.
37890 */
37891 - host->access.set_intr_mask(host, 0);
37892 + host->access->set_intr_mask(host, 0);
37893 getgeometry(ctlr);
37894 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
37895 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
37896
37897 for(i=0; i<NWD; i++) {
37898 struct gendisk *disk = ida_gendisk[ctlr][i];
37899 @@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
37900 /* Wait (up to 2 seconds) for a command to complete */
37901
37902 for (i = 200000; i > 0; i--) {
37903 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
37904 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
37905 if (done == 0) {
37906 udelay(10); /* a short fixed delay */
37907 } else
37908 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
37909 index be73e9d..7fbf140 100644
37910 --- a/drivers/block/cpqarray.h
37911 +++ b/drivers/block/cpqarray.h
37912 @@ -99,7 +99,7 @@ struct ctlr_info {
37913 drv_info_t drv[NWD];
37914 struct proc_dir_entry *proc;
37915
37916 - struct access_method access;
37917 + struct access_method *access;
37918
37919 cmdlist_t *reqQ;
37920 cmdlist_t *cmpQ;
37921 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
37922 index e7093d4..b364085 100644
37923 --- a/drivers/block/drbd/drbd_int.h
37924 +++ b/drivers/block/drbd/drbd_int.h
37925 @@ -331,7 +331,7 @@ struct drbd_epoch {
37926 struct drbd_connection *connection;
37927 struct list_head list;
37928 unsigned int barrier_nr;
37929 - atomic_t epoch_size; /* increased on every request added. */
37930 + atomic_unchecked_t epoch_size; /* increased on every request added. */
37931 atomic_t active; /* increased on every req. added, and dec on every finished. */
37932 unsigned long flags;
37933 };
37934 @@ -787,7 +787,7 @@ struct drbd_device {
37935 unsigned int al_tr_number;
37936 int al_tr_cycle;
37937 wait_queue_head_t seq_wait;
37938 - atomic_t packet_seq;
37939 + atomic_unchecked_t packet_seq;
37940 unsigned int peer_seq;
37941 spinlock_t peer_seq_lock;
37942 unsigned int minor;
37943 @@ -1361,7 +1361,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
37944 char __user *uoptval;
37945 int err;
37946
37947 - uoptval = (char __user __force *)optval;
37948 + uoptval = (char __force_user *)optval;
37949
37950 set_fs(KERNEL_DS);
37951 if (level == SOL_SOCKET)
37952 diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
37953 index 89c497c..9c736ae 100644
37954 --- a/drivers/block/drbd/drbd_interval.c
37955 +++ b/drivers/block/drbd/drbd_interval.c
37956 @@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
37957 }
37958
37959 static const struct rb_augment_callbacks augment_callbacks = {
37960 - augment_propagate,
37961 - augment_copy,
37962 - augment_rotate,
37963 + .propagate = augment_propagate,
37964 + .copy = augment_copy,
37965 + .rotate = augment_rotate,
37966 };
37967
37968 /**
37969 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
37970 index 331e5cc..6d657bce 100644
37971 --- a/drivers/block/drbd/drbd_main.c
37972 +++ b/drivers/block/drbd/drbd_main.c
37973 @@ -1322,7 +1322,7 @@ static int _drbd_send_ack(struct drbd_peer_device *peer_device, enum drbd_packet
37974 p->sector = sector;
37975 p->block_id = block_id;
37976 p->blksize = blksize;
37977 - p->seq_num = cpu_to_be32(atomic_inc_return(&peer_device->device->packet_seq));
37978 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&peer_device->device->packet_seq));
37979 return drbd_send_command(peer_device, sock, cmd, sizeof(*p), NULL, 0);
37980 }
37981
37982 @@ -1628,7 +1628,7 @@ int drbd_send_dblock(struct drbd_peer_device *peer_device, struct drbd_request *
37983 return -EIO;
37984 p->sector = cpu_to_be64(req->i.sector);
37985 p->block_id = (unsigned long)req;
37986 - p->seq_num = cpu_to_be32(atomic_inc_return(&device->packet_seq));
37987 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&device->packet_seq));
37988 dp_flags = bio_flags_to_wire(peer_device->connection, req->master_bio->bi_rw);
37989 if (device->state.conn >= C_SYNC_SOURCE &&
37990 device->state.conn <= C_PAUSED_SYNC_T)
37991 @@ -2658,8 +2658,8 @@ void drbd_destroy_connection(struct kref *kref)
37992 struct drbd_connection *connection = container_of(kref, struct drbd_connection, kref);
37993 struct drbd_resource *resource = connection->resource;
37994
37995 - if (atomic_read(&connection->current_epoch->epoch_size) != 0)
37996 - drbd_err(connection, "epoch_size:%d\n", atomic_read(&connection->current_epoch->epoch_size));
37997 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size) != 0)
37998 + drbd_err(connection, "epoch_size:%d\n", atomic_read_unchecked(&connection->current_epoch->epoch_size));
37999 kfree(connection->current_epoch);
38000
38001 idr_destroy(&connection->peer_devices);
38002 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
38003 index 526414b..4eb8184 100644
38004 --- a/drivers/block/drbd/drbd_nl.c
38005 +++ b/drivers/block/drbd/drbd_nl.c
38006 @@ -3505,7 +3505,7 @@ out:
38007
38008 void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
38009 {
38010 - static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38011 + static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38012 struct sk_buff *msg;
38013 struct drbd_genlmsghdr *d_out;
38014 unsigned seq;
38015 @@ -3518,7 +3518,7 @@ void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
38016 return;
38017 }
38018
38019 - seq = atomic_inc_return(&drbd_genl_seq);
38020 + seq = atomic_inc_return_unchecked(&drbd_genl_seq);
38021 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
38022 if (!msg)
38023 goto failed;
38024 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
38025 index 68e3992..1aca24a 100644
38026 --- a/drivers/block/drbd/drbd_receiver.c
38027 +++ b/drivers/block/drbd/drbd_receiver.c
38028 @@ -826,7 +826,7 @@ int drbd_connected(struct drbd_peer_device *peer_device)
38029 struct drbd_device *device = peer_device->device;
38030 int err;
38031
38032 - atomic_set(&device->packet_seq, 0);
38033 + atomic_set_unchecked(&device->packet_seq, 0);
38034 device->peer_seq = 0;
38035
38036 device->state_mutex = peer_device->connection->agreed_pro_version < 100 ?
38037 @@ -1188,7 +1188,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
38038 do {
38039 next_epoch = NULL;
38040
38041 - epoch_size = atomic_read(&epoch->epoch_size);
38042 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
38043
38044 switch (ev & ~EV_CLEANUP) {
38045 case EV_PUT:
38046 @@ -1228,7 +1228,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
38047 rv = FE_DESTROYED;
38048 } else {
38049 epoch->flags = 0;
38050 - atomic_set(&epoch->epoch_size, 0);
38051 + atomic_set_unchecked(&epoch->epoch_size, 0);
38052 /* atomic_set(&epoch->active, 0); is already zero */
38053 if (rv == FE_STILL_LIVE)
38054 rv = FE_RECYCLED;
38055 @@ -1456,7 +1456,7 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
38056 conn_wait_active_ee_empty(connection);
38057 drbd_flush(connection);
38058
38059 - if (atomic_read(&connection->current_epoch->epoch_size)) {
38060 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
38061 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
38062 if (epoch)
38063 break;
38064 @@ -1469,11 +1469,11 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
38065 }
38066
38067 epoch->flags = 0;
38068 - atomic_set(&epoch->epoch_size, 0);
38069 + atomic_set_unchecked(&epoch->epoch_size, 0);
38070 atomic_set(&epoch->active, 0);
38071
38072 spin_lock(&connection->epoch_lock);
38073 - if (atomic_read(&connection->current_epoch->epoch_size)) {
38074 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
38075 list_add(&epoch->list, &connection->current_epoch->list);
38076 connection->current_epoch = epoch;
38077 connection->epochs++;
38078 @@ -2182,7 +2182,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
38079
38080 err = wait_for_and_update_peer_seq(peer_device, peer_seq);
38081 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
38082 - atomic_inc(&connection->current_epoch->epoch_size);
38083 + atomic_inc_unchecked(&connection->current_epoch->epoch_size);
38084 err2 = drbd_drain_block(peer_device, pi->size);
38085 if (!err)
38086 err = err2;
38087 @@ -2216,7 +2216,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
38088
38089 spin_lock(&connection->epoch_lock);
38090 peer_req->epoch = connection->current_epoch;
38091 - atomic_inc(&peer_req->epoch->epoch_size);
38092 + atomic_inc_unchecked(&peer_req->epoch->epoch_size);
38093 atomic_inc(&peer_req->epoch->active);
38094 spin_unlock(&connection->epoch_lock);
38095
38096 @@ -4396,7 +4396,7 @@ struct data_cmd {
38097 int expect_payload;
38098 size_t pkt_size;
38099 int (*fn)(struct drbd_connection *, struct packet_info *);
38100 -};
38101 +} __do_const;
38102
38103 static struct data_cmd drbd_cmd_handler[] = {
38104 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
38105 @@ -4506,7 +4506,7 @@ static void conn_disconnect(struct drbd_connection *connection)
38106 if (!list_empty(&connection->current_epoch->list))
38107 drbd_err(connection, "ASSERTION FAILED: connection->current_epoch->list not empty\n");
38108 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
38109 - atomic_set(&connection->current_epoch->epoch_size, 0);
38110 + atomic_set_unchecked(&connection->current_epoch->epoch_size, 0);
38111 connection->send.seen_any_write_yet = false;
38112
38113 drbd_info(connection, "Connection closed\n");
38114 @@ -5281,7 +5281,7 @@ static int connection_finish_peer_reqs(struct drbd_connection *connection)
38115 struct asender_cmd {
38116 size_t pkt_size;
38117 int (*fn)(struct drbd_connection *connection, struct packet_info *);
38118 -};
38119 +} __do_const;
38120
38121 static struct asender_cmd asender_tbl[] = {
38122 [P_PING] = { 0, got_Ping },
38123 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
38124 index f70a230..9dc90d5 100644
38125 --- a/drivers/block/loop.c
38126 +++ b/drivers/block/loop.c
38127 @@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
38128
38129 file_start_write(file);
38130 set_fs(get_ds());
38131 - bw = file->f_op->write(file, buf, len, &pos);
38132 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
38133 set_fs(old_fs);
38134 file_end_write(file);
38135 if (likely(bw == len))
38136 diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
38137 index 091b9ea..f5428f8 100644
38138 --- a/drivers/block/null_blk.c
38139 +++ b/drivers/block/null_blk.c
38140 @@ -382,15 +382,25 @@ static int null_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
38141 return 0;
38142 }
38143
38144 -static struct blk_mq_ops null_mq_ops = {
38145 - .queue_rq = null_queue_rq,
38146 - .map_queue = blk_mq_map_queue,
38147 +static struct blk_mq_ops null_mq_single_ops = {
38148 + .queue_rq = null_queue_rq,
38149 + .map_queue = blk_mq_map_queue,
38150 .init_hctx = null_init_hctx,
38151 .complete = null_softirq_done_fn,
38152 + .alloc_hctx = blk_mq_alloc_single_hw_queue,
38153 + .free_hctx = blk_mq_free_single_hw_queue,
38154 +};
38155 +
38156 +static struct blk_mq_ops null_mq_per_node_ops = {
38157 + .queue_rq = null_queue_rq,
38158 + .map_queue = blk_mq_map_queue,
38159 + .init_hctx = null_init_hctx,
38160 + .alloc_hctx = null_alloc_hctx,
38161 + .free_hctx = null_free_hctx,
38162 };
38163
38164 static struct blk_mq_reg null_mq_reg = {
38165 - .ops = &null_mq_ops,
38166 + .ops = &null_mq_single_ops,
38167 .queue_depth = 64,
38168 .cmd_size = sizeof(struct nullb_cmd),
38169 .flags = BLK_MQ_F_SHOULD_MERGE,
38170 @@ -521,13 +531,8 @@ static int null_add_dev(void)
38171 null_mq_reg.queue_depth = hw_queue_depth;
38172 null_mq_reg.nr_hw_queues = submit_queues;
38173
38174 - if (use_per_node_hctx) {
38175 - null_mq_reg.ops->alloc_hctx = null_alloc_hctx;
38176 - null_mq_reg.ops->free_hctx = null_free_hctx;
38177 - } else {
38178 - null_mq_reg.ops->alloc_hctx = blk_mq_alloc_single_hw_queue;
38179 - null_mq_reg.ops->free_hctx = blk_mq_free_single_hw_queue;
38180 - }
38181 + if (use_per_node_hctx)
38182 + null_mq_reg.ops = &null_mq_per_node_ops;
38183
38184 nullb->q = blk_mq_init_queue(&null_mq_reg, nullb);
38185 } else if (queue_mode == NULL_Q_BIO) {
38186 diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
38187 index a2af73d..c0b8f61 100644
38188 --- a/drivers/block/pktcdvd.c
38189 +++ b/drivers/block/pktcdvd.c
38190 @@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
38191
38192 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
38193 {
38194 - return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
38195 + return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
38196 }
38197
38198 /*
38199 @@ -1888,7 +1888,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
38200 return -EROFS;
38201 }
38202 pd->settings.fp = ti.fp;
38203 - pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
38204 + pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
38205
38206 if (ti.nwa_v) {
38207 pd->nwa = be32_to_cpu(ti.next_writable);
38208 diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
38209 index e5565fb..71be10b4 100644
38210 --- a/drivers/block/smart1,2.h
38211 +++ b/drivers/block/smart1,2.h
38212 @@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
38213 }
38214
38215 static struct access_method smart4_access = {
38216 - smart4_submit_command,
38217 - smart4_intr_mask,
38218 - smart4_fifo_full,
38219 - smart4_intr_pending,
38220 - smart4_completed,
38221 + .submit_command = smart4_submit_command,
38222 + .set_intr_mask = smart4_intr_mask,
38223 + .fifo_full = smart4_fifo_full,
38224 + .intr_pending = smart4_intr_pending,
38225 + .command_completed = smart4_completed,
38226 };
38227
38228 /*
38229 @@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
38230 }
38231
38232 static struct access_method smart2_access = {
38233 - smart2_submit_command,
38234 - smart2_intr_mask,
38235 - smart2_fifo_full,
38236 - smart2_intr_pending,
38237 - smart2_completed,
38238 + .submit_command = smart2_submit_command,
38239 + .set_intr_mask = smart2_intr_mask,
38240 + .fifo_full = smart2_fifo_full,
38241 + .intr_pending = smart2_intr_pending,
38242 + .command_completed = smart2_completed,
38243 };
38244
38245 /*
38246 @@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
38247 }
38248
38249 static struct access_method smart2e_access = {
38250 - smart2e_submit_command,
38251 - smart2e_intr_mask,
38252 - smart2e_fifo_full,
38253 - smart2e_intr_pending,
38254 - smart2e_completed,
38255 + .submit_command = smart2e_submit_command,
38256 + .set_intr_mask = smart2e_intr_mask,
38257 + .fifo_full = smart2e_fifo_full,
38258 + .intr_pending = smart2e_intr_pending,
38259 + .command_completed = smart2e_completed,
38260 };
38261
38262 /*
38263 @@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
38264 }
38265
38266 static struct access_method smart1_access = {
38267 - smart1_submit_command,
38268 - smart1_intr_mask,
38269 - smart1_fifo_full,
38270 - smart1_intr_pending,
38271 - smart1_completed,
38272 + .submit_command = smart1_submit_command,
38273 + .set_intr_mask = smart1_intr_mask,
38274 + .fifo_full = smart1_fifo_full,
38275 + .intr_pending = smart1_intr_pending,
38276 + .command_completed = smart1_completed,
38277 };
38278 diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
38279 index f038dba..bb74c08 100644
38280 --- a/drivers/bluetooth/btwilink.c
38281 +++ b/drivers/bluetooth/btwilink.c
38282 @@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
38283
38284 static int bt_ti_probe(struct platform_device *pdev)
38285 {
38286 - static struct ti_st *hst;
38287 + struct ti_st *hst;
38288 struct hci_dev *hdev;
38289 int err;
38290
38291 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
38292 index 8a3aff7..d7538c2 100644
38293 --- a/drivers/cdrom/cdrom.c
38294 +++ b/drivers/cdrom/cdrom.c
38295 @@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
38296 ENSURE(reset, CDC_RESET);
38297 ENSURE(generic_packet, CDC_GENERIC_PACKET);
38298 cdi->mc_flags = 0;
38299 - cdo->n_minors = 0;
38300 cdi->options = CDO_USE_FFLAGS;
38301
38302 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
38303 @@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
38304 else
38305 cdi->cdda_method = CDDA_OLD;
38306
38307 - if (!cdo->generic_packet)
38308 - cdo->generic_packet = cdrom_dummy_generic_packet;
38309 + if (!cdo->generic_packet) {
38310 + pax_open_kernel();
38311 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
38312 + pax_close_kernel();
38313 + }
38314
38315 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
38316 mutex_lock(&cdrom_mutex);
38317 @@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
38318 if (cdi->exit)
38319 cdi->exit(cdi);
38320
38321 - cdi->ops->n_minors--;
38322 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
38323 }
38324
38325 @@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
38326 */
38327 nr = nframes;
38328 do {
38329 - cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38330 + cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38331 if (cgc.buffer)
38332 break;
38333
38334 @@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
38335 struct cdrom_device_info *cdi;
38336 int ret;
38337
38338 - ret = scnprintf(info + *pos, max_size - *pos, header);
38339 + ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
38340 if (!ret)
38341 return 1;
38342
38343 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
38344 index 51e75ad..39c4c76 100644
38345 --- a/drivers/cdrom/gdrom.c
38346 +++ b/drivers/cdrom/gdrom.c
38347 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
38348 .audio_ioctl = gdrom_audio_ioctl,
38349 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
38350 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
38351 - .n_minors = 1,
38352 };
38353
38354 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
38355 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
38356 index 6e9f74a..50c7cea 100644
38357 --- a/drivers/char/Kconfig
38358 +++ b/drivers/char/Kconfig
38359 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
38360
38361 config DEVKMEM
38362 bool "/dev/kmem virtual device support"
38363 - default y
38364 + default n
38365 + depends on !GRKERNSEC_KMEM
38366 help
38367 Say Y here if you want to support the /dev/kmem device. The
38368 /dev/kmem device is rarely used, but can be used for certain
38369 @@ -577,6 +578,7 @@ config DEVPORT
38370 bool
38371 depends on !M68K
38372 depends on ISA || PCI
38373 + depends on !GRKERNSEC_KMEM
38374 default y
38375
38376 source "drivers/s390/char/Kconfig"
38377 diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
38378 index a48e05b..6bac831 100644
38379 --- a/drivers/char/agp/compat_ioctl.c
38380 +++ b/drivers/char/agp/compat_ioctl.c
38381 @@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
38382 return -ENOMEM;
38383 }
38384
38385 - if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
38386 + if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
38387 sizeof(*usegment) * ureserve.seg_count)) {
38388 kfree(usegment);
38389 kfree(ksegment);
38390 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
38391 index b297033..fa217ca 100644
38392 --- a/drivers/char/agp/frontend.c
38393 +++ b/drivers/char/agp/frontend.c
38394 @@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38395 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
38396 return -EFAULT;
38397
38398 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
38399 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
38400 return -EFAULT;
38401
38402 client = agp_find_client_by_pid(reserve.pid);
38403 @@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38404 if (segment == NULL)
38405 return -ENOMEM;
38406
38407 - if (copy_from_user(segment, (void __user *) reserve.seg_list,
38408 + if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
38409 sizeof(struct agp_segment) * reserve.seg_count)) {
38410 kfree(segment);
38411 return -EFAULT;
38412 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
38413 index 4f94375..413694e 100644
38414 --- a/drivers/char/genrtc.c
38415 +++ b/drivers/char/genrtc.c
38416 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
38417 switch (cmd) {
38418
38419 case RTC_PLL_GET:
38420 + memset(&pll, 0, sizeof(pll));
38421 if (get_rtc_pll(&pll))
38422 return -EINVAL;
38423 else
38424 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
38425 index d5d4cd8..22d561d 100644
38426 --- a/drivers/char/hpet.c
38427 +++ b/drivers/char/hpet.c
38428 @@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
38429 }
38430
38431 static int
38432 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
38433 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
38434 struct hpet_info *info)
38435 {
38436 struct hpet_timer __iomem *timer;
38437 diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
38438 index 86fe45c..c0ea948 100644
38439 --- a/drivers/char/hw_random/intel-rng.c
38440 +++ b/drivers/char/hw_random/intel-rng.c
38441 @@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
38442
38443 if (no_fwh_detect)
38444 return -ENODEV;
38445 - printk(warning);
38446 + printk("%s", warning);
38447 return -EBUSY;
38448 }
38449
38450 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
38451 index e6db938..835e3a2 100644
38452 --- a/drivers/char/ipmi/ipmi_msghandler.c
38453 +++ b/drivers/char/ipmi/ipmi_msghandler.c
38454 @@ -438,7 +438,7 @@ struct ipmi_smi {
38455 struct proc_dir_entry *proc_dir;
38456 char proc_dir_name[10];
38457
38458 - atomic_t stats[IPMI_NUM_STATS];
38459 + atomic_unchecked_t stats[IPMI_NUM_STATS];
38460
38461 /*
38462 * run_to_completion duplicate of smb_info, smi_info
38463 @@ -470,9 +470,9 @@ static LIST_HEAD(smi_watchers);
38464 static DEFINE_MUTEX(smi_watchers_mutex);
38465
38466 #define ipmi_inc_stat(intf, stat) \
38467 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
38468 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
38469 #define ipmi_get_stat(intf, stat) \
38470 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
38471 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
38472
38473 static int is_lan_addr(struct ipmi_addr *addr)
38474 {
38475 @@ -2926,7 +2926,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
38476 INIT_LIST_HEAD(&intf->cmd_rcvrs);
38477 init_waitqueue_head(&intf->waitq);
38478 for (i = 0; i < IPMI_NUM_STATS; i++)
38479 - atomic_set(&intf->stats[i], 0);
38480 + atomic_set_unchecked(&intf->stats[i], 0);
38481
38482 intf->proc_dir = NULL;
38483
38484 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
38485 index 1c4bb4f..719e873 100644
38486 --- a/drivers/char/ipmi/ipmi_si_intf.c
38487 +++ b/drivers/char/ipmi/ipmi_si_intf.c
38488 @@ -285,7 +285,7 @@ struct smi_info {
38489 unsigned char slave_addr;
38490
38491 /* Counters and things for the proc filesystem. */
38492 - atomic_t stats[SI_NUM_STATS];
38493 + atomic_unchecked_t stats[SI_NUM_STATS];
38494
38495 struct task_struct *thread;
38496
38497 @@ -294,9 +294,9 @@ struct smi_info {
38498 };
38499
38500 #define smi_inc_stat(smi, stat) \
38501 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
38502 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
38503 #define smi_get_stat(smi, stat) \
38504 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
38505 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
38506
38507 #define SI_MAX_PARMS 4
38508
38509 @@ -3374,7 +3374,7 @@ static int try_smi_init(struct smi_info *new_smi)
38510 atomic_set(&new_smi->req_events, 0);
38511 new_smi->run_to_completion = false;
38512 for (i = 0; i < SI_NUM_STATS; i++)
38513 - atomic_set(&new_smi->stats[i], 0);
38514 + atomic_set_unchecked(&new_smi->stats[i], 0);
38515
38516 new_smi->interrupt_disabled = true;
38517 atomic_set(&new_smi->stop_operation, 0);
38518 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
38519 index 917403f..dddd899 100644
38520 --- a/drivers/char/mem.c
38521 +++ b/drivers/char/mem.c
38522 @@ -18,6 +18,7 @@
38523 #include <linux/raw.h>
38524 #include <linux/tty.h>
38525 #include <linux/capability.h>
38526 +#include <linux/security.h>
38527 #include <linux/ptrace.h>
38528 #include <linux/device.h>
38529 #include <linux/highmem.h>
38530 @@ -36,6 +37,10 @@
38531
38532 #define DEVPORT_MINOR 4
38533
38534 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38535 +extern const struct file_operations grsec_fops;
38536 +#endif
38537 +
38538 static inline unsigned long size_inside_page(unsigned long start,
38539 unsigned long size)
38540 {
38541 @@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38542
38543 while (cursor < to) {
38544 if (!devmem_is_allowed(pfn)) {
38545 +#ifdef CONFIG_GRKERNSEC_KMEM
38546 + gr_handle_mem_readwrite(from, to);
38547 +#else
38548 printk(KERN_INFO
38549 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
38550 current->comm, from, to);
38551 +#endif
38552 return 0;
38553 }
38554 cursor += PAGE_SIZE;
38555 @@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38556 }
38557 return 1;
38558 }
38559 +#elif defined(CONFIG_GRKERNSEC_KMEM)
38560 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38561 +{
38562 + return 0;
38563 +}
38564 #else
38565 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38566 {
38567 @@ -122,6 +136,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38568
38569 while (count > 0) {
38570 unsigned long remaining;
38571 + char *temp;
38572
38573 sz = size_inside_page(p, count);
38574
38575 @@ -137,7 +152,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38576 if (!ptr)
38577 return -EFAULT;
38578
38579 - remaining = copy_to_user(buf, ptr, sz);
38580 +#ifdef CONFIG_PAX_USERCOPY
38581 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38582 + if (!temp) {
38583 + unxlate_dev_mem_ptr(p, ptr);
38584 + return -ENOMEM;
38585 + }
38586 + memcpy(temp, ptr, sz);
38587 +#else
38588 + temp = ptr;
38589 +#endif
38590 +
38591 + remaining = copy_to_user(buf, temp, sz);
38592 +
38593 +#ifdef CONFIG_PAX_USERCOPY
38594 + kfree(temp);
38595 +#endif
38596 +
38597 unxlate_dev_mem_ptr(p, ptr);
38598 if (remaining)
38599 return -EFAULT;
38600 @@ -369,9 +400,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38601 size_t count, loff_t *ppos)
38602 {
38603 unsigned long p = *ppos;
38604 - ssize_t low_count, read, sz;
38605 + ssize_t low_count, read, sz, err = 0;
38606 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
38607 - int err = 0;
38608
38609 read = 0;
38610 if (p < (unsigned long) high_memory) {
38611 @@ -393,6 +423,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38612 }
38613 #endif
38614 while (low_count > 0) {
38615 + char *temp;
38616 +
38617 sz = size_inside_page(p, low_count);
38618
38619 /*
38620 @@ -402,7 +434,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38621 */
38622 kbuf = xlate_dev_kmem_ptr((char *)p);
38623
38624 - if (copy_to_user(buf, kbuf, sz))
38625 +#ifdef CONFIG_PAX_USERCOPY
38626 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38627 + if (!temp)
38628 + return -ENOMEM;
38629 + memcpy(temp, kbuf, sz);
38630 +#else
38631 + temp = kbuf;
38632 +#endif
38633 +
38634 + err = copy_to_user(buf, temp, sz);
38635 +
38636 +#ifdef CONFIG_PAX_USERCOPY
38637 + kfree(temp);
38638 +#endif
38639 +
38640 + if (err)
38641 return -EFAULT;
38642 buf += sz;
38643 p += sz;
38644 @@ -827,6 +874,9 @@ static const struct memdev {
38645 #ifdef CONFIG_PRINTK
38646 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
38647 #endif
38648 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38649 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
38650 +#endif
38651 };
38652
38653 static int memory_open(struct inode *inode, struct file *filp)
38654 @@ -898,7 +948,7 @@ static int __init chr_dev_init(void)
38655 continue;
38656
38657 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
38658 - NULL, devlist[minor].name);
38659 + NULL, "%s", devlist[minor].name);
38660 }
38661
38662 return tty_init();
38663 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
38664 index 9df78e2..01ba9ae 100644
38665 --- a/drivers/char/nvram.c
38666 +++ b/drivers/char/nvram.c
38667 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
38668
38669 spin_unlock_irq(&rtc_lock);
38670
38671 - if (copy_to_user(buf, contents, tmp - contents))
38672 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
38673 return -EFAULT;
38674
38675 *ppos = i;
38676 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
38677 index 8320abd..ec48108 100644
38678 --- a/drivers/char/pcmcia/synclink_cs.c
38679 +++ b/drivers/char/pcmcia/synclink_cs.c
38680 @@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38681
38682 if (debug_level >= DEBUG_LEVEL_INFO)
38683 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
38684 - __FILE__, __LINE__, info->device_name, port->count);
38685 + __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
38686
38687 - WARN_ON(!port->count);
38688 + WARN_ON(!atomic_read(&port->count));
38689
38690 if (tty_port_close_start(port, tty, filp) == 0)
38691 goto cleanup;
38692 @@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38693 cleanup:
38694 if (debug_level >= DEBUG_LEVEL_INFO)
38695 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
38696 - tty->driver->name, port->count);
38697 + tty->driver->name, atomic_read(&port->count));
38698 }
38699
38700 /* Wait until the transmitter is empty.
38701 @@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38702
38703 if (debug_level >= DEBUG_LEVEL_INFO)
38704 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
38705 - __FILE__, __LINE__, tty->driver->name, port->count);
38706 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
38707
38708 /* If port is closing, signal caller to try again */
38709 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
38710 @@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38711 goto cleanup;
38712 }
38713 spin_lock(&port->lock);
38714 - port->count++;
38715 + atomic_inc(&port->count);
38716 spin_unlock(&port->lock);
38717 spin_unlock_irqrestore(&info->netlock, flags);
38718
38719 - if (port->count == 1) {
38720 + if (atomic_read(&port->count) == 1) {
38721 /* 1st open on this device, init hardware */
38722 retval = startup(info, tty);
38723 if (retval < 0)
38724 @@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38725 unsigned short new_crctype;
38726
38727 /* return error if TTY interface open */
38728 - if (info->port.count)
38729 + if (atomic_read(&info->port.count))
38730 return -EBUSY;
38731
38732 switch (encoding)
38733 @@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
38734
38735 /* arbitrate between network and tty opens */
38736 spin_lock_irqsave(&info->netlock, flags);
38737 - if (info->port.count != 0 || info->netcount != 0) {
38738 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38739 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38740 spin_unlock_irqrestore(&info->netlock, flags);
38741 return -EBUSY;
38742 @@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38743 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
38744
38745 /* return error if TTY interface open */
38746 - if (info->port.count)
38747 + if (atomic_read(&info->port.count))
38748 return -EBUSY;
38749
38750 if (cmd != SIOCWANDEV)
38751 diff --git a/drivers/char/random.c b/drivers/char/random.c
38752 index 18ec404..32033f3 100644
38753 --- a/drivers/char/random.c
38754 +++ b/drivers/char/random.c
38755 @@ -270,10 +270,17 @@
38756 /*
38757 * Configuration information
38758 */
38759 +#ifdef CONFIG_GRKERNSEC_RANDNET
38760 +#define INPUT_POOL_SHIFT 14
38761 +#define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38762 +#define OUTPUT_POOL_SHIFT 12
38763 +#define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38764 +#else
38765 #define INPUT_POOL_SHIFT 12
38766 #define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38767 #define OUTPUT_POOL_SHIFT 10
38768 #define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38769 +#endif
38770 #define SEC_XFER_SIZE 512
38771 #define EXTRACT_SIZE 10
38772
38773 @@ -284,9 +291,6 @@
38774 /*
38775 * To allow fractional bits to be tracked, the entropy_count field is
38776 * denominated in units of 1/8th bits.
38777 - *
38778 - * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
38779 - * credit_entropy_bits() needs to be 64 bits wide.
38780 */
38781 #define ENTROPY_SHIFT 3
38782 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
38783 @@ -361,12 +365,19 @@ static struct poolinfo {
38784 #define S(x) ilog2(x)+5, (x), (x)*4, (x)*32, (x) << (ENTROPY_SHIFT+5)
38785 int tap1, tap2, tap3, tap4, tap5;
38786 } poolinfo_table[] = {
38787 +#ifdef CONFIG_GRKERNSEC_RANDNET
38788 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
38789 + { S(512), 411, 308, 208, 104, 1 },
38790 + /* x^128 + x^104 + x^76 + x^51 + x^25 + x + 1 -- 105 */
38791 + { S(128), 104, 76, 51, 25, 1 },
38792 +#else
38793 /* was: x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 */
38794 /* x^128 + x^104 + x^76 + x^51 +x^25 + x + 1 */
38795 { S(128), 104, 76, 51, 25, 1 },
38796 /* was: x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 */
38797 /* x^32 + x^26 + x^19 + x^14 + x^7 + x + 1 */
38798 { S(32), 26, 19, 14, 7, 1 },
38799 +#endif
38800 #if 0
38801 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
38802 { S(2048), 1638, 1231, 819, 411, 1 },
38803 @@ -433,9 +444,9 @@ struct entropy_store {
38804 };
38805
38806 static void push_to_pool(struct work_struct *work);
38807 -static __u32 input_pool_data[INPUT_POOL_WORDS];
38808 -static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
38809 -static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
38810 +static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
38811 +static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38812 +static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38813
38814 static struct entropy_store input_pool = {
38815 .poolinfo = &poolinfo_table[0],
38816 @@ -524,8 +535,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
38817 input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
38818 }
38819
38820 - ACCESS_ONCE(r->input_rotate) = input_rotate;
38821 - ACCESS_ONCE(r->add_ptr) = i;
38822 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
38823 + ACCESS_ONCE_RW(r->add_ptr) = i;
38824 smp_wmb();
38825
38826 if (out)
38827 @@ -632,7 +643,7 @@ retry:
38828 /* The +2 corresponds to the /4 in the denominator */
38829
38830 do {
38831 - unsigned int anfrac = min(pnfrac, pool_size/2);
38832 + u64 anfrac = min(pnfrac, pool_size/2);
38833 unsigned int add =
38834 ((pool_size - entropy_count)*anfrac*3) >> s;
38835
38836 @@ -1176,7 +1187,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
38837
38838 extract_buf(r, tmp);
38839 i = min_t(int, nbytes, EXTRACT_SIZE);
38840 - if (copy_to_user(buf, tmp, i)) {
38841 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
38842 ret = -EFAULT;
38843 break;
38844 }
38845 @@ -1566,7 +1577,7 @@ static char sysctl_bootid[16];
38846 static int proc_do_uuid(struct ctl_table *table, int write,
38847 void __user *buffer, size_t *lenp, loff_t *ppos)
38848 {
38849 - struct ctl_table fake_table;
38850 + ctl_table_no_const fake_table;
38851 unsigned char buf[64], tmp_uuid[16], *uuid;
38852
38853 uuid = table->data;
38854 @@ -1596,7 +1607,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
38855 static int proc_do_entropy(ctl_table *table, int write,
38856 void __user *buffer, size_t *lenp, loff_t *ppos)
38857 {
38858 - ctl_table fake_table;
38859 + ctl_table_no_const fake_table;
38860 int entropy_count;
38861
38862 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
38863 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
38864 index 7cc1fe22..b602d6b 100644
38865 --- a/drivers/char/sonypi.c
38866 +++ b/drivers/char/sonypi.c
38867 @@ -54,6 +54,7 @@
38868
38869 #include <asm/uaccess.h>
38870 #include <asm/io.h>
38871 +#include <asm/local.h>
38872
38873 #include <linux/sonypi.h>
38874
38875 @@ -490,7 +491,7 @@ static struct sonypi_device {
38876 spinlock_t fifo_lock;
38877 wait_queue_head_t fifo_proc_list;
38878 struct fasync_struct *fifo_async;
38879 - int open_count;
38880 + local_t open_count;
38881 int model;
38882 struct input_dev *input_jog_dev;
38883 struct input_dev *input_key_dev;
38884 @@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
38885 static int sonypi_misc_release(struct inode *inode, struct file *file)
38886 {
38887 mutex_lock(&sonypi_device.lock);
38888 - sonypi_device.open_count--;
38889 + local_dec(&sonypi_device.open_count);
38890 mutex_unlock(&sonypi_device.lock);
38891 return 0;
38892 }
38893 @@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
38894 {
38895 mutex_lock(&sonypi_device.lock);
38896 /* Flush input queue on first open */
38897 - if (!sonypi_device.open_count)
38898 + if (!local_read(&sonypi_device.open_count))
38899 kfifo_reset(&sonypi_device.fifo);
38900 - sonypi_device.open_count++;
38901 + local_inc(&sonypi_device.open_count);
38902 mutex_unlock(&sonypi_device.lock);
38903
38904 return 0;
38905 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
38906 index b9a57fa..5bb9e38 100644
38907 --- a/drivers/char/tpm/tpm_acpi.c
38908 +++ b/drivers/char/tpm/tpm_acpi.c
38909 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
38910 virt = acpi_os_map_memory(start, len);
38911 if (!virt) {
38912 kfree(log->bios_event_log);
38913 + log->bios_event_log = NULL;
38914 printk("%s: ERROR - Unable to map memory\n", __func__);
38915 return -EIO;
38916 }
38917
38918 - memcpy_fromio(log->bios_event_log, virt, len);
38919 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
38920
38921 acpi_os_unmap_memory(virt, len);
38922 return 0;
38923 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
38924 index 59f7cb2..bac8b6d 100644
38925 --- a/drivers/char/tpm/tpm_eventlog.c
38926 +++ b/drivers/char/tpm/tpm_eventlog.c
38927 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
38928 event = addr;
38929
38930 if ((event->event_type == 0 && event->event_size == 0) ||
38931 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
38932 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
38933 return NULL;
38934
38935 return addr;
38936 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
38937 return NULL;
38938
38939 if ((event->event_type == 0 && event->event_size == 0) ||
38940 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
38941 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
38942 return NULL;
38943
38944 (*pos)++;
38945 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
38946 int i;
38947
38948 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
38949 - seq_putc(m, data[i]);
38950 + if (!seq_putc(m, data[i]))
38951 + return -EFAULT;
38952
38953 return 0;
38954 }
38955 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
38956 index 60aafb8..10c08e0 100644
38957 --- a/drivers/char/virtio_console.c
38958 +++ b/drivers/char/virtio_console.c
38959 @@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
38960 if (to_user) {
38961 ssize_t ret;
38962
38963 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
38964 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
38965 if (ret)
38966 return -EFAULT;
38967 } else {
38968 @@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
38969 if (!port_has_data(port) && !port->host_connected)
38970 return 0;
38971
38972 - return fill_readbuf(port, ubuf, count, true);
38973 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
38974 }
38975
38976 static int wait_port_writable(struct port *port, bool nonblock)
38977 diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
38978 index 57a078e..c17cde8 100644
38979 --- a/drivers/clk/clk-composite.c
38980 +++ b/drivers/clk/clk-composite.c
38981 @@ -146,7 +146,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
38982 struct clk *clk;
38983 struct clk_init_data init;
38984 struct clk_composite *composite;
38985 - struct clk_ops *clk_composite_ops;
38986 + clk_ops_no_const *clk_composite_ops;
38987
38988 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
38989 if (!composite) {
38990 diff --git a/drivers/clk/socfpga/clk-gate.c b/drivers/clk/socfpga/clk-gate.c
38991 index 501d513..fb0ecf9 100644
38992 --- a/drivers/clk/socfpga/clk-gate.c
38993 +++ b/drivers/clk/socfpga/clk-gate.c
38994 @@ -22,6 +22,7 @@
38995 #include <linux/mfd/syscon.h>
38996 #include <linux/of.h>
38997 #include <linux/regmap.h>
38998 +#include <asm/pgtable.h>
38999
39000 #include "clk.h"
39001
39002 @@ -175,7 +176,7 @@ static int socfpga_clk_prepare(struct clk_hw *hwclk)
39003 return 0;
39004 }
39005
39006 -static struct clk_ops gateclk_ops = {
39007 +static clk_ops_no_const gateclk_ops __read_only = {
39008 .prepare = socfpga_clk_prepare,
39009 .recalc_rate = socfpga_clk_recalc_rate,
39010 .get_parent = socfpga_clk_get_parent,
39011 @@ -209,8 +210,10 @@ static void __init __socfpga_gate_init(struct device_node *node,
39012 socfpga_clk->hw.reg = clk_mgr_base_addr + clk_gate[0];
39013 socfpga_clk->hw.bit_idx = clk_gate[1];
39014
39015 - gateclk_ops.enable = clk_gate_ops.enable;
39016 - gateclk_ops.disable = clk_gate_ops.disable;
39017 + pax_open_kernel();
39018 + *(void **)&gateclk_ops.enable = clk_gate_ops.enable;
39019 + *(void **)&gateclk_ops.disable = clk_gate_ops.disable;
39020 + pax_close_kernel();
39021 }
39022
39023 rc = of_property_read_u32(node, "fixed-divider", &fixed_div);
39024 diff --git a/drivers/clk/socfpga/clk-pll.c b/drivers/clk/socfpga/clk-pll.c
39025 index de6da95..c98278b 100644
39026 --- a/drivers/clk/socfpga/clk-pll.c
39027 +++ b/drivers/clk/socfpga/clk-pll.c
39028 @@ -21,6 +21,7 @@
39029 #include <linux/io.h>
39030 #include <linux/of.h>
39031 #include <linux/of_address.h>
39032 +#include <asm/pgtable.h>
39033
39034 #include "clk.h"
39035
39036 @@ -76,7 +77,7 @@ static u8 clk_pll_get_parent(struct clk_hw *hwclk)
39037 CLK_MGR_PLL_CLK_SRC_MASK;
39038 }
39039
39040 -static struct clk_ops clk_pll_ops = {
39041 +static clk_ops_no_const clk_pll_ops __read_only = {
39042 .recalc_rate = clk_pll_recalc_rate,
39043 .get_parent = clk_pll_get_parent,
39044 };
39045 @@ -120,8 +121,10 @@ static __init struct clk *__socfpga_pll_init(struct device_node *node,
39046 pll_clk->hw.hw.init = &init;
39047
39048 pll_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
39049 - clk_pll_ops.enable = clk_gate_ops.enable;
39050 - clk_pll_ops.disable = clk_gate_ops.disable;
39051 + pax_open_kernel();
39052 + *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
39053 + *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
39054 + pax_close_kernel();
39055
39056 clk = clk_register(NULL, &pll_clk->hw.hw);
39057 if (WARN_ON(IS_ERR(clk))) {
39058 diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
39059 index 000e4e0..4770351 100644
39060 --- a/drivers/cpufreq/acpi-cpufreq.c
39061 +++ b/drivers/cpufreq/acpi-cpufreq.c
39062 @@ -676,8 +676,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39063 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
39064 per_cpu(acfreq_data, cpu) = data;
39065
39066 - if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
39067 - acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39068 + if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
39069 + pax_open_kernel();
39070 + *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39071 + pax_close_kernel();
39072 + }
39073
39074 result = acpi_processor_register_performance(data->acpi_data, cpu);
39075 if (result)
39076 @@ -810,7 +813,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39077 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
39078 break;
39079 case ACPI_ADR_SPACE_FIXED_HARDWARE:
39080 - acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39081 + pax_open_kernel();
39082 + *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39083 + pax_close_kernel();
39084 break;
39085 default:
39086 break;
39087 @@ -904,8 +909,10 @@ static void __init acpi_cpufreq_boost_init(void)
39088 if (!msrs)
39089 return;
39090
39091 - acpi_cpufreq_driver.boost_supported = true;
39092 - acpi_cpufreq_driver.boost_enabled = boost_state(0);
39093 + pax_open_kernel();
39094 + *(bool *)&acpi_cpufreq_driver.boost_supported = true;
39095 + *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
39096 + pax_close_kernel();
39097
39098 cpu_notifier_register_begin();
39099
39100 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
39101 index dcac12d..f12df60 100644
39102 --- a/drivers/cpufreq/cpufreq.c
39103 +++ b/drivers/cpufreq/cpufreq.c
39104 @@ -2024,7 +2024,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
39105 }
39106
39107 mutex_lock(&cpufreq_governor_mutex);
39108 - list_del(&governor->governor_list);
39109 + pax_list_del(&governor->governor_list);
39110 mutex_unlock(&cpufreq_governor_mutex);
39111 return;
39112 }
39113 @@ -2240,7 +2240,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
39114 return NOTIFY_OK;
39115 }
39116
39117 -static struct notifier_block __refdata cpufreq_cpu_notifier = {
39118 +static struct notifier_block cpufreq_cpu_notifier = {
39119 .notifier_call = cpufreq_cpu_callback,
39120 };
39121
39122 @@ -2280,13 +2280,17 @@ int cpufreq_boost_trigger_state(int state)
39123 return 0;
39124
39125 write_lock_irqsave(&cpufreq_driver_lock, flags);
39126 - cpufreq_driver->boost_enabled = state;
39127 + pax_open_kernel();
39128 + *(bool *)&cpufreq_driver->boost_enabled = state;
39129 + pax_close_kernel();
39130 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39131
39132 ret = cpufreq_driver->set_boost(state);
39133 if (ret) {
39134 write_lock_irqsave(&cpufreq_driver_lock, flags);
39135 - cpufreq_driver->boost_enabled = !state;
39136 + pax_open_kernel();
39137 + *(bool *)&cpufreq_driver->boost_enabled = !state;
39138 + pax_close_kernel();
39139 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39140
39141 pr_err("%s: Cannot %s BOOST\n",
39142 @@ -2342,8 +2346,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39143
39144 pr_debug("trying to register driver %s\n", driver_data->name);
39145
39146 - if (driver_data->setpolicy)
39147 - driver_data->flags |= CPUFREQ_CONST_LOOPS;
39148 + if (driver_data->setpolicy) {
39149 + pax_open_kernel();
39150 + *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
39151 + pax_close_kernel();
39152 + }
39153
39154 write_lock_irqsave(&cpufreq_driver_lock, flags);
39155 if (cpufreq_driver) {
39156 @@ -2358,8 +2365,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39157 * Check if driver provides function to enable boost -
39158 * if not, use cpufreq_boost_set_sw as default
39159 */
39160 - if (!cpufreq_driver->set_boost)
39161 - cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39162 + if (!cpufreq_driver->set_boost) {
39163 + pax_open_kernel();
39164 + *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39165 + pax_close_kernel();
39166 + }
39167
39168 ret = cpufreq_sysfs_create_file(&boost.attr);
39169 if (ret) {
39170 diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
39171 index e1c6433..31203ae 100644
39172 --- a/drivers/cpufreq/cpufreq_governor.c
39173 +++ b/drivers/cpufreq/cpufreq_governor.c
39174 @@ -191,7 +191,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39175 struct dbs_data *dbs_data;
39176 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
39177 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
39178 - struct od_ops *od_ops = NULL;
39179 + const struct od_ops *od_ops = NULL;
39180 struct od_dbs_tuners *od_tuners = NULL;
39181 struct cs_dbs_tuners *cs_tuners = NULL;
39182 struct cpu_dbs_common_info *cpu_cdbs;
39183 @@ -257,7 +257,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39184
39185 if ((cdata->governor == GOV_CONSERVATIVE) &&
39186 (!policy->governor->initialized)) {
39187 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39188 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39189
39190 cpufreq_register_notifier(cs_ops->notifier_block,
39191 CPUFREQ_TRANSITION_NOTIFIER);
39192 @@ -277,7 +277,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39193
39194 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
39195 (policy->governor->initialized == 1)) {
39196 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39197 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39198
39199 cpufreq_unregister_notifier(cs_ops->notifier_block,
39200 CPUFREQ_TRANSITION_NOTIFIER);
39201 diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
39202 index bfb9ae1..e1d3a7e 100644
39203 --- a/drivers/cpufreq/cpufreq_governor.h
39204 +++ b/drivers/cpufreq/cpufreq_governor.h
39205 @@ -205,7 +205,7 @@ struct common_dbs_data {
39206 void (*exit)(struct dbs_data *dbs_data);
39207
39208 /* Governor specific ops, see below */
39209 - void *gov_ops;
39210 + const void *gov_ops;
39211 };
39212
39213 /* Governor Per policy data */
39214 @@ -225,7 +225,7 @@ struct od_ops {
39215 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
39216 unsigned int freq_next, unsigned int relation);
39217 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
39218 -};
39219 +} __no_const;
39220
39221 struct cs_ops {
39222 struct notifier_block *notifier_block;
39223 diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
39224 index 18d4091..434be15 100644
39225 --- a/drivers/cpufreq/cpufreq_ondemand.c
39226 +++ b/drivers/cpufreq/cpufreq_ondemand.c
39227 @@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
39228
39229 define_get_cpu_dbs_routines(od_cpu_dbs_info);
39230
39231 -static struct od_ops od_ops = {
39232 +static struct od_ops od_ops __read_only = {
39233 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
39234 .powersave_bias_target = generic_powersave_bias_target,
39235 .freq_increase = dbs_freq_increase,
39236 @@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
39237 (struct cpufreq_policy *, unsigned int, unsigned int),
39238 unsigned int powersave_bias)
39239 {
39240 - od_ops.powersave_bias_target = f;
39241 + pax_open_kernel();
39242 + *(void **)&od_ops.powersave_bias_target = f;
39243 + pax_close_kernel();
39244 od_set_powersave_bias(powersave_bias);
39245 }
39246 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
39247
39248 void od_unregister_powersave_bias_handler(void)
39249 {
39250 - od_ops.powersave_bias_target = generic_powersave_bias_target;
39251 + pax_open_kernel();
39252 + *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
39253 + pax_close_kernel();
39254 od_set_powersave_bias(0);
39255 }
39256 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
39257 diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
39258 index 870eecc..787bbca 100644
39259 --- a/drivers/cpufreq/intel_pstate.c
39260 +++ b/drivers/cpufreq/intel_pstate.c
39261 @@ -125,10 +125,10 @@ struct pstate_funcs {
39262 struct cpu_defaults {
39263 struct pstate_adjust_policy pid_policy;
39264 struct pstate_funcs funcs;
39265 -};
39266 +} __do_const;
39267
39268 static struct pstate_adjust_policy pid_params;
39269 -static struct pstate_funcs pstate_funcs;
39270 +static struct pstate_funcs *pstate_funcs;
39271
39272 struct perf_limits {
39273 int no_turbo;
39274 @@ -530,7 +530,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
39275
39276 cpu->pstate.current_pstate = pstate;
39277
39278 - pstate_funcs.set(cpu, pstate);
39279 + pstate_funcs->set(cpu, pstate);
39280 }
39281
39282 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
39283 @@ -552,12 +552,12 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
39284 {
39285 sprintf(cpu->name, "Intel 2nd generation core");
39286
39287 - cpu->pstate.min_pstate = pstate_funcs.get_min();
39288 - cpu->pstate.max_pstate = pstate_funcs.get_max();
39289 - cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
39290 + cpu->pstate.min_pstate = pstate_funcs->get_min();
39291 + cpu->pstate.max_pstate = pstate_funcs->get_max();
39292 + cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
39293
39294 - if (pstate_funcs.get_vid)
39295 - pstate_funcs.get_vid(cpu);
39296 + if (pstate_funcs->get_vid)
39297 + pstate_funcs->get_vid(cpu);
39298 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate);
39299 }
39300
39301 @@ -847,9 +847,9 @@ static int intel_pstate_msrs_not_valid(void)
39302 rdmsrl(MSR_IA32_APERF, aperf);
39303 rdmsrl(MSR_IA32_MPERF, mperf);
39304
39305 - if (!pstate_funcs.get_max() ||
39306 - !pstate_funcs.get_min() ||
39307 - !pstate_funcs.get_turbo())
39308 + if (!pstate_funcs->get_max() ||
39309 + !pstate_funcs->get_min() ||
39310 + !pstate_funcs->get_turbo())
39311 return -ENODEV;
39312
39313 rdmsrl(MSR_IA32_APERF, tmp);
39314 @@ -863,7 +863,7 @@ static int intel_pstate_msrs_not_valid(void)
39315 return 0;
39316 }
39317
39318 -static void copy_pid_params(struct pstate_adjust_policy *policy)
39319 +static void copy_pid_params(const struct pstate_adjust_policy *policy)
39320 {
39321 pid_params.sample_rate_ms = policy->sample_rate_ms;
39322 pid_params.p_gain_pct = policy->p_gain_pct;
39323 @@ -875,11 +875,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
39324
39325 static void copy_cpu_funcs(struct pstate_funcs *funcs)
39326 {
39327 - pstate_funcs.get_max = funcs->get_max;
39328 - pstate_funcs.get_min = funcs->get_min;
39329 - pstate_funcs.get_turbo = funcs->get_turbo;
39330 - pstate_funcs.set = funcs->set;
39331 - pstate_funcs.get_vid = funcs->get_vid;
39332 + pstate_funcs = funcs;
39333 }
39334
39335 #if IS_ENABLED(CONFIG_ACPI)
39336 diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
39337 index 529cfd9..0e28fff 100644
39338 --- a/drivers/cpufreq/p4-clockmod.c
39339 +++ b/drivers/cpufreq/p4-clockmod.c
39340 @@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39341 case 0x0F: /* Core Duo */
39342 case 0x16: /* Celeron Core */
39343 case 0x1C: /* Atom */
39344 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39345 + pax_open_kernel();
39346 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39347 + pax_close_kernel();
39348 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
39349 case 0x0D: /* Pentium M (Dothan) */
39350 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39351 + pax_open_kernel();
39352 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39353 + pax_close_kernel();
39354 /* fall through */
39355 case 0x09: /* Pentium M (Banias) */
39356 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
39357 @@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39358
39359 /* on P-4s, the TSC runs with constant frequency independent whether
39360 * throttling is active or not. */
39361 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39362 + pax_open_kernel();
39363 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39364 + pax_close_kernel();
39365
39366 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
39367 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
39368 diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
39369 index 9bb42ba..b01b4a2 100644
39370 --- a/drivers/cpufreq/sparc-us3-cpufreq.c
39371 +++ b/drivers/cpufreq/sparc-us3-cpufreq.c
39372 @@ -18,14 +18,12 @@
39373 #include <asm/head.h>
39374 #include <asm/timer.h>
39375
39376 -static struct cpufreq_driver *cpufreq_us3_driver;
39377 -
39378 struct us3_freq_percpu_info {
39379 struct cpufreq_frequency_table table[4];
39380 };
39381
39382 /* Indexed by cpu number. */
39383 -static struct us3_freq_percpu_info *us3_freq_table;
39384 +static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
39385
39386 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
39387 * in the Safari config register.
39388 @@ -156,16 +154,27 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
39389
39390 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
39391 {
39392 - if (cpufreq_us3_driver)
39393 - us3_freq_target(policy, 0);
39394 + us3_freq_target(policy, 0);
39395
39396 return 0;
39397 }
39398
39399 +static int __init us3_freq_init(void);
39400 +static void __exit us3_freq_exit(void);
39401 +
39402 +static struct cpufreq_driver cpufreq_us3_driver = {
39403 + .init = us3_freq_cpu_init,
39404 + .verify = cpufreq_generic_frequency_table_verify,
39405 + .target_index = us3_freq_target,
39406 + .get = us3_freq_get,
39407 + .exit = us3_freq_cpu_exit,
39408 + .name = "UltraSPARC-III",
39409 +
39410 +};
39411 +
39412 static int __init us3_freq_init(void)
39413 {
39414 unsigned long manuf, impl, ver;
39415 - int ret;
39416
39417 if (tlb_type != cheetah && tlb_type != cheetah_plus)
39418 return -ENODEV;
39419 @@ -178,55 +187,15 @@ static int __init us3_freq_init(void)
39420 (impl == CHEETAH_IMPL ||
39421 impl == CHEETAH_PLUS_IMPL ||
39422 impl == JAGUAR_IMPL ||
39423 - impl == PANTHER_IMPL)) {
39424 - struct cpufreq_driver *driver;
39425 -
39426 - ret = -ENOMEM;
39427 - driver = kzalloc(sizeof(*driver), GFP_KERNEL);
39428 - if (!driver)
39429 - goto err_out;
39430 -
39431 - us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
39432 - GFP_KERNEL);
39433 - if (!us3_freq_table)
39434 - goto err_out;
39435 -
39436 - driver->init = us3_freq_cpu_init;
39437 - driver->verify = cpufreq_generic_frequency_table_verify;
39438 - driver->target_index = us3_freq_target;
39439 - driver->get = us3_freq_get;
39440 - driver->exit = us3_freq_cpu_exit;
39441 - strcpy(driver->name, "UltraSPARC-III");
39442 -
39443 - cpufreq_us3_driver = driver;
39444 - ret = cpufreq_register_driver(driver);
39445 - if (ret)
39446 - goto err_out;
39447 -
39448 - return 0;
39449 -
39450 -err_out:
39451 - if (driver) {
39452 - kfree(driver);
39453 - cpufreq_us3_driver = NULL;
39454 - }
39455 - kfree(us3_freq_table);
39456 - us3_freq_table = NULL;
39457 - return ret;
39458 - }
39459 + impl == PANTHER_IMPL))
39460 + return cpufreq_register_driver(&cpufreq_us3_driver);
39461
39462 return -ENODEV;
39463 }
39464
39465 static void __exit us3_freq_exit(void)
39466 {
39467 - if (cpufreq_us3_driver) {
39468 - cpufreq_unregister_driver(cpufreq_us3_driver);
39469 - kfree(cpufreq_us3_driver);
39470 - cpufreq_us3_driver = NULL;
39471 - kfree(us3_freq_table);
39472 - us3_freq_table = NULL;
39473 - }
39474 + cpufreq_unregister_driver(&cpufreq_us3_driver);
39475 }
39476
39477 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
39478 diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
39479 index 6723f03..3465190 100644
39480 --- a/drivers/cpufreq/speedstep-centrino.c
39481 +++ b/drivers/cpufreq/speedstep-centrino.c
39482 @@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
39483 !cpu_has(cpu, X86_FEATURE_EST))
39484 return -ENODEV;
39485
39486 - if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
39487 - centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39488 + if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
39489 + pax_open_kernel();
39490 + *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39491 + pax_close_kernel();
39492 + }
39493
39494 if (policy->cpu != 0)
39495 return -ENODEV;
39496 diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
39497 index 136d6a2..06e373d 100644
39498 --- a/drivers/cpuidle/driver.c
39499 +++ b/drivers/cpuidle/driver.c
39500 @@ -202,7 +202,7 @@ static int poll_idle(struct cpuidle_device *dev,
39501
39502 static void poll_idle_init(struct cpuidle_driver *drv)
39503 {
39504 - struct cpuidle_state *state = &drv->states[0];
39505 + cpuidle_state_no_const *state = &drv->states[0];
39506
39507 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
39508 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
39509 diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
39510 index ca89412..a7b9c49 100644
39511 --- a/drivers/cpuidle/governor.c
39512 +++ b/drivers/cpuidle/governor.c
39513 @@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
39514 mutex_lock(&cpuidle_lock);
39515 if (__cpuidle_find_governor(gov->name) == NULL) {
39516 ret = 0;
39517 - list_add_tail(&gov->governor_list, &cpuidle_governors);
39518 + pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
39519 if (!cpuidle_curr_governor ||
39520 cpuidle_curr_governor->rating < gov->rating)
39521 cpuidle_switch_governor(gov);
39522 diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
39523 index efe2f17..b8124f9 100644
39524 --- a/drivers/cpuidle/sysfs.c
39525 +++ b/drivers/cpuidle/sysfs.c
39526 @@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
39527 NULL
39528 };
39529
39530 -static struct attribute_group cpuidle_attr_group = {
39531 +static attribute_group_no_const cpuidle_attr_group = {
39532 .attrs = cpuidle_default_attrs,
39533 .name = "cpuidle",
39534 };
39535 diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
39536 index 12fea3e..1e28f47 100644
39537 --- a/drivers/crypto/hifn_795x.c
39538 +++ b/drivers/crypto/hifn_795x.c
39539 @@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
39540 MODULE_PARM_DESC(hifn_pll_ref,
39541 "PLL reference clock (pci[freq] or ext[freq], default ext)");
39542
39543 -static atomic_t hifn_dev_number;
39544 +static atomic_unchecked_t hifn_dev_number;
39545
39546 #define ACRYPTO_OP_DECRYPT 0
39547 #define ACRYPTO_OP_ENCRYPT 1
39548 @@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
39549 goto err_out_disable_pci_device;
39550
39551 snprintf(name, sizeof(name), "hifn%d",
39552 - atomic_inc_return(&hifn_dev_number)-1);
39553 + atomic_inc_return_unchecked(&hifn_dev_number)-1);
39554
39555 err = pci_request_regions(pdev, name);
39556 if (err)
39557 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
39558 index 2042ec3..a9ce67f 100644
39559 --- a/drivers/devfreq/devfreq.c
39560 +++ b/drivers/devfreq/devfreq.c
39561 @@ -616,7 +616,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
39562 goto err_out;
39563 }
39564
39565 - list_add(&governor->node, &devfreq_governor_list);
39566 + pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
39567
39568 list_for_each_entry(devfreq, &devfreq_list, node) {
39569 int ret = 0;
39570 @@ -704,7 +704,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
39571 }
39572 }
39573
39574 - list_del(&governor->node);
39575 + pax_list_del((struct list_head *)&governor->node);
39576 err_out:
39577 mutex_unlock(&devfreq_list_lock);
39578
39579 diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
39580 index 5239677..1cb71a8 100644
39581 --- a/drivers/dma/sh/shdma-base.c
39582 +++ b/drivers/dma/sh/shdma-base.c
39583 @@ -267,8 +267,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
39584 schan->slave_id = -EINVAL;
39585 }
39586
39587 - schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
39588 - sdev->desc_size, GFP_KERNEL);
39589 + schan->desc = kcalloc(sdev->desc_size,
39590 + NR_DESCS_PER_CHANNEL, GFP_KERNEL);
39591 if (!schan->desc) {
39592 ret = -ENOMEM;
39593 goto edescalloc;
39594 diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
39595 index dda7e75..0a4c867 100644
39596 --- a/drivers/dma/sh/shdmac.c
39597 +++ b/drivers/dma/sh/shdmac.c
39598 @@ -513,7 +513,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
39599 return ret;
39600 }
39601
39602 -static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
39603 +static struct notifier_block sh_dmae_nmi_notifier = {
39604 .notifier_call = sh_dmae_nmi_handler,
39605
39606 /* Run before NMI debug handler and KGDB */
39607 diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
39608 index 592af5f..bb1d583 100644
39609 --- a/drivers/edac/edac_device.c
39610 +++ b/drivers/edac/edac_device.c
39611 @@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
39612 */
39613 int edac_device_alloc_index(void)
39614 {
39615 - static atomic_t device_indexes = ATOMIC_INIT(0);
39616 + static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
39617
39618 - return atomic_inc_return(&device_indexes) - 1;
39619 + return atomic_inc_return_unchecked(&device_indexes) - 1;
39620 }
39621 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
39622
39623 diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
39624 index 01fae82..1dd8289 100644
39625 --- a/drivers/edac/edac_mc_sysfs.c
39626 +++ b/drivers/edac/edac_mc_sysfs.c
39627 @@ -152,7 +152,7 @@ static const char * const edac_caps[] = {
39628 struct dev_ch_attribute {
39629 struct device_attribute attr;
39630 int channel;
39631 -};
39632 +} __do_const;
39633
39634 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
39635 struct dev_ch_attribute dev_attr_legacy_##_name = \
39636 @@ -1009,14 +1009,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
39637 }
39638
39639 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
39640 + pax_open_kernel();
39641 if (mci->get_sdram_scrub_rate) {
39642 - dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39643 - dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39644 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39645 + *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39646 }
39647 if (mci->set_sdram_scrub_rate) {
39648 - dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39649 - dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39650 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39651 + *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39652 }
39653 + pax_close_kernel();
39654 err = device_create_file(&mci->dev,
39655 &dev_attr_sdram_scrub_rate);
39656 if (err) {
39657 diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
39658 index 2cf44b4d..6dd2dc7 100644
39659 --- a/drivers/edac/edac_pci.c
39660 +++ b/drivers/edac/edac_pci.c
39661 @@ -29,7 +29,7 @@
39662
39663 static DEFINE_MUTEX(edac_pci_ctls_mutex);
39664 static LIST_HEAD(edac_pci_list);
39665 -static atomic_t pci_indexes = ATOMIC_INIT(0);
39666 +static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
39667
39668 /*
39669 * edac_pci_alloc_ctl_info
39670 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
39671 */
39672 int edac_pci_alloc_index(void)
39673 {
39674 - return atomic_inc_return(&pci_indexes) - 1;
39675 + return atomic_inc_return_unchecked(&pci_indexes) - 1;
39676 }
39677 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
39678
39679 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
39680 index e8658e4..22746d6 100644
39681 --- a/drivers/edac/edac_pci_sysfs.c
39682 +++ b/drivers/edac/edac_pci_sysfs.c
39683 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
39684 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
39685 static int edac_pci_poll_msec = 1000; /* one second workq period */
39686
39687 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
39688 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
39689 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
39690 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
39691
39692 static struct kobject *edac_pci_top_main_kobj;
39693 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
39694 @@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
39695 void *value;
39696 ssize_t(*show) (void *, char *);
39697 ssize_t(*store) (void *, const char *, size_t);
39698 -};
39699 +} __do_const;
39700
39701 /* Set of show/store abstract level functions for PCI Parity object */
39702 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
39703 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39704 edac_printk(KERN_CRIT, EDAC_PCI,
39705 "Signaled System Error on %s\n",
39706 pci_name(dev));
39707 - atomic_inc(&pci_nonparity_count);
39708 + atomic_inc_unchecked(&pci_nonparity_count);
39709 }
39710
39711 if (status & (PCI_STATUS_PARITY)) {
39712 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39713 "Master Data Parity Error on %s\n",
39714 pci_name(dev));
39715
39716 - atomic_inc(&pci_parity_count);
39717 + atomic_inc_unchecked(&pci_parity_count);
39718 }
39719
39720 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39721 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39722 "Detected Parity Error on %s\n",
39723 pci_name(dev));
39724
39725 - atomic_inc(&pci_parity_count);
39726 + atomic_inc_unchecked(&pci_parity_count);
39727 }
39728 }
39729
39730 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39731 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
39732 "Signaled System Error on %s\n",
39733 pci_name(dev));
39734 - atomic_inc(&pci_nonparity_count);
39735 + atomic_inc_unchecked(&pci_nonparity_count);
39736 }
39737
39738 if (status & (PCI_STATUS_PARITY)) {
39739 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39740 "Master Data Parity Error on "
39741 "%s\n", pci_name(dev));
39742
39743 - atomic_inc(&pci_parity_count);
39744 + atomic_inc_unchecked(&pci_parity_count);
39745 }
39746
39747 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39748 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39749 "Detected Parity Error on %s\n",
39750 pci_name(dev));
39751
39752 - atomic_inc(&pci_parity_count);
39753 + atomic_inc_unchecked(&pci_parity_count);
39754 }
39755 }
39756 }
39757 @@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
39758 if (!check_pci_errors)
39759 return;
39760
39761 - before_count = atomic_read(&pci_parity_count);
39762 + before_count = atomic_read_unchecked(&pci_parity_count);
39763
39764 /* scan all PCI devices looking for a Parity Error on devices and
39765 * bridges.
39766 @@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
39767 /* Only if operator has selected panic on PCI Error */
39768 if (edac_pci_get_panic_on_pe()) {
39769 /* If the count is different 'after' from 'before' */
39770 - if (before_count != atomic_read(&pci_parity_count))
39771 + if (before_count != atomic_read_unchecked(&pci_parity_count))
39772 panic("EDAC: PCI Parity Error");
39773 }
39774 }
39775 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
39776 index 51b7e3a..aa8a3e8 100644
39777 --- a/drivers/edac/mce_amd.h
39778 +++ b/drivers/edac/mce_amd.h
39779 @@ -77,7 +77,7 @@ struct amd_decoder_ops {
39780 bool (*mc0_mce)(u16, u8);
39781 bool (*mc1_mce)(u16, u8);
39782 bool (*mc2_mce)(u16, u8);
39783 -};
39784 +} __no_const;
39785
39786 void amd_report_gart_errors(bool);
39787 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
39788 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
39789 index 57ea7f4..af06b76 100644
39790 --- a/drivers/firewire/core-card.c
39791 +++ b/drivers/firewire/core-card.c
39792 @@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
39793 const struct fw_card_driver *driver,
39794 struct device *device)
39795 {
39796 - static atomic_t index = ATOMIC_INIT(-1);
39797 + static atomic_unchecked_t index = ATOMIC_INIT(-1);
39798
39799 - card->index = atomic_inc_return(&index);
39800 + card->index = atomic_inc_return_unchecked(&index);
39801 card->driver = driver;
39802 card->device = device;
39803 card->current_tlabel = 0;
39804 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
39805
39806 void fw_core_remove_card(struct fw_card *card)
39807 {
39808 - struct fw_card_driver dummy_driver = dummy_driver_template;
39809 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
39810
39811 card->driver->update_phy_reg(card, 4,
39812 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
39813 diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
39814 index 2c6d5e1..a2cca6b 100644
39815 --- a/drivers/firewire/core-device.c
39816 +++ b/drivers/firewire/core-device.c
39817 @@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
39818 struct config_rom_attribute {
39819 struct device_attribute attr;
39820 u32 key;
39821 -};
39822 +} __do_const;
39823
39824 static ssize_t show_immediate(struct device *dev,
39825 struct device_attribute *dattr, char *buf)
39826 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
39827 index eb6935c..3cc2bfa 100644
39828 --- a/drivers/firewire/core-transaction.c
39829 +++ b/drivers/firewire/core-transaction.c
39830 @@ -38,6 +38,7 @@
39831 #include <linux/timer.h>
39832 #include <linux/types.h>
39833 #include <linux/workqueue.h>
39834 +#include <linux/sched.h>
39835
39836 #include <asm/byteorder.h>
39837
39838 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
39839 index f477308..2795f24 100644
39840 --- a/drivers/firewire/core.h
39841 +++ b/drivers/firewire/core.h
39842 @@ -111,6 +111,7 @@ struct fw_card_driver {
39843
39844 int (*stop_iso)(struct fw_iso_context *ctx);
39845 };
39846 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
39847
39848 void fw_card_initialize(struct fw_card *card,
39849 const struct fw_card_driver *driver, struct device *device);
39850 diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
39851 index 586f2f7..3545ad2 100644
39852 --- a/drivers/firewire/ohci.c
39853 +++ b/drivers/firewire/ohci.c
39854 @@ -2049,10 +2049,12 @@ static void bus_reset_work(struct work_struct *work)
39855 be32_to_cpu(ohci->next_header));
39856 }
39857
39858 +#ifndef CONFIG_GRKERNSEC
39859 if (param_remote_dma) {
39860 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
39861 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
39862 }
39863 +#endif
39864
39865 spin_unlock_irq(&ohci->lock);
39866
39867 @@ -2584,8 +2586,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
39868 unsigned long flags;
39869 int n, ret = 0;
39870
39871 +#ifndef CONFIG_GRKERNSEC
39872 if (param_remote_dma)
39873 return 0;
39874 +#endif
39875
39876 /*
39877 * FIXME: Make sure this bitmask is cleared when we clear the busReset
39878 diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
39879 index 94a58a0..f5eba42 100644
39880 --- a/drivers/firmware/dmi-id.c
39881 +++ b/drivers/firmware/dmi-id.c
39882 @@ -16,7 +16,7 @@
39883 struct dmi_device_attribute{
39884 struct device_attribute dev_attr;
39885 int field;
39886 -};
39887 +} __do_const;
39888 #define to_dmi_dev_attr(_dev_attr) \
39889 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
39890
39891 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
39892 index 17afc51..0ef90cd 100644
39893 --- a/drivers/firmware/dmi_scan.c
39894 +++ b/drivers/firmware/dmi_scan.c
39895 @@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
39896 if (buf == NULL)
39897 return -1;
39898
39899 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
39900 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
39901
39902 dmi_unmap(buf);
39903 return 0;
39904 diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
39905 index 1491dd4..aa910db 100644
39906 --- a/drivers/firmware/efi/cper.c
39907 +++ b/drivers/firmware/efi/cper.c
39908 @@ -41,12 +41,12 @@
39909 */
39910 u64 cper_next_record_id(void)
39911 {
39912 - static atomic64_t seq;
39913 + static atomic64_unchecked_t seq;
39914
39915 - if (!atomic64_read(&seq))
39916 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
39917 + if (!atomic64_read_unchecked(&seq))
39918 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
39919
39920 - return atomic64_inc_return(&seq);
39921 + return atomic64_inc_return_unchecked(&seq);
39922 }
39923 EXPORT_SYMBOL_GPL(cper_next_record_id);
39924
39925 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
39926 index af20f17..4e4e545 100644
39927 --- a/drivers/firmware/efi/efi.c
39928 +++ b/drivers/firmware/efi/efi.c
39929 @@ -120,14 +120,16 @@ static struct attribute_group efi_subsys_attr_group = {
39930 };
39931
39932 static struct efivars generic_efivars;
39933 -static struct efivar_operations generic_ops;
39934 +static efivar_operations_no_const generic_ops __read_only;
39935
39936 static int generic_ops_register(void)
39937 {
39938 - generic_ops.get_variable = efi.get_variable;
39939 - generic_ops.set_variable = efi.set_variable;
39940 - generic_ops.get_next_variable = efi.get_next_variable;
39941 - generic_ops.query_variable_store = efi_query_variable_store;
39942 + pax_open_kernel();
39943 + *(void **)&generic_ops.get_variable = efi.get_variable;
39944 + *(void **)&generic_ops.set_variable = efi.set_variable;
39945 + *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
39946 + *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
39947 + pax_close_kernel();
39948
39949 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
39950 }
39951 diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
39952 index 50ea412..caccd6e9 100644
39953 --- a/drivers/firmware/efi/efivars.c
39954 +++ b/drivers/firmware/efi/efivars.c
39955 @@ -456,7 +456,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
39956 static int
39957 create_efivars_bin_attributes(void)
39958 {
39959 - struct bin_attribute *attr;
39960 + bin_attribute_no_const *attr;
39961 int error;
39962
39963 /* new_var */
39964 diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
39965 index 2f569aa..c95f4fb 100644
39966 --- a/drivers/firmware/google/memconsole.c
39967 +++ b/drivers/firmware/google/memconsole.c
39968 @@ -155,7 +155,10 @@ static int __init memconsole_init(void)
39969 if (!found_memconsole())
39970 return -ENODEV;
39971
39972 - memconsole_bin_attr.size = memconsole_length;
39973 + pax_open_kernel();
39974 + *(size_t *)&memconsole_bin_attr.size = memconsole_length;
39975 + pax_close_kernel();
39976 +
39977 return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
39978 }
39979
39980 diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
39981 index 8765bd6..2e5b147 100644
39982 --- a/drivers/gpio/gpio-em.c
39983 +++ b/drivers/gpio/gpio-em.c
39984 @@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
39985 struct em_gio_priv *p;
39986 struct resource *io[2], *irq[2];
39987 struct gpio_chip *gpio_chip;
39988 - struct irq_chip *irq_chip;
39989 + irq_chip_no_const *irq_chip;
39990 const char *name = dev_name(&pdev->dev);
39991 int ret;
39992
39993 diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
39994 index 7030422..42a3fe9 100644
39995 --- a/drivers/gpio/gpio-ich.c
39996 +++ b/drivers/gpio/gpio-ich.c
39997 @@ -94,7 +94,7 @@ struct ichx_desc {
39998 * this option allows driver caching written output values
39999 */
40000 bool use_outlvl_cache;
40001 -};
40002 +} __do_const;
40003
40004 static struct {
40005 spinlock_t lock;
40006 diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
40007 index 03c9148..c66e753 100644
40008 --- a/drivers/gpio/gpio-rcar.c
40009 +++ b/drivers/gpio/gpio-rcar.c
40010 @@ -355,7 +355,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
40011 struct gpio_rcar_priv *p;
40012 struct resource *io, *irq;
40013 struct gpio_chip *gpio_chip;
40014 - struct irq_chip *irq_chip;
40015 + irq_chip_no_const *irq_chip;
40016 struct device *dev = &pdev->dev;
40017 const char *name = dev_name(dev);
40018 int ret;
40019 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
40020 index 66cbcc1..0c5e622 100644
40021 --- a/drivers/gpio/gpio-vr41xx.c
40022 +++ b/drivers/gpio/gpio-vr41xx.c
40023 @@ -224,7 +224,7 @@ static int giu_get_irq(unsigned int irq)
40024 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
40025 maskl, pendl, maskh, pendh);
40026
40027 - atomic_inc(&irq_err_count);
40028 + atomic_inc_unchecked(&irq_err_count);
40029
40030 return -EINVAL;
40031 }
40032 diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
40033 index f48817d..d35d7f8 100644
40034 --- a/drivers/gpio/gpiolib.c
40035 +++ b/drivers/gpio/gpiolib.c
40036 @@ -1458,8 +1458,10 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip)
40037 }
40038
40039 if (gpiochip->irqchip) {
40040 - gpiochip->irqchip->irq_request_resources = NULL;
40041 - gpiochip->irqchip->irq_release_resources = NULL;
40042 + pax_open_kernel();
40043 + *(void **)&gpiochip->irqchip->irq_request_resources = NULL;
40044 + *(void **)&gpiochip->irqchip->irq_release_resources = NULL;
40045 + pax_close_kernel();
40046 gpiochip->irqchip = NULL;
40047 }
40048 }
40049 @@ -1524,8 +1526,10 @@ int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
40050 gpiochip->irqchip = NULL;
40051 return -EINVAL;
40052 }
40053 - irqchip->irq_request_resources = gpiochip_irq_reqres;
40054 - irqchip->irq_release_resources = gpiochip_irq_relres;
40055 + pax_open_kernel();
40056 + *(void **)&irqchip->irq_request_resources = gpiochip_irq_reqres;
40057 + *(void **)&irqchip->irq_release_resources = gpiochip_irq_relres;
40058 + pax_close_kernel();
40059
40060 /*
40061 * Prepare the mapping since the irqchip shall be orthogonal to
40062 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
40063 index d8b7099..8a314a5 100644
40064 --- a/drivers/gpu/drm/drm_crtc.c
40065 +++ b/drivers/gpu/drm/drm_crtc.c
40066 @@ -3500,7 +3500,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
40067 goto done;
40068 }
40069
40070 - if (copy_to_user(&enum_ptr[copied].name,
40071 + if (copy_to_user(enum_ptr[copied].name,
40072 &prop_enum->name, DRM_PROP_NAME_LEN)) {
40073 ret = -EFAULT;
40074 goto done;
40075 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
40076 old mode 100644
40077 new mode 100755
40078 index 8218078..9960928a
40079 --- a/drivers/gpu/drm/drm_drv.c
40080 +++ b/drivers/gpu/drm/drm_drv.c
40081 @@ -233,7 +233,7 @@ module_exit(drm_core_exit);
40082 /**
40083 * Copy and IOCTL return string to user space
40084 */
40085 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
40086 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
40087 {
40088 int len;
40089
40090 @@ -342,7 +342,7 @@ long drm_ioctl(struct file *filp,
40091 struct drm_file *file_priv = filp->private_data;
40092 struct drm_device *dev;
40093 const struct drm_ioctl_desc *ioctl = NULL;
40094 - drm_ioctl_t *func;
40095 + drm_ioctl_no_const_t func;
40096 unsigned int nr = DRM_IOCTL_NR(cmd);
40097 int retcode = -EINVAL;
40098 char stack_kdata[128];
40099 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
40100 index e1eba0b..98f69f9 100644
40101 --- a/drivers/gpu/drm/drm_fops.c
40102 +++ b/drivers/gpu/drm/drm_fops.c
40103 @@ -89,7 +89,7 @@ int drm_open(struct inode *inode, struct file *filp)
40104 return PTR_ERR(minor);
40105
40106 dev = minor->dev;
40107 - if (!dev->open_count++)
40108 + if (local_inc_return(&dev->open_count) == 1)
40109 need_setup = 1;
40110
40111 /* share address_space across all char-devs of a single device */
40112 @@ -106,7 +106,7 @@ int drm_open(struct inode *inode, struct file *filp)
40113 return 0;
40114
40115 err_undo:
40116 - dev->open_count--;
40117 + local_dec(&dev->open_count);
40118 drm_minor_release(minor);
40119 return retcode;
40120 }
40121 @@ -430,7 +430,7 @@ int drm_release(struct inode *inode, struct file *filp)
40122
40123 mutex_lock(&drm_global_mutex);
40124
40125 - DRM_DEBUG("open_count = %d\n", dev->open_count);
40126 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
40127
40128 if (dev->driver->preclose)
40129 dev->driver->preclose(dev, file_priv);
40130 @@ -439,10 +439,10 @@ int drm_release(struct inode *inode, struct file *filp)
40131 * Begin inline drm_release
40132 */
40133
40134 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
40135 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
40136 task_pid_nr(current),
40137 (long)old_encode_dev(file_priv->minor->kdev->devt),
40138 - dev->open_count);
40139 + local_read(&dev->open_count));
40140
40141 /* Release any auth tokens that might point to this file_priv,
40142 (do that under the drm_global_mutex) */
40143 @@ -543,7 +543,7 @@ int drm_release(struct inode *inode, struct file *filp)
40144 * End inline drm_release
40145 */
40146
40147 - if (!--dev->open_count) {
40148 + if (local_dec_and_test(&dev->open_count)) {
40149 retcode = drm_lastclose(dev);
40150 if (drm_device_is_unplugged(dev))
40151 drm_put_dev(dev);
40152 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
40153 index 3d2e91c..d31c4c9 100644
40154 --- a/drivers/gpu/drm/drm_global.c
40155 +++ b/drivers/gpu/drm/drm_global.c
40156 @@ -36,7 +36,7 @@
40157 struct drm_global_item {
40158 struct mutex mutex;
40159 void *object;
40160 - int refcount;
40161 + atomic_t refcount;
40162 };
40163
40164 static struct drm_global_item glob[DRM_GLOBAL_NUM];
40165 @@ -49,7 +49,7 @@ void drm_global_init(void)
40166 struct drm_global_item *item = &glob[i];
40167 mutex_init(&item->mutex);
40168 item->object = NULL;
40169 - item->refcount = 0;
40170 + atomic_set(&item->refcount, 0);
40171 }
40172 }
40173
40174 @@ -59,7 +59,7 @@ void drm_global_release(void)
40175 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
40176 struct drm_global_item *item = &glob[i];
40177 BUG_ON(item->object != NULL);
40178 - BUG_ON(item->refcount != 0);
40179 + BUG_ON(atomic_read(&item->refcount) != 0);
40180 }
40181 }
40182
40183 @@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40184 struct drm_global_item *item = &glob[ref->global_type];
40185
40186 mutex_lock(&item->mutex);
40187 - if (item->refcount == 0) {
40188 + if (atomic_read(&item->refcount) == 0) {
40189 item->object = kzalloc(ref->size, GFP_KERNEL);
40190 if (unlikely(item->object == NULL)) {
40191 ret = -ENOMEM;
40192 @@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40193 goto out_err;
40194
40195 }
40196 - ++item->refcount;
40197 + atomic_inc(&item->refcount);
40198 ref->object = item->object;
40199 mutex_unlock(&item->mutex);
40200 return 0;
40201 @@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
40202 struct drm_global_item *item = &glob[ref->global_type];
40203
40204 mutex_lock(&item->mutex);
40205 - BUG_ON(item->refcount == 0);
40206 + BUG_ON(atomic_read(&item->refcount) == 0);
40207 BUG_ON(ref->object != item->object);
40208 - if (--item->refcount == 0) {
40209 + if (atomic_dec_and_test(&item->refcount)) {
40210 ref->release(ref);
40211 item->object = NULL;
40212 }
40213 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
40214 index 7473035..a48b9c5 100644
40215 --- a/drivers/gpu/drm/drm_info.c
40216 +++ b/drivers/gpu/drm/drm_info.c
40217 @@ -75,10 +75,13 @@ int drm_vm_info(struct seq_file *m, void *data)
40218 struct drm_local_map *map;
40219 struct drm_map_list *r_list;
40220
40221 - /* Hardcoded from _DRM_FRAME_BUFFER,
40222 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
40223 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
40224 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
40225 + static const char * const types[] = {
40226 + [_DRM_FRAME_BUFFER] = "FB",
40227 + [_DRM_REGISTERS] = "REG",
40228 + [_DRM_SHM] = "SHM",
40229 + [_DRM_AGP] = "AGP",
40230 + [_DRM_SCATTER_GATHER] = "SG",
40231 + [_DRM_CONSISTENT] = "PCI"};
40232 const char *type;
40233 int i;
40234
40235 @@ -89,7 +92,7 @@ int drm_vm_info(struct seq_file *m, void *data)
40236 map = r_list->map;
40237 if (!map)
40238 continue;
40239 - if (map->type < 0 || map->type > 5)
40240 + if (map->type >= ARRAY_SIZE(types))
40241 type = "??";
40242 else
40243 type = types[map->type];
40244 @@ -261,7 +264,11 @@ int drm_vma_info(struct seq_file *m, void *data)
40245 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
40246 vma->vm_flags & VM_LOCKED ? 'l' : '-',
40247 vma->vm_flags & VM_IO ? 'i' : '-',
40248 +#ifdef CONFIG_GRKERNSEC_HIDESYM
40249 + 0);
40250 +#else
40251 vma->vm_pgoff);
40252 +#endif
40253
40254 #if defined(__i386__)
40255 pgprot = pgprot_val(vma->vm_page_prot);
40256 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
40257 index 2f4c4343..dd12cd2 100644
40258 --- a/drivers/gpu/drm/drm_ioc32.c
40259 +++ b/drivers/gpu/drm/drm_ioc32.c
40260 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
40261 request = compat_alloc_user_space(nbytes);
40262 if (!access_ok(VERIFY_WRITE, request, nbytes))
40263 return -EFAULT;
40264 - list = (struct drm_buf_desc *) (request + 1);
40265 + list = (struct drm_buf_desc __user *) (request + 1);
40266
40267 if (__put_user(count, &request->count)
40268 || __put_user(list, &request->list))
40269 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
40270 request = compat_alloc_user_space(nbytes);
40271 if (!access_ok(VERIFY_WRITE, request, nbytes))
40272 return -EFAULT;
40273 - list = (struct drm_buf_pub *) (request + 1);
40274 + list = (struct drm_buf_pub __user *) (request + 1);
40275
40276 if (__put_user(count, &request->count)
40277 || __put_user(list, &request->list))
40278 @@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
40279 return 0;
40280 }
40281
40282 -drm_ioctl_compat_t *drm_compat_ioctls[] = {
40283 +drm_ioctl_compat_t drm_compat_ioctls[] = {
40284 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
40285 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
40286 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
40287 @@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
40288 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40289 {
40290 unsigned int nr = DRM_IOCTL_NR(cmd);
40291 - drm_ioctl_compat_t *fn;
40292 int ret;
40293
40294 /* Assume that ioctls without an explicit compat routine will just
40295 @@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40296 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
40297 return drm_ioctl(filp, cmd, arg);
40298
40299 - fn = drm_compat_ioctls[nr];
40300 -
40301 - if (fn != NULL)
40302 - ret = (*fn) (filp, cmd, arg);
40303 + if (drm_compat_ioctls[nr] != NULL)
40304 + ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
40305 else
40306 ret = drm_ioctl(filp, cmd, arg);
40307
40308 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
40309 index 4c24c3a..c903cab 100644
40310 --- a/drivers/gpu/drm/drm_stub.c
40311 +++ b/drivers/gpu/drm/drm_stub.c
40312 @@ -455,7 +455,7 @@ void drm_unplug_dev(struct drm_device *dev)
40313
40314 drm_device_set_unplugged(dev);
40315
40316 - if (dev->open_count == 0) {
40317 + if (local_read(&dev->open_count) == 0) {
40318 drm_put_dev(dev);
40319 }
40320 mutex_unlock(&drm_global_mutex);
40321 diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
40322 index c22c309..ae758c3 100644
40323 --- a/drivers/gpu/drm/drm_sysfs.c
40324 +++ b/drivers/gpu/drm/drm_sysfs.c
40325 @@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
40326 */
40327 int drm_sysfs_device_add(struct drm_minor *minor)
40328 {
40329 - char *minor_str;
40330 + const char *minor_str;
40331 int r;
40332
40333 if (minor->type == DRM_MINOR_CONTROL)
40334 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
40335 index d4d16ed..8fb0b51 100644
40336 --- a/drivers/gpu/drm/i810/i810_drv.h
40337 +++ b/drivers/gpu/drm/i810/i810_drv.h
40338 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
40339 int page_flipping;
40340
40341 wait_queue_head_t irq_queue;
40342 - atomic_t irq_received;
40343 - atomic_t irq_emitted;
40344 + atomic_unchecked_t irq_received;
40345 + atomic_unchecked_t irq_emitted;
40346
40347 int front_offset;
40348 } drm_i810_private_t;
40349 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
40350 index eedb023..25076a4 100644
40351 --- a/drivers/gpu/drm/i915/i915_dma.c
40352 +++ b/drivers/gpu/drm/i915/i915_dma.c
40353 @@ -1280,7 +1280,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
40354 bool can_switch;
40355
40356 spin_lock(&dev->count_lock);
40357 - can_switch = (dev->open_count == 0);
40358 + can_switch = (local_read(&dev->open_count) == 0);
40359 spin_unlock(&dev->count_lock);
40360 return can_switch;
40361 }
40362 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40363 index 20fef6c..76c78fb 100644
40364 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40365 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40366 @@ -886,9 +886,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
40367
40368 static int
40369 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
40370 - int count)
40371 + unsigned int count)
40372 {
40373 - int i;
40374 + unsigned int i;
40375 unsigned relocs_total = 0;
40376 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
40377
40378 diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
40379 index 3c59584..500f2e9 100644
40380 --- a/drivers/gpu/drm/i915/i915_ioc32.c
40381 +++ b/drivers/gpu/drm/i915/i915_ioc32.c
40382 @@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
40383 (unsigned long)request);
40384 }
40385
40386 -static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40387 +static drm_ioctl_compat_t i915_compat_ioctls[] = {
40388 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
40389 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
40390 [DRM_I915_GETPARAM] = compat_i915_getparam,
40391 @@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40392 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40393 {
40394 unsigned int nr = DRM_IOCTL_NR(cmd);
40395 - drm_ioctl_compat_t *fn = NULL;
40396 int ret;
40397
40398 if (nr < DRM_COMMAND_BASE)
40399 return drm_compat_ioctl(filp, cmd, arg);
40400
40401 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
40402 - fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40403 -
40404 - if (fn != NULL)
40405 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
40406 + drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40407 ret = (*fn) (filp, cmd, arg);
40408 - else
40409 + } else
40410 ret = drm_ioctl(filp, cmd, arg);
40411
40412 return ret;
40413 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
40414 index c83eb75..d205e5b2 100644
40415 --- a/drivers/gpu/drm/i915/intel_display.c
40416 +++ b/drivers/gpu/drm/i915/intel_display.c
40417 @@ -11179,13 +11179,13 @@ struct intel_quirk {
40418 int subsystem_vendor;
40419 int subsystem_device;
40420 void (*hook)(struct drm_device *dev);
40421 -};
40422 +} __do_const;
40423
40424 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
40425 struct intel_dmi_quirk {
40426 void (*hook)(struct drm_device *dev);
40427 const struct dmi_system_id (*dmi_id_list)[];
40428 -};
40429 +} __do_const;
40430
40431 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40432 {
40433 @@ -11193,18 +11193,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40434 return 1;
40435 }
40436
40437 -static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40438 +static const struct dmi_system_id intel_dmi_quirks_table[] = {
40439 {
40440 - .dmi_id_list = &(const struct dmi_system_id[]) {
40441 - {
40442 - .callback = intel_dmi_reverse_brightness,
40443 - .ident = "NCR Corporation",
40444 - .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40445 - DMI_MATCH(DMI_PRODUCT_NAME, ""),
40446 - },
40447 - },
40448 - { } /* terminating entry */
40449 + .callback = intel_dmi_reverse_brightness,
40450 + .ident = "NCR Corporation",
40451 + .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40452 + DMI_MATCH(DMI_PRODUCT_NAME, ""),
40453 },
40454 + },
40455 + { } /* terminating entry */
40456 +};
40457 +
40458 +static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40459 + {
40460 + .dmi_id_list = &intel_dmi_quirks_table,
40461 .hook = quirk_invert_brightness,
40462 },
40463 };
40464 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
40465 index fe45321..836fdca 100644
40466 --- a/drivers/gpu/drm/mga/mga_drv.h
40467 +++ b/drivers/gpu/drm/mga/mga_drv.h
40468 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
40469 u32 clear_cmd;
40470 u32 maccess;
40471
40472 - atomic_t vbl_received; /**< Number of vblanks received. */
40473 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
40474 wait_queue_head_t fence_queue;
40475 - atomic_t last_fence_retired;
40476 + atomic_unchecked_t last_fence_retired;
40477 u32 next_fence_to_post;
40478
40479 unsigned int fb_cpp;
40480 diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
40481 index 86b4bb8..ae237ad 100644
40482 --- a/drivers/gpu/drm/mga/mga_ioc32.c
40483 +++ b/drivers/gpu/drm/mga/mga_ioc32.c
40484 @@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
40485 return 0;
40486 }
40487
40488 -drm_ioctl_compat_t *mga_compat_ioctls[] = {
40489 +drm_ioctl_compat_t mga_compat_ioctls[] = {
40490 [DRM_MGA_INIT] = compat_mga_init,
40491 [DRM_MGA_GETPARAM] = compat_mga_getparam,
40492 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
40493 @@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
40494 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40495 {
40496 unsigned int nr = DRM_IOCTL_NR(cmd);
40497 - drm_ioctl_compat_t *fn = NULL;
40498 int ret;
40499
40500 if (nr < DRM_COMMAND_BASE)
40501 return drm_compat_ioctl(filp, cmd, arg);
40502
40503 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
40504 - fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40505 -
40506 - if (fn != NULL)
40507 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
40508 + drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40509 ret = (*fn) (filp, cmd, arg);
40510 - else
40511 + } else
40512 ret = drm_ioctl(filp, cmd, arg);
40513
40514 return ret;
40515 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
40516 index 1b071b8..de8601a 100644
40517 --- a/drivers/gpu/drm/mga/mga_irq.c
40518 +++ b/drivers/gpu/drm/mga/mga_irq.c
40519 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
40520 if (crtc != 0)
40521 return 0;
40522
40523 - return atomic_read(&dev_priv->vbl_received);
40524 + return atomic_read_unchecked(&dev_priv->vbl_received);
40525 }
40526
40527
40528 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40529 /* VBLANK interrupt */
40530 if (status & MGA_VLINEPEN) {
40531 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
40532 - atomic_inc(&dev_priv->vbl_received);
40533 + atomic_inc_unchecked(&dev_priv->vbl_received);
40534 drm_handle_vblank(dev, 0);
40535 handled = 1;
40536 }
40537 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40538 if ((prim_start & ~0x03) != (prim_end & ~0x03))
40539 MGA_WRITE(MGA_PRIMEND, prim_end);
40540
40541 - atomic_inc(&dev_priv->last_fence_retired);
40542 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
40543 wake_up(&dev_priv->fence_queue);
40544 handled = 1;
40545 }
40546 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
40547 * using fences.
40548 */
40549 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
40550 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
40551 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
40552 - *sequence) <= (1 << 23)));
40553
40554 *sequence = cur_fence;
40555 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
40556 index 8268a4c..5105708 100644
40557 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
40558 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
40559 @@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
40560 struct bit_table {
40561 const char id;
40562 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
40563 -};
40564 +} __no_const;
40565
40566 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
40567
40568 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
40569 index 7efbafa..19f8087 100644
40570 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
40571 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
40572 @@ -97,7 +97,6 @@ struct nouveau_drm {
40573 struct drm_global_reference mem_global_ref;
40574 struct ttm_bo_global_ref bo_global_ref;
40575 struct ttm_bo_device bdev;
40576 - atomic_t validate_sequence;
40577 int (*move)(struct nouveau_channel *,
40578 struct ttm_buffer_object *,
40579 struct ttm_mem_reg *, struct ttm_mem_reg *);
40580 diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40581 index c1a7e5a..38b8539 100644
40582 --- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40583 +++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40584 @@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
40585 unsigned long arg)
40586 {
40587 unsigned int nr = DRM_IOCTL_NR(cmd);
40588 - drm_ioctl_compat_t *fn = NULL;
40589 + drm_ioctl_compat_t fn = NULL;
40590 int ret;
40591
40592 if (nr < DRM_COMMAND_BASE)
40593 diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40594 index ab0228f..20b756b 100644
40595 --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
40596 +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40597 @@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40598 }
40599
40600 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
40601 - nouveau_vram_manager_init,
40602 - nouveau_vram_manager_fini,
40603 - nouveau_vram_manager_new,
40604 - nouveau_vram_manager_del,
40605 - nouveau_vram_manager_debug
40606 + .init = nouveau_vram_manager_init,
40607 + .takedown = nouveau_vram_manager_fini,
40608 + .get_node = nouveau_vram_manager_new,
40609 + .put_node = nouveau_vram_manager_del,
40610 + .debug = nouveau_vram_manager_debug
40611 };
40612
40613 static int
40614 @@ -199,11 +199,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40615 }
40616
40617 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
40618 - nouveau_gart_manager_init,
40619 - nouveau_gart_manager_fini,
40620 - nouveau_gart_manager_new,
40621 - nouveau_gart_manager_del,
40622 - nouveau_gart_manager_debug
40623 + .init = nouveau_gart_manager_init,
40624 + .takedown = nouveau_gart_manager_fini,
40625 + .get_node = nouveau_gart_manager_new,
40626 + .put_node = nouveau_gart_manager_del,
40627 + .debug = nouveau_gart_manager_debug
40628 };
40629
40630 #include <core/subdev/vm/nv04.h>
40631 @@ -271,11 +271,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40632 }
40633
40634 const struct ttm_mem_type_manager_func nv04_gart_manager = {
40635 - nv04_gart_manager_init,
40636 - nv04_gart_manager_fini,
40637 - nv04_gart_manager_new,
40638 - nv04_gart_manager_del,
40639 - nv04_gart_manager_debug
40640 + .init = nv04_gart_manager_init,
40641 + .takedown = nv04_gart_manager_fini,
40642 + .get_node = nv04_gart_manager_new,
40643 + .put_node = nv04_gart_manager_del,
40644 + .debug = nv04_gart_manager_debug
40645 };
40646
40647 int
40648 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
40649 index fb84da3..d7ee463 100644
40650 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
40651 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
40652 @@ -67,7 +67,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
40653 bool can_switch;
40654
40655 spin_lock(&dev->count_lock);
40656 - can_switch = (dev->open_count == 0);
40657 + can_switch = (local_read(&dev->open_count) == 0);
40658 spin_unlock(&dev->count_lock);
40659 return can_switch;
40660 }
40661 diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
40662 index eb89653..613cf71 100644
40663 --- a/drivers/gpu/drm/qxl/qxl_cmd.c
40664 +++ b/drivers/gpu/drm/qxl/qxl_cmd.c
40665 @@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
40666 int ret;
40667
40668 mutex_lock(&qdev->async_io_mutex);
40669 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
40670 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40671 if (qdev->last_sent_io_cmd > irq_num) {
40672 if (intr)
40673 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40674 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40675 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40676 else
40677 ret = wait_event_timeout(qdev->io_cmd_event,
40678 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40679 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40680 /* 0 is timeout, just bail the "hw" has gone away */
40681 if (ret <= 0)
40682 goto out;
40683 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
40684 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40685 }
40686 outb(val, addr);
40687 qdev->last_sent_io_cmd = irq_num + 1;
40688 if (intr)
40689 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40690 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40691 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40692 else
40693 ret = wait_event_timeout(qdev->io_cmd_event,
40694 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40695 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40696 out:
40697 if (ret > 0)
40698 ret = 0;
40699 diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
40700 index c3c2bbd..bc3c0fb 100644
40701 --- a/drivers/gpu/drm/qxl/qxl_debugfs.c
40702 +++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
40703 @@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
40704 struct drm_info_node *node = (struct drm_info_node *) m->private;
40705 struct qxl_device *qdev = node->minor->dev->dev_private;
40706
40707 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
40708 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
40709 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
40710 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
40711 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
40712 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
40713 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
40714 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
40715 seq_printf(m, "%d\n", qdev->irq_received_error);
40716 return 0;
40717 }
40718 diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
40719 index 36ed40b..0397633 100644
40720 --- a/drivers/gpu/drm/qxl/qxl_drv.h
40721 +++ b/drivers/gpu/drm/qxl/qxl_drv.h
40722 @@ -290,10 +290,10 @@ struct qxl_device {
40723 unsigned int last_sent_io_cmd;
40724
40725 /* interrupt handling */
40726 - atomic_t irq_received;
40727 - atomic_t irq_received_display;
40728 - atomic_t irq_received_cursor;
40729 - atomic_t irq_received_io_cmd;
40730 + atomic_unchecked_t irq_received;
40731 + atomic_unchecked_t irq_received_display;
40732 + atomic_unchecked_t irq_received_cursor;
40733 + atomic_unchecked_t irq_received_io_cmd;
40734 unsigned irq_received_error;
40735 wait_queue_head_t display_event;
40736 wait_queue_head_t cursor_event;
40737 diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
40738 index 0bb86e6..d41416d 100644
40739 --- a/drivers/gpu/drm/qxl/qxl_ioctl.c
40740 +++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
40741 @@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40742
40743 /* TODO copy slow path code from i915 */
40744 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
40745 - 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);
40746 + 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);
40747
40748 {
40749 struct qxl_drawable *draw = fb_cmd;
40750 @@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40751 struct drm_qxl_reloc reloc;
40752
40753 if (copy_from_user(&reloc,
40754 - &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
40755 + &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
40756 sizeof(reloc))) {
40757 ret = -EFAULT;
40758 goto out_free_bos;
40759 @@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
40760
40761 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
40762
40763 - struct drm_qxl_command *commands =
40764 - (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
40765 + struct drm_qxl_command __user *commands =
40766 + (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
40767
40768 - if (copy_from_user(&user_cmd, &commands[cmd_num],
40769 + if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
40770 sizeof(user_cmd)))
40771 return -EFAULT;
40772
40773 diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
40774 index 3485bdc..20d26e3 100644
40775 --- a/drivers/gpu/drm/qxl/qxl_irq.c
40776 +++ b/drivers/gpu/drm/qxl/qxl_irq.c
40777 @@ -36,19 +36,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
40778 if (!pending)
40779 return IRQ_NONE;
40780
40781 - atomic_inc(&qdev->irq_received);
40782 + atomic_inc_unchecked(&qdev->irq_received);
40783
40784 if (pending & QXL_INTERRUPT_DISPLAY) {
40785 - atomic_inc(&qdev->irq_received_display);
40786 + atomic_inc_unchecked(&qdev->irq_received_display);
40787 wake_up_all(&qdev->display_event);
40788 qxl_queue_garbage_collect(qdev, false);
40789 }
40790 if (pending & QXL_INTERRUPT_CURSOR) {
40791 - atomic_inc(&qdev->irq_received_cursor);
40792 + atomic_inc_unchecked(&qdev->irq_received_cursor);
40793 wake_up_all(&qdev->cursor_event);
40794 }
40795 if (pending & QXL_INTERRUPT_IO_CMD) {
40796 - atomic_inc(&qdev->irq_received_io_cmd);
40797 + atomic_inc_unchecked(&qdev->irq_received_io_cmd);
40798 wake_up_all(&qdev->io_cmd_event);
40799 }
40800 if (pending & QXL_INTERRUPT_ERROR) {
40801 @@ -85,10 +85,10 @@ int qxl_irq_init(struct qxl_device *qdev)
40802 init_waitqueue_head(&qdev->io_cmd_event);
40803 INIT_WORK(&qdev->client_monitors_config_work,
40804 qxl_client_monitors_config_work_func);
40805 - atomic_set(&qdev->irq_received, 0);
40806 - atomic_set(&qdev->irq_received_display, 0);
40807 - atomic_set(&qdev->irq_received_cursor, 0);
40808 - atomic_set(&qdev->irq_received_io_cmd, 0);
40809 + atomic_set_unchecked(&qdev->irq_received, 0);
40810 + atomic_set_unchecked(&qdev->irq_received_display, 0);
40811 + atomic_set_unchecked(&qdev->irq_received_cursor, 0);
40812 + atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
40813 qdev->irq_received_error = 0;
40814 ret = drm_irq_install(qdev->ddev);
40815 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
40816 diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
40817 index d52c275..4e6b43d 100644
40818 --- a/drivers/gpu/drm/qxl/qxl_ttm.c
40819 +++ b/drivers/gpu/drm/qxl/qxl_ttm.c
40820 @@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
40821 }
40822 }
40823
40824 -static struct vm_operations_struct qxl_ttm_vm_ops;
40825 +static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
40826 static const struct vm_operations_struct *ttm_vm_ops;
40827
40828 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40829 @@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
40830 return r;
40831 if (unlikely(ttm_vm_ops == NULL)) {
40832 ttm_vm_ops = vma->vm_ops;
40833 + pax_open_kernel();
40834 qxl_ttm_vm_ops = *ttm_vm_ops;
40835 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
40836 + pax_close_kernel();
40837 }
40838 vma->vm_ops = &qxl_ttm_vm_ops;
40839 return 0;
40840 @@ -561,25 +563,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
40841 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
40842 {
40843 #if defined(CONFIG_DEBUG_FS)
40844 - static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
40845 - static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
40846 - unsigned i;
40847 + static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
40848 + {
40849 + .name = "qxl_mem_mm",
40850 + .show = &qxl_mm_dump_table,
40851 + },
40852 + {
40853 + .name = "qxl_surf_mm",
40854 + .show = &qxl_mm_dump_table,
40855 + }
40856 + };
40857
40858 - for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
40859 - if (i == 0)
40860 - sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
40861 - else
40862 - sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
40863 - qxl_mem_types_list[i].name = qxl_mem_types_names[i];
40864 - qxl_mem_types_list[i].show = &qxl_mm_dump_table;
40865 - qxl_mem_types_list[i].driver_features = 0;
40866 - if (i == 0)
40867 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40868 - else
40869 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40870 + pax_open_kernel();
40871 + *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40872 + *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40873 + pax_close_kernel();
40874
40875 - }
40876 - return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
40877 + return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
40878 #else
40879 return 0;
40880 #endif
40881 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
40882 index 59459fe..be26b31 100644
40883 --- a/drivers/gpu/drm/r128/r128_cce.c
40884 +++ b/drivers/gpu/drm/r128/r128_cce.c
40885 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
40886
40887 /* GH: Simple idle check.
40888 */
40889 - atomic_set(&dev_priv->idle_count, 0);
40890 + atomic_set_unchecked(&dev_priv->idle_count, 0);
40891
40892 /* We don't support anything other than bus-mastering ring mode,
40893 * but the ring can be in either AGP or PCI space for the ring
40894 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
40895 index 5bf3f5f..7000661 100644
40896 --- a/drivers/gpu/drm/r128/r128_drv.h
40897 +++ b/drivers/gpu/drm/r128/r128_drv.h
40898 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
40899 int is_pci;
40900 unsigned long cce_buffers_offset;
40901
40902 - atomic_t idle_count;
40903 + atomic_unchecked_t idle_count;
40904
40905 int page_flipping;
40906 int current_page;
40907 u32 crtc_offset;
40908 u32 crtc_offset_cntl;
40909
40910 - atomic_t vbl_received;
40911 + atomic_unchecked_t vbl_received;
40912
40913 u32 color_fmt;
40914 unsigned int front_offset;
40915 diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
40916 index b0d0fd3..a6fbbe4 100644
40917 --- a/drivers/gpu/drm/r128/r128_ioc32.c
40918 +++ b/drivers/gpu/drm/r128/r128_ioc32.c
40919 @@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
40920 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
40921 }
40922
40923 -drm_ioctl_compat_t *r128_compat_ioctls[] = {
40924 +drm_ioctl_compat_t r128_compat_ioctls[] = {
40925 [DRM_R128_INIT] = compat_r128_init,
40926 [DRM_R128_DEPTH] = compat_r128_depth,
40927 [DRM_R128_STIPPLE] = compat_r128_stipple,
40928 @@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
40929 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40930 {
40931 unsigned int nr = DRM_IOCTL_NR(cmd);
40932 - drm_ioctl_compat_t *fn = NULL;
40933 int ret;
40934
40935 if (nr < DRM_COMMAND_BASE)
40936 return drm_compat_ioctl(filp, cmd, arg);
40937
40938 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
40939 - fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40940 -
40941 - if (fn != NULL)
40942 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
40943 + drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40944 ret = (*fn) (filp, cmd, arg);
40945 - else
40946 + } else
40947 ret = drm_ioctl(filp, cmd, arg);
40948
40949 return ret;
40950 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
40951 index c2ae496..30b5993 100644
40952 --- a/drivers/gpu/drm/r128/r128_irq.c
40953 +++ b/drivers/gpu/drm/r128/r128_irq.c
40954 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
40955 if (crtc != 0)
40956 return 0;
40957
40958 - return atomic_read(&dev_priv->vbl_received);
40959 + return atomic_read_unchecked(&dev_priv->vbl_received);
40960 }
40961
40962 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
40963 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
40964 /* VBLANK interrupt */
40965 if (status & R128_CRTC_VBLANK_INT) {
40966 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
40967 - atomic_inc(&dev_priv->vbl_received);
40968 + atomic_inc_unchecked(&dev_priv->vbl_received);
40969 drm_handle_vblank(dev, 0);
40970 return IRQ_HANDLED;
40971 }
40972 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
40973 index e806dac..f81d32f 100644
40974 --- a/drivers/gpu/drm/r128/r128_state.c
40975 +++ b/drivers/gpu/drm/r128/r128_state.c
40976 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
40977
40978 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
40979 {
40980 - if (atomic_read(&dev_priv->idle_count) == 0)
40981 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
40982 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
40983 else
40984 - atomic_set(&dev_priv->idle_count, 0);
40985 + atomic_set_unchecked(&dev_priv->idle_count, 0);
40986 }
40987
40988 #endif
40989 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
40990 index 4a85bb6..aaea819 100644
40991 --- a/drivers/gpu/drm/radeon/mkregtable.c
40992 +++ b/drivers/gpu/drm/radeon/mkregtable.c
40993 @@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
40994 regex_t mask_rex;
40995 regmatch_t match[4];
40996 char buf[1024];
40997 - size_t end;
40998 + long end;
40999 int len;
41000 int done = 0;
41001 int r;
41002 unsigned o;
41003 struct offset *offset;
41004 char last_reg_s[10];
41005 - int last_reg;
41006 + unsigned long last_reg;
41007
41008 if (regcomp
41009 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
41010 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
41011 index 2cd144c..a01c95a 100644
41012 --- a/drivers/gpu/drm/radeon/radeon_device.c
41013 +++ b/drivers/gpu/drm/radeon/radeon_device.c
41014 @@ -1129,7 +1129,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
41015 bool can_switch;
41016
41017 spin_lock(&dev->count_lock);
41018 - can_switch = (dev->open_count == 0);
41019 + can_switch = (local_read(&dev->open_count) == 0);
41020 spin_unlock(&dev->count_lock);
41021 return can_switch;
41022 }
41023 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
41024 index dafd812..1bf20c7 100644
41025 --- a/drivers/gpu/drm/radeon/radeon_drv.h
41026 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
41027 @@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
41028
41029 /* SW interrupt */
41030 wait_queue_head_t swi_queue;
41031 - atomic_t swi_emitted;
41032 + atomic_unchecked_t swi_emitted;
41033 int vblank_crtc;
41034 uint32_t irq_enable_reg;
41035 uint32_t r500_disp_irq_reg;
41036 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
41037 index bdb0f93..5ff558f 100644
41038 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
41039 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
41040 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41041 request = compat_alloc_user_space(sizeof(*request));
41042 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
41043 || __put_user(req32.param, &request->param)
41044 - || __put_user((void __user *)(unsigned long)req32.value,
41045 + || __put_user((unsigned long)req32.value,
41046 &request->value))
41047 return -EFAULT;
41048
41049 @@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41050 #define compat_radeon_cp_setparam NULL
41051 #endif /* X86_64 || IA64 */
41052
41053 -static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41054 +static drm_ioctl_compat_t radeon_compat_ioctls[] = {
41055 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
41056 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
41057 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
41058 @@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41059 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41060 {
41061 unsigned int nr = DRM_IOCTL_NR(cmd);
41062 - drm_ioctl_compat_t *fn = NULL;
41063 int ret;
41064
41065 if (nr < DRM_COMMAND_BASE)
41066 return drm_compat_ioctl(filp, cmd, arg);
41067
41068 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
41069 - fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41070 -
41071 - if (fn != NULL)
41072 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
41073 + drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41074 ret = (*fn) (filp, cmd, arg);
41075 - else
41076 + } else
41077 ret = drm_ioctl(filp, cmd, arg);
41078
41079 return ret;
41080 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
41081 index 244b19b..c19226d 100644
41082 --- a/drivers/gpu/drm/radeon/radeon_irq.c
41083 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
41084 @@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
41085 unsigned int ret;
41086 RING_LOCALS;
41087
41088 - atomic_inc(&dev_priv->swi_emitted);
41089 - ret = atomic_read(&dev_priv->swi_emitted);
41090 + atomic_inc_unchecked(&dev_priv->swi_emitted);
41091 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
41092
41093 BEGIN_RING(4);
41094 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
41095 @@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
41096 drm_radeon_private_t *dev_priv =
41097 (drm_radeon_private_t *) dev->dev_private;
41098
41099 - atomic_set(&dev_priv->swi_emitted, 0);
41100 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
41101 init_waitqueue_head(&dev_priv->swi_queue);
41102
41103 dev->max_vblank_count = 0x001fffff;
41104 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
41105 index 956ab7f..fbd36d8 100644
41106 --- a/drivers/gpu/drm/radeon/radeon_state.c
41107 +++ b/drivers/gpu/drm/radeon/radeon_state.c
41108 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
41109 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
41110 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
41111
41112 - if (copy_from_user(&depth_boxes, clear->depth_boxes,
41113 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
41114 sarea_priv->nbox * sizeof(depth_boxes[0])))
41115 return -EFAULT;
41116
41117 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
41118 {
41119 drm_radeon_private_t *dev_priv = dev->dev_private;
41120 drm_radeon_getparam_t *param = data;
41121 - int value;
41122 + int value = 0;
41123
41124 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
41125
41126 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
41127 index c8a8a51..219dacc 100644
41128 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
41129 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
41130 @@ -797,7 +797,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
41131 man->size = size >> PAGE_SHIFT;
41132 }
41133
41134 -static struct vm_operations_struct radeon_ttm_vm_ops;
41135 +static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
41136 static const struct vm_operations_struct *ttm_vm_ops = NULL;
41137
41138 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41139 @@ -838,8 +838,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
41140 }
41141 if (unlikely(ttm_vm_ops == NULL)) {
41142 ttm_vm_ops = vma->vm_ops;
41143 + pax_open_kernel();
41144 radeon_ttm_vm_ops = *ttm_vm_ops;
41145 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
41146 + pax_close_kernel();
41147 }
41148 vma->vm_ops = &radeon_ttm_vm_ops;
41149 return 0;
41150 diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
41151 index edb871d..a275c6ed 100644
41152 --- a/drivers/gpu/drm/tegra/dc.c
41153 +++ b/drivers/gpu/drm/tegra/dc.c
41154 @@ -1057,7 +1057,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
41155 }
41156
41157 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
41158 - dc->debugfs_files[i].data = dc;
41159 + *(void **)&dc->debugfs_files[i].data = dc;
41160
41161 err = drm_debugfs_create_files(dc->debugfs_files,
41162 ARRAY_SIZE(debugfs_files),
41163 diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
41164 index 0e599f0..c9ea7c7 100644
41165 --- a/drivers/gpu/drm/tegra/dsi.c
41166 +++ b/drivers/gpu/drm/tegra/dsi.c
41167 @@ -39,7 +39,7 @@ struct tegra_dsi {
41168 struct clk *clk_lp;
41169 struct clk *clk;
41170
41171 - struct drm_info_list *debugfs_files;
41172 + drm_info_list_no_const *debugfs_files;
41173 struct drm_minor *minor;
41174 struct dentry *debugfs;
41175
41176 diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
41177 index 6928015..c9853e7 100644
41178 --- a/drivers/gpu/drm/tegra/hdmi.c
41179 +++ b/drivers/gpu/drm/tegra/hdmi.c
41180 @@ -59,7 +59,7 @@ struct tegra_hdmi {
41181 bool stereo;
41182 bool dvi;
41183
41184 - struct drm_info_list *debugfs_files;
41185 + drm_info_list_no_const *debugfs_files;
41186 struct drm_minor *minor;
41187 struct dentry *debugfs;
41188 };
41189 diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41190 index bd850c9..d9f3573 100644
41191 --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
41192 +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41193 @@ -146,10 +146,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
41194 }
41195
41196 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
41197 - ttm_bo_man_init,
41198 - ttm_bo_man_takedown,
41199 - ttm_bo_man_get_node,
41200 - ttm_bo_man_put_node,
41201 - ttm_bo_man_debug
41202 + .init = ttm_bo_man_init,
41203 + .takedown = ttm_bo_man_takedown,
41204 + .get_node = ttm_bo_man_get_node,
41205 + .put_node = ttm_bo_man_put_node,
41206 + .debug = ttm_bo_man_debug
41207 };
41208 EXPORT_SYMBOL(ttm_bo_manager_func);
41209 diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
41210 index dbc2def..0a9f710 100644
41211 --- a/drivers/gpu/drm/ttm/ttm_memory.c
41212 +++ b/drivers/gpu/drm/ttm/ttm_memory.c
41213 @@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
41214 zone->glob = glob;
41215 glob->zone_kernel = zone;
41216 ret = kobject_init_and_add(
41217 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41218 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41219 if (unlikely(ret != 0)) {
41220 kobject_put(&zone->kobj);
41221 return ret;
41222 @@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
41223 zone->glob = glob;
41224 glob->zone_dma32 = zone;
41225 ret = kobject_init_and_add(
41226 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41227 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41228 if (unlikely(ret != 0)) {
41229 kobject_put(&zone->kobj);
41230 return ret;
41231 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41232 index 863bef9..cba15cf 100644
41233 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
41234 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41235 @@ -391,9 +391,9 @@ out:
41236 static unsigned long
41237 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41238 {
41239 - static atomic_t start_pool = ATOMIC_INIT(0);
41240 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
41241 unsigned i;
41242 - unsigned pool_offset = atomic_add_return(1, &start_pool);
41243 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
41244 struct ttm_page_pool *pool;
41245 int shrink_pages = sc->nr_to_scan;
41246 unsigned long freed = 0;
41247 diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
41248 index 3771763..883f206 100644
41249 --- a/drivers/gpu/drm/udl/udl_fb.c
41250 +++ b/drivers/gpu/drm/udl/udl_fb.c
41251 @@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
41252 fb_deferred_io_cleanup(info);
41253 kfree(info->fbdefio);
41254 info->fbdefio = NULL;
41255 - info->fbops->fb_mmap = udl_fb_mmap;
41256 }
41257
41258 pr_warn("released /dev/fb%d user=%d count=%d\n",
41259 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
41260 index ad02732..144f5ed 100644
41261 --- a/drivers/gpu/drm/via/via_drv.h
41262 +++ b/drivers/gpu/drm/via/via_drv.h
41263 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
41264 typedef uint32_t maskarray_t[5];
41265
41266 typedef struct drm_via_irq {
41267 - atomic_t irq_received;
41268 + atomic_unchecked_t irq_received;
41269 uint32_t pending_mask;
41270 uint32_t enable_mask;
41271 wait_queue_head_t irq_queue;
41272 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
41273 struct timeval last_vblank;
41274 int last_vblank_valid;
41275 unsigned usec_per_vblank;
41276 - atomic_t vbl_received;
41277 + atomic_unchecked_t vbl_received;
41278 drm_via_state_t hc_state;
41279 char pci_buf[VIA_PCI_BUF_SIZE];
41280 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
41281 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
41282 index 1319433..a993b0c 100644
41283 --- a/drivers/gpu/drm/via/via_irq.c
41284 +++ b/drivers/gpu/drm/via/via_irq.c
41285 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
41286 if (crtc != 0)
41287 return 0;
41288
41289 - return atomic_read(&dev_priv->vbl_received);
41290 + return atomic_read_unchecked(&dev_priv->vbl_received);
41291 }
41292
41293 irqreturn_t via_driver_irq_handler(int irq, void *arg)
41294 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41295
41296 status = VIA_READ(VIA_REG_INTERRUPT);
41297 if (status & VIA_IRQ_VBLANK_PENDING) {
41298 - atomic_inc(&dev_priv->vbl_received);
41299 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
41300 + atomic_inc_unchecked(&dev_priv->vbl_received);
41301 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
41302 do_gettimeofday(&cur_vblank);
41303 if (dev_priv->last_vblank_valid) {
41304 dev_priv->usec_per_vblank =
41305 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41306 dev_priv->last_vblank = cur_vblank;
41307 dev_priv->last_vblank_valid = 1;
41308 }
41309 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
41310 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
41311 DRM_DEBUG("US per vblank is: %u\n",
41312 dev_priv->usec_per_vblank);
41313 }
41314 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41315
41316 for (i = 0; i < dev_priv->num_irqs; ++i) {
41317 if (status & cur_irq->pending_mask) {
41318 - atomic_inc(&cur_irq->irq_received);
41319 + atomic_inc_unchecked(&cur_irq->irq_received);
41320 wake_up(&cur_irq->irq_queue);
41321 handled = 1;
41322 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
41323 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
41324 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41325 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
41326 masks[irq][4]));
41327 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
41328 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
41329 } else {
41330 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41331 (((cur_irq_sequence =
41332 - atomic_read(&cur_irq->irq_received)) -
41333 + atomic_read_unchecked(&cur_irq->irq_received)) -
41334 *sequence) <= (1 << 23)));
41335 }
41336 *sequence = cur_irq_sequence;
41337 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
41338 }
41339
41340 for (i = 0; i < dev_priv->num_irqs; ++i) {
41341 - atomic_set(&cur_irq->irq_received, 0);
41342 + atomic_set_unchecked(&cur_irq->irq_received, 0);
41343 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
41344 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
41345 init_waitqueue_head(&cur_irq->irq_queue);
41346 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
41347 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
41348 case VIA_IRQ_RELATIVE:
41349 irqwait->request.sequence +=
41350 - atomic_read(&cur_irq->irq_received);
41351 + atomic_read_unchecked(&cur_irq->irq_received);
41352 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
41353 case VIA_IRQ_ABSOLUTE:
41354 break;
41355 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41356 index 6b252a8..5975dfe 100644
41357 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41358 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41359 @@ -437,7 +437,7 @@ struct vmw_private {
41360 * Fencing and IRQs.
41361 */
41362
41363 - atomic_t marker_seq;
41364 + atomic_unchecked_t marker_seq;
41365 wait_queue_head_t fence_queue;
41366 wait_queue_head_t fifo_queue;
41367 int fence_queue_waiters; /* Protected by hw_mutex */
41368 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41369 index 6ccd993..618d592 100644
41370 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41371 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41372 @@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
41373 (unsigned int) min,
41374 (unsigned int) fifo->capabilities);
41375
41376 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41377 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41378 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
41379 vmw_marker_queue_init(&fifo->marker_queue);
41380 return vmw_fifo_send_fence(dev_priv, &dummy);
41381 @@ -372,7 +372,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
41382 if (reserveable)
41383 iowrite32(bytes, fifo_mem +
41384 SVGA_FIFO_RESERVED);
41385 - return fifo_mem + (next_cmd >> 2);
41386 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
41387 } else {
41388 need_bounce = true;
41389 }
41390 @@ -492,7 +492,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41391
41392 fm = vmw_fifo_reserve(dev_priv, bytes);
41393 if (unlikely(fm == NULL)) {
41394 - *seqno = atomic_read(&dev_priv->marker_seq);
41395 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41396 ret = -ENOMEM;
41397 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
41398 false, 3*HZ);
41399 @@ -500,7 +500,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41400 }
41401
41402 do {
41403 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
41404 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
41405 } while (*seqno == 0);
41406
41407 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
41408 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41409 index b1273e8..9c274fd 100644
41410 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41411 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41412 @@ -164,9 +164,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
41413 }
41414
41415 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
41416 - vmw_gmrid_man_init,
41417 - vmw_gmrid_man_takedown,
41418 - vmw_gmrid_man_get_node,
41419 - vmw_gmrid_man_put_node,
41420 - vmw_gmrid_man_debug
41421 + .init = vmw_gmrid_man_init,
41422 + .takedown = vmw_gmrid_man_takedown,
41423 + .get_node = vmw_gmrid_man_get_node,
41424 + .put_node = vmw_gmrid_man_put_node,
41425 + .debug = vmw_gmrid_man_debug
41426 };
41427 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41428 index 37881ec..319065d 100644
41429 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41430 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41431 @@ -235,7 +235,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
41432 int ret;
41433
41434 num_clips = arg->num_clips;
41435 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41436 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41437
41438 if (unlikely(num_clips == 0))
41439 return 0;
41440 @@ -318,7 +318,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
41441 int ret;
41442
41443 num_clips = arg->num_clips;
41444 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41445 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41446
41447 if (unlikely(num_clips == 0))
41448 return 0;
41449 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41450 index 0c42376..6febe77 100644
41451 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41452 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41453 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
41454 * emitted. Then the fence is stale and signaled.
41455 */
41456
41457 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
41458 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
41459 > VMW_FENCE_WRAP);
41460
41461 return ret;
41462 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
41463
41464 if (fifo_idle)
41465 down_read(&fifo_state->rwsem);
41466 - signal_seq = atomic_read(&dev_priv->marker_seq);
41467 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
41468 ret = 0;
41469
41470 for (;;) {
41471 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41472 index 8a8725c2..afed796 100644
41473 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41474 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41475 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
41476 while (!vmw_lag_lt(queue, us)) {
41477 spin_lock(&queue->lock);
41478 if (list_empty(&queue->head))
41479 - seqno = atomic_read(&dev_priv->marker_seq);
41480 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41481 else {
41482 marker = list_first_entry(&queue->head,
41483 struct vmw_marker, head);
41484 diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
41485 index 6866448..2ad2b34 100644
41486 --- a/drivers/gpu/vga/vga_switcheroo.c
41487 +++ b/drivers/gpu/vga/vga_switcheroo.c
41488 @@ -644,7 +644,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
41489
41490 /* this version is for the case where the power switch is separate
41491 to the device being powered down. */
41492 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
41493 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
41494 {
41495 /* copy over all the bus versions */
41496 if (dev->bus && dev->bus->pm) {
41497 @@ -689,7 +689,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
41498 return ret;
41499 }
41500
41501 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
41502 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
41503 {
41504 /* copy over all the bus versions */
41505 if (dev->bus && dev->bus->pm) {
41506 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
41507 index a5c7927..025a2b4 100644
41508 --- a/drivers/hid/hid-core.c
41509 +++ b/drivers/hid/hid-core.c
41510 @@ -2476,7 +2476,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
41511
41512 int hid_add_device(struct hid_device *hdev)
41513 {
41514 - static atomic_t id = ATOMIC_INIT(0);
41515 + static atomic_unchecked_t id = ATOMIC_INIT(0);
41516 int ret;
41517
41518 if (WARN_ON(hdev->status & HID_STAT_ADDED))
41519 @@ -2518,7 +2518,7 @@ int hid_add_device(struct hid_device *hdev)
41520 /* XXX hack, any other cleaner solution after the driver core
41521 * is converted to allow more than 20 bytes as the device name? */
41522 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
41523 - hdev->vendor, hdev->product, atomic_inc_return(&id));
41524 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
41525
41526 hid_debug_register(hdev, dev_name(&hdev->dev));
41527 ret = device_add(&hdev->dev);
41528 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
41529 index c13fb5b..55a3802 100644
41530 --- a/drivers/hid/hid-wiimote-debug.c
41531 +++ b/drivers/hid/hid-wiimote-debug.c
41532 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
41533 else if (size == 0)
41534 return -EIO;
41535
41536 - if (copy_to_user(u, buf, size))
41537 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
41538 return -EFAULT;
41539
41540 *off += size;
41541 diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
41542 index 0d078c3..cd0962c 100644
41543 --- a/drivers/hid/uhid.c
41544 +++ b/drivers/hid/uhid.c
41545 @@ -47,7 +47,7 @@ struct uhid_device {
41546 struct mutex report_lock;
41547 wait_queue_head_t report_wait;
41548 atomic_t report_done;
41549 - atomic_t report_id;
41550 + atomic_unchecked_t report_id;
41551 struct uhid_event report_buf;
41552 };
41553
41554 @@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
41555
41556 spin_lock_irqsave(&uhid->qlock, flags);
41557 ev->type = UHID_FEATURE;
41558 - ev->u.feature.id = atomic_inc_return(&uhid->report_id);
41559 + ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
41560 ev->u.feature.rnum = rnum;
41561 ev->u.feature.rtype = report_type;
41562
41563 @@ -539,7 +539,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
41564 spin_lock_irqsave(&uhid->qlock, flags);
41565
41566 /* id for old report; drop it silently */
41567 - if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
41568 + if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
41569 goto unlock;
41570 if (atomic_read(&uhid->report_done))
41571 goto unlock;
41572 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
41573 index 602ca86..10a6573 100644
41574 --- a/drivers/hv/channel.c
41575 +++ b/drivers/hv/channel.c
41576 @@ -365,8 +365,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
41577 int ret = 0;
41578 int t;
41579
41580 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
41581 - atomic_inc(&vmbus_connection.next_gpadl_handle);
41582 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
41583 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
41584
41585 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
41586 if (ret)
41587 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
41588 index bcb4950..61dba6c 100644
41589 --- a/drivers/hv/hv.c
41590 +++ b/drivers/hv/hv.c
41591 @@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
41592 u64 output_address = (output) ? virt_to_phys(output) : 0;
41593 u32 output_address_hi = output_address >> 32;
41594 u32 output_address_lo = output_address & 0xFFFFFFFF;
41595 - void *hypercall_page = hv_context.hypercall_page;
41596 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
41597
41598 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
41599 "=a"(hv_status_lo) : "d" (control_hi),
41600 @@ -154,7 +154,7 @@ int hv_init(void)
41601 /* See if the hypercall page is already set */
41602 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
41603
41604 - virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
41605 + virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
41606
41607 if (!virtaddr)
41608 goto cleanup;
41609 diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
41610 index 5e90c5d..d8fcefb 100644
41611 --- a/drivers/hv/hv_balloon.c
41612 +++ b/drivers/hv/hv_balloon.c
41613 @@ -470,7 +470,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
41614
41615 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
41616 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
41617 -static atomic_t trans_id = ATOMIC_INIT(0);
41618 +static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
41619
41620 static int dm_ring_size = (5 * PAGE_SIZE);
41621
41622 @@ -893,7 +893,7 @@ static void hot_add_req(struct work_struct *dummy)
41623 pr_info("Memory hot add failed\n");
41624
41625 dm->state = DM_INITIALIZED;
41626 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
41627 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41628 vmbus_sendpacket(dm->dev->channel, &resp,
41629 sizeof(struct dm_hot_add_response),
41630 (unsigned long)NULL,
41631 @@ -973,7 +973,7 @@ static void post_status(struct hv_dynmem_device *dm)
41632 memset(&status, 0, sizeof(struct dm_status));
41633 status.hdr.type = DM_STATUS_REPORT;
41634 status.hdr.size = sizeof(struct dm_status);
41635 - status.hdr.trans_id = atomic_inc_return(&trans_id);
41636 + status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41637
41638 /*
41639 * The host expects the guest to report free memory.
41640 @@ -993,7 +993,7 @@ static void post_status(struct hv_dynmem_device *dm)
41641 * send the status. This can happen if we were interrupted
41642 * after we picked our transaction ID.
41643 */
41644 - if (status.hdr.trans_id != atomic_read(&trans_id))
41645 + if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
41646 return;
41647
41648 /*
41649 @@ -1129,7 +1129,7 @@ static void balloon_up(struct work_struct *dummy)
41650 */
41651
41652 do {
41653 - bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
41654 + bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41655 ret = vmbus_sendpacket(dm_device.dev->channel,
41656 bl_resp,
41657 bl_resp->hdr.size,
41658 @@ -1175,7 +1175,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
41659
41660 memset(&resp, 0, sizeof(struct dm_unballoon_response));
41661 resp.hdr.type = DM_UNBALLOON_RESPONSE;
41662 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
41663 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41664 resp.hdr.size = sizeof(struct dm_unballoon_response);
41665
41666 vmbus_sendpacket(dm_device.dev->channel, &resp,
41667 @@ -1239,7 +1239,7 @@ static void version_resp(struct hv_dynmem_device *dm,
41668 memset(&version_req, 0, sizeof(struct dm_version_request));
41669 version_req.hdr.type = DM_VERSION_REQUEST;
41670 version_req.hdr.size = sizeof(struct dm_version_request);
41671 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41672 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41673 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
41674 version_req.is_last_attempt = 1;
41675
41676 @@ -1409,7 +1409,7 @@ static int balloon_probe(struct hv_device *dev,
41677 memset(&version_req, 0, sizeof(struct dm_version_request));
41678 version_req.hdr.type = DM_VERSION_REQUEST;
41679 version_req.hdr.size = sizeof(struct dm_version_request);
41680 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41681 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41682 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
41683 version_req.is_last_attempt = 0;
41684
41685 @@ -1440,7 +1440,7 @@ static int balloon_probe(struct hv_device *dev,
41686 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
41687 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
41688 cap_msg.hdr.size = sizeof(struct dm_capabilities);
41689 - cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
41690 + cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41691
41692 cap_msg.caps.cap_bits.balloon = 1;
41693 cap_msg.caps.cap_bits.hot_add = 1;
41694 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
41695 index 860134d..ea3a79a 100644
41696 --- a/drivers/hv/hyperv_vmbus.h
41697 +++ b/drivers/hv/hyperv_vmbus.h
41698 @@ -602,7 +602,7 @@ enum vmbus_connect_state {
41699 struct vmbus_connection {
41700 enum vmbus_connect_state conn_state;
41701
41702 - atomic_t next_gpadl_handle;
41703 + atomic_unchecked_t next_gpadl_handle;
41704
41705 /*
41706 * Represents channel interrupts. Each bit position represents a
41707 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
41708 index 8e53a3c..7a64e44 100644
41709 --- a/drivers/hv/vmbus_drv.c
41710 +++ b/drivers/hv/vmbus_drv.c
41711 @@ -807,10 +807,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
41712 {
41713 int ret = 0;
41714
41715 - static atomic_t device_num = ATOMIC_INIT(0);
41716 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
41717
41718 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
41719 - atomic_inc_return(&device_num));
41720 + atomic_inc_return_unchecked(&device_num));
41721
41722 child_device_obj->device.bus = &hv_bus;
41723 child_device_obj->device.parent = &hv_acpi_dev->dev;
41724 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
41725 index 579bdf9..75118b5 100644
41726 --- a/drivers/hwmon/acpi_power_meter.c
41727 +++ b/drivers/hwmon/acpi_power_meter.c
41728 @@ -116,7 +116,7 @@ struct sensor_template {
41729 struct device_attribute *devattr,
41730 const char *buf, size_t count);
41731 int index;
41732 -};
41733 +} __do_const;
41734
41735 /* Averaging interval */
41736 static int update_avg_interval(struct acpi_power_meter_resource *resource)
41737 @@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
41738 struct sensor_template *attrs)
41739 {
41740 struct device *dev = &resource->acpi_dev->dev;
41741 - struct sensor_device_attribute *sensors =
41742 + sensor_device_attribute_no_const *sensors =
41743 &resource->sensors[resource->num_sensors];
41744 int res = 0;
41745
41746 diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
41747 index 3288f13..71cfb4e 100644
41748 --- a/drivers/hwmon/applesmc.c
41749 +++ b/drivers/hwmon/applesmc.c
41750 @@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
41751 {
41752 struct applesmc_node_group *grp;
41753 struct applesmc_dev_attr *node;
41754 - struct attribute *attr;
41755 + attribute_no_const *attr;
41756 int ret, i;
41757
41758 for (grp = groups; grp->format; grp++) {
41759 diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
41760 index ae208f6..48b6c5b 100644
41761 --- a/drivers/hwmon/asus_atk0110.c
41762 +++ b/drivers/hwmon/asus_atk0110.c
41763 @@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
41764 struct atk_sensor_data {
41765 struct list_head list;
41766 struct atk_data *data;
41767 - struct device_attribute label_attr;
41768 - struct device_attribute input_attr;
41769 - struct device_attribute limit1_attr;
41770 - struct device_attribute limit2_attr;
41771 + device_attribute_no_const label_attr;
41772 + device_attribute_no_const input_attr;
41773 + device_attribute_no_const limit1_attr;
41774 + device_attribute_no_const limit2_attr;
41775 char label_attr_name[ATTR_NAME_SIZE];
41776 char input_attr_name[ATTR_NAME_SIZE];
41777 char limit1_attr_name[ATTR_NAME_SIZE];
41778 @@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
41779 static struct device_attribute atk_name_attr =
41780 __ATTR(name, 0444, atk_name_show, NULL);
41781
41782 -static void atk_init_attribute(struct device_attribute *attr, char *name,
41783 +static void atk_init_attribute(device_attribute_no_const *attr, char *name,
41784 sysfs_show_func show)
41785 {
41786 sysfs_attr_init(&attr->attr);
41787 diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
41788 index d76f0b7..55ae976 100644
41789 --- a/drivers/hwmon/coretemp.c
41790 +++ b/drivers/hwmon/coretemp.c
41791 @@ -784,7 +784,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
41792 return NOTIFY_OK;
41793 }
41794
41795 -static struct notifier_block coretemp_cpu_notifier __refdata = {
41796 +static struct notifier_block coretemp_cpu_notifier = {
41797 .notifier_call = coretemp_cpu_callback,
41798 };
41799
41800 diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
41801 index 632f1dc..57e6a58 100644
41802 --- a/drivers/hwmon/ibmaem.c
41803 +++ b/drivers/hwmon/ibmaem.c
41804 @@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
41805 struct aem_rw_sensor_template *rw)
41806 {
41807 struct device *dev = &data->pdev->dev;
41808 - struct sensor_device_attribute *sensors = data->sensors;
41809 + sensor_device_attribute_no_const *sensors = data->sensors;
41810 int err;
41811
41812 /* Set up read-only sensors */
41813 diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
41814 index 9fbb1b1..efbaa3e 100644
41815 --- a/drivers/hwmon/iio_hwmon.c
41816 +++ b/drivers/hwmon/iio_hwmon.c
41817 @@ -61,7 +61,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
41818 {
41819 struct device *dev = &pdev->dev;
41820 struct iio_hwmon_state *st;
41821 - struct sensor_device_attribute *a;
41822 + sensor_device_attribute_no_const *a;
41823 int ret, i;
41824 int in_i = 1, temp_i = 1, curr_i = 1;
41825 enum iio_chan_type type;
41826 diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
41827 index 38d5a63..cf2c2ea 100644
41828 --- a/drivers/hwmon/nct6775.c
41829 +++ b/drivers/hwmon/nct6775.c
41830 @@ -944,10 +944,10 @@ static struct attribute_group *
41831 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
41832 int repeat)
41833 {
41834 - struct attribute_group *group;
41835 + attribute_group_no_const *group;
41836 struct sensor_device_attr_u *su;
41837 - struct sensor_device_attribute *a;
41838 - struct sensor_device_attribute_2 *a2;
41839 + sensor_device_attribute_no_const *a;
41840 + sensor_device_attribute_2_no_const *a2;
41841 struct attribute **attrs;
41842 struct sensor_device_template **t;
41843 int i, count;
41844 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
41845 index 291d11f..3f0dbbd 100644
41846 --- a/drivers/hwmon/pmbus/pmbus_core.c
41847 +++ b/drivers/hwmon/pmbus/pmbus_core.c
41848 @@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
41849 return 0;
41850 }
41851
41852 -static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41853 +static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
41854 const char *name,
41855 umode_t mode,
41856 ssize_t (*show)(struct device *dev,
41857 @@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41858 dev_attr->store = store;
41859 }
41860
41861 -static void pmbus_attr_init(struct sensor_device_attribute *a,
41862 +static void pmbus_attr_init(sensor_device_attribute_no_const *a,
41863 const char *name,
41864 umode_t mode,
41865 ssize_t (*show)(struct device *dev,
41866 @@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
41867 u16 reg, u8 mask)
41868 {
41869 struct pmbus_boolean *boolean;
41870 - struct sensor_device_attribute *a;
41871 + sensor_device_attribute_no_const *a;
41872
41873 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
41874 if (!boolean)
41875 @@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
41876 bool update, bool readonly)
41877 {
41878 struct pmbus_sensor *sensor;
41879 - struct device_attribute *a;
41880 + device_attribute_no_const *a;
41881
41882 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
41883 if (!sensor)
41884 @@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
41885 const char *lstring, int index)
41886 {
41887 struct pmbus_label *label;
41888 - struct device_attribute *a;
41889 + device_attribute_no_const *a;
41890
41891 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
41892 if (!label)
41893 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
41894 index 97cd45a..ac54d8b 100644
41895 --- a/drivers/hwmon/sht15.c
41896 +++ b/drivers/hwmon/sht15.c
41897 @@ -169,7 +169,7 @@ struct sht15_data {
41898 int supply_uv;
41899 bool supply_uv_valid;
41900 struct work_struct update_supply_work;
41901 - atomic_t interrupt_handled;
41902 + atomic_unchecked_t interrupt_handled;
41903 };
41904
41905 /**
41906 @@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
41907 ret = gpio_direction_input(data->pdata->gpio_data);
41908 if (ret)
41909 return ret;
41910 - atomic_set(&data->interrupt_handled, 0);
41911 + atomic_set_unchecked(&data->interrupt_handled, 0);
41912
41913 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41914 if (gpio_get_value(data->pdata->gpio_data) == 0) {
41915 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
41916 /* Only relevant if the interrupt hasn't occurred. */
41917 - if (!atomic_read(&data->interrupt_handled))
41918 + if (!atomic_read_unchecked(&data->interrupt_handled))
41919 schedule_work(&data->read_work);
41920 }
41921 ret = wait_event_timeout(data->wait_queue,
41922 @@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
41923
41924 /* First disable the interrupt */
41925 disable_irq_nosync(irq);
41926 - atomic_inc(&data->interrupt_handled);
41927 + atomic_inc_unchecked(&data->interrupt_handled);
41928 /* Then schedule a reading work struct */
41929 if (data->state != SHT15_READING_NOTHING)
41930 schedule_work(&data->read_work);
41931 @@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
41932 * If not, then start the interrupt again - care here as could
41933 * have gone low in meantime so verify it hasn't!
41934 */
41935 - atomic_set(&data->interrupt_handled, 0);
41936 + atomic_set_unchecked(&data->interrupt_handled, 0);
41937 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41938 /* If still not occurred or another handler was scheduled */
41939 if (gpio_get_value(data->pdata->gpio_data)
41940 - || atomic_read(&data->interrupt_handled))
41941 + || atomic_read_unchecked(&data->interrupt_handled))
41942 return;
41943 }
41944
41945 diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
41946 index 8df43c5..b07b91d 100644
41947 --- a/drivers/hwmon/via-cputemp.c
41948 +++ b/drivers/hwmon/via-cputemp.c
41949 @@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
41950 return NOTIFY_OK;
41951 }
41952
41953 -static struct notifier_block via_cputemp_cpu_notifier __refdata = {
41954 +static struct notifier_block via_cputemp_cpu_notifier = {
41955 .notifier_call = via_cputemp_cpu_callback,
41956 };
41957
41958 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
41959 index 41fc683..a39cfea 100644
41960 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
41961 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
41962 @@ -43,7 +43,7 @@
41963 extern struct i2c_adapter amd756_smbus;
41964
41965 static struct i2c_adapter *s4882_adapter;
41966 -static struct i2c_algorithm *s4882_algo;
41967 +static i2c_algorithm_no_const *s4882_algo;
41968
41969 /* Wrapper access functions for multiplexed SMBus */
41970 static DEFINE_MUTEX(amd756_lock);
41971 diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
41972 index 721f7eb..0fd2a09 100644
41973 --- a/drivers/i2c/busses/i2c-diolan-u2c.c
41974 +++ b/drivers/i2c/busses/i2c-diolan-u2c.c
41975 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
41976 /* usb layer */
41977
41978 /* Send command to device, and get response. */
41979 -static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41980 +static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41981 {
41982 int ret = 0;
41983 int actual;
41984 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
41985 index b170bdf..3c76427 100644
41986 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
41987 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
41988 @@ -41,7 +41,7 @@
41989 extern struct i2c_adapter *nforce2_smbus;
41990
41991 static struct i2c_adapter *s4985_adapter;
41992 -static struct i2c_algorithm *s4985_algo;
41993 +static i2c_algorithm_no_const *s4985_algo;
41994
41995 /* Wrapper access functions for multiplexed SMBus */
41996 static DEFINE_MUTEX(nforce2_lock);
41997 diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
41998 index 80b47e8..1a6040d9 100644
41999 --- a/drivers/i2c/i2c-dev.c
42000 +++ b/drivers/i2c/i2c-dev.c
42001 @@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
42002 break;
42003 }
42004
42005 - data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
42006 + data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
42007 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
42008 if (IS_ERR(rdwr_pa[i].buf)) {
42009 res = PTR_ERR(rdwr_pa[i].buf);
42010 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
42011 index 0b510ba..4fbb5085 100644
42012 --- a/drivers/ide/ide-cd.c
42013 +++ b/drivers/ide/ide-cd.c
42014 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
42015 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
42016 if ((unsigned long)buf & alignment
42017 || blk_rq_bytes(rq) & q->dma_pad_mask
42018 - || object_is_on_stack(buf))
42019 + || object_starts_on_stack(buf))
42020 drive->dma = 0;
42021 }
42022 }
42023 diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
42024 index ede16aec..e423e8a 100644
42025 --- a/drivers/iio/industrialio-core.c
42026 +++ b/drivers/iio/industrialio-core.c
42027 @@ -527,7 +527,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
42028 }
42029
42030 static
42031 -int __iio_device_attr_init(struct device_attribute *dev_attr,
42032 +int __iio_device_attr_init(device_attribute_no_const *dev_attr,
42033 const char *postfix,
42034 struct iio_chan_spec const *chan,
42035 ssize_t (*readfunc)(struct device *dev,
42036 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
42037 index c323917..6ddea8b 100644
42038 --- a/drivers/infiniband/core/cm.c
42039 +++ b/drivers/infiniband/core/cm.c
42040 @@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
42041
42042 struct cm_counter_group {
42043 struct kobject obj;
42044 - atomic_long_t counter[CM_ATTR_COUNT];
42045 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
42046 };
42047
42048 struct cm_counter_attribute {
42049 @@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
42050 struct ib_mad_send_buf *msg = NULL;
42051 int ret;
42052
42053 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42054 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42055 counter[CM_REQ_COUNTER]);
42056
42057 /* Quick state check to discard duplicate REQs. */
42058 @@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
42059 if (!cm_id_priv)
42060 return;
42061
42062 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42063 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42064 counter[CM_REP_COUNTER]);
42065 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
42066 if (ret)
42067 @@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
42068 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
42069 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
42070 spin_unlock_irq(&cm_id_priv->lock);
42071 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42072 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42073 counter[CM_RTU_COUNTER]);
42074 goto out;
42075 }
42076 @@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
42077 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
42078 dreq_msg->local_comm_id);
42079 if (!cm_id_priv) {
42080 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42081 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42082 counter[CM_DREQ_COUNTER]);
42083 cm_issue_drep(work->port, work->mad_recv_wc);
42084 return -EINVAL;
42085 @@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
42086 case IB_CM_MRA_REP_RCVD:
42087 break;
42088 case IB_CM_TIMEWAIT:
42089 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42090 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42091 counter[CM_DREQ_COUNTER]);
42092 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42093 goto unlock;
42094 @@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
42095 cm_free_msg(msg);
42096 goto deref;
42097 case IB_CM_DREQ_RCVD:
42098 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42099 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42100 counter[CM_DREQ_COUNTER]);
42101 goto unlock;
42102 default:
42103 @@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
42104 ib_modify_mad(cm_id_priv->av.port->mad_agent,
42105 cm_id_priv->msg, timeout)) {
42106 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
42107 - atomic_long_inc(&work->port->
42108 + atomic_long_inc_unchecked(&work->port->
42109 counter_group[CM_RECV_DUPLICATES].
42110 counter[CM_MRA_COUNTER]);
42111 goto out;
42112 @@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
42113 break;
42114 case IB_CM_MRA_REQ_RCVD:
42115 case IB_CM_MRA_REP_RCVD:
42116 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42117 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42118 counter[CM_MRA_COUNTER]);
42119 /* fall through */
42120 default:
42121 @@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
42122 case IB_CM_LAP_IDLE:
42123 break;
42124 case IB_CM_MRA_LAP_SENT:
42125 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42126 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42127 counter[CM_LAP_COUNTER]);
42128 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42129 goto unlock;
42130 @@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
42131 cm_free_msg(msg);
42132 goto deref;
42133 case IB_CM_LAP_RCVD:
42134 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42135 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42136 counter[CM_LAP_COUNTER]);
42137 goto unlock;
42138 default:
42139 @@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
42140 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
42141 if (cur_cm_id_priv) {
42142 spin_unlock_irq(&cm.lock);
42143 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42144 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42145 counter[CM_SIDR_REQ_COUNTER]);
42146 goto out; /* Duplicate message. */
42147 }
42148 @@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
42149 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
42150 msg->retries = 1;
42151
42152 - atomic_long_add(1 + msg->retries,
42153 + atomic_long_add_unchecked(1 + msg->retries,
42154 &port->counter_group[CM_XMIT].counter[attr_index]);
42155 if (msg->retries)
42156 - atomic_long_add(msg->retries,
42157 + atomic_long_add_unchecked(msg->retries,
42158 &port->counter_group[CM_XMIT_RETRIES].
42159 counter[attr_index]);
42160
42161 @@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
42162 }
42163
42164 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
42165 - atomic_long_inc(&port->counter_group[CM_RECV].
42166 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
42167 counter[attr_id - CM_ATTR_ID_OFFSET]);
42168
42169 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
42170 @@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
42171 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
42172
42173 return sprintf(buf, "%ld\n",
42174 - atomic_long_read(&group->counter[cm_attr->index]));
42175 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
42176 }
42177
42178 static const struct sysfs_ops cm_counter_ops = {
42179 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
42180 index 9f5ad7c..588cd84 100644
42181 --- a/drivers/infiniband/core/fmr_pool.c
42182 +++ b/drivers/infiniband/core/fmr_pool.c
42183 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
42184
42185 struct task_struct *thread;
42186
42187 - atomic_t req_ser;
42188 - atomic_t flush_ser;
42189 + atomic_unchecked_t req_ser;
42190 + atomic_unchecked_t flush_ser;
42191
42192 wait_queue_head_t force_wait;
42193 };
42194 @@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42195 struct ib_fmr_pool *pool = pool_ptr;
42196
42197 do {
42198 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
42199 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
42200 ib_fmr_batch_release(pool);
42201
42202 - atomic_inc(&pool->flush_ser);
42203 + atomic_inc_unchecked(&pool->flush_ser);
42204 wake_up_interruptible(&pool->force_wait);
42205
42206 if (pool->flush_function)
42207 @@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42208 }
42209
42210 set_current_state(TASK_INTERRUPTIBLE);
42211 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
42212 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
42213 !kthread_should_stop())
42214 schedule();
42215 __set_current_state(TASK_RUNNING);
42216 @@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
42217 pool->dirty_watermark = params->dirty_watermark;
42218 pool->dirty_len = 0;
42219 spin_lock_init(&pool->pool_lock);
42220 - atomic_set(&pool->req_ser, 0);
42221 - atomic_set(&pool->flush_ser, 0);
42222 + atomic_set_unchecked(&pool->req_ser, 0);
42223 + atomic_set_unchecked(&pool->flush_ser, 0);
42224 init_waitqueue_head(&pool->force_wait);
42225
42226 pool->thread = kthread_run(ib_fmr_cleanup_thread,
42227 @@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
42228 }
42229 spin_unlock_irq(&pool->pool_lock);
42230
42231 - serial = atomic_inc_return(&pool->req_ser);
42232 + serial = atomic_inc_return_unchecked(&pool->req_ser);
42233 wake_up_process(pool->thread);
42234
42235 if (wait_event_interruptible(pool->force_wait,
42236 - atomic_read(&pool->flush_ser) - serial >= 0))
42237 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
42238 return -EINTR;
42239
42240 return 0;
42241 @@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
42242 } else {
42243 list_add_tail(&fmr->list, &pool->dirty_list);
42244 if (++pool->dirty_len >= pool->dirty_watermark) {
42245 - atomic_inc(&pool->req_ser);
42246 + atomic_inc_unchecked(&pool->req_ser);
42247 wake_up_process(pool->thread);
42248 }
42249 }
42250 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
42251 index ec7a298..8742e59 100644
42252 --- a/drivers/infiniband/hw/cxgb4/mem.c
42253 +++ b/drivers/infiniband/hw/cxgb4/mem.c
42254 @@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42255 int err;
42256 struct fw_ri_tpte tpt;
42257 u32 stag_idx;
42258 - static atomic_t key;
42259 + static atomic_unchecked_t key;
42260
42261 if (c4iw_fatal_error(rdev))
42262 return -EIO;
42263 @@ -270,7 +270,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42264 if (rdev->stats.stag.cur > rdev->stats.stag.max)
42265 rdev->stats.stag.max = rdev->stats.stag.cur;
42266 mutex_unlock(&rdev->stats.lock);
42267 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
42268 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
42269 }
42270 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
42271 __func__, stag_state, type, pdid, stag_idx);
42272 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
42273 index 79b3dbc..96e5fcc 100644
42274 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
42275 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
42276 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42277 struct ib_atomic_eth *ateth;
42278 struct ipath_ack_entry *e;
42279 u64 vaddr;
42280 - atomic64_t *maddr;
42281 + atomic64_unchecked_t *maddr;
42282 u64 sdata;
42283 u32 rkey;
42284 u8 next;
42285 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42286 IB_ACCESS_REMOTE_ATOMIC)))
42287 goto nack_acc_unlck;
42288 /* Perform atomic OP and save result. */
42289 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42290 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42291 sdata = be64_to_cpu(ateth->swap_data);
42292 e = &qp->s_ack_queue[qp->r_head_ack_queue];
42293 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
42294 - (u64) atomic64_add_return(sdata, maddr) - sdata :
42295 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42296 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42297 be64_to_cpu(ateth->compare_data),
42298 sdata);
42299 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
42300 index 1f95bba..9530f87 100644
42301 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
42302 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
42303 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
42304 unsigned long flags;
42305 struct ib_wc wc;
42306 u64 sdata;
42307 - atomic64_t *maddr;
42308 + atomic64_unchecked_t *maddr;
42309 enum ib_wc_status send_status;
42310
42311 /*
42312 @@ -382,11 +382,11 @@ again:
42313 IB_ACCESS_REMOTE_ATOMIC)))
42314 goto acc_err;
42315 /* Perform atomic OP and save result. */
42316 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42317 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42318 sdata = wqe->wr.wr.atomic.compare_add;
42319 *(u64 *) sqp->s_sge.sge.vaddr =
42320 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
42321 - (u64) atomic64_add_return(sdata, maddr) - sdata :
42322 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42323 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42324 sdata, wqe->wr.wr.atomic.swap);
42325 goto send_comp;
42326 diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
42327 index fd36ec6..a6a082f 100644
42328 --- a/drivers/infiniband/hw/mlx4/mad.c
42329 +++ b/drivers/infiniband/hw/mlx4/mad.c
42330 @@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
42331
42332 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
42333 {
42334 - return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
42335 + return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
42336 cpu_to_be64(0xff00000000000000LL);
42337 }
42338
42339 diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
42340 index ed327e6..ca1739e0 100644
42341 --- a/drivers/infiniband/hw/mlx4/mcg.c
42342 +++ b/drivers/infiniband/hw/mlx4/mcg.c
42343 @@ -1041,7 +1041,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
42344 {
42345 char name[20];
42346
42347 - atomic_set(&ctx->tid, 0);
42348 + atomic_set_unchecked(&ctx->tid, 0);
42349 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
42350 ctx->mcg_wq = create_singlethread_workqueue(name);
42351 if (!ctx->mcg_wq)
42352 diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42353 index 66b0b7d..f14836a 100644
42354 --- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
42355 +++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42356 @@ -425,7 +425,7 @@ struct mlx4_ib_demux_ctx {
42357 struct list_head mcg_mgid0_list;
42358 struct workqueue_struct *mcg_wq;
42359 struct mlx4_ib_demux_pv_ctx **tun;
42360 - atomic_t tid;
42361 + atomic_unchecked_t tid;
42362 int flushing; /* flushing the work queue */
42363 };
42364
42365 diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
42366 index 9d3e5c1..6f166df 100644
42367 --- a/drivers/infiniband/hw/mthca/mthca_cmd.c
42368 +++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
42369 @@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
42370 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
42371 }
42372
42373 -int mthca_QUERY_FW(struct mthca_dev *dev)
42374 +int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
42375 {
42376 struct mthca_mailbox *mailbox;
42377 u32 *outbox;
42378 @@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42379 CMD_TIME_CLASS_B);
42380 }
42381
42382 -int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42383 +int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42384 int num_mtt)
42385 {
42386 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
42387 @@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
42388 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
42389 }
42390
42391 -int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42392 +int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42393 int eq_num)
42394 {
42395 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
42396 @@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
42397 CMD_TIME_CLASS_B);
42398 }
42399
42400 -int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42401 +int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42402 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
42403 void *in_mad, void *response_mad)
42404 {
42405 diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
42406 index ded76c1..0cf0a08 100644
42407 --- a/drivers/infiniband/hw/mthca/mthca_main.c
42408 +++ b/drivers/infiniband/hw/mthca/mthca_main.c
42409 @@ -692,7 +692,7 @@ err_close:
42410 return err;
42411 }
42412
42413 -static int mthca_setup_hca(struct mthca_dev *dev)
42414 +static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
42415 {
42416 int err;
42417
42418 diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
42419 index ed9a989..6aa5dc2 100644
42420 --- a/drivers/infiniband/hw/mthca/mthca_mr.c
42421 +++ b/drivers/infiniband/hw/mthca/mthca_mr.c
42422 @@ -81,7 +81,7 @@ struct mthca_mpt_entry {
42423 * through the bitmaps)
42424 */
42425
42426 -static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42427 +static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42428 {
42429 int o;
42430 int m;
42431 @@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
42432 return key;
42433 }
42434
42435 -int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42436 +int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42437 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
42438 {
42439 struct mthca_mailbox *mailbox;
42440 @@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
42441 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
42442 }
42443
42444 -int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42445 +int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42446 u64 *buffer_list, int buffer_size_shift,
42447 int list_len, u64 iova, u64 total_size,
42448 u32 access, struct mthca_mr *mr)
42449 diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
42450 index 415f8e1..e34214e 100644
42451 --- a/drivers/infiniband/hw/mthca/mthca_provider.c
42452 +++ b/drivers/infiniband/hw/mthca/mthca_provider.c
42453 @@ -764,7 +764,7 @@ unlock:
42454 return 0;
42455 }
42456
42457 -static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42458 +static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42459 {
42460 struct mthca_dev *dev = to_mdev(ibcq->device);
42461 struct mthca_cq *cq = to_mcq(ibcq);
42462 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
42463 index 353c7b0..c6ce921 100644
42464 --- a/drivers/infiniband/hw/nes/nes.c
42465 +++ b/drivers/infiniband/hw/nes/nes.c
42466 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
42467 LIST_HEAD(nes_adapter_list);
42468 static LIST_HEAD(nes_dev_list);
42469
42470 -atomic_t qps_destroyed;
42471 +atomic_unchecked_t qps_destroyed;
42472
42473 static unsigned int ee_flsh_adapter;
42474 static unsigned int sysfs_nonidx_addr;
42475 @@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
42476 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
42477 struct nes_adapter *nesadapter = nesdev->nesadapter;
42478
42479 - atomic_inc(&qps_destroyed);
42480 + atomic_inc_unchecked(&qps_destroyed);
42481
42482 /* Free the control structures */
42483
42484 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
42485 index 33cc589..3bd6538 100644
42486 --- a/drivers/infiniband/hw/nes/nes.h
42487 +++ b/drivers/infiniband/hw/nes/nes.h
42488 @@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
42489 extern unsigned int wqm_quanta;
42490 extern struct list_head nes_adapter_list;
42491
42492 -extern atomic_t cm_connects;
42493 -extern atomic_t cm_accepts;
42494 -extern atomic_t cm_disconnects;
42495 -extern atomic_t cm_closes;
42496 -extern atomic_t cm_connecteds;
42497 -extern atomic_t cm_connect_reqs;
42498 -extern atomic_t cm_rejects;
42499 -extern atomic_t mod_qp_timouts;
42500 -extern atomic_t qps_created;
42501 -extern atomic_t qps_destroyed;
42502 -extern atomic_t sw_qps_destroyed;
42503 +extern atomic_unchecked_t cm_connects;
42504 +extern atomic_unchecked_t cm_accepts;
42505 +extern atomic_unchecked_t cm_disconnects;
42506 +extern atomic_unchecked_t cm_closes;
42507 +extern atomic_unchecked_t cm_connecteds;
42508 +extern atomic_unchecked_t cm_connect_reqs;
42509 +extern atomic_unchecked_t cm_rejects;
42510 +extern atomic_unchecked_t mod_qp_timouts;
42511 +extern atomic_unchecked_t qps_created;
42512 +extern atomic_unchecked_t qps_destroyed;
42513 +extern atomic_unchecked_t sw_qps_destroyed;
42514 extern u32 mh_detected;
42515 extern u32 mh_pauses_sent;
42516 extern u32 cm_packets_sent;
42517 @@ -196,16 +196,16 @@ extern u32 cm_packets_created;
42518 extern u32 cm_packets_received;
42519 extern u32 cm_packets_dropped;
42520 extern u32 cm_packets_retrans;
42521 -extern atomic_t cm_listens_created;
42522 -extern atomic_t cm_listens_destroyed;
42523 +extern atomic_unchecked_t cm_listens_created;
42524 +extern atomic_unchecked_t cm_listens_destroyed;
42525 extern u32 cm_backlog_drops;
42526 -extern atomic_t cm_loopbacks;
42527 -extern atomic_t cm_nodes_created;
42528 -extern atomic_t cm_nodes_destroyed;
42529 -extern atomic_t cm_accel_dropped_pkts;
42530 -extern atomic_t cm_resets_recvd;
42531 -extern atomic_t pau_qps_created;
42532 -extern atomic_t pau_qps_destroyed;
42533 +extern atomic_unchecked_t cm_loopbacks;
42534 +extern atomic_unchecked_t cm_nodes_created;
42535 +extern atomic_unchecked_t cm_nodes_destroyed;
42536 +extern atomic_unchecked_t cm_accel_dropped_pkts;
42537 +extern atomic_unchecked_t cm_resets_recvd;
42538 +extern atomic_unchecked_t pau_qps_created;
42539 +extern atomic_unchecked_t pau_qps_destroyed;
42540
42541 extern u32 int_mod_timer_init;
42542 extern u32 int_mod_cq_depth_256;
42543 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
42544 index dfa9df4..6bf7221 100644
42545 --- a/drivers/infiniband/hw/nes/nes_cm.c
42546 +++ b/drivers/infiniband/hw/nes/nes_cm.c
42547 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
42548 u32 cm_packets_retrans;
42549 u32 cm_packets_created;
42550 u32 cm_packets_received;
42551 -atomic_t cm_listens_created;
42552 -atomic_t cm_listens_destroyed;
42553 +atomic_unchecked_t cm_listens_created;
42554 +atomic_unchecked_t cm_listens_destroyed;
42555 u32 cm_backlog_drops;
42556 -atomic_t cm_loopbacks;
42557 -atomic_t cm_nodes_created;
42558 -atomic_t cm_nodes_destroyed;
42559 -atomic_t cm_accel_dropped_pkts;
42560 -atomic_t cm_resets_recvd;
42561 +atomic_unchecked_t cm_loopbacks;
42562 +atomic_unchecked_t cm_nodes_created;
42563 +atomic_unchecked_t cm_nodes_destroyed;
42564 +atomic_unchecked_t cm_accel_dropped_pkts;
42565 +atomic_unchecked_t cm_resets_recvd;
42566
42567 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
42568 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
42569 @@ -134,28 +134,28 @@ static void record_ird_ord(struct nes_cm_node *, u16, u16);
42570 /* instance of function pointers for client API */
42571 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
42572 static struct nes_cm_ops nes_cm_api = {
42573 - mini_cm_accelerated,
42574 - mini_cm_listen,
42575 - mini_cm_del_listen,
42576 - mini_cm_connect,
42577 - mini_cm_close,
42578 - mini_cm_accept,
42579 - mini_cm_reject,
42580 - mini_cm_recv_pkt,
42581 - mini_cm_dealloc_core,
42582 - mini_cm_get,
42583 - mini_cm_set
42584 + .accelerated = mini_cm_accelerated,
42585 + .listen = mini_cm_listen,
42586 + .stop_listener = mini_cm_del_listen,
42587 + .connect = mini_cm_connect,
42588 + .close = mini_cm_close,
42589 + .accept = mini_cm_accept,
42590 + .reject = mini_cm_reject,
42591 + .recv_pkt = mini_cm_recv_pkt,
42592 + .destroy_cm_core = mini_cm_dealloc_core,
42593 + .get = mini_cm_get,
42594 + .set = mini_cm_set
42595 };
42596
42597 static struct nes_cm_core *g_cm_core;
42598
42599 -atomic_t cm_connects;
42600 -atomic_t cm_accepts;
42601 -atomic_t cm_disconnects;
42602 -atomic_t cm_closes;
42603 -atomic_t cm_connecteds;
42604 -atomic_t cm_connect_reqs;
42605 -atomic_t cm_rejects;
42606 +atomic_unchecked_t cm_connects;
42607 +atomic_unchecked_t cm_accepts;
42608 +atomic_unchecked_t cm_disconnects;
42609 +atomic_unchecked_t cm_closes;
42610 +atomic_unchecked_t cm_connecteds;
42611 +atomic_unchecked_t cm_connect_reqs;
42612 +atomic_unchecked_t cm_rejects;
42613
42614 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
42615 {
42616 @@ -1319,7 +1319,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
42617 kfree(listener);
42618 listener = NULL;
42619 ret = 0;
42620 - atomic_inc(&cm_listens_destroyed);
42621 + atomic_inc_unchecked(&cm_listens_destroyed);
42622 } else {
42623 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
42624 }
42625 @@ -1513,7 +1513,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
42626 cm_node->rem_mac);
42627
42628 add_hte_node(cm_core, cm_node);
42629 - atomic_inc(&cm_nodes_created);
42630 + atomic_inc_unchecked(&cm_nodes_created);
42631
42632 return cm_node;
42633 }
42634 @@ -1571,7 +1571,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
42635 }
42636
42637 atomic_dec(&cm_core->node_cnt);
42638 - atomic_inc(&cm_nodes_destroyed);
42639 + atomic_inc_unchecked(&cm_nodes_destroyed);
42640 nesqp = cm_node->nesqp;
42641 if (nesqp) {
42642 nesqp->cm_node = NULL;
42643 @@ -1635,7 +1635,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
42644
42645 static void drop_packet(struct sk_buff *skb)
42646 {
42647 - atomic_inc(&cm_accel_dropped_pkts);
42648 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
42649 dev_kfree_skb_any(skb);
42650 }
42651
42652 @@ -1698,7 +1698,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
42653 {
42654
42655 int reset = 0; /* whether to send reset in case of err.. */
42656 - atomic_inc(&cm_resets_recvd);
42657 + atomic_inc_unchecked(&cm_resets_recvd);
42658 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
42659 " refcnt=%d\n", cm_node, cm_node->state,
42660 atomic_read(&cm_node->ref_count));
42661 @@ -2339,7 +2339,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
42662 rem_ref_cm_node(cm_node->cm_core, cm_node);
42663 return NULL;
42664 }
42665 - atomic_inc(&cm_loopbacks);
42666 + atomic_inc_unchecked(&cm_loopbacks);
42667 loopbackremotenode->loopbackpartner = cm_node;
42668 loopbackremotenode->tcp_cntxt.rcv_wscale =
42669 NES_CM_DEFAULT_RCV_WND_SCALE;
42670 @@ -2614,7 +2614,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
42671 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
42672 else {
42673 rem_ref_cm_node(cm_core, cm_node);
42674 - atomic_inc(&cm_accel_dropped_pkts);
42675 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
42676 dev_kfree_skb_any(skb);
42677 }
42678 break;
42679 @@ -2922,7 +2922,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42680
42681 if ((cm_id) && (cm_id->event_handler)) {
42682 if (issue_disconn) {
42683 - atomic_inc(&cm_disconnects);
42684 + atomic_inc_unchecked(&cm_disconnects);
42685 cm_event.event = IW_CM_EVENT_DISCONNECT;
42686 cm_event.status = disconn_status;
42687 cm_event.local_addr = cm_id->local_addr;
42688 @@ -2944,7 +2944,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42689 }
42690
42691 if (issue_close) {
42692 - atomic_inc(&cm_closes);
42693 + atomic_inc_unchecked(&cm_closes);
42694 nes_disconnect(nesqp, 1);
42695
42696 cm_id->provider_data = nesqp;
42697 @@ -3082,7 +3082,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42698
42699 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
42700 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
42701 - atomic_inc(&cm_accepts);
42702 + atomic_inc_unchecked(&cm_accepts);
42703
42704 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
42705 netdev_refcnt_read(nesvnic->netdev));
42706 @@ -3278,7 +3278,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
42707 struct nes_cm_core *cm_core;
42708 u8 *start_buff;
42709
42710 - atomic_inc(&cm_rejects);
42711 + atomic_inc_unchecked(&cm_rejects);
42712 cm_node = (struct nes_cm_node *)cm_id->provider_data;
42713 loopback = cm_node->loopbackpartner;
42714 cm_core = cm_node->cm_core;
42715 @@ -3340,7 +3340,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42716 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
42717 ntohs(laddr->sin_port));
42718
42719 - atomic_inc(&cm_connects);
42720 + atomic_inc_unchecked(&cm_connects);
42721 nesqp->active_conn = 1;
42722
42723 /* cache the cm_id in the qp */
42724 @@ -3451,7 +3451,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
42725 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
42726 return err;
42727 }
42728 - atomic_inc(&cm_listens_created);
42729 + atomic_inc_unchecked(&cm_listens_created);
42730 }
42731
42732 cm_id->add_ref(cm_id);
42733 @@ -3558,7 +3558,7 @@ static void cm_event_connected(struct nes_cm_event *event)
42734
42735 if (nesqp->destroyed)
42736 return;
42737 - atomic_inc(&cm_connecteds);
42738 + atomic_inc_unchecked(&cm_connecteds);
42739 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
42740 " local port 0x%04X. jiffies = %lu.\n",
42741 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
42742 @@ -3741,7 +3741,7 @@ static void cm_event_reset(struct nes_cm_event *event)
42743
42744 cm_id->add_ref(cm_id);
42745 ret = cm_id->event_handler(cm_id, &cm_event);
42746 - atomic_inc(&cm_closes);
42747 + atomic_inc_unchecked(&cm_closes);
42748 cm_event.event = IW_CM_EVENT_CLOSE;
42749 cm_event.status = 0;
42750 cm_event.provider_data = cm_id->provider_data;
42751 @@ -3781,7 +3781,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
42752 return;
42753 cm_id = cm_node->cm_id;
42754
42755 - atomic_inc(&cm_connect_reqs);
42756 + atomic_inc_unchecked(&cm_connect_reqs);
42757 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42758 cm_node, cm_id, jiffies);
42759
42760 @@ -3830,7 +3830,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
42761 return;
42762 cm_id = cm_node->cm_id;
42763
42764 - atomic_inc(&cm_connect_reqs);
42765 + atomic_inc_unchecked(&cm_connect_reqs);
42766 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42767 cm_node, cm_id, jiffies);
42768
42769 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
42770 index 4166452..fc952c3 100644
42771 --- a/drivers/infiniband/hw/nes/nes_mgt.c
42772 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
42773 @@ -40,8 +40,8 @@
42774 #include "nes.h"
42775 #include "nes_mgt.h"
42776
42777 -atomic_t pau_qps_created;
42778 -atomic_t pau_qps_destroyed;
42779 +atomic_unchecked_t pau_qps_created;
42780 +atomic_unchecked_t pau_qps_destroyed;
42781
42782 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
42783 {
42784 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
42785 {
42786 struct sk_buff *skb;
42787 unsigned long flags;
42788 - atomic_inc(&pau_qps_destroyed);
42789 + atomic_inc_unchecked(&pau_qps_destroyed);
42790
42791 /* Free packets that have not yet been forwarded */
42792 /* Lock is acquired by skb_dequeue when removing the skb */
42793 @@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
42794 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
42795 skb_queue_head_init(&nesqp->pau_list);
42796 spin_lock_init(&nesqp->pau_lock);
42797 - atomic_inc(&pau_qps_created);
42798 + atomic_inc_unchecked(&pau_qps_created);
42799 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
42800 }
42801
42802 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
42803 index 49eb511..a774366 100644
42804 --- a/drivers/infiniband/hw/nes/nes_nic.c
42805 +++ b/drivers/infiniband/hw/nes/nes_nic.c
42806 @@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
42807 target_stat_values[++index] = mh_detected;
42808 target_stat_values[++index] = mh_pauses_sent;
42809 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
42810 - target_stat_values[++index] = atomic_read(&cm_connects);
42811 - target_stat_values[++index] = atomic_read(&cm_accepts);
42812 - target_stat_values[++index] = atomic_read(&cm_disconnects);
42813 - target_stat_values[++index] = atomic_read(&cm_connecteds);
42814 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
42815 - target_stat_values[++index] = atomic_read(&cm_rejects);
42816 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
42817 - target_stat_values[++index] = atomic_read(&qps_created);
42818 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
42819 - target_stat_values[++index] = atomic_read(&qps_destroyed);
42820 - target_stat_values[++index] = atomic_read(&cm_closes);
42821 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
42822 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
42823 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
42824 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
42825 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
42826 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
42827 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
42828 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
42829 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
42830 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
42831 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
42832 target_stat_values[++index] = cm_packets_sent;
42833 target_stat_values[++index] = cm_packets_bounced;
42834 target_stat_values[++index] = cm_packets_created;
42835 target_stat_values[++index] = cm_packets_received;
42836 target_stat_values[++index] = cm_packets_dropped;
42837 target_stat_values[++index] = cm_packets_retrans;
42838 - target_stat_values[++index] = atomic_read(&cm_listens_created);
42839 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
42840 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
42841 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
42842 target_stat_values[++index] = cm_backlog_drops;
42843 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
42844 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
42845 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
42846 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
42847 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
42848 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
42849 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
42850 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
42851 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
42852 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
42853 target_stat_values[++index] = nesadapter->free_4kpbl;
42854 target_stat_values[++index] = nesadapter->free_256pbl;
42855 target_stat_values[++index] = int_mod_timer_init;
42856 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
42857 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
42858 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
42859 - target_stat_values[++index] = atomic_read(&pau_qps_created);
42860 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
42861 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
42862 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
42863 }
42864
42865 /**
42866 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
42867 index 218dd35..97ce31d 100644
42868 --- a/drivers/infiniband/hw/nes/nes_verbs.c
42869 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
42870 @@ -46,9 +46,9 @@
42871
42872 #include <rdma/ib_umem.h>
42873
42874 -atomic_t mod_qp_timouts;
42875 -atomic_t qps_created;
42876 -atomic_t sw_qps_destroyed;
42877 +atomic_unchecked_t mod_qp_timouts;
42878 +atomic_unchecked_t qps_created;
42879 +atomic_unchecked_t sw_qps_destroyed;
42880
42881 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
42882
42883 @@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
42884 if (init_attr->create_flags)
42885 return ERR_PTR(-EINVAL);
42886
42887 - atomic_inc(&qps_created);
42888 + atomic_inc_unchecked(&qps_created);
42889 switch (init_attr->qp_type) {
42890 case IB_QPT_RC:
42891 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
42892 @@ -1468,7 +1468,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
42893 struct iw_cm_event cm_event;
42894 int ret = 0;
42895
42896 - atomic_inc(&sw_qps_destroyed);
42897 + atomic_inc_unchecked(&sw_qps_destroyed);
42898 nesqp->destroyed = 1;
42899
42900 /* Blow away the connection if it exists. */
42901 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
42902 index c00ae09..04e91be 100644
42903 --- a/drivers/infiniband/hw/qib/qib.h
42904 +++ b/drivers/infiniband/hw/qib/qib.h
42905 @@ -52,6 +52,7 @@
42906 #include <linux/kref.h>
42907 #include <linux/sched.h>
42908 #include <linux/kthread.h>
42909 +#include <linux/slab.h>
42910
42911 #include "qib_common.h"
42912 #include "qib_verbs.h"
42913 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
42914 index 24c41ba..102d71f 100644
42915 --- a/drivers/input/gameport/gameport.c
42916 +++ b/drivers/input/gameport/gameport.c
42917 @@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
42918 */
42919 static void gameport_init_port(struct gameport *gameport)
42920 {
42921 - static atomic_t gameport_no = ATOMIC_INIT(0);
42922 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
42923
42924 __module_get(THIS_MODULE);
42925
42926 mutex_init(&gameport->drv_mutex);
42927 device_initialize(&gameport->dev);
42928 dev_set_name(&gameport->dev, "gameport%lu",
42929 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
42930 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
42931 gameport->dev.bus = &gameport_bus;
42932 gameport->dev.release = gameport_release_port;
42933 if (gameport->parent)
42934 diff --git a/drivers/input/input.c b/drivers/input/input.c
42935 index 29ca0bb..f4bc2e3 100644
42936 --- a/drivers/input/input.c
42937 +++ b/drivers/input/input.c
42938 @@ -1774,7 +1774,7 @@ EXPORT_SYMBOL_GPL(input_class);
42939 */
42940 struct input_dev *input_allocate_device(void)
42941 {
42942 - static atomic_t input_no = ATOMIC_INIT(0);
42943 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
42944 struct input_dev *dev;
42945
42946 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
42947 @@ -1789,7 +1789,7 @@ struct input_dev *input_allocate_device(void)
42948 INIT_LIST_HEAD(&dev->node);
42949
42950 dev_set_name(&dev->dev, "input%ld",
42951 - (unsigned long) atomic_inc_return(&input_no) - 1);
42952 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
42953
42954 __module_get(THIS_MODULE);
42955 }
42956 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
42957 index 4a95b22..874c182 100644
42958 --- a/drivers/input/joystick/sidewinder.c
42959 +++ b/drivers/input/joystick/sidewinder.c
42960 @@ -30,6 +30,7 @@
42961 #include <linux/kernel.h>
42962 #include <linux/module.h>
42963 #include <linux/slab.h>
42964 +#include <linux/sched.h>
42965 #include <linux/input.h>
42966 #include <linux/gameport.h>
42967 #include <linux/jiffies.h>
42968 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
42969 index 603fe0d..f63decc 100644
42970 --- a/drivers/input/joystick/xpad.c
42971 +++ b/drivers/input/joystick/xpad.c
42972 @@ -737,7 +737,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
42973
42974 static int xpad_led_probe(struct usb_xpad *xpad)
42975 {
42976 - static atomic_t led_seq = ATOMIC_INIT(0);
42977 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
42978 long led_no;
42979 struct xpad_led *led;
42980 struct led_classdev *led_cdev;
42981 @@ -750,7 +750,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
42982 if (!led)
42983 return -ENOMEM;
42984
42985 - led_no = (long)atomic_inc_return(&led_seq) - 1;
42986 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
42987
42988 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
42989 led->xpad = xpad;
42990 diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
42991 index 5a73639..d586683 100644
42992 --- a/drivers/input/misc/ims-pcu.c
42993 +++ b/drivers/input/misc/ims-pcu.c
42994 @@ -1850,7 +1850,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
42995
42996 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42997 {
42998 - static atomic_t device_no = ATOMIC_INIT(0);
42999 + static atomic_unchecked_t device_no = ATOMIC_INIT(0);
43000
43001 const struct ims_pcu_device_info *info;
43002 int error;
43003 @@ -1881,7 +1881,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43004 }
43005
43006 /* Device appears to be operable, complete initialization */
43007 - pcu->device_no = atomic_inc_return(&device_no) - 1;
43008 + pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
43009
43010 /*
43011 * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor
43012 diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
43013 index 2f0b39d..7370f13 100644
43014 --- a/drivers/input/mouse/psmouse.h
43015 +++ b/drivers/input/mouse/psmouse.h
43016 @@ -116,7 +116,7 @@ struct psmouse_attribute {
43017 ssize_t (*set)(struct psmouse *psmouse, void *data,
43018 const char *buf, size_t count);
43019 bool protect;
43020 -};
43021 +} __do_const;
43022 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
43023
43024 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
43025 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
43026 index b604564..3f14ae4 100644
43027 --- a/drivers/input/mousedev.c
43028 +++ b/drivers/input/mousedev.c
43029 @@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
43030
43031 spin_unlock_irq(&client->packet_lock);
43032
43033 - if (copy_to_user(buffer, data, count))
43034 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
43035 return -EFAULT;
43036
43037 return count;
43038 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
43039 index b29134d..394deb0 100644
43040 --- a/drivers/input/serio/serio.c
43041 +++ b/drivers/input/serio/serio.c
43042 @@ -514,7 +514,7 @@ static void serio_release_port(struct device *dev)
43043 */
43044 static void serio_init_port(struct serio *serio)
43045 {
43046 - static atomic_t serio_no = ATOMIC_INIT(0);
43047 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
43048
43049 __module_get(THIS_MODULE);
43050
43051 @@ -525,7 +525,7 @@ static void serio_init_port(struct serio *serio)
43052 mutex_init(&serio->drv_mutex);
43053 device_initialize(&serio->dev);
43054 dev_set_name(&serio->dev, "serio%ld",
43055 - (long)atomic_inc_return(&serio_no) - 1);
43056 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
43057 serio->dev.bus = &serio_bus;
43058 serio->dev.release = serio_release_port;
43059 serio->dev.groups = serio_device_attr_groups;
43060 diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
43061 index c9a02fe..0debc75 100644
43062 --- a/drivers/input/serio/serio_raw.c
43063 +++ b/drivers/input/serio/serio_raw.c
43064 @@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
43065
43066 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43067 {
43068 - static atomic_t serio_raw_no = ATOMIC_INIT(0);
43069 + static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
43070 struct serio_raw *serio_raw;
43071 int err;
43072
43073 @@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43074 }
43075
43076 snprintf(serio_raw->name, sizeof(serio_raw->name),
43077 - "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
43078 + "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
43079 kref_init(&serio_raw->kref);
43080 INIT_LIST_HEAD(&serio_raw->client_list);
43081 init_waitqueue_head(&serio_raw->wait);
43082 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
43083 index e5555fc..937986d 100644
43084 --- a/drivers/iommu/iommu.c
43085 +++ b/drivers/iommu/iommu.c
43086 @@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
43087 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
43088 {
43089 bus_register_notifier(bus, &iommu_bus_nb);
43090 - bus_for_each_dev(bus, NULL, ops, add_iommu_group);
43091 + bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
43092 }
43093
43094 /**
43095 diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
43096 index 228632c9..edfe331 100644
43097 --- a/drivers/iommu/irq_remapping.c
43098 +++ b/drivers/iommu/irq_remapping.c
43099 @@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
43100 void panic_if_irq_remap(const char *msg)
43101 {
43102 if (irq_remapping_enabled)
43103 - panic(msg);
43104 + panic("%s", msg);
43105 }
43106
43107 static void ir_ack_apic_edge(struct irq_data *data)
43108 @@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
43109
43110 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
43111 {
43112 - chip->irq_print_chip = ir_print_prefix;
43113 - chip->irq_ack = ir_ack_apic_edge;
43114 - chip->irq_eoi = ir_ack_apic_level;
43115 - chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43116 + pax_open_kernel();
43117 + *(void **)&chip->irq_print_chip = ir_print_prefix;
43118 + *(void **)&chip->irq_ack = ir_ack_apic_edge;
43119 + *(void **)&chip->irq_eoi = ir_ack_apic_level;
43120 + *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43121 + pax_close_kernel();
43122 }
43123
43124 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
43125 diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
43126 index 739ca67..42ee3f1 100644
43127 --- a/drivers/irqchip/irq-gic.c
43128 +++ b/drivers/irqchip/irq-gic.c
43129 @@ -85,7 +85,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
43130 * Supported arch specific GIC irq extension.
43131 * Default make them NULL.
43132 */
43133 -struct irq_chip gic_arch_extn = {
43134 +irq_chip_no_const gic_arch_extn = {
43135 .irq_eoi = NULL,
43136 .irq_mask = NULL,
43137 .irq_unmask = NULL,
43138 @@ -337,7 +337,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
43139 chained_irq_exit(chip, desc);
43140 }
43141
43142 -static struct irq_chip gic_chip = {
43143 +static irq_chip_no_const gic_chip __read_only = {
43144 .name = "GIC",
43145 .irq_mask = gic_mask_irq,
43146 .irq_unmask = gic_unmask_irq,
43147 diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
43148 index 8777065..a4a9967 100644
43149 --- a/drivers/irqchip/irq-renesas-irqc.c
43150 +++ b/drivers/irqchip/irq-renesas-irqc.c
43151 @@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
43152 struct irqc_priv *p;
43153 struct resource *io;
43154 struct resource *irq;
43155 - struct irq_chip *irq_chip;
43156 + irq_chip_no_const *irq_chip;
43157 const char *name = dev_name(&pdev->dev);
43158 int ret;
43159 int k;
43160 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
43161 index ac6f72b..81150f2 100644
43162 --- a/drivers/isdn/capi/capi.c
43163 +++ b/drivers/isdn/capi/capi.c
43164 @@ -81,8 +81,8 @@ struct capiminor {
43165
43166 struct capi20_appl *ap;
43167 u32 ncci;
43168 - atomic_t datahandle;
43169 - atomic_t msgid;
43170 + atomic_unchecked_t datahandle;
43171 + atomic_unchecked_t msgid;
43172
43173 struct tty_port port;
43174 int ttyinstop;
43175 @@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
43176 capimsg_setu16(s, 2, mp->ap->applid);
43177 capimsg_setu8 (s, 4, CAPI_DATA_B3);
43178 capimsg_setu8 (s, 5, CAPI_RESP);
43179 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
43180 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
43181 capimsg_setu32(s, 8, mp->ncci);
43182 capimsg_setu16(s, 12, datahandle);
43183 }
43184 @@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
43185 mp->outbytes -= len;
43186 spin_unlock_bh(&mp->outlock);
43187
43188 - datahandle = atomic_inc_return(&mp->datahandle);
43189 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
43190 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
43191 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43192 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43193 capimsg_setu16(skb->data, 2, mp->ap->applid);
43194 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
43195 capimsg_setu8 (skb->data, 5, CAPI_REQ);
43196 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
43197 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
43198 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
43199 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
43200 capimsg_setu16(skb->data, 16, len); /* Data length */
43201 diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
43202 index c44950d..10ac276 100644
43203 --- a/drivers/isdn/gigaset/bas-gigaset.c
43204 +++ b/drivers/isdn/gigaset/bas-gigaset.c
43205 @@ -2564,22 +2564,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
43206
43207
43208 static const struct gigaset_ops gigops = {
43209 - gigaset_write_cmd,
43210 - gigaset_write_room,
43211 - gigaset_chars_in_buffer,
43212 - gigaset_brkchars,
43213 - gigaset_init_bchannel,
43214 - gigaset_close_bchannel,
43215 - gigaset_initbcshw,
43216 - gigaset_freebcshw,
43217 - gigaset_reinitbcshw,
43218 - gigaset_initcshw,
43219 - gigaset_freecshw,
43220 - gigaset_set_modem_ctrl,
43221 - gigaset_baud_rate,
43222 - gigaset_set_line_ctrl,
43223 - gigaset_isoc_send_skb,
43224 - gigaset_isoc_input,
43225 + .write_cmd = gigaset_write_cmd,
43226 + .write_room = gigaset_write_room,
43227 + .chars_in_buffer = gigaset_chars_in_buffer,
43228 + .brkchars = gigaset_brkchars,
43229 + .init_bchannel = gigaset_init_bchannel,
43230 + .close_bchannel = gigaset_close_bchannel,
43231 + .initbcshw = gigaset_initbcshw,
43232 + .freebcshw = gigaset_freebcshw,
43233 + .reinitbcshw = gigaset_reinitbcshw,
43234 + .initcshw = gigaset_initcshw,
43235 + .freecshw = gigaset_freecshw,
43236 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43237 + .baud_rate = gigaset_baud_rate,
43238 + .set_line_ctrl = gigaset_set_line_ctrl,
43239 + .send_skb = gigaset_isoc_send_skb,
43240 + .handle_input = gigaset_isoc_input,
43241 };
43242
43243 /* bas_gigaset_init
43244 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
43245 index 600c79b..3752bab 100644
43246 --- a/drivers/isdn/gigaset/interface.c
43247 +++ b/drivers/isdn/gigaset/interface.c
43248 @@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
43249 }
43250 tty->driver_data = cs;
43251
43252 - ++cs->port.count;
43253 + atomic_inc(&cs->port.count);
43254
43255 - if (cs->port.count == 1) {
43256 + if (atomic_read(&cs->port.count) == 1) {
43257 tty_port_tty_set(&cs->port, tty);
43258 cs->port.low_latency = 1;
43259 }
43260 @@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
43261
43262 if (!cs->connected)
43263 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
43264 - else if (!cs->port.count)
43265 + else if (!atomic_read(&cs->port.count))
43266 dev_warn(cs->dev, "%s: device not opened\n", __func__);
43267 - else if (!--cs->port.count)
43268 + else if (!atomic_dec_return(&cs->port.count))
43269 tty_port_tty_set(&cs->port, NULL);
43270
43271 mutex_unlock(&cs->mutex);
43272 diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
43273 index 8c91fd5..14f13ce 100644
43274 --- a/drivers/isdn/gigaset/ser-gigaset.c
43275 +++ b/drivers/isdn/gigaset/ser-gigaset.c
43276 @@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
43277 }
43278
43279 static const struct gigaset_ops ops = {
43280 - gigaset_write_cmd,
43281 - gigaset_write_room,
43282 - gigaset_chars_in_buffer,
43283 - gigaset_brkchars,
43284 - gigaset_init_bchannel,
43285 - gigaset_close_bchannel,
43286 - gigaset_initbcshw,
43287 - gigaset_freebcshw,
43288 - gigaset_reinitbcshw,
43289 - gigaset_initcshw,
43290 - gigaset_freecshw,
43291 - gigaset_set_modem_ctrl,
43292 - gigaset_baud_rate,
43293 - gigaset_set_line_ctrl,
43294 - gigaset_m10x_send_skb, /* asyncdata.c */
43295 - gigaset_m10x_input, /* asyncdata.c */
43296 + .write_cmd = gigaset_write_cmd,
43297 + .write_room = gigaset_write_room,
43298 + .chars_in_buffer = gigaset_chars_in_buffer,
43299 + .brkchars = gigaset_brkchars,
43300 + .init_bchannel = gigaset_init_bchannel,
43301 + .close_bchannel = gigaset_close_bchannel,
43302 + .initbcshw = gigaset_initbcshw,
43303 + .freebcshw = gigaset_freebcshw,
43304 + .reinitbcshw = gigaset_reinitbcshw,
43305 + .initcshw = gigaset_initcshw,
43306 + .freecshw = gigaset_freecshw,
43307 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43308 + .baud_rate = gigaset_baud_rate,
43309 + .set_line_ctrl = gigaset_set_line_ctrl,
43310 + .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
43311 + .handle_input = gigaset_m10x_input, /* asyncdata.c */
43312 };
43313
43314
43315 diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
43316 index d0a41cb..b953e50 100644
43317 --- a/drivers/isdn/gigaset/usb-gigaset.c
43318 +++ b/drivers/isdn/gigaset/usb-gigaset.c
43319 @@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
43320 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
43321 memcpy(cs->hw.usb->bchars, buf, 6);
43322 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
43323 - 0, 0, &buf, 6, 2000);
43324 + 0, 0, buf, 6, 2000);
43325 }
43326
43327 static void gigaset_freebcshw(struct bc_state *bcs)
43328 @@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
43329 }
43330
43331 static const struct gigaset_ops ops = {
43332 - gigaset_write_cmd,
43333 - gigaset_write_room,
43334 - gigaset_chars_in_buffer,
43335 - gigaset_brkchars,
43336 - gigaset_init_bchannel,
43337 - gigaset_close_bchannel,
43338 - gigaset_initbcshw,
43339 - gigaset_freebcshw,
43340 - gigaset_reinitbcshw,
43341 - gigaset_initcshw,
43342 - gigaset_freecshw,
43343 - gigaset_set_modem_ctrl,
43344 - gigaset_baud_rate,
43345 - gigaset_set_line_ctrl,
43346 - gigaset_m10x_send_skb,
43347 - gigaset_m10x_input,
43348 + .write_cmd = gigaset_write_cmd,
43349 + .write_room = gigaset_write_room,
43350 + .chars_in_buffer = gigaset_chars_in_buffer,
43351 + .brkchars = gigaset_brkchars,
43352 + .init_bchannel = gigaset_init_bchannel,
43353 + .close_bchannel = gigaset_close_bchannel,
43354 + .initbcshw = gigaset_initbcshw,
43355 + .freebcshw = gigaset_freebcshw,
43356 + .reinitbcshw = gigaset_reinitbcshw,
43357 + .initcshw = gigaset_initcshw,
43358 + .freecshw = gigaset_freecshw,
43359 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43360 + .baud_rate = gigaset_baud_rate,
43361 + .set_line_ctrl = gigaset_set_line_ctrl,
43362 + .send_skb = gigaset_m10x_send_skb,
43363 + .handle_input = gigaset_m10x_input,
43364 };
43365
43366 /*
43367 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
43368 index 4d9b195..455075c 100644
43369 --- a/drivers/isdn/hardware/avm/b1.c
43370 +++ b/drivers/isdn/hardware/avm/b1.c
43371 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
43372 }
43373 if (left) {
43374 if (t4file->user) {
43375 - if (copy_from_user(buf, dp, left))
43376 + if (left > sizeof buf || copy_from_user(buf, dp, left))
43377 return -EFAULT;
43378 } else {
43379 memcpy(buf, dp, left);
43380 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
43381 }
43382 if (left) {
43383 if (config->user) {
43384 - if (copy_from_user(buf, dp, left))
43385 + if (left > sizeof buf || copy_from_user(buf, dp, left))
43386 return -EFAULT;
43387 } else {
43388 memcpy(buf, dp, left);
43389 diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
43390 index 9b856e1..fa03c92 100644
43391 --- a/drivers/isdn/i4l/isdn_common.c
43392 +++ b/drivers/isdn/i4l/isdn_common.c
43393 @@ -1654,6 +1654,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
43394 } else
43395 return -EINVAL;
43396 case IIOCDBGVAR:
43397 + if (!capable(CAP_SYS_RAWIO))
43398 + return -EPERM;
43399 if (arg) {
43400 if (copy_to_user(argp, &dev, sizeof(ulong)))
43401 return -EFAULT;
43402 diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
43403 index 91d5730..336523e 100644
43404 --- a/drivers/isdn/i4l/isdn_concap.c
43405 +++ b/drivers/isdn/i4l/isdn_concap.c
43406 @@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
43407 }
43408
43409 struct concap_device_ops isdn_concap_reliable_dl_dops = {
43410 - &isdn_concap_dl_data_req,
43411 - &isdn_concap_dl_connect_req,
43412 - &isdn_concap_dl_disconn_req
43413 + .data_req = &isdn_concap_dl_data_req,
43414 + .connect_req = &isdn_concap_dl_connect_req,
43415 + .disconn_req = &isdn_concap_dl_disconn_req
43416 };
43417
43418 /* The following should better go into a dedicated source file such that
43419 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
43420 index 3c5f249..5fac4d0 100644
43421 --- a/drivers/isdn/i4l/isdn_tty.c
43422 +++ b/drivers/isdn/i4l/isdn_tty.c
43423 @@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
43424
43425 #ifdef ISDN_DEBUG_MODEM_OPEN
43426 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
43427 - port->count);
43428 + atomic_read(&port->count));
43429 #endif
43430 - port->count++;
43431 + atomic_inc(&port->count);
43432 port->tty = tty;
43433 /*
43434 * Start up serial port
43435 @@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43436 #endif
43437 return;
43438 }
43439 - if ((tty->count == 1) && (port->count != 1)) {
43440 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
43441 /*
43442 * Uh, oh. tty->count is 1, which means that the tty
43443 * structure will be freed. Info->count should always
43444 @@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43445 * serial port won't be shutdown.
43446 */
43447 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
43448 - "info->count is %d\n", port->count);
43449 - port->count = 1;
43450 + "info->count is %d\n", atomic_read(&port->count));
43451 + atomic_set(&port->count, 1);
43452 }
43453 - if (--port->count < 0) {
43454 + if (atomic_dec_return(&port->count) < 0) {
43455 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
43456 - info->line, port->count);
43457 - port->count = 0;
43458 + info->line, atomic_read(&port->count));
43459 + atomic_set(&port->count, 0);
43460 }
43461 - if (port->count) {
43462 + if (atomic_read(&port->count)) {
43463 #ifdef ISDN_DEBUG_MODEM_OPEN
43464 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
43465 #endif
43466 @@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
43467 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
43468 return;
43469 isdn_tty_shutdown(info);
43470 - port->count = 0;
43471 + atomic_set(&port->count, 0);
43472 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43473 port->tty = NULL;
43474 wake_up_interruptible(&port->open_wait);
43475 @@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
43476 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
43477 modem_info *info = &dev->mdm.info[i];
43478
43479 - if (info->port.count == 0)
43480 + if (atomic_read(&info->port.count) == 0)
43481 continue;
43482 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
43483 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
43484 diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
43485 index e2d4e58..40cd045 100644
43486 --- a/drivers/isdn/i4l/isdn_x25iface.c
43487 +++ b/drivers/isdn/i4l/isdn_x25iface.c
43488 @@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
43489
43490
43491 static struct concap_proto_ops ix25_pops = {
43492 - &isdn_x25iface_proto_new,
43493 - &isdn_x25iface_proto_del,
43494 - &isdn_x25iface_proto_restart,
43495 - &isdn_x25iface_proto_close,
43496 - &isdn_x25iface_xmit,
43497 - &isdn_x25iface_receive,
43498 - &isdn_x25iface_connect_ind,
43499 - &isdn_x25iface_disconn_ind
43500 + .proto_new = &isdn_x25iface_proto_new,
43501 + .proto_del = &isdn_x25iface_proto_del,
43502 + .restart = &isdn_x25iface_proto_restart,
43503 + .close = &isdn_x25iface_proto_close,
43504 + .encap_and_xmit = &isdn_x25iface_xmit,
43505 + .data_ind = &isdn_x25iface_receive,
43506 + .connect_ind = &isdn_x25iface_connect_ind,
43507 + .disconn_ind = &isdn_x25iface_disconn_ind
43508 };
43509
43510 /* error message helper function */
43511 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
43512 index 6a7447c..cae33fe 100644
43513 --- a/drivers/isdn/icn/icn.c
43514 +++ b/drivers/isdn/icn/icn.c
43515 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
43516 if (count > len)
43517 count = len;
43518 if (user) {
43519 - if (copy_from_user(msg, buf, count))
43520 + if (count > sizeof msg || copy_from_user(msg, buf, count))
43521 return -EFAULT;
43522 } else
43523 memcpy(msg, buf, count);
43524 diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
43525 index a4f05c5..1433bc5 100644
43526 --- a/drivers/isdn/mISDN/dsp_cmx.c
43527 +++ b/drivers/isdn/mISDN/dsp_cmx.c
43528 @@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
43529 static u16 dsp_count; /* last sample count */
43530 static int dsp_count_valid; /* if we have last sample count */
43531
43532 -void
43533 +void __intentional_overflow(-1)
43534 dsp_cmx_send(void *arg)
43535 {
43536 struct dsp_conf *conf;
43537 diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
43538 index f58a354..fbae176 100644
43539 --- a/drivers/leds/leds-clevo-mail.c
43540 +++ b/drivers/leds/leds-clevo-mail.c
43541 @@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
43542 * detected as working, but in reality it is not) as low as
43543 * possible.
43544 */
43545 -static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
43546 +static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
43547 {
43548 .callback = clevo_mail_led_dmi_callback,
43549 .ident = "Clevo D410J",
43550 diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
43551 index 2eb3ef6..295891f 100644
43552 --- a/drivers/leds/leds-ss4200.c
43553 +++ b/drivers/leds/leds-ss4200.c
43554 @@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
43555 * detected as working, but in reality it is not) as low as
43556 * possible.
43557 */
43558 -static struct dmi_system_id nas_led_whitelist[] __initdata = {
43559 +static struct dmi_system_id nas_led_whitelist[] __initconst = {
43560 {
43561 .callback = ss4200_led_dmi_callback,
43562 .ident = "Intel SS4200-E",
43563 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
43564 index 0bf1e4e..b4bf44e 100644
43565 --- a/drivers/lguest/core.c
43566 +++ b/drivers/lguest/core.c
43567 @@ -97,9 +97,17 @@ static __init int map_switcher(void)
43568 * The end address needs +1 because __get_vm_area allocates an
43569 * extra guard page, so we need space for that.
43570 */
43571 +
43572 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
43573 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43574 + VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
43575 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43576 +#else
43577 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43578 VM_ALLOC, switcher_addr, switcher_addr
43579 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43580 +#endif
43581 +
43582 if (!switcher_vma) {
43583 err = -ENOMEM;
43584 printk("lguest: could not map switcher pages high\n");
43585 @@ -124,7 +132,7 @@ static __init int map_switcher(void)
43586 * Now the Switcher is mapped at the right address, we can't fail!
43587 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
43588 */
43589 - memcpy(switcher_vma->addr, start_switcher_text,
43590 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
43591 end_switcher_text - start_switcher_text);
43592
43593 printk(KERN_INFO "lguest: mapped switcher at %p\n",
43594 diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
43595 index e8b55c3..3514c37 100644
43596 --- a/drivers/lguest/page_tables.c
43597 +++ b/drivers/lguest/page_tables.c
43598 @@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
43599 /*:*/
43600
43601 #ifdef CONFIG_X86_PAE
43602 -static void release_pmd(pmd_t *spmd)
43603 +static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
43604 {
43605 /* If the entry's not present, there's nothing to release. */
43606 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
43607 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
43608 index 922a1ac..9dd0c2a 100644
43609 --- a/drivers/lguest/x86/core.c
43610 +++ b/drivers/lguest/x86/core.c
43611 @@ -59,7 +59,7 @@ static struct {
43612 /* Offset from where switcher.S was compiled to where we've copied it */
43613 static unsigned long switcher_offset(void)
43614 {
43615 - return switcher_addr - (unsigned long)start_switcher_text;
43616 + return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
43617 }
43618
43619 /* This cpu's struct lguest_pages (after the Switcher text page) */
43620 @@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
43621 * These copies are pretty cheap, so we do them unconditionally: */
43622 /* Save the current Host top-level page directory.
43623 */
43624 +
43625 +#ifdef CONFIG_PAX_PER_CPU_PGD
43626 + pages->state.host_cr3 = read_cr3();
43627 +#else
43628 pages->state.host_cr3 = __pa(current->mm->pgd);
43629 +#endif
43630 +
43631 /*
43632 * Set up the Guest's page tables to see this CPU's pages (and no
43633 * other CPU's pages).
43634 @@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
43635 * compiled-in switcher code and the high-mapped copy we just made.
43636 */
43637 for (i = 0; i < IDT_ENTRIES; i++)
43638 - default_idt_entries[i] += switcher_offset();
43639 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
43640
43641 /*
43642 * Set up the Switcher's per-cpu areas.
43643 @@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
43644 * it will be undisturbed when we switch. To change %cs and jump we
43645 * need this structure to feed to Intel's "lcall" instruction.
43646 */
43647 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
43648 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
43649 lguest_entry.segment = LGUEST_CS;
43650
43651 /*
43652 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
43653 index 40634b0..4f5855e 100644
43654 --- a/drivers/lguest/x86/switcher_32.S
43655 +++ b/drivers/lguest/x86/switcher_32.S
43656 @@ -87,6 +87,7 @@
43657 #include <asm/page.h>
43658 #include <asm/segment.h>
43659 #include <asm/lguest.h>
43660 +#include <asm/processor-flags.h>
43661
43662 // We mark the start of the code to copy
43663 // It's placed in .text tho it's never run here
43664 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
43665 // Changes type when we load it: damn Intel!
43666 // For after we switch over our page tables
43667 // That entry will be read-only: we'd crash.
43668 +
43669 +#ifdef CONFIG_PAX_KERNEXEC
43670 + mov %cr0, %edx
43671 + xor $X86_CR0_WP, %edx
43672 + mov %edx, %cr0
43673 +#endif
43674 +
43675 movl $(GDT_ENTRY_TSS*8), %edx
43676 ltr %dx
43677
43678 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
43679 // Let's clear it again for our return.
43680 // The GDT descriptor of the Host
43681 // Points to the table after two "size" bytes
43682 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
43683 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
43684 // Clear "used" from type field (byte 5, bit 2)
43685 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
43686 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
43687 +
43688 +#ifdef CONFIG_PAX_KERNEXEC
43689 + mov %cr0, %eax
43690 + xor $X86_CR0_WP, %eax
43691 + mov %eax, %cr0
43692 +#endif
43693
43694 // Once our page table's switched, the Guest is live!
43695 // The Host fades as we run this final step.
43696 @@ -295,13 +309,12 @@ deliver_to_host:
43697 // I consulted gcc, and it gave
43698 // These instructions, which I gladly credit:
43699 leal (%edx,%ebx,8), %eax
43700 - movzwl (%eax),%edx
43701 - movl 4(%eax), %eax
43702 - xorw %ax, %ax
43703 - orl %eax, %edx
43704 + movl 4(%eax), %edx
43705 + movw (%eax), %dx
43706 // Now the address of the handler's in %edx
43707 // We call it now: its "iret" drops us home.
43708 - jmp *%edx
43709 + ljmp $__KERNEL_CS, $1f
43710 +1: jmp *%edx
43711
43712 // Every interrupt can come to us here
43713 // But we must truly tell each apart.
43714 diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
43715 index 7ef7461..5a09dac 100644
43716 --- a/drivers/md/bcache/closure.h
43717 +++ b/drivers/md/bcache/closure.h
43718 @@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
43719 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
43720 struct workqueue_struct *wq)
43721 {
43722 - BUG_ON(object_is_on_stack(cl));
43723 + BUG_ON(object_starts_on_stack(cl));
43724 closure_set_ip(cl);
43725 cl->fn = fn;
43726 cl->wq = wq;
43727 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
43728 index 9a8e66a..10cc762 100644
43729 --- a/drivers/md/bitmap.c
43730 +++ b/drivers/md/bitmap.c
43731 @@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
43732 chunk_kb ? "KB" : "B");
43733 if (bitmap->storage.file) {
43734 seq_printf(seq, ", file: ");
43735 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
43736 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
43737 }
43738
43739 seq_printf(seq, "\n");
43740 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
43741 index 5152142..623d141 100644
43742 --- a/drivers/md/dm-ioctl.c
43743 +++ b/drivers/md/dm-ioctl.c
43744 @@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
43745 cmd == DM_LIST_VERSIONS_CMD)
43746 return 0;
43747
43748 - if ((cmd == DM_DEV_CREATE_CMD)) {
43749 + if (cmd == DM_DEV_CREATE_CMD) {
43750 if (!*param->name) {
43751 DMWARN("name not supplied when creating device");
43752 return -EINVAL;
43753 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
43754 index 7dfdb5c..4caada6 100644
43755 --- a/drivers/md/dm-raid1.c
43756 +++ b/drivers/md/dm-raid1.c
43757 @@ -40,7 +40,7 @@ enum dm_raid1_error {
43758
43759 struct mirror {
43760 struct mirror_set *ms;
43761 - atomic_t error_count;
43762 + atomic_unchecked_t error_count;
43763 unsigned long error_type;
43764 struct dm_dev *dev;
43765 sector_t offset;
43766 @@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
43767 struct mirror *m;
43768
43769 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
43770 - if (!atomic_read(&m->error_count))
43771 + if (!atomic_read_unchecked(&m->error_count))
43772 return m;
43773
43774 return NULL;
43775 @@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
43776 * simple way to tell if a device has encountered
43777 * errors.
43778 */
43779 - atomic_inc(&m->error_count);
43780 + atomic_inc_unchecked(&m->error_count);
43781
43782 if (test_and_set_bit(error_type, &m->error_type))
43783 return;
43784 @@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
43785 struct mirror *m = get_default_mirror(ms);
43786
43787 do {
43788 - if (likely(!atomic_read(&m->error_count)))
43789 + if (likely(!atomic_read_unchecked(&m->error_count)))
43790 return m;
43791
43792 if (m-- == ms->mirror)
43793 @@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
43794 {
43795 struct mirror *default_mirror = get_default_mirror(m->ms);
43796
43797 - return !atomic_read(&default_mirror->error_count);
43798 + return !atomic_read_unchecked(&default_mirror->error_count);
43799 }
43800
43801 static int mirror_available(struct mirror_set *ms, struct bio *bio)
43802 @@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
43803 */
43804 if (likely(region_in_sync(ms, region, 1)))
43805 m = choose_mirror(ms, bio->bi_iter.bi_sector);
43806 - else if (m && atomic_read(&m->error_count))
43807 + else if (m && atomic_read_unchecked(&m->error_count))
43808 m = NULL;
43809
43810 if (likely(m))
43811 @@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
43812 }
43813
43814 ms->mirror[mirror].ms = ms;
43815 - atomic_set(&(ms->mirror[mirror].error_count), 0);
43816 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
43817 ms->mirror[mirror].error_type = 0;
43818 ms->mirror[mirror].offset = offset;
43819
43820 @@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
43821 */
43822 static char device_status_char(struct mirror *m)
43823 {
43824 - if (!atomic_read(&(m->error_count)))
43825 + if (!atomic_read_unchecked(&(m->error_count)))
43826 return 'A';
43827
43828 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
43829 diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
43830 index 28a9012..9c0f6a5 100644
43831 --- a/drivers/md/dm-stats.c
43832 +++ b/drivers/md/dm-stats.c
43833 @@ -382,7 +382,7 @@ do_sync_free:
43834 synchronize_rcu_expedited();
43835 dm_stat_free(&s->rcu_head);
43836 } else {
43837 - ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
43838 + ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
43839 call_rcu(&s->rcu_head, dm_stat_free);
43840 }
43841 return 0;
43842 @@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
43843 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
43844 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
43845 ));
43846 - ACCESS_ONCE(last->last_sector) = end_sector;
43847 - ACCESS_ONCE(last->last_rw) = bi_rw;
43848 + ACCESS_ONCE_RW(last->last_sector) = end_sector;
43849 + ACCESS_ONCE_RW(last->last_rw) = bi_rw;
43850 }
43851
43852 rcu_read_lock();
43853 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
43854 index d1600d2..4c3af3a 100644
43855 --- a/drivers/md/dm-stripe.c
43856 +++ b/drivers/md/dm-stripe.c
43857 @@ -21,7 +21,7 @@ struct stripe {
43858 struct dm_dev *dev;
43859 sector_t physical_start;
43860
43861 - atomic_t error_count;
43862 + atomic_unchecked_t error_count;
43863 };
43864
43865 struct stripe_c {
43866 @@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
43867 kfree(sc);
43868 return r;
43869 }
43870 - atomic_set(&(sc->stripe[i].error_count), 0);
43871 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
43872 }
43873
43874 ti->private = sc;
43875 @@ -330,7 +330,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
43876 DMEMIT("%d ", sc->stripes);
43877 for (i = 0; i < sc->stripes; i++) {
43878 DMEMIT("%s ", sc->stripe[i].dev->name);
43879 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
43880 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
43881 'D' : 'A';
43882 }
43883 buffer[i] = '\0';
43884 @@ -375,8 +375,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
43885 */
43886 for (i = 0; i < sc->stripes; i++)
43887 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
43888 - atomic_inc(&(sc->stripe[i].error_count));
43889 - if (atomic_read(&(sc->stripe[i].error_count)) <
43890 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
43891 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
43892 DM_IO_ERROR_THRESHOLD)
43893 schedule_work(&sc->trigger_event);
43894 }
43895 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
43896 index 50601ec..6d3b9dc 100644
43897 --- a/drivers/md/dm-table.c
43898 +++ b/drivers/md/dm-table.c
43899 @@ -274,7 +274,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
43900 static int open_dev(struct dm_dev_internal *d, dev_t dev,
43901 struct mapped_device *md)
43902 {
43903 - static char *_claim_ptr = "I belong to device-mapper";
43904 + static char _claim_ptr[] = "I belong to device-mapper";
43905 struct block_device *bdev;
43906
43907 int r;
43908 @@ -342,7 +342,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
43909 if (!dev_size)
43910 return 0;
43911
43912 - if ((start >= dev_size) || (start + len > dev_size)) {
43913 + if ((start >= dev_size) || (len > dev_size - start)) {
43914 DMWARN("%s: %s too small for target: "
43915 "start=%llu, len=%llu, dev_size=%llu",
43916 dm_device_name(ti->table->md), bdevname(bdev, b),
43917 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
43918 index e9d33ad..dae9880d 100644
43919 --- a/drivers/md/dm-thin-metadata.c
43920 +++ b/drivers/md/dm-thin-metadata.c
43921 @@ -404,7 +404,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43922 {
43923 pmd->info.tm = pmd->tm;
43924 pmd->info.levels = 2;
43925 - pmd->info.value_type.context = pmd->data_sm;
43926 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43927 pmd->info.value_type.size = sizeof(__le64);
43928 pmd->info.value_type.inc = data_block_inc;
43929 pmd->info.value_type.dec = data_block_dec;
43930 @@ -423,7 +423,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43931
43932 pmd->bl_info.tm = pmd->tm;
43933 pmd->bl_info.levels = 1;
43934 - pmd->bl_info.value_type.context = pmd->data_sm;
43935 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43936 pmd->bl_info.value_type.size = sizeof(__le64);
43937 pmd->bl_info.value_type.inc = data_block_inc;
43938 pmd->bl_info.value_type.dec = data_block_dec;
43939 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
43940 index 490ac23..b9790cd 100644
43941 --- a/drivers/md/dm.c
43942 +++ b/drivers/md/dm.c
43943 @@ -180,9 +180,9 @@ struct mapped_device {
43944 /*
43945 * Event handling.
43946 */
43947 - atomic_t event_nr;
43948 + atomic_unchecked_t event_nr;
43949 wait_queue_head_t eventq;
43950 - atomic_t uevent_seq;
43951 + atomic_unchecked_t uevent_seq;
43952 struct list_head uevent_list;
43953 spinlock_t uevent_lock; /* Protect access to uevent_list */
43954
43955 @@ -1895,8 +1895,8 @@ static struct mapped_device *alloc_dev(int minor)
43956 spin_lock_init(&md->deferred_lock);
43957 atomic_set(&md->holders, 1);
43958 atomic_set(&md->open_count, 0);
43959 - atomic_set(&md->event_nr, 0);
43960 - atomic_set(&md->uevent_seq, 0);
43961 + atomic_set_unchecked(&md->event_nr, 0);
43962 + atomic_set_unchecked(&md->uevent_seq, 0);
43963 INIT_LIST_HEAD(&md->uevent_list);
43964 spin_lock_init(&md->uevent_lock);
43965
43966 @@ -2050,7 +2050,7 @@ static void event_callback(void *context)
43967
43968 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
43969
43970 - atomic_inc(&md->event_nr);
43971 + atomic_inc_unchecked(&md->event_nr);
43972 wake_up(&md->eventq);
43973 }
43974
43975 @@ -2743,18 +2743,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
43976
43977 uint32_t dm_next_uevent_seq(struct mapped_device *md)
43978 {
43979 - return atomic_add_return(1, &md->uevent_seq);
43980 + return atomic_add_return_unchecked(1, &md->uevent_seq);
43981 }
43982
43983 uint32_t dm_get_event_nr(struct mapped_device *md)
43984 {
43985 - return atomic_read(&md->event_nr);
43986 + return atomic_read_unchecked(&md->event_nr);
43987 }
43988
43989 int dm_wait_event(struct mapped_device *md, int event_nr)
43990 {
43991 return wait_event_interruptible(md->eventq,
43992 - (event_nr != atomic_read(&md->event_nr)));
43993 + (event_nr != atomic_read_unchecked(&md->event_nr)));
43994 }
43995
43996 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
43997 diff --git a/drivers/md/md.c b/drivers/md/md.c
43998 index 9a18209..ec4d3ec 100644
43999 --- a/drivers/md/md.c
44000 +++ b/drivers/md/md.c
44001 @@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
44002 * start build, activate spare
44003 */
44004 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
44005 -static atomic_t md_event_count;
44006 +static atomic_unchecked_t md_event_count;
44007 void md_new_event(struct mddev *mddev)
44008 {
44009 - atomic_inc(&md_event_count);
44010 + atomic_inc_unchecked(&md_event_count);
44011 wake_up(&md_event_waiters);
44012 }
44013 EXPORT_SYMBOL_GPL(md_new_event);
44014 @@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
44015 */
44016 static void md_new_event_inintr(struct mddev *mddev)
44017 {
44018 - atomic_inc(&md_event_count);
44019 + atomic_inc_unchecked(&md_event_count);
44020 wake_up(&md_event_waiters);
44021 }
44022
44023 @@ -1462,7 +1462,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
44024 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
44025 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
44026 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
44027 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44028 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44029
44030 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
44031 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
44032 @@ -1713,7 +1713,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
44033 else
44034 sb->resync_offset = cpu_to_le64(0);
44035
44036 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
44037 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
44038
44039 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
44040 sb->size = cpu_to_le64(mddev->dev_sectors);
44041 @@ -2725,7 +2725,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
44042 static ssize_t
44043 errors_show(struct md_rdev *rdev, char *page)
44044 {
44045 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
44046 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
44047 }
44048
44049 static ssize_t
44050 @@ -2734,7 +2734,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
44051 char *e;
44052 unsigned long n = simple_strtoul(buf, &e, 10);
44053 if (*buf && (*e == 0 || *e == '\n')) {
44054 - atomic_set(&rdev->corrected_errors, n);
44055 + atomic_set_unchecked(&rdev->corrected_errors, n);
44056 return len;
44057 }
44058 return -EINVAL;
44059 @@ -3183,8 +3183,8 @@ int md_rdev_init(struct md_rdev *rdev)
44060 rdev->sb_loaded = 0;
44061 rdev->bb_page = NULL;
44062 atomic_set(&rdev->nr_pending, 0);
44063 - atomic_set(&rdev->read_errors, 0);
44064 - atomic_set(&rdev->corrected_errors, 0);
44065 + atomic_set_unchecked(&rdev->read_errors, 0);
44066 + atomic_set_unchecked(&rdev->corrected_errors, 0);
44067
44068 INIT_LIST_HEAD(&rdev->same_set);
44069 init_waitqueue_head(&rdev->blocked_wait);
44070 @@ -7058,7 +7058,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
44071
44072 spin_unlock(&pers_lock);
44073 seq_printf(seq, "\n");
44074 - seq->poll_event = atomic_read(&md_event_count);
44075 + seq->poll_event = atomic_read_unchecked(&md_event_count);
44076 return 0;
44077 }
44078 if (v == (void*)2) {
44079 @@ -7161,7 +7161,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
44080 return error;
44081
44082 seq = file->private_data;
44083 - seq->poll_event = atomic_read(&md_event_count);
44084 + seq->poll_event = atomic_read_unchecked(&md_event_count);
44085 return error;
44086 }
44087
44088 @@ -7178,7 +7178,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
44089 /* always allow read */
44090 mask = POLLIN | POLLRDNORM;
44091
44092 - if (seq->poll_event != atomic_read(&md_event_count))
44093 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
44094 mask |= POLLERR | POLLPRI;
44095 return mask;
44096 }
44097 @@ -7222,7 +7222,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
44098 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
44099 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
44100 (int)part_stat_read(&disk->part0, sectors[1]) -
44101 - atomic_read(&disk->sync_io);
44102 + atomic_read_unchecked(&disk->sync_io);
44103 /* sync IO will cause sync_io to increase before the disk_stats
44104 * as sync_io is counted when a request starts, and
44105 * disk_stats is counted when it completes.
44106 diff --git a/drivers/md/md.h b/drivers/md/md.h
44107 index a49d991..3582bb7 100644
44108 --- a/drivers/md/md.h
44109 +++ b/drivers/md/md.h
44110 @@ -94,13 +94,13 @@ struct md_rdev {
44111 * only maintained for arrays that
44112 * support hot removal
44113 */
44114 - atomic_t read_errors; /* number of consecutive read errors that
44115 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
44116 * we have tried to ignore.
44117 */
44118 struct timespec last_read_error; /* monotonic time since our
44119 * last read error
44120 */
44121 - atomic_t corrected_errors; /* number of corrected read errors,
44122 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
44123 * for reporting to userspace and storing
44124 * in superblock.
44125 */
44126 @@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
44127
44128 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
44129 {
44130 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44131 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44132 }
44133
44134 struct md_personality
44135 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
44136 index 786b689..ea8c956 100644
44137 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
44138 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
44139 @@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
44140 * Flick into a mode where all blocks get allocated in the new area.
44141 */
44142 smm->begin = old_len;
44143 - memcpy(sm, &bootstrap_ops, sizeof(*sm));
44144 + memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
44145
44146 /*
44147 * Extend.
44148 @@ -710,7 +710,7 @@ out:
44149 /*
44150 * Switch back to normal behaviour.
44151 */
44152 - memcpy(sm, &ops, sizeof(*sm));
44153 + memcpy((void *)sm, &ops, sizeof(*sm));
44154 return r;
44155 }
44156
44157 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
44158 index 3e6d115..ffecdeb 100644
44159 --- a/drivers/md/persistent-data/dm-space-map.h
44160 +++ b/drivers/md/persistent-data/dm-space-map.h
44161 @@ -71,6 +71,7 @@ struct dm_space_map {
44162 dm_sm_threshold_fn fn,
44163 void *context);
44164 };
44165 +typedef struct dm_space_map __no_const dm_space_map_no_const;
44166
44167 /*----------------------------------------------------------------*/
44168
44169 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
44170 index 56e24c0..e1c8e1f 100644
44171 --- a/drivers/md/raid1.c
44172 +++ b/drivers/md/raid1.c
44173 @@ -1931,7 +1931,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
44174 if (r1_sync_page_io(rdev, sect, s,
44175 bio->bi_io_vec[idx].bv_page,
44176 READ) != 0)
44177 - atomic_add(s, &rdev->corrected_errors);
44178 + atomic_add_unchecked(s, &rdev->corrected_errors);
44179 }
44180 sectors -= s;
44181 sect += s;
44182 @@ -2165,7 +2165,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
44183 test_bit(In_sync, &rdev->flags)) {
44184 if (r1_sync_page_io(rdev, sect, s,
44185 conf->tmppage, READ)) {
44186 - atomic_add(s, &rdev->corrected_errors);
44187 + atomic_add_unchecked(s, &rdev->corrected_errors);
44188 printk(KERN_INFO
44189 "md/raid1:%s: read error corrected "
44190 "(%d sectors at %llu on %s)\n",
44191 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
44192 index cb882aa..9bd076e 100644
44193 --- a/drivers/md/raid10.c
44194 +++ b/drivers/md/raid10.c
44195 @@ -1949,7 +1949,7 @@ static void end_sync_read(struct bio *bio, int error)
44196 /* The write handler will notice the lack of
44197 * R10BIO_Uptodate and record any errors etc
44198 */
44199 - atomic_add(r10_bio->sectors,
44200 + atomic_add_unchecked(r10_bio->sectors,
44201 &conf->mirrors[d].rdev->corrected_errors);
44202
44203 /* for reconstruct, we always reschedule after a read.
44204 @@ -2307,7 +2307,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44205 {
44206 struct timespec cur_time_mon;
44207 unsigned long hours_since_last;
44208 - unsigned int read_errors = atomic_read(&rdev->read_errors);
44209 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
44210
44211 ktime_get_ts(&cur_time_mon);
44212
44213 @@ -2329,9 +2329,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44214 * overflowing the shift of read_errors by hours_since_last.
44215 */
44216 if (hours_since_last >= 8 * sizeof(read_errors))
44217 - atomic_set(&rdev->read_errors, 0);
44218 + atomic_set_unchecked(&rdev->read_errors, 0);
44219 else
44220 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
44221 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
44222 }
44223
44224 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
44225 @@ -2385,8 +2385,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44226 return;
44227
44228 check_decay_read_errors(mddev, rdev);
44229 - atomic_inc(&rdev->read_errors);
44230 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
44231 + atomic_inc_unchecked(&rdev->read_errors);
44232 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
44233 char b[BDEVNAME_SIZE];
44234 bdevname(rdev->bdev, b);
44235
44236 @@ -2394,7 +2394,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44237 "md/raid10:%s: %s: Raid device exceeded "
44238 "read_error threshold [cur %d:max %d]\n",
44239 mdname(mddev), b,
44240 - atomic_read(&rdev->read_errors), max_read_errors);
44241 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
44242 printk(KERN_NOTICE
44243 "md/raid10:%s: %s: Failing raid device\n",
44244 mdname(mddev), b);
44245 @@ -2549,7 +2549,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44246 sect +
44247 choose_data_offset(r10_bio, rdev)),
44248 bdevname(rdev->bdev, b));
44249 - atomic_add(s, &rdev->corrected_errors);
44250 + atomic_add_unchecked(s, &rdev->corrected_errors);
44251 }
44252
44253 rdev_dec_pending(rdev, mddev);
44254 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
44255 index ad1b9be..b417412 100644
44256 --- a/drivers/md/raid5.c
44257 +++ b/drivers/md/raid5.c
44258 @@ -1702,6 +1702,10 @@ static int grow_one_stripe(struct r5conf *conf, int hash)
44259 return 1;
44260 }
44261
44262 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44263 +static atomic_unchecked_t raid5_cache_id = ATOMIC_INIT(0);
44264 +#endif
44265 +
44266 static int grow_stripes(struct r5conf *conf, int num)
44267 {
44268 struct kmem_cache *sc;
44269 @@ -1713,7 +1717,11 @@ static int grow_stripes(struct r5conf *conf, int num)
44270 "raid%d-%s", conf->level, mdname(conf->mddev));
44271 else
44272 sprintf(conf->cache_name[0],
44273 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44274 + "raid%d-%08lx", conf->level, atomic_inc_return_unchecked(&raid5_cache_id));
44275 +#else
44276 "raid%d-%p", conf->level, conf->mddev);
44277 +#endif
44278 sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]);
44279
44280 conf->active_name = 0;
44281 @@ -1986,21 +1994,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
44282 mdname(conf->mddev), STRIPE_SECTORS,
44283 (unsigned long long)s,
44284 bdevname(rdev->bdev, b));
44285 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
44286 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
44287 clear_bit(R5_ReadError, &sh->dev[i].flags);
44288 clear_bit(R5_ReWrite, &sh->dev[i].flags);
44289 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
44290 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
44291
44292 - if (atomic_read(&rdev->read_errors))
44293 - atomic_set(&rdev->read_errors, 0);
44294 + if (atomic_read_unchecked(&rdev->read_errors))
44295 + atomic_set_unchecked(&rdev->read_errors, 0);
44296 } else {
44297 const char *bdn = bdevname(rdev->bdev, b);
44298 int retry = 0;
44299 int set_bad = 0;
44300
44301 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
44302 - atomic_inc(&rdev->read_errors);
44303 + atomic_inc_unchecked(&rdev->read_errors);
44304 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
44305 printk_ratelimited(
44306 KERN_WARNING
44307 @@ -2028,7 +2036,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
44308 mdname(conf->mddev),
44309 (unsigned long long)s,
44310 bdn);
44311 - } else if (atomic_read(&rdev->read_errors)
44312 + } else if (atomic_read_unchecked(&rdev->read_errors)
44313 > conf->max_nr_stripes)
44314 printk(KERN_WARNING
44315 "md/raid:%s: Too many read errors, failing device %s.\n",
44316 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
44317 index 983db75..ef9248c 100644
44318 --- a/drivers/media/dvb-core/dvbdev.c
44319 +++ b/drivers/media/dvb-core/dvbdev.c
44320 @@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
44321 const struct dvb_device *template, void *priv, int type)
44322 {
44323 struct dvb_device *dvbdev;
44324 - struct file_operations *dvbdevfops;
44325 + file_operations_no_const *dvbdevfops;
44326 struct device *clsdev;
44327 int minor;
44328 int id;
44329 diff --git a/drivers/media/dvb-frontends/af9033.h b/drivers/media/dvb-frontends/af9033.h
44330 index 539f4db..cdd403b 100644
44331 --- a/drivers/media/dvb-frontends/af9033.h
44332 +++ b/drivers/media/dvb-frontends/af9033.h
44333 @@ -82,7 +82,7 @@ struct af9033_ops {
44334 int (*pid_filter_ctrl)(struct dvb_frontend *fe, int onoff);
44335 int (*pid_filter)(struct dvb_frontend *fe, int index, u16 pid,
44336 int onoff);
44337 -};
44338 +} __no_const;
44339
44340
44341 #if IS_ENABLED(CONFIG_DVB_AF9033)
44342 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
44343 index 9b6c3bb..baeb5c7 100644
44344 --- a/drivers/media/dvb-frontends/dib3000.h
44345 +++ b/drivers/media/dvb-frontends/dib3000.h
44346 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
44347 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
44348 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
44349 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
44350 -};
44351 +} __no_const;
44352
44353 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
44354 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
44355 diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
44356 index ed8cb90..5ef7f79 100644
44357 --- a/drivers/media/pci/cx88/cx88-video.c
44358 +++ b/drivers/media/pci/cx88/cx88-video.c
44359 @@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
44360
44361 /* ------------------------------------------------------------------ */
44362
44363 -static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44364 -static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44365 -static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44366 +static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44367 +static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44368 +static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44369
44370 module_param_array(video_nr, int, NULL, 0444);
44371 module_param_array(vbi_nr, int, NULL, 0444);
44372 diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
44373 index 802642d..5534900 100644
44374 --- a/drivers/media/pci/ivtv/ivtv-driver.c
44375 +++ b/drivers/media/pci/ivtv/ivtv-driver.c
44376 @@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
44377 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
44378
44379 /* ivtv instance counter */
44380 -static atomic_t ivtv_instance = ATOMIC_INIT(0);
44381 +static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
44382
44383 /* Parameter declarations */
44384 static int cardtype[IVTV_MAX_CARDS];
44385 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
44386 index 9a726ea..f5e9b52 100644
44387 --- a/drivers/media/platform/omap/omap_vout.c
44388 +++ b/drivers/media/platform/omap/omap_vout.c
44389 @@ -63,7 +63,6 @@ enum omap_vout_channels {
44390 OMAP_VIDEO2,
44391 };
44392
44393 -static struct videobuf_queue_ops video_vbq_ops;
44394 /* Variables configurable through module params*/
44395 static u32 video1_numbuffers = 3;
44396 static u32 video2_numbuffers = 3;
44397 @@ -1015,6 +1014,12 @@ static int omap_vout_open(struct file *file)
44398 {
44399 struct videobuf_queue *q;
44400 struct omap_vout_device *vout = NULL;
44401 + static struct videobuf_queue_ops video_vbq_ops = {
44402 + .buf_setup = omap_vout_buffer_setup,
44403 + .buf_prepare = omap_vout_buffer_prepare,
44404 + .buf_release = omap_vout_buffer_release,
44405 + .buf_queue = omap_vout_buffer_queue,
44406 + };
44407
44408 vout = video_drvdata(file);
44409 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
44410 @@ -1032,10 +1037,6 @@ static int omap_vout_open(struct file *file)
44411 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
44412
44413 q = &vout->vbq;
44414 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
44415 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
44416 - video_vbq_ops.buf_release = omap_vout_buffer_release;
44417 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
44418 spin_lock_init(&vout->vbq_lock);
44419
44420 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
44421 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
44422 index fb2acc5..a2fcbdc4 100644
44423 --- a/drivers/media/platform/s5p-tv/mixer.h
44424 +++ b/drivers/media/platform/s5p-tv/mixer.h
44425 @@ -156,7 +156,7 @@ struct mxr_layer {
44426 /** layer index (unique identifier) */
44427 int idx;
44428 /** callbacks for layer methods */
44429 - struct mxr_layer_ops ops;
44430 + struct mxr_layer_ops *ops;
44431 /** format array */
44432 const struct mxr_format **fmt_array;
44433 /** size of format array */
44434 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44435 index 74344c7..a39e70e 100644
44436 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44437 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44438 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
44439 {
44440 struct mxr_layer *layer;
44441 int ret;
44442 - struct mxr_layer_ops ops = {
44443 + static struct mxr_layer_ops ops = {
44444 .release = mxr_graph_layer_release,
44445 .buffer_set = mxr_graph_buffer_set,
44446 .stream_set = mxr_graph_stream_set,
44447 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
44448 index b713403..53cb5ad 100644
44449 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
44450 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
44451 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
44452 layer->update_buf = next;
44453 }
44454
44455 - layer->ops.buffer_set(layer, layer->update_buf);
44456 + layer->ops->buffer_set(layer, layer->update_buf);
44457
44458 if (done && done != layer->shadow_buf)
44459 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
44460 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
44461 index a1ce55f..4a3c4d9 100644
44462 --- a/drivers/media/platform/s5p-tv/mixer_video.c
44463 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
44464 @@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
44465 layer->geo.src.height = layer->geo.src.full_height;
44466
44467 mxr_geometry_dump(mdev, &layer->geo);
44468 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44469 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44470 mxr_geometry_dump(mdev, &layer->geo);
44471 }
44472
44473 @@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
44474 layer->geo.dst.full_width = mbus_fmt.width;
44475 layer->geo.dst.full_height = mbus_fmt.height;
44476 layer->geo.dst.field = mbus_fmt.field;
44477 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44478 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44479
44480 mxr_geometry_dump(mdev, &layer->geo);
44481 }
44482 @@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
44483 /* set source size to highest accepted value */
44484 geo->src.full_width = max(geo->dst.full_width, pix->width);
44485 geo->src.full_height = max(geo->dst.full_height, pix->height);
44486 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44487 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44488 mxr_geometry_dump(mdev, &layer->geo);
44489 /* set cropping to total visible screen */
44490 geo->src.width = pix->width;
44491 @@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
44492 geo->src.x_offset = 0;
44493 geo->src.y_offset = 0;
44494 /* assure consistency of geometry */
44495 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44496 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44497 mxr_geometry_dump(mdev, &layer->geo);
44498 /* set full size to lowest possible value */
44499 geo->src.full_width = 0;
44500 geo->src.full_height = 0;
44501 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44502 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44503 mxr_geometry_dump(mdev, &layer->geo);
44504
44505 /* returning results */
44506 @@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
44507 target->width = s->r.width;
44508 target->height = s->r.height;
44509
44510 - layer->ops.fix_geometry(layer, stage, s->flags);
44511 + layer->ops->fix_geometry(layer, stage, s->flags);
44512
44513 /* retrieve update selection rectangle */
44514 res.left = target->x_offset;
44515 @@ -950,13 +950,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
44516 mxr_output_get(mdev);
44517
44518 mxr_layer_update_output(layer);
44519 - layer->ops.format_set(layer);
44520 + layer->ops->format_set(layer);
44521 /* enabling layer in hardware */
44522 spin_lock_irqsave(&layer->enq_slock, flags);
44523 layer->state = MXR_LAYER_STREAMING;
44524 spin_unlock_irqrestore(&layer->enq_slock, flags);
44525
44526 - layer->ops.stream_set(layer, MXR_ENABLE);
44527 + layer->ops->stream_set(layer, MXR_ENABLE);
44528 mxr_streamer_get(mdev);
44529
44530 return 0;
44531 @@ -1026,7 +1026,7 @@ static int stop_streaming(struct vb2_queue *vq)
44532 spin_unlock_irqrestore(&layer->enq_slock, flags);
44533
44534 /* disabling layer in hardware */
44535 - layer->ops.stream_set(layer, MXR_DISABLE);
44536 + layer->ops->stream_set(layer, MXR_DISABLE);
44537 /* remove one streamer */
44538 mxr_streamer_put(mdev);
44539 /* allow changes in output configuration */
44540 @@ -1065,8 +1065,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
44541
44542 void mxr_layer_release(struct mxr_layer *layer)
44543 {
44544 - if (layer->ops.release)
44545 - layer->ops.release(layer);
44546 + if (layer->ops->release)
44547 + layer->ops->release(layer);
44548 }
44549
44550 void mxr_base_layer_release(struct mxr_layer *layer)
44551 @@ -1092,7 +1092,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
44552
44553 layer->mdev = mdev;
44554 layer->idx = idx;
44555 - layer->ops = *ops;
44556 + layer->ops = ops;
44557
44558 spin_lock_init(&layer->enq_slock);
44559 INIT_LIST_HEAD(&layer->enq_list);
44560 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44561 index c9388c4..ce71ece 100644
44562 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44563 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44564 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
44565 {
44566 struct mxr_layer *layer;
44567 int ret;
44568 - struct mxr_layer_ops ops = {
44569 + static struct mxr_layer_ops ops = {
44570 .release = mxr_vp_layer_release,
44571 .buffer_set = mxr_vp_buffer_set,
44572 .stream_set = mxr_vp_stream_set,
44573 diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
44574 index 3890f4f..b5c7511 100644
44575 --- a/drivers/media/platform/vivi.c
44576 +++ b/drivers/media/platform/vivi.c
44577 @@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
44578 MODULE_LICENSE("Dual BSD/GPL");
44579 MODULE_VERSION(VIVI_VERSION);
44580
44581 -static unsigned video_nr = -1;
44582 -module_param(video_nr, uint, 0644);
44583 +static int video_nr = -1;
44584 +module_param(video_nr, int, 0644);
44585 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
44586
44587 static unsigned n_devs = 1;
44588 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
44589 index d719e59..63f3470 100644
44590 --- a/drivers/media/radio/radio-cadet.c
44591 +++ b/drivers/media/radio/radio-cadet.c
44592 @@ -333,6 +333,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44593 unsigned char readbuf[RDS_BUFFER];
44594 int i = 0;
44595
44596 + if (count > RDS_BUFFER)
44597 + return -EFAULT;
44598 mutex_lock(&dev->lock);
44599 if (dev->rdsstat == 0)
44600 cadet_start_rds(dev);
44601 @@ -349,8 +351,9 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44602 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
44603 mutex_unlock(&dev->lock);
44604
44605 - if (i && copy_to_user(data, readbuf, i))
44606 - return -EFAULT;
44607 + if (i > sizeof(readbuf) || (i && copy_to_user(data, readbuf, i)))
44608 + i = -EFAULT;
44609 +
44610 return i;
44611 }
44612
44613 diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
44614 index 5236035..c622c74 100644
44615 --- a/drivers/media/radio/radio-maxiradio.c
44616 +++ b/drivers/media/radio/radio-maxiradio.c
44617 @@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
44618 /* TEA5757 pin mappings */
44619 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
44620
44621 -static atomic_t maxiradio_instance = ATOMIC_INIT(0);
44622 +static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
44623
44624 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
44625 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
44626 diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
44627 index 050b3bb..79f62b9 100644
44628 --- a/drivers/media/radio/radio-shark.c
44629 +++ b/drivers/media/radio/radio-shark.c
44630 @@ -79,7 +79,7 @@ struct shark_device {
44631 u32 last_val;
44632 };
44633
44634 -static atomic_t shark_instance = ATOMIC_INIT(0);
44635 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44636
44637 static void shark_write_val(struct snd_tea575x *tea, u32 val)
44638 {
44639 diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
44640 index 8654e0d..0608a64 100644
44641 --- a/drivers/media/radio/radio-shark2.c
44642 +++ b/drivers/media/radio/radio-shark2.c
44643 @@ -74,7 +74,7 @@ struct shark_device {
44644 u8 *transfer_buffer;
44645 };
44646
44647 -static atomic_t shark_instance = ATOMIC_INIT(0);
44648 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44649
44650 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
44651 {
44652 diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
44653 index 2fd9009..278cc1e 100644
44654 --- a/drivers/media/radio/radio-si476x.c
44655 +++ b/drivers/media/radio/radio-si476x.c
44656 @@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
44657 struct si476x_radio *radio;
44658 struct v4l2_ctrl *ctrl;
44659
44660 - static atomic_t instance = ATOMIC_INIT(0);
44661 + static atomic_unchecked_t instance = ATOMIC_INIT(0);
44662
44663 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
44664 if (!radio)
44665 diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
44666 index a1c641e..3007da9 100644
44667 --- a/drivers/media/usb/dvb-usb/cxusb.c
44668 +++ b/drivers/media/usb/dvb-usb/cxusb.c
44669 @@ -1112,7 +1112,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
44670
44671 struct dib0700_adapter_state {
44672 int (*set_param_save) (struct dvb_frontend *);
44673 -};
44674 +} __no_const;
44675
44676 static int dib7070_set_param_override(struct dvb_frontend *fe)
44677 {
44678 diff --git a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
44679 index 733a7ff..f8b52e3 100644
44680 --- a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
44681 +++ b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
44682 @@ -35,42 +35,57 @@ static int usb_cypress_writemem(struct usb_device *udev,u16 addr,u8 *data, u8 le
44683
44684 int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type)
44685 {
44686 - struct hexline hx;
44687 - u8 reset;
44688 + struct hexline *hx;
44689 + u8 *reset;
44690 int ret,pos=0;
44691
44692 + reset = kmalloc(1, GFP_KERNEL);
44693 + if (reset == NULL)
44694 + return -ENOMEM;
44695 +
44696 + hx = kmalloc(sizeof(struct hexline), GFP_KERNEL);
44697 + if (hx == NULL) {
44698 + kfree(reset);
44699 + return -ENOMEM;
44700 + }
44701 +
44702 /* stop the CPU */
44703 - reset = 1;
44704 - if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1)) != 1)
44705 + reset[0] = 1;
44706 + if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1)) != 1)
44707 err("could not stop the USB controller CPU.");
44708
44709 - while ((ret = dvb_usb_get_hexline(fw,&hx,&pos)) > 0) {
44710 - deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx.addr,hx.len,hx.chk);
44711 - ret = usb_cypress_writemem(udev,hx.addr,hx.data,hx.len);
44712 + while ((ret = dvb_usb_get_hexline(fw,hx,&pos)) > 0) {
44713 + deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx->addr,hx->len,hx->chk);
44714 + ret = usb_cypress_writemem(udev,hx->addr,hx->data,hx->len);
44715
44716 - if (ret != hx.len) {
44717 + if (ret != hx->len) {
44718 err("error while transferring firmware "
44719 "(transferred size: %d, block size: %d)",
44720 - ret,hx.len);
44721 + ret,hx->len);
44722 ret = -EINVAL;
44723 break;
44724 }
44725 }
44726 if (ret < 0) {
44727 err("firmware download failed at %d with %d",pos,ret);
44728 + kfree(reset);
44729 + kfree(hx);
44730 return ret;
44731 }
44732
44733 if (ret == 0) {
44734 /* restart the CPU */
44735 - reset = 0;
44736 - if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1) != 1) {
44737 + reset[0] = 0;
44738 + if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1) != 1) {
44739 err("could not restart the USB controller CPU.");
44740 ret = -EINVAL;
44741 }
44742 } else
44743 ret = -EIO;
44744
44745 + kfree(reset);
44746 + kfree(hx);
44747 +
44748 return ret;
44749 }
44750 EXPORT_SYMBOL(usb_cypress_load_firmware);
44751 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
44752 index ae0f56a..ec71784 100644
44753 --- a/drivers/media/usb/dvb-usb/dw2102.c
44754 +++ b/drivers/media/usb/dvb-usb/dw2102.c
44755 @@ -118,7 +118,7 @@ struct su3000_state {
44756
44757 struct s6x0_state {
44758 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
44759 -};
44760 +} __no_const;
44761
44762 /* debug */
44763 static int dvb_usb_dw2102_debug;
44764 diff --git a/drivers/media/usb/dvb-usb/technisat-usb2.c b/drivers/media/usb/dvb-usb/technisat-usb2.c
44765 index 98d24ae..bc22415 100644
44766 --- a/drivers/media/usb/dvb-usb/technisat-usb2.c
44767 +++ b/drivers/media/usb/dvb-usb/technisat-usb2.c
44768 @@ -87,8 +87,11 @@ struct technisat_usb2_state {
44769 static int technisat_usb2_i2c_access(struct usb_device *udev,
44770 u8 device_addr, u8 *tx, u8 txlen, u8 *rx, u8 rxlen)
44771 {
44772 - u8 b[64];
44773 - int ret, actual_length;
44774 + u8 *b = kmalloc(64, GFP_KERNEL);
44775 + int ret, actual_length, error = 0;
44776 +
44777 + if (b == NULL)
44778 + return -ENOMEM;
44779
44780 deb_i2c("i2c-access: %02x, tx: ", device_addr);
44781 debug_dump(tx, txlen, deb_i2c);
44782 @@ -121,7 +124,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
44783
44784 if (ret < 0) {
44785 err("i2c-error: out failed %02x = %d", device_addr, ret);
44786 - return -ENODEV;
44787 + error = -ENODEV;
44788 + goto out;
44789 }
44790
44791 ret = usb_bulk_msg(udev,
44792 @@ -129,7 +133,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
44793 b, 64, &actual_length, 1000);
44794 if (ret < 0) {
44795 err("i2c-error: in failed %02x = %d", device_addr, ret);
44796 - return -ENODEV;
44797 + error = -ENODEV;
44798 + goto out;
44799 }
44800
44801 if (b[0] != I2C_STATUS_OK) {
44802 @@ -137,8 +142,10 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
44803 /* handle tuner-i2c-nak */
44804 if (!(b[0] == I2C_STATUS_NAK &&
44805 device_addr == 0x60
44806 - /* && device_is_technisat_usb2 */))
44807 - return -ENODEV;
44808 + /* && device_is_technisat_usb2 */)) {
44809 + error = -ENODEV;
44810 + goto out;
44811 + }
44812 }
44813
44814 deb_i2c("status: %d, ", b[0]);
44815 @@ -152,7 +159,9 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
44816
44817 deb_i2c("\n");
44818
44819 - return 0;
44820 +out:
44821 + kfree(b);
44822 + return error;
44823 }
44824
44825 static int technisat_usb2_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
44826 @@ -224,14 +233,16 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
44827 {
44828 int ret;
44829
44830 - u8 led[8] = {
44831 - red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
44832 - 0
44833 - };
44834 + u8 *led = kzalloc(8, GFP_KERNEL);
44835 +
44836 + if (led == NULL)
44837 + return -ENOMEM;
44838
44839 if (disable_led_control && state != LED_OFF)
44840 return 0;
44841
44842 + led[0] = red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST;
44843 +
44844 switch (state) {
44845 case LED_ON:
44846 led[1] = 0x82;
44847 @@ -263,16 +274,22 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
44848 red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
44849 USB_TYPE_VENDOR | USB_DIR_OUT,
44850 0, 0,
44851 - led, sizeof(led), 500);
44852 + led, 8, 500);
44853
44854 mutex_unlock(&d->i2c_mutex);
44855 +
44856 + kfree(led);
44857 +
44858 return ret;
44859 }
44860
44861 static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 green)
44862 {
44863 int ret;
44864 - u8 b = 0;
44865 + u8 *b = kzalloc(1, GFP_KERNEL);
44866 +
44867 + if (b == NULL)
44868 + return -ENOMEM;
44869
44870 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
44871 return -EAGAIN;
44872 @@ -281,10 +298,12 @@ static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 gre
44873 SET_LED_TIMER_DIVIDER_VENDOR_REQUEST,
44874 USB_TYPE_VENDOR | USB_DIR_OUT,
44875 (red << 8) | green, 0,
44876 - &b, 1, 500);
44877 + b, 1, 500);
44878
44879 mutex_unlock(&d->i2c_mutex);
44880
44881 + kfree(b);
44882 +
44883 return ret;
44884 }
44885
44886 @@ -328,7 +347,7 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
44887 struct dvb_usb_device_description **desc, int *cold)
44888 {
44889 int ret;
44890 - u8 version[3];
44891 + u8 *version = kmalloc(3, GFP_KERNEL);
44892
44893 /* first select the interface */
44894 if (usb_set_interface(udev, 0, 1) != 0)
44895 @@ -338,11 +357,14 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
44896
44897 *cold = 0; /* by default do not download a firmware - just in case something is wrong */
44898
44899 + if (version == NULL)
44900 + return 0;
44901 +
44902 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
44903 GET_VERSION_INFO_VENDOR_REQUEST,
44904 USB_TYPE_VENDOR | USB_DIR_IN,
44905 0, 0,
44906 - version, sizeof(version), 500);
44907 + version, 3, 500);
44908
44909 if (ret < 0)
44910 *cold = 1;
44911 @@ -351,6 +373,8 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
44912 *cold = 0;
44913 }
44914
44915 + kfree(version);
44916 +
44917 return 0;
44918 }
44919
44920 @@ -591,10 +615,15 @@ static int technisat_usb2_frontend_attach(struct dvb_usb_adapter *a)
44921
44922 static int technisat_usb2_get_ir(struct dvb_usb_device *d)
44923 {
44924 - u8 buf[62], *b;
44925 + u8 *buf, *b;
44926 int ret;
44927 struct ir_raw_event ev;
44928
44929 + buf = kmalloc(62, GFP_KERNEL);
44930 +
44931 + if (buf == NULL)
44932 + return -ENOMEM;
44933 +
44934 buf[0] = GET_IR_DATA_VENDOR_REQUEST;
44935 buf[1] = 0x08;
44936 buf[2] = 0x8f;
44937 @@ -617,16 +646,20 @@ static int technisat_usb2_get_ir(struct dvb_usb_device *d)
44938 GET_IR_DATA_VENDOR_REQUEST,
44939 USB_TYPE_VENDOR | USB_DIR_IN,
44940 0x8080, 0,
44941 - buf, sizeof(buf), 500);
44942 + buf, 62, 500);
44943
44944 unlock:
44945 mutex_unlock(&d->i2c_mutex);
44946
44947 - if (ret < 0)
44948 + if (ret < 0) {
44949 + kfree(buf);
44950 return ret;
44951 + }
44952
44953 - if (ret == 1)
44954 + if (ret == 1) {
44955 + kfree(buf);
44956 return 0; /* no key pressed */
44957 + }
44958
44959 /* decoding */
44960 b = buf+1;
44961 @@ -653,6 +686,8 @@ unlock:
44962
44963 ir_raw_event_handle(d->rc_dev);
44964
44965 + kfree(buf);
44966 +
44967 return 1;
44968 }
44969
44970 diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44971 index 7e2411c..cef73ca 100644
44972 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44973 +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44974 @@ -328,7 +328,7 @@ struct v4l2_buffer32 {
44975 __u32 reserved;
44976 };
44977
44978 -static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44979 +static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44980 enum v4l2_memory memory)
44981 {
44982 void __user *up_pln;
44983 @@ -357,7 +357,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44984 return 0;
44985 }
44986
44987 -static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44988 +static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44989 enum v4l2_memory memory)
44990 {
44991 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
44992 @@ -427,7 +427,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44993 * by passing a very big num_planes value */
44994 uplane = compat_alloc_user_space(num_planes *
44995 sizeof(struct v4l2_plane));
44996 - kp->m.planes = uplane;
44997 + kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
44998
44999 while (--num_planes >= 0) {
45000 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
45001 @@ -498,7 +498,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
45002 if (num_planes == 0)
45003 return 0;
45004
45005 - uplane = kp->m.planes;
45006 + uplane = (struct v4l2_plane __force_user *)kp->m.planes;
45007 if (get_user(p, &up->m.planes))
45008 return -EFAULT;
45009 uplane32 = compat_ptr(p);
45010 @@ -552,7 +552,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
45011 get_user(kp->capability, &up->capability) ||
45012 get_user(kp->flags, &up->flags))
45013 return -EFAULT;
45014 - kp->base = compat_ptr(tmp);
45015 + kp->base = (void __force_kernel *)compat_ptr(tmp);
45016 get_v4l2_pix_format(&kp->fmt, &up->fmt);
45017 return 0;
45018 }
45019 @@ -658,7 +658,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
45020 n * sizeof(struct v4l2_ext_control32)))
45021 return -EFAULT;
45022 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
45023 - kp->controls = kcontrols;
45024 + kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
45025 while (--n >= 0) {
45026 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
45027 return -EFAULT;
45028 @@ -680,7 +680,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
45029 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
45030 {
45031 struct v4l2_ext_control32 __user *ucontrols;
45032 - struct v4l2_ext_control __user *kcontrols = kp->controls;
45033 + struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
45034 int n = kp->count;
45035 compat_caddr_t p;
45036
45037 @@ -774,7 +774,7 @@ static int put_v4l2_edid32(struct v4l2_edid *kp, struct v4l2_edid32 __user *up)
45038 put_user(kp->start_block, &up->start_block) ||
45039 put_user(kp->blocks, &up->blocks) ||
45040 put_user(tmp, &up->edid) ||
45041 - copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
45042 + copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
45043 return -EFAULT;
45044 return 0;
45045 }
45046 diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
45047 index 55c6832..a91c7a6 100644
45048 --- a/drivers/media/v4l2-core/v4l2-ctrls.c
45049 +++ b/drivers/media/v4l2-core/v4l2-ctrls.c
45050 @@ -1431,8 +1431,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
45051 return 0;
45052
45053 case V4L2_CTRL_TYPE_STRING:
45054 - len = strlen(c->string);
45055 - if (len < ctrl->minimum)
45056 + len = strlen_user(c->string);
45057 + if (!len || len < ctrl->minimum)
45058 return -ERANGE;
45059 if ((len - ctrl->minimum) % ctrl->step)
45060 return -ERANGE;
45061 diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
45062 index 02d1b63..5fd6b16 100644
45063 --- a/drivers/media/v4l2-core/v4l2-device.c
45064 +++ b/drivers/media/v4l2-core/v4l2-device.c
45065 @@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
45066 EXPORT_SYMBOL_GPL(v4l2_device_put);
45067
45068 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
45069 - atomic_t *instance)
45070 + atomic_unchecked_t *instance)
45071 {
45072 - int num = atomic_inc_return(instance) - 1;
45073 + int num = atomic_inc_return_unchecked(instance) - 1;
45074 int len = strlen(basename);
45075
45076 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
45077 diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
45078 index d9113cc..7de6ccc 100644
45079 --- a/drivers/media/v4l2-core/v4l2-ioctl.c
45080 +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
45081 @@ -2003,7 +2003,8 @@ struct v4l2_ioctl_info {
45082 struct file *file, void *fh, void *p);
45083 } u;
45084 void (*debug)(const void *arg, bool write_only);
45085 -};
45086 +} __do_const;
45087 +typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
45088
45089 /* This control needs a priority check */
45090 #define INFO_FL_PRIO (1 << 0)
45091 @@ -2186,7 +2187,7 @@ static long __video_do_ioctl(struct file *file,
45092 struct video_device *vfd = video_devdata(file);
45093 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
45094 bool write_only = false;
45095 - struct v4l2_ioctl_info default_info;
45096 + v4l2_ioctl_info_no_const default_info;
45097 const struct v4l2_ioctl_info *info;
45098 void *fh = file->private_data;
45099 struct v4l2_fh *vfh = NULL;
45100 @@ -2260,7 +2261,7 @@ done:
45101 }
45102
45103 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
45104 - void * __user *user_ptr, void ***kernel_ptr)
45105 + void __user **user_ptr, void ***kernel_ptr)
45106 {
45107 int ret = 0;
45108
45109 @@ -2276,7 +2277,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
45110 ret = -EINVAL;
45111 break;
45112 }
45113 - *user_ptr = (void __user *)buf->m.planes;
45114 + *user_ptr = (void __force_user *)buf->m.planes;
45115 *kernel_ptr = (void *)&buf->m.planes;
45116 *array_size = sizeof(struct v4l2_plane) * buf->length;
45117 ret = 1;
45118 @@ -2311,7 +2312,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
45119 ret = -EINVAL;
45120 break;
45121 }
45122 - *user_ptr = (void __user *)ctrls->controls;
45123 + *user_ptr = (void __force_user *)ctrls->controls;
45124 *kernel_ptr = (void *)&ctrls->controls;
45125 *array_size = sizeof(struct v4l2_ext_control)
45126 * ctrls->count;
45127 @@ -2412,7 +2413,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
45128 }
45129
45130 if (has_array_args) {
45131 - *kernel_ptr = user_ptr;
45132 + *kernel_ptr = (void __force_kernel *)user_ptr;
45133 if (copy_to_user(user_ptr, mbuf, array_size))
45134 err = -EFAULT;
45135 goto out_array_args;
45136 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
45137 index 570b18a..f880314 100644
45138 --- a/drivers/message/fusion/mptbase.c
45139 +++ b/drivers/message/fusion/mptbase.c
45140 @@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
45141 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
45142 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
45143
45144 +#ifdef CONFIG_GRKERNSEC_HIDESYM
45145 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
45146 +#else
45147 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
45148 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
45149 +#endif
45150 +
45151 /*
45152 * Rounding UP to nearest 4-kB boundary here...
45153 */
45154 @@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
45155 ioc->facts.GlobalCredits);
45156
45157 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
45158 +#ifdef CONFIG_GRKERNSEC_HIDESYM
45159 + NULL, NULL);
45160 +#else
45161 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
45162 +#endif
45163 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
45164 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
45165 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
45166 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
45167 index 00d339c..2ea899d 100644
45168 --- a/drivers/message/fusion/mptsas.c
45169 +++ b/drivers/message/fusion/mptsas.c
45170 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
45171 return 0;
45172 }
45173
45174 +static inline void
45175 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
45176 +{
45177 + if (phy_info->port_details) {
45178 + phy_info->port_details->rphy = rphy;
45179 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
45180 + ioc->name, rphy));
45181 + }
45182 +
45183 + if (rphy) {
45184 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
45185 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
45186 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
45187 + ioc->name, rphy, rphy->dev.release));
45188 + }
45189 +}
45190 +
45191 /* no mutex */
45192 static void
45193 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
45194 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
45195 return NULL;
45196 }
45197
45198 -static inline void
45199 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
45200 -{
45201 - if (phy_info->port_details) {
45202 - phy_info->port_details->rphy = rphy;
45203 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
45204 - ioc->name, rphy));
45205 - }
45206 -
45207 - if (rphy) {
45208 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
45209 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
45210 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
45211 - ioc->name, rphy, rphy->dev.release));
45212 - }
45213 -}
45214 -
45215 static inline struct sas_port *
45216 mptsas_get_port(struct mptsas_phyinfo *phy_info)
45217 {
45218 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
45219 index 727819c..ad74694 100644
45220 --- a/drivers/message/fusion/mptscsih.c
45221 +++ b/drivers/message/fusion/mptscsih.c
45222 @@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
45223
45224 h = shost_priv(SChost);
45225
45226 - if (h) {
45227 - if (h->info_kbuf == NULL)
45228 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
45229 - return h->info_kbuf;
45230 - h->info_kbuf[0] = '\0';
45231 + if (!h)
45232 + return NULL;
45233
45234 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
45235 - h->info_kbuf[size-1] = '\0';
45236 - }
45237 + if (h->info_kbuf == NULL)
45238 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
45239 + return h->info_kbuf;
45240 + h->info_kbuf[0] = '\0';
45241 +
45242 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
45243 + h->info_kbuf[size-1] = '\0';
45244
45245 return h->info_kbuf;
45246 }
45247 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
45248 index b7d87cd..3fb36da 100644
45249 --- a/drivers/message/i2o/i2o_proc.c
45250 +++ b/drivers/message/i2o/i2o_proc.c
45251 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
45252 "Array Controller Device"
45253 };
45254
45255 -static char *chtostr(char *tmp, u8 *chars, int n)
45256 -{
45257 - tmp[0] = 0;
45258 - return strncat(tmp, (char *)chars, n);
45259 -}
45260 -
45261 static int i2o_report_query_status(struct seq_file *seq, int block_status,
45262 char *group)
45263 {
45264 @@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
45265 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
45266 {
45267 struct i2o_controller *c = (struct i2o_controller *)seq->private;
45268 - static u32 work32[5];
45269 - static u8 *work8 = (u8 *) work32;
45270 - static u16 *work16 = (u16 *) work32;
45271 + u32 work32[5];
45272 + u8 *work8 = (u8 *) work32;
45273 + u16 *work16 = (u16 *) work32;
45274 int token;
45275 u32 hwcap;
45276
45277 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
45278 } *result;
45279
45280 i2o_exec_execute_ddm_table ddm_table;
45281 - char tmp[28 + 1];
45282
45283 result = kmalloc(sizeof(*result), GFP_KERNEL);
45284 if (!result)
45285 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
45286
45287 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
45288 seq_printf(seq, "%-#8x", ddm_table.module_id);
45289 - seq_printf(seq, "%-29s",
45290 - chtostr(tmp, ddm_table.module_name_version, 28));
45291 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
45292 seq_printf(seq, "%9d ", ddm_table.data_size);
45293 seq_printf(seq, "%8d", ddm_table.code_size);
45294
45295 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
45296
45297 i2o_driver_result_table *result;
45298 i2o_driver_store_table *dst;
45299 - char tmp[28 + 1];
45300
45301 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
45302 if (result == NULL)
45303 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
45304
45305 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
45306 seq_printf(seq, "%-#8x", dst->module_id);
45307 - seq_printf(seq, "%-29s",
45308 - chtostr(tmp, dst->module_name_version, 28));
45309 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
45310 + seq_printf(seq, "%-.28s", dst->module_name_version);
45311 + seq_printf(seq, "%-.8s", dst->date);
45312 seq_printf(seq, "%8d ", dst->module_size);
45313 seq_printf(seq, "%8d ", dst->mpb_size);
45314 seq_printf(seq, "0x%04x", dst->module_flags);
45315 @@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
45316 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
45317 {
45318 struct i2o_device *d = (struct i2o_device *)seq->private;
45319 - static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
45320 + u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
45321 // == (allow) 512d bytes (max)
45322 - static u16 *work16 = (u16 *) work32;
45323 + u16 *work16 = (u16 *) work32;
45324 int token;
45325 - char tmp[16 + 1];
45326
45327 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
45328
45329 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
45330 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
45331 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
45332 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
45333 - seq_printf(seq, "Vendor info : %s\n",
45334 - chtostr(tmp, (u8 *) (work32 + 2), 16));
45335 - seq_printf(seq, "Product info : %s\n",
45336 - chtostr(tmp, (u8 *) (work32 + 6), 16));
45337 - seq_printf(seq, "Description : %s\n",
45338 - chtostr(tmp, (u8 *) (work32 + 10), 16));
45339 - seq_printf(seq, "Product rev. : %s\n",
45340 - chtostr(tmp, (u8 *) (work32 + 14), 8));
45341 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
45342 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
45343 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
45344 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
45345
45346 seq_printf(seq, "Serial number : ");
45347 print_serial_number(seq, (u8 *) (work32 + 16),
45348 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
45349 u8 pad[256]; // allow up to 256 byte (max) serial number
45350 } result;
45351
45352 - char tmp[24 + 1];
45353 -
45354 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
45355
45356 if (token < 0) {
45357 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
45358 }
45359
45360 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
45361 - seq_printf(seq, "Module name : %s\n",
45362 - chtostr(tmp, result.module_name, 24));
45363 - seq_printf(seq, "Module revision : %s\n",
45364 - chtostr(tmp, result.module_rev, 8));
45365 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
45366 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
45367
45368 seq_printf(seq, "Serial number : ");
45369 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
45370 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45371 u8 instance_number[4];
45372 } result;
45373
45374 - char tmp[64 + 1];
45375 -
45376 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
45377
45378 if (token < 0) {
45379 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45380 return 0;
45381 }
45382
45383 - seq_printf(seq, "Device name : %s\n",
45384 - chtostr(tmp, result.device_name, 64));
45385 - seq_printf(seq, "Service name : %s\n",
45386 - chtostr(tmp, result.service_name, 64));
45387 - seq_printf(seq, "Physical name : %s\n",
45388 - chtostr(tmp, result.physical_location, 64));
45389 - seq_printf(seq, "Instance number : %s\n",
45390 - chtostr(tmp, result.instance_number, 4));
45391 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
45392 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
45393 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
45394 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
45395
45396 return 0;
45397 }
45398 @@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45399 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
45400 {
45401 struct i2o_device *d = (struct i2o_device *)seq->private;
45402 - static u32 work32[12];
45403 - static u16 *work16 = (u16 *) work32;
45404 - static u8 *work8 = (u8 *) work32;
45405 + u32 work32[12];
45406 + u16 *work16 = (u16 *) work32;
45407 + u8 *work8 = (u8 *) work32;
45408 int token;
45409
45410 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
45411 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
45412 index 92752fb..a7494f6 100644
45413 --- a/drivers/message/i2o/iop.c
45414 +++ b/drivers/message/i2o/iop.c
45415 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
45416
45417 spin_lock_irqsave(&c->context_list_lock, flags);
45418
45419 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
45420 - atomic_inc(&c->context_list_counter);
45421 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
45422 + atomic_inc_unchecked(&c->context_list_counter);
45423
45424 - entry->context = atomic_read(&c->context_list_counter);
45425 + entry->context = atomic_read_unchecked(&c->context_list_counter);
45426
45427 list_add(&entry->list, &c->context_list);
45428
45429 @@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(void)
45430
45431 #if BITS_PER_LONG == 64
45432 spin_lock_init(&c->context_list_lock);
45433 - atomic_set(&c->context_list_counter, 0);
45434 + atomic_set_unchecked(&c->context_list_counter, 0);
45435 INIT_LIST_HEAD(&c->context_list);
45436 #endif
45437
45438 diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
45439 index d1a22aa..d0f7bf7 100644
45440 --- a/drivers/mfd/ab8500-debugfs.c
45441 +++ b/drivers/mfd/ab8500-debugfs.c
45442 @@ -100,7 +100,7 @@ static int irq_last;
45443 static u32 *irq_count;
45444 static int num_irqs;
45445
45446 -static struct device_attribute **dev_attr;
45447 +static device_attribute_no_const **dev_attr;
45448 static char **event_name;
45449
45450 static u8 avg_sample = SAMPLE_16;
45451 diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
45452 index a83eed5..62a58a9 100644
45453 --- a/drivers/mfd/max8925-i2c.c
45454 +++ b/drivers/mfd/max8925-i2c.c
45455 @@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
45456 const struct i2c_device_id *id)
45457 {
45458 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
45459 - static struct max8925_chip *chip;
45460 + struct max8925_chip *chip;
45461 struct device_node *node = client->dev.of_node;
45462
45463 if (node && !pdata) {
45464 diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
45465 index 460a014..21d3061 100644
45466 --- a/drivers/mfd/tps65910.c
45467 +++ b/drivers/mfd/tps65910.c
45468 @@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
45469 struct tps65910_platform_data *pdata)
45470 {
45471 int ret = 0;
45472 - static struct regmap_irq_chip *tps6591x_irqs_chip;
45473 + struct regmap_irq_chip *tps6591x_irqs_chip;
45474
45475 if (!irq) {
45476 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
45477 diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
45478 index 596b1f6..5b6ab74 100644
45479 --- a/drivers/mfd/twl4030-irq.c
45480 +++ b/drivers/mfd/twl4030-irq.c
45481 @@ -34,6 +34,7 @@
45482 #include <linux/of.h>
45483 #include <linux/irqdomain.h>
45484 #include <linux/i2c/twl.h>
45485 +#include <asm/pgtable.h>
45486
45487 #include "twl-core.h"
45488
45489 @@ -725,10 +726,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
45490 * Install an irq handler for each of the SIH modules;
45491 * clone dummy irq_chip since PIH can't *do* anything
45492 */
45493 - twl4030_irq_chip = dummy_irq_chip;
45494 - twl4030_irq_chip.name = "twl4030";
45495 + pax_open_kernel();
45496 + memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
45497 + *(const char **)&twl4030_irq_chip.name = "twl4030";
45498
45499 - twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45500 + *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45501 + pax_close_kernel();
45502
45503 for (i = irq_base; i < irq_end; i++) {
45504 irq_set_chip_and_handler(i, &twl4030_irq_chip,
45505 diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
45506 index 464419b..64bae8d 100644
45507 --- a/drivers/misc/c2port/core.c
45508 +++ b/drivers/misc/c2port/core.c
45509 @@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
45510 goto error_idr_alloc;
45511 c2dev->id = ret;
45512
45513 - bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45514 + pax_open_kernel();
45515 + *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45516 + pax_close_kernel();
45517
45518 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
45519 "c2port%d", c2dev->id);
45520 diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
45521 index 3f2b625..945e179 100644
45522 --- a/drivers/misc/eeprom/sunxi_sid.c
45523 +++ b/drivers/misc/eeprom/sunxi_sid.c
45524 @@ -126,7 +126,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
45525
45526 platform_set_drvdata(pdev, sid_data);
45527
45528 - sid_bin_attr.size = sid_data->keysize;
45529 + pax_open_kernel();
45530 + *(size_t *)&sid_bin_attr.size = sid_data->keysize;
45531 + pax_close_kernel();
45532 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
45533 return -ENODEV;
45534
45535 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
45536 index 36f5d52..32311c3 100644
45537 --- a/drivers/misc/kgdbts.c
45538 +++ b/drivers/misc/kgdbts.c
45539 @@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
45540 char before[BREAK_INSTR_SIZE];
45541 char after[BREAK_INSTR_SIZE];
45542
45543 - probe_kernel_read(before, (char *)kgdbts_break_test,
45544 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
45545 BREAK_INSTR_SIZE);
45546 init_simple_test();
45547 ts.tst = plant_and_detach_test;
45548 @@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
45549 /* Activate test with initial breakpoint */
45550 if (!is_early)
45551 kgdb_breakpoint();
45552 - probe_kernel_read(after, (char *)kgdbts_break_test,
45553 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
45554 BREAK_INSTR_SIZE);
45555 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
45556 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
45557 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
45558 index 3ef4627..8d00486 100644
45559 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
45560 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
45561 @@ -497,7 +497,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
45562 * the lid is closed. This leads to interrupts as soon as a little move
45563 * is done.
45564 */
45565 - atomic_inc(&lis3->count);
45566 + atomic_inc_unchecked(&lis3->count);
45567
45568 wake_up_interruptible(&lis3->misc_wait);
45569 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
45570 @@ -583,7 +583,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
45571 if (lis3->pm_dev)
45572 pm_runtime_get_sync(lis3->pm_dev);
45573
45574 - atomic_set(&lis3->count, 0);
45575 + atomic_set_unchecked(&lis3->count, 0);
45576 return 0;
45577 }
45578
45579 @@ -615,7 +615,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
45580 add_wait_queue(&lis3->misc_wait, &wait);
45581 while (true) {
45582 set_current_state(TASK_INTERRUPTIBLE);
45583 - data = atomic_xchg(&lis3->count, 0);
45584 + data = atomic_xchg_unchecked(&lis3->count, 0);
45585 if (data)
45586 break;
45587
45588 @@ -656,7 +656,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
45589 struct lis3lv02d, miscdev);
45590
45591 poll_wait(file, &lis3->misc_wait, wait);
45592 - if (atomic_read(&lis3->count))
45593 + if (atomic_read_unchecked(&lis3->count))
45594 return POLLIN | POLLRDNORM;
45595 return 0;
45596 }
45597 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
45598 index c439c82..1f20f57 100644
45599 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
45600 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
45601 @@ -297,7 +297,7 @@ struct lis3lv02d {
45602 struct input_polled_dev *idev; /* input device */
45603 struct platform_device *pdev; /* platform device */
45604 struct regulator_bulk_data regulators[2];
45605 - atomic_t count; /* interrupt count after last read */
45606 + atomic_unchecked_t count; /* interrupt count after last read */
45607 union axis_conversion ac; /* hw -> logical axis */
45608 int mapped_btns[3];
45609
45610 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
45611 index 2f30bad..c4c13d0 100644
45612 --- a/drivers/misc/sgi-gru/gruhandles.c
45613 +++ b/drivers/misc/sgi-gru/gruhandles.c
45614 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
45615 unsigned long nsec;
45616
45617 nsec = CLKS2NSEC(clks);
45618 - atomic_long_inc(&mcs_op_statistics[op].count);
45619 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
45620 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
45621 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
45622 if (mcs_op_statistics[op].max < nsec)
45623 mcs_op_statistics[op].max = nsec;
45624 }
45625 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
45626 index 4f76359..cdfcb2e 100644
45627 --- a/drivers/misc/sgi-gru/gruprocfs.c
45628 +++ b/drivers/misc/sgi-gru/gruprocfs.c
45629 @@ -32,9 +32,9 @@
45630
45631 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
45632
45633 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
45634 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
45635 {
45636 - unsigned long val = atomic_long_read(v);
45637 + unsigned long val = atomic_long_read_unchecked(v);
45638
45639 seq_printf(s, "%16lu %s\n", val, id);
45640 }
45641 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
45642
45643 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
45644 for (op = 0; op < mcsop_last; op++) {
45645 - count = atomic_long_read(&mcs_op_statistics[op].count);
45646 - total = atomic_long_read(&mcs_op_statistics[op].total);
45647 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
45648 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
45649 max = mcs_op_statistics[op].max;
45650 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
45651 count ? total / count : 0, max);
45652 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
45653 index 5c3ce24..4915ccb 100644
45654 --- a/drivers/misc/sgi-gru/grutables.h
45655 +++ b/drivers/misc/sgi-gru/grutables.h
45656 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
45657 * GRU statistics.
45658 */
45659 struct gru_stats_s {
45660 - atomic_long_t vdata_alloc;
45661 - atomic_long_t vdata_free;
45662 - atomic_long_t gts_alloc;
45663 - atomic_long_t gts_free;
45664 - atomic_long_t gms_alloc;
45665 - atomic_long_t gms_free;
45666 - atomic_long_t gts_double_allocate;
45667 - atomic_long_t assign_context;
45668 - atomic_long_t assign_context_failed;
45669 - atomic_long_t free_context;
45670 - atomic_long_t load_user_context;
45671 - atomic_long_t load_kernel_context;
45672 - atomic_long_t lock_kernel_context;
45673 - atomic_long_t unlock_kernel_context;
45674 - atomic_long_t steal_user_context;
45675 - atomic_long_t steal_kernel_context;
45676 - atomic_long_t steal_context_failed;
45677 - atomic_long_t nopfn;
45678 - atomic_long_t asid_new;
45679 - atomic_long_t asid_next;
45680 - atomic_long_t asid_wrap;
45681 - atomic_long_t asid_reuse;
45682 - atomic_long_t intr;
45683 - atomic_long_t intr_cbr;
45684 - atomic_long_t intr_tfh;
45685 - atomic_long_t intr_spurious;
45686 - atomic_long_t intr_mm_lock_failed;
45687 - atomic_long_t call_os;
45688 - atomic_long_t call_os_wait_queue;
45689 - atomic_long_t user_flush_tlb;
45690 - atomic_long_t user_unload_context;
45691 - atomic_long_t user_exception;
45692 - atomic_long_t set_context_option;
45693 - atomic_long_t check_context_retarget_intr;
45694 - atomic_long_t check_context_unload;
45695 - atomic_long_t tlb_dropin;
45696 - atomic_long_t tlb_preload_page;
45697 - atomic_long_t tlb_dropin_fail_no_asid;
45698 - atomic_long_t tlb_dropin_fail_upm;
45699 - atomic_long_t tlb_dropin_fail_invalid;
45700 - atomic_long_t tlb_dropin_fail_range_active;
45701 - atomic_long_t tlb_dropin_fail_idle;
45702 - atomic_long_t tlb_dropin_fail_fmm;
45703 - atomic_long_t tlb_dropin_fail_no_exception;
45704 - atomic_long_t tfh_stale_on_fault;
45705 - atomic_long_t mmu_invalidate_range;
45706 - atomic_long_t mmu_invalidate_page;
45707 - atomic_long_t flush_tlb;
45708 - atomic_long_t flush_tlb_gru;
45709 - atomic_long_t flush_tlb_gru_tgh;
45710 - atomic_long_t flush_tlb_gru_zero_asid;
45711 + atomic_long_unchecked_t vdata_alloc;
45712 + atomic_long_unchecked_t vdata_free;
45713 + atomic_long_unchecked_t gts_alloc;
45714 + atomic_long_unchecked_t gts_free;
45715 + atomic_long_unchecked_t gms_alloc;
45716 + atomic_long_unchecked_t gms_free;
45717 + atomic_long_unchecked_t gts_double_allocate;
45718 + atomic_long_unchecked_t assign_context;
45719 + atomic_long_unchecked_t assign_context_failed;
45720 + atomic_long_unchecked_t free_context;
45721 + atomic_long_unchecked_t load_user_context;
45722 + atomic_long_unchecked_t load_kernel_context;
45723 + atomic_long_unchecked_t lock_kernel_context;
45724 + atomic_long_unchecked_t unlock_kernel_context;
45725 + atomic_long_unchecked_t steal_user_context;
45726 + atomic_long_unchecked_t steal_kernel_context;
45727 + atomic_long_unchecked_t steal_context_failed;
45728 + atomic_long_unchecked_t nopfn;
45729 + atomic_long_unchecked_t asid_new;
45730 + atomic_long_unchecked_t asid_next;
45731 + atomic_long_unchecked_t asid_wrap;
45732 + atomic_long_unchecked_t asid_reuse;
45733 + atomic_long_unchecked_t intr;
45734 + atomic_long_unchecked_t intr_cbr;
45735 + atomic_long_unchecked_t intr_tfh;
45736 + atomic_long_unchecked_t intr_spurious;
45737 + atomic_long_unchecked_t intr_mm_lock_failed;
45738 + atomic_long_unchecked_t call_os;
45739 + atomic_long_unchecked_t call_os_wait_queue;
45740 + atomic_long_unchecked_t user_flush_tlb;
45741 + atomic_long_unchecked_t user_unload_context;
45742 + atomic_long_unchecked_t user_exception;
45743 + atomic_long_unchecked_t set_context_option;
45744 + atomic_long_unchecked_t check_context_retarget_intr;
45745 + atomic_long_unchecked_t check_context_unload;
45746 + atomic_long_unchecked_t tlb_dropin;
45747 + atomic_long_unchecked_t tlb_preload_page;
45748 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
45749 + atomic_long_unchecked_t tlb_dropin_fail_upm;
45750 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
45751 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
45752 + atomic_long_unchecked_t tlb_dropin_fail_idle;
45753 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
45754 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
45755 + atomic_long_unchecked_t tfh_stale_on_fault;
45756 + atomic_long_unchecked_t mmu_invalidate_range;
45757 + atomic_long_unchecked_t mmu_invalidate_page;
45758 + atomic_long_unchecked_t flush_tlb;
45759 + atomic_long_unchecked_t flush_tlb_gru;
45760 + atomic_long_unchecked_t flush_tlb_gru_tgh;
45761 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
45762
45763 - atomic_long_t copy_gpa;
45764 - atomic_long_t read_gpa;
45765 + atomic_long_unchecked_t copy_gpa;
45766 + atomic_long_unchecked_t read_gpa;
45767
45768 - atomic_long_t mesq_receive;
45769 - atomic_long_t mesq_receive_none;
45770 - atomic_long_t mesq_send;
45771 - atomic_long_t mesq_send_failed;
45772 - atomic_long_t mesq_noop;
45773 - atomic_long_t mesq_send_unexpected_error;
45774 - atomic_long_t mesq_send_lb_overflow;
45775 - atomic_long_t mesq_send_qlimit_reached;
45776 - atomic_long_t mesq_send_amo_nacked;
45777 - atomic_long_t mesq_send_put_nacked;
45778 - atomic_long_t mesq_page_overflow;
45779 - atomic_long_t mesq_qf_locked;
45780 - atomic_long_t mesq_qf_noop_not_full;
45781 - atomic_long_t mesq_qf_switch_head_failed;
45782 - atomic_long_t mesq_qf_unexpected_error;
45783 - atomic_long_t mesq_noop_unexpected_error;
45784 - atomic_long_t mesq_noop_lb_overflow;
45785 - atomic_long_t mesq_noop_qlimit_reached;
45786 - atomic_long_t mesq_noop_amo_nacked;
45787 - atomic_long_t mesq_noop_put_nacked;
45788 - atomic_long_t mesq_noop_page_overflow;
45789 + atomic_long_unchecked_t mesq_receive;
45790 + atomic_long_unchecked_t mesq_receive_none;
45791 + atomic_long_unchecked_t mesq_send;
45792 + atomic_long_unchecked_t mesq_send_failed;
45793 + atomic_long_unchecked_t mesq_noop;
45794 + atomic_long_unchecked_t mesq_send_unexpected_error;
45795 + atomic_long_unchecked_t mesq_send_lb_overflow;
45796 + atomic_long_unchecked_t mesq_send_qlimit_reached;
45797 + atomic_long_unchecked_t mesq_send_amo_nacked;
45798 + atomic_long_unchecked_t mesq_send_put_nacked;
45799 + atomic_long_unchecked_t mesq_page_overflow;
45800 + atomic_long_unchecked_t mesq_qf_locked;
45801 + atomic_long_unchecked_t mesq_qf_noop_not_full;
45802 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
45803 + atomic_long_unchecked_t mesq_qf_unexpected_error;
45804 + atomic_long_unchecked_t mesq_noop_unexpected_error;
45805 + atomic_long_unchecked_t mesq_noop_lb_overflow;
45806 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
45807 + atomic_long_unchecked_t mesq_noop_amo_nacked;
45808 + atomic_long_unchecked_t mesq_noop_put_nacked;
45809 + atomic_long_unchecked_t mesq_noop_page_overflow;
45810
45811 };
45812
45813 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
45814 tghop_invalidate, mcsop_last};
45815
45816 struct mcs_op_statistic {
45817 - atomic_long_t count;
45818 - atomic_long_t total;
45819 + atomic_long_unchecked_t count;
45820 + atomic_long_unchecked_t total;
45821 unsigned long max;
45822 };
45823
45824 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
45825
45826 #define STAT(id) do { \
45827 if (gru_options & OPT_STATS) \
45828 - atomic_long_inc(&gru_stats.id); \
45829 + atomic_long_inc_unchecked(&gru_stats.id); \
45830 } while (0)
45831
45832 #ifdef CONFIG_SGI_GRU_DEBUG
45833 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
45834 index c862cd4..0d176fe 100644
45835 --- a/drivers/misc/sgi-xp/xp.h
45836 +++ b/drivers/misc/sgi-xp/xp.h
45837 @@ -288,7 +288,7 @@ struct xpc_interface {
45838 xpc_notify_func, void *);
45839 void (*received) (short, int, void *);
45840 enum xp_retval (*partid_to_nasids) (short, void *);
45841 -};
45842 +} __no_const;
45843
45844 extern struct xpc_interface xpc_interface;
45845
45846 diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
45847 index 01be66d..e3a0c7e 100644
45848 --- a/drivers/misc/sgi-xp/xp_main.c
45849 +++ b/drivers/misc/sgi-xp/xp_main.c
45850 @@ -78,13 +78,13 @@ xpc_notloaded(void)
45851 }
45852
45853 struct xpc_interface xpc_interface = {
45854 - (void (*)(int))xpc_notloaded,
45855 - (void (*)(int))xpc_notloaded,
45856 - (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45857 - (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45858 + .connect = (void (*)(int))xpc_notloaded,
45859 + .disconnect = (void (*)(int))xpc_notloaded,
45860 + .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45861 + .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45862 void *))xpc_notloaded,
45863 - (void (*)(short, int, void *))xpc_notloaded,
45864 - (enum xp_retval(*)(short, void *))xpc_notloaded
45865 + .received = (void (*)(short, int, void *))xpc_notloaded,
45866 + .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
45867 };
45868 EXPORT_SYMBOL_GPL(xpc_interface);
45869
45870 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
45871 index b94d5f7..7f494c5 100644
45872 --- a/drivers/misc/sgi-xp/xpc.h
45873 +++ b/drivers/misc/sgi-xp/xpc.h
45874 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
45875 void (*received_payload) (struct xpc_channel *, void *);
45876 void (*notify_senders_of_disconnect) (struct xpc_channel *);
45877 };
45878 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
45879
45880 /* struct xpc_partition act_state values (for XPC HB) */
45881
45882 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
45883 /* found in xpc_main.c */
45884 extern struct device *xpc_part;
45885 extern struct device *xpc_chan;
45886 -extern struct xpc_arch_operations xpc_arch_ops;
45887 +extern xpc_arch_operations_no_const xpc_arch_ops;
45888 extern int xpc_disengage_timelimit;
45889 extern int xpc_disengage_timedout;
45890 extern int xpc_activate_IRQ_rcvd;
45891 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
45892 index 82dc574..8539ab2 100644
45893 --- a/drivers/misc/sgi-xp/xpc_main.c
45894 +++ b/drivers/misc/sgi-xp/xpc_main.c
45895 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
45896 .notifier_call = xpc_system_die,
45897 };
45898
45899 -struct xpc_arch_operations xpc_arch_ops;
45900 +xpc_arch_operations_no_const xpc_arch_ops;
45901
45902 /*
45903 * Timer function to enforce the timelimit on the partition disengage.
45904 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
45905
45906 if (((die_args->trapnr == X86_TRAP_MF) ||
45907 (die_args->trapnr == X86_TRAP_XF)) &&
45908 - !user_mode_vm(die_args->regs))
45909 + !user_mode(die_args->regs))
45910 xpc_die_deactivate();
45911
45912 break;
45913 diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
45914 index 452782b..0c10e40 100644
45915 --- a/drivers/mmc/card/block.c
45916 +++ b/drivers/mmc/card/block.c
45917 @@ -574,7 +574,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
45918 if (idata->ic.postsleep_min_us)
45919 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
45920
45921 - if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
45922 + if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
45923 err = -EFAULT;
45924 goto cmd_rel_host;
45925 }
45926 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
45927 index f51b5ba..86614a7 100644
45928 --- a/drivers/mmc/core/mmc_ops.c
45929 +++ b/drivers/mmc/core/mmc_ops.c
45930 @@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
45931 void *data_buf;
45932 int is_on_stack;
45933
45934 - is_on_stack = object_is_on_stack(buf);
45935 + is_on_stack = object_starts_on_stack(buf);
45936 if (is_on_stack) {
45937 /*
45938 * dma onto stack is unsafe/nonportable, but callers to this
45939 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
45940 index 6834977..824ee1b 100644
45941 --- a/drivers/mmc/host/dw_mmc.h
45942 +++ b/drivers/mmc/host/dw_mmc.h
45943 @@ -259,5 +259,5 @@ struct dw_mci_drv_data {
45944 int (*parse_dt)(struct dw_mci *host);
45945 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
45946 struct dw_mci_tuning_data *tuning_data);
45947 -};
45948 +} __do_const;
45949 #endif /* _DW_MMC_H_ */
45950 diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
45951 index 771c60a..12cb615 100644
45952 --- a/drivers/mmc/host/mmci.c
45953 +++ b/drivers/mmc/host/mmci.c
45954 @@ -1570,7 +1570,9 @@ static int mmci_probe(struct amba_device *dev,
45955 mmc->caps2 = plat->capabilities2;
45956
45957 if (variant->busy_detect) {
45958 - mmci_ops.card_busy = mmci_card_busy;
45959 + pax_open_kernel();
45960 + *(void **)&mmci_ops.card_busy = mmci_card_busy;
45961 + pax_close_kernel();
45962 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
45963 mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
45964 mmc->max_busy_timeout = 0;
45965 diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
45966 index b841bb7..d82712f5 100644
45967 --- a/drivers/mmc/host/sdhci-esdhc-imx.c
45968 +++ b/drivers/mmc/host/sdhci-esdhc-imx.c
45969 @@ -1031,9 +1031,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
45970 host->mmc->caps |= MMC_CAP_1_8V_DDR;
45971 }
45972
45973 - if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
45974 - sdhci_esdhc_ops.platform_execute_tuning =
45975 + if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
45976 + pax_open_kernel();
45977 + *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
45978 esdhc_executing_tuning;
45979 + pax_close_kernel();
45980 + }
45981
45982 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
45983 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
45984 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
45985 index d61eb5a..88c0f5d 100644
45986 --- a/drivers/mmc/host/sdhci-s3c.c
45987 +++ b/drivers/mmc/host/sdhci-s3c.c
45988 @@ -657,9 +657,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
45989 * we can use overriding functions instead of default.
45990 */
45991 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
45992 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45993 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45994 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45995 + pax_open_kernel();
45996 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45997 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45998 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45999 + pax_close_kernel();
46000 }
46001
46002 /* It supports additional host capabilities if needed */
46003 diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
46004 index 6293855..3415551 100644
46005 --- a/drivers/mtd/chips/cfi_cmdset_0020.c
46006 +++ b/drivers/mtd/chips/cfi_cmdset_0020.c
46007 @@ -666,7 +666,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
46008 size_t totlen = 0, thislen;
46009 int ret = 0;
46010 size_t buflen = 0;
46011 - static char *buffer;
46012 + char *buffer;
46013
46014 if (!ECCBUF_SIZE) {
46015 /* We should fall back to a general writev implementation.
46016 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
46017 index c07cd57..61c4fbd 100644
46018 --- a/drivers/mtd/nand/denali.c
46019 +++ b/drivers/mtd/nand/denali.c
46020 @@ -24,6 +24,7 @@
46021 #include <linux/slab.h>
46022 #include <linux/mtd/mtd.h>
46023 #include <linux/module.h>
46024 +#include <linux/slab.h>
46025
46026 #include "denali.h"
46027
46028 diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
46029 index bb77f75..47539b1 100644
46030 --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
46031 +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
46032 @@ -370,7 +370,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
46033
46034 /* first try to map the upper buffer directly */
46035 if (virt_addr_valid(this->upper_buf) &&
46036 - !object_is_on_stack(this->upper_buf)) {
46037 + !object_starts_on_stack(this->upper_buf)) {
46038 sg_init_one(sgl, this->upper_buf, this->upper_len);
46039 ret = dma_map_sg(this->dev, sgl, 1, dr);
46040 if (ret == 0)
46041 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
46042 index 51b9d6a..52af9a7 100644
46043 --- a/drivers/mtd/nftlmount.c
46044 +++ b/drivers/mtd/nftlmount.c
46045 @@ -24,6 +24,7 @@
46046 #include <asm/errno.h>
46047 #include <linux/delay.h>
46048 #include <linux/slab.h>
46049 +#include <linux/sched.h>
46050 #include <linux/mtd/mtd.h>
46051 #include <linux/mtd/nand.h>
46052 #include <linux/mtd/nftl.h>
46053 diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
46054 index cf49c22..971b133 100644
46055 --- a/drivers/mtd/sm_ftl.c
46056 +++ b/drivers/mtd/sm_ftl.c
46057 @@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
46058 #define SM_CIS_VENDOR_OFFSET 0x59
46059 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
46060 {
46061 - struct attribute_group *attr_group;
46062 + attribute_group_no_const *attr_group;
46063 struct attribute **attributes;
46064 struct sm_sysfs_attribute *vendor_attribute;
46065 char *vendor;
46066 diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
46067 index f847e16..fc8dbe9 100644
46068 --- a/drivers/net/bonding/bond_netlink.c
46069 +++ b/drivers/net/bonding/bond_netlink.c
46070 @@ -542,7 +542,7 @@ nla_put_failure:
46071 return -EMSGSIZE;
46072 }
46073
46074 -struct rtnl_link_ops bond_link_ops __read_mostly = {
46075 +struct rtnl_link_ops bond_link_ops = {
46076 .kind = "bond",
46077 .priv_size = sizeof(struct bonding),
46078 .setup = bond_setup,
46079 diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
46080 index 9e7d95d..d447b88 100644
46081 --- a/drivers/net/can/Kconfig
46082 +++ b/drivers/net/can/Kconfig
46083 @@ -104,7 +104,7 @@ config CAN_JANZ_ICAN3
46084
46085 config CAN_FLEXCAN
46086 tristate "Support for Freescale FLEXCAN based chips"
46087 - depends on ARM || PPC
46088 + depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
46089 ---help---
46090 Say Y here if you want to support for Freescale FlexCAN.
46091
46092 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
46093 index 455d4c3..3353ee7 100644
46094 --- a/drivers/net/ethernet/8390/ax88796.c
46095 +++ b/drivers/net/ethernet/8390/ax88796.c
46096 @@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
46097 if (ax->plat->reg_offsets)
46098 ei_local->reg_offset = ax->plat->reg_offsets;
46099 else {
46100 + resource_size_t _mem_size = mem_size;
46101 + do_div(_mem_size, 0x18);
46102 ei_local->reg_offset = ax->reg_offsets;
46103 for (ret = 0; ret < 0x18; ret++)
46104 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
46105 + ax->reg_offsets[ret] = _mem_size * ret;
46106 }
46107
46108 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
46109 diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
46110 index 7330681..7e9e463 100644
46111 --- a/drivers/net/ethernet/altera/altera_tse_main.c
46112 +++ b/drivers/net/ethernet/altera/altera_tse_main.c
46113 @@ -1182,7 +1182,7 @@ static int tse_shutdown(struct net_device *dev)
46114 return 0;
46115 }
46116
46117 -static struct net_device_ops altera_tse_netdev_ops = {
46118 +static net_device_ops_no_const altera_tse_netdev_ops __read_only = {
46119 .ndo_open = tse_open,
46120 .ndo_stop = tse_shutdown,
46121 .ndo_start_xmit = tse_start_xmit,
46122 @@ -1439,11 +1439,13 @@ static int altera_tse_probe(struct platform_device *pdev)
46123 ndev->netdev_ops = &altera_tse_netdev_ops;
46124 altera_tse_set_ethtool_ops(ndev);
46125
46126 + pax_open_kernel();
46127 altera_tse_netdev_ops.ndo_set_rx_mode = tse_set_rx_mode;
46128
46129 if (priv->hash_filter)
46130 altera_tse_netdev_ops.ndo_set_rx_mode =
46131 tse_set_rx_mode_hashfilter;
46132 + pax_close_kernel();
46133
46134 /* Scatter/gather IO is not supported,
46135 * so it is turned off
46136 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
46137 index 3448cc0..67b2dc4 100644
46138 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
46139 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
46140 @@ -1058,7 +1058,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
46141 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
46142 {
46143 /* RX_MODE controlling object */
46144 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
46145 + bnx2x_init_rx_mode_obj(bp);
46146
46147 /* multicast configuration controlling object */
46148 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
46149 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
46150 index 31297266..944cf6e 100644
46151 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
46152 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
46153 @@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
46154 return rc;
46155 }
46156
46157 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
46158 - struct bnx2x_rx_mode_obj *o)
46159 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
46160 {
46161 if (CHIP_IS_E1x(bp)) {
46162 - o->wait_comp = bnx2x_empty_rx_mode_wait;
46163 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
46164 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
46165 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
46166 } else {
46167 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
46168 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
46169 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
46170 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
46171 }
46172 }
46173
46174 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
46175 index 80f6c79..fb7d12d 100644
46176 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
46177 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
46178 @@ -1340,8 +1340,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
46179
46180 /********************* RX MODE ****************/
46181
46182 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
46183 - struct bnx2x_rx_mode_obj *o);
46184 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
46185
46186 /**
46187 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
46188 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.h
46189 index 6929adb..cc68830 100644
46190 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.h
46191 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.h
46192 @@ -571,7 +571,7 @@ static inline void __iomem *bnx2x_vf_doorbells(struct bnx2x *bp)
46193 return NULL;
46194 }
46195
46196 -static inline void bnx2x_vf_pci_dealloc(struct bnx2 *bp) {return 0; }
46197 +static inline void bnx2x_vf_pci_dealloc(struct bnx2x *bp) { }
46198 static inline int bnx2x_vf_pci_alloc(struct bnx2x *bp) {return 0; }
46199 static inline void bnx2x_pf_set_vfs_vlan(struct bnx2x *bp) {}
46200 static inline int bnx2x_sriov_configure(struct pci_dev *dev, int num_vfs) {return 0; }
46201 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
46202 index 04321e5..b51cdc4 100644
46203 --- a/drivers/net/ethernet/broadcom/tg3.h
46204 +++ b/drivers/net/ethernet/broadcom/tg3.h
46205 @@ -150,6 +150,7 @@
46206 #define CHIPREV_ID_5750_A0 0x4000
46207 #define CHIPREV_ID_5750_A1 0x4001
46208 #define CHIPREV_ID_5750_A3 0x4003
46209 +#define CHIPREV_ID_5750_C1 0x4201
46210 #define CHIPREV_ID_5750_C2 0x4202
46211 #define CHIPREV_ID_5752_A0_HW 0x5000
46212 #define CHIPREV_ID_5752_A0 0x6000
46213 diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
46214 index 13f9636..228040f 100644
46215 --- a/drivers/net/ethernet/brocade/bna/bna_enet.c
46216 +++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
46217 @@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
46218 }
46219
46220 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
46221 - bna_cb_ioceth_enable,
46222 - bna_cb_ioceth_disable,
46223 - bna_cb_ioceth_hbfail,
46224 - bna_cb_ioceth_reset
46225 + .enable_cbfn = bna_cb_ioceth_enable,
46226 + .disable_cbfn = bna_cb_ioceth_disable,
46227 + .hbfail_cbfn = bna_cb_ioceth_hbfail,
46228 + .reset_cbfn = bna_cb_ioceth_reset
46229 };
46230
46231 static void bna_attr_init(struct bna_ioceth *ioceth)
46232 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
46233 index 8cffcdf..aadf043 100644
46234 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
46235 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
46236 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
46237 */
46238 struct l2t_skb_cb {
46239 arp_failure_handler_func arp_failure_handler;
46240 -};
46241 +} __no_const;
46242
46243 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
46244
46245 diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
46246 index 24e16e3..bfe6ef2 100644
46247 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
46248 +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
46249 @@ -2139,7 +2139,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
46250
46251 int i;
46252 struct adapter *ap = netdev2adap(dev);
46253 - static const unsigned int *reg_ranges;
46254 + const unsigned int *reg_ranges;
46255 int arr_size = 0, buf_size = 0;
46256
46257 if (is_t4(ap->params.chip)) {
46258 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
46259 index c05b66d..ed69872 100644
46260 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
46261 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
46262 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
46263 for (i=0; i<ETH_ALEN; i++) {
46264 tmp.addr[i] = dev->dev_addr[i];
46265 }
46266 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
46267 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
46268 break;
46269
46270 case DE4X5_SET_HWADDR: /* Set the hardware address */
46271 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
46272 spin_lock_irqsave(&lp->lock, flags);
46273 memcpy(&statbuf, &lp->pktStats, ioc->len);
46274 spin_unlock_irqrestore(&lp->lock, flags);
46275 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
46276 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
46277 return -EFAULT;
46278 break;
46279 }
46280 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
46281 index 2b5ab7c..20e2e7f 100644
46282 --- a/drivers/net/ethernet/emulex/benet/be_main.c
46283 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
46284 @@ -535,7 +535,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
46285
46286 if (wrapped)
46287 newacc += 65536;
46288 - ACCESS_ONCE(*acc) = newacc;
46289 + ACCESS_ONCE_RW(*acc) = newacc;
46290 }
46291
46292 static void populate_erx_stats(struct be_adapter *adapter,
46293 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
46294 index 68069ea..c4484f6 100644
46295 --- a/drivers/net/ethernet/faraday/ftgmac100.c
46296 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
46297 @@ -30,6 +30,8 @@
46298 #include <linux/netdevice.h>
46299 #include <linux/phy.h>
46300 #include <linux/platform_device.h>
46301 +#include <linux/interrupt.h>
46302 +#include <linux/irqreturn.h>
46303 #include <net/ip.h>
46304
46305 #include "ftgmac100.h"
46306 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
46307 index 8be5b40..081bc1b 100644
46308 --- a/drivers/net/ethernet/faraday/ftmac100.c
46309 +++ b/drivers/net/ethernet/faraday/ftmac100.c
46310 @@ -31,6 +31,8 @@
46311 #include <linux/module.h>
46312 #include <linux/netdevice.h>
46313 #include <linux/platform_device.h>
46314 +#include <linux/interrupt.h>
46315 +#include <linux/irqreturn.h>
46316
46317 #include "ftmac100.h"
46318
46319 diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46320 index e61e637..9117795 100644
46321 --- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46322 +++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46323 @@ -436,7 +436,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
46324 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
46325
46326 /* Update the base adjustement value. */
46327 - ACCESS_ONCE(pf->ptp_base_adj) = incval;
46328 + ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
46329 smp_mb(); /* Force the above update. */
46330 }
46331
46332 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46333 index 8902ae6..e7bcdce 100644
46334 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46335 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46336 @@ -771,7 +771,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
46337 }
46338
46339 /* update the base incval used to calculate frequency adjustment */
46340 - ACCESS_ONCE(adapter->base_incval) = incval;
46341 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
46342 smp_mb();
46343
46344 /* need lock to prevent incorrect read while modifying cyclecounter */
46345 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
46346 index 089b713..28d87ae 100644
46347 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
46348 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
46349 @@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
46350 struct __vxge_hw_fifo *fifo;
46351 struct vxge_hw_fifo_config *config;
46352 u32 txdl_size, txdl_per_memblock;
46353 - struct vxge_hw_mempool_cbs fifo_mp_callback;
46354 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
46355 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
46356 + };
46357 +
46358 struct __vxge_hw_virtualpath *vpath;
46359
46360 if ((vp == NULL) || (attr == NULL)) {
46361 @@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
46362 goto exit;
46363 }
46364
46365 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
46366 -
46367 fifo->mempool =
46368 __vxge_hw_mempool_create(vpath->hldev,
46369 fifo->config->memblock_size,
46370 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46371 index ba20c72..f30c0fe 100644
46372 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46373 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46374 @@ -2176,7 +2176,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
46375 max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
46376 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
46377 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
46378 - adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
46379 + pax_open_kernel();
46380 + *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
46381 + pax_close_kernel();
46382 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46383 max_sds_rings = QLCNIC_MAX_SDS_RINGS;
46384 max_tx_rings = QLCNIC_MAX_TX_RINGS;
46385 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46386 index be7d7a6..a8983f8 100644
46387 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46388 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46389 @@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
46390 case QLCNIC_NON_PRIV_FUNC:
46391 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
46392 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46393 - nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
46394 + pax_open_kernel();
46395 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
46396 + pax_close_kernel();
46397 break;
46398 case QLCNIC_PRIV_FUNC:
46399 ahw->op_mode = QLCNIC_PRIV_FUNC;
46400 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
46401 - nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
46402 + pax_open_kernel();
46403 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
46404 + pax_close_kernel();
46405 break;
46406 case QLCNIC_MGMT_FUNC:
46407 ahw->op_mode = QLCNIC_MGMT_FUNC;
46408 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46409 - nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
46410 + pax_open_kernel();
46411 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
46412 + pax_close_kernel();
46413 break;
46414 default:
46415 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
46416 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46417 index 37b979b..50f5b95 100644
46418 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46419 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46420 @@ -1217,7 +1217,7 @@ flash_temp:
46421 int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
46422 {
46423 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
46424 - static const struct qlcnic_dump_operations *fw_dump_ops;
46425 + const struct qlcnic_dump_operations *fw_dump_ops;
46426 struct qlcnic_83xx_dump_template_hdr *hdr_83xx;
46427 u32 entry_offset, dump, no_entries, buf_offset = 0;
46428 int i, k, ops_cnt, ops_index, dump_size = 0;
46429 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
46430 index aa1c079..2b1a3e8 100644
46431 --- a/drivers/net/ethernet/realtek/r8169.c
46432 +++ b/drivers/net/ethernet/realtek/r8169.c
46433 @@ -758,22 +758,22 @@ struct rtl8169_private {
46434 struct mdio_ops {
46435 void (*write)(struct rtl8169_private *, int, int);
46436 int (*read)(struct rtl8169_private *, int);
46437 - } mdio_ops;
46438 + } __no_const mdio_ops;
46439
46440 struct pll_power_ops {
46441 void (*down)(struct rtl8169_private *);
46442 void (*up)(struct rtl8169_private *);
46443 - } pll_power_ops;
46444 + } __no_const pll_power_ops;
46445
46446 struct jumbo_ops {
46447 void (*enable)(struct rtl8169_private *);
46448 void (*disable)(struct rtl8169_private *);
46449 - } jumbo_ops;
46450 + } __no_const jumbo_ops;
46451
46452 struct csi_ops {
46453 void (*write)(struct rtl8169_private *, int, int);
46454 u32 (*read)(struct rtl8169_private *, int);
46455 - } csi_ops;
46456 + } __no_const csi_ops;
46457
46458 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
46459 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
46460 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
46461 index 6b861e3..204ac86 100644
46462 --- a/drivers/net/ethernet/sfc/ptp.c
46463 +++ b/drivers/net/ethernet/sfc/ptp.c
46464 @@ -822,7 +822,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
46465 ptp->start.dma_addr);
46466
46467 /* Clear flag that signals MC ready */
46468 - ACCESS_ONCE(*start) = 0;
46469 + ACCESS_ONCE_RW(*start) = 0;
46470 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
46471 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
46472 EFX_BUG_ON_PARANOID(rc);
46473 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46474 index 50617c5..b13724c 100644
46475 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46476 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46477 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
46478
46479 writel(value, ioaddr + MMC_CNTRL);
46480
46481 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46482 - MMC_CNTRL, value);
46483 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46484 +// MMC_CNTRL, value);
46485 }
46486
46487 /* To mask all all interrupts.*/
46488 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
46489 index d18f711d..5755800 100644
46490 --- a/drivers/net/hyperv/hyperv_net.h
46491 +++ b/drivers/net/hyperv/hyperv_net.h
46492 @@ -101,7 +101,7 @@ struct rndis_device {
46493
46494 enum rndis_device_state state;
46495 bool link_state;
46496 - atomic_t new_req_id;
46497 + atomic_unchecked_t new_req_id;
46498
46499 spinlock_t request_lock;
46500 struct list_head req_list;
46501 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
46502 index 143a98c..d54fbaa 100644
46503 --- a/drivers/net/hyperv/rndis_filter.c
46504 +++ b/drivers/net/hyperv/rndis_filter.c
46505 @@ -100,7 +100,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
46506 * template
46507 */
46508 set = &rndis_msg->msg.set_req;
46509 - set->req_id = atomic_inc_return(&dev->new_req_id);
46510 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46511
46512 /* Add to the request list */
46513 spin_lock_irqsave(&dev->request_lock, flags);
46514 @@ -834,7 +834,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
46515
46516 /* Setup the rndis set */
46517 halt = &request->request_msg.msg.halt_req;
46518 - halt->req_id = atomic_inc_return(&dev->new_req_id);
46519 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46520
46521 /* Ignore return since this msg is optional. */
46522 rndis_filter_send_request(dev, request);
46523 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
46524 index 78f18be..1d19c62 100644
46525 --- a/drivers/net/ieee802154/fakehard.c
46526 +++ b/drivers/net/ieee802154/fakehard.c
46527 @@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
46528 phy->transmit_power = 0xbf;
46529
46530 dev->netdev_ops = &fake_ops;
46531 - dev->ml_priv = &fake_mlme;
46532 + dev->ml_priv = (void *)&fake_mlme;
46533
46534 priv = netdev_priv(dev);
46535 priv->phy = phy;
46536 diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
46537 index d650b91..7717c68 100644
46538 --- a/drivers/net/macvlan.c
46539 +++ b/drivers/net/macvlan.c
46540 @@ -985,13 +985,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
46541 int macvlan_link_register(struct rtnl_link_ops *ops)
46542 {
46543 /* common fields */
46544 - ops->priv_size = sizeof(struct macvlan_dev);
46545 - ops->validate = macvlan_validate;
46546 - ops->maxtype = IFLA_MACVLAN_MAX;
46547 - ops->policy = macvlan_policy;
46548 - ops->changelink = macvlan_changelink;
46549 - ops->get_size = macvlan_get_size;
46550 - ops->fill_info = macvlan_fill_info;
46551 + pax_open_kernel();
46552 + *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
46553 + *(void **)&ops->validate = macvlan_validate;
46554 + *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
46555 + *(const void **)&ops->policy = macvlan_policy;
46556 + *(void **)&ops->changelink = macvlan_changelink;
46557 + *(void **)&ops->get_size = macvlan_get_size;
46558 + *(void **)&ops->fill_info = macvlan_fill_info;
46559 + pax_close_kernel();
46560
46561 return rtnl_link_register(ops);
46562 };
46563 @@ -1045,7 +1047,7 @@ static int macvlan_device_event(struct notifier_block *unused,
46564 return NOTIFY_DONE;
46565 }
46566
46567 -static struct notifier_block macvlan_notifier_block __read_mostly = {
46568 +static struct notifier_block macvlan_notifier_block = {
46569 .notifier_call = macvlan_device_event,
46570 };
46571
46572 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
46573 index 3381c4f..dea5fd5 100644
46574 --- a/drivers/net/macvtap.c
46575 +++ b/drivers/net/macvtap.c
46576 @@ -1020,7 +1020,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
46577 }
46578
46579 ret = 0;
46580 - if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46581 + if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46582 put_user(q->flags, &ifr->ifr_flags))
46583 ret = -EFAULT;
46584 macvtap_put_vlan(vlan);
46585 @@ -1190,7 +1190,7 @@ static int macvtap_device_event(struct notifier_block *unused,
46586 return NOTIFY_DONE;
46587 }
46588
46589 -static struct notifier_block macvtap_notifier_block __read_mostly = {
46590 +static struct notifier_block macvtap_notifier_block = {
46591 .notifier_call = macvtap_device_event,
46592 };
46593
46594 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
46595 index 3c41a83..5fe2d7f 100644
46596 --- a/drivers/net/ppp/ppp_generic.c
46597 +++ b/drivers/net/ppp/ppp_generic.c
46598 @@ -1016,7 +1016,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46599 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
46600 struct ppp_stats stats;
46601 struct ppp_comp_stats cstats;
46602 - char *vers;
46603
46604 switch (cmd) {
46605 case SIOCGPPPSTATS:
46606 @@ -1038,8 +1037,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46607 break;
46608
46609 case SIOCGPPPVER:
46610 - vers = PPP_VERSION;
46611 - if (copy_to_user(addr, vers, strlen(vers) + 1))
46612 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
46613 break;
46614 err = 0;
46615 break;
46616 diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
46617 index 1252d9c..80e660b 100644
46618 --- a/drivers/net/slip/slhc.c
46619 +++ b/drivers/net/slip/slhc.c
46620 @@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
46621 register struct tcphdr *thp;
46622 register struct iphdr *ip;
46623 register struct cstate *cs;
46624 - int len, hdrlen;
46625 + long len, hdrlen;
46626 unsigned char *cp = icp;
46627
46628 /* We've got a compressed packet; read the change byte */
46629 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
46630 index ce4989b..b40b328 100644
46631 --- a/drivers/net/team/team.c
46632 +++ b/drivers/net/team/team.c
46633 @@ -2868,7 +2868,7 @@ static int team_device_event(struct notifier_block *unused,
46634 return NOTIFY_DONE;
46635 }
46636
46637 -static struct notifier_block team_notifier_block __read_mostly = {
46638 +static struct notifier_block team_notifier_block = {
46639 .notifier_call = team_device_event,
46640 };
46641
46642 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
46643 index ee328ba..c4a0041 100644
46644 --- a/drivers/net/tun.c
46645 +++ b/drivers/net/tun.c
46646 @@ -1876,7 +1876,7 @@ unlock:
46647 }
46648
46649 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46650 - unsigned long arg, int ifreq_len)
46651 + unsigned long arg, size_t ifreq_len)
46652 {
46653 struct tun_file *tfile = file->private_data;
46654 struct tun_struct *tun;
46655 @@ -1889,6 +1889,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46656 unsigned int ifindex;
46657 int ret;
46658
46659 + if (ifreq_len > sizeof ifr)
46660 + return -EFAULT;
46661 +
46662 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
46663 if (copy_from_user(&ifr, argp, ifreq_len))
46664 return -EFAULT;
46665 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
46666 index 660bd5e..ac59452 100644
46667 --- a/drivers/net/usb/hso.c
46668 +++ b/drivers/net/usb/hso.c
46669 @@ -71,7 +71,7 @@
46670 #include <asm/byteorder.h>
46671 #include <linux/serial_core.h>
46672 #include <linux/serial.h>
46673 -
46674 +#include <asm/local.h>
46675
46676 #define MOD_AUTHOR "Option Wireless"
46677 #define MOD_DESCRIPTION "USB High Speed Option driver"
46678 @@ -1179,7 +1179,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
46679 struct urb *urb;
46680
46681 urb = serial->rx_urb[0];
46682 - if (serial->port.count > 0) {
46683 + if (atomic_read(&serial->port.count) > 0) {
46684 count = put_rxbuf_data(urb, serial);
46685 if (count == -1)
46686 return;
46687 @@ -1217,7 +1217,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
46688 DUMP1(urb->transfer_buffer, urb->actual_length);
46689
46690 /* Anyone listening? */
46691 - if (serial->port.count == 0)
46692 + if (atomic_read(&serial->port.count) == 0)
46693 return;
46694
46695 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
46696 @@ -1287,8 +1287,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46697 tty_port_tty_set(&serial->port, tty);
46698
46699 /* check for port already opened, if not set the termios */
46700 - serial->port.count++;
46701 - if (serial->port.count == 1) {
46702 + if (atomic_inc_return(&serial->port.count) == 1) {
46703 serial->rx_state = RX_IDLE;
46704 /* Force default termio settings */
46705 _hso_serial_set_termios(tty, NULL);
46706 @@ -1300,7 +1299,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46707 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
46708 if (result) {
46709 hso_stop_serial_device(serial->parent);
46710 - serial->port.count--;
46711 + atomic_dec(&serial->port.count);
46712 kref_put(&serial->parent->ref, hso_serial_ref_free);
46713 }
46714 } else {
46715 @@ -1337,10 +1336,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
46716
46717 /* reset the rts and dtr */
46718 /* do the actual close */
46719 - serial->port.count--;
46720 + atomic_dec(&serial->port.count);
46721
46722 - if (serial->port.count <= 0) {
46723 - serial->port.count = 0;
46724 + if (atomic_read(&serial->port.count) <= 0) {
46725 + atomic_set(&serial->port.count, 0);
46726 tty_port_tty_set(&serial->port, NULL);
46727 if (!usb_gone)
46728 hso_stop_serial_device(serial->parent);
46729 @@ -1416,7 +1415,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
46730
46731 /* the actual setup */
46732 spin_lock_irqsave(&serial->serial_lock, flags);
46733 - if (serial->port.count)
46734 + if (atomic_read(&serial->port.count))
46735 _hso_serial_set_termios(tty, old);
46736 else
46737 tty->termios = *old;
46738 @@ -1885,7 +1884,7 @@ static void intr_callback(struct urb *urb)
46739 D1("Pending read interrupt on port %d\n", i);
46740 spin_lock(&serial->serial_lock);
46741 if (serial->rx_state == RX_IDLE &&
46742 - serial->port.count > 0) {
46743 + atomic_read(&serial->port.count) > 0) {
46744 /* Setup and send a ctrl req read on
46745 * port i */
46746 if (!serial->rx_urb_filled[0]) {
46747 @@ -3061,7 +3060,7 @@ static int hso_resume(struct usb_interface *iface)
46748 /* Start all serial ports */
46749 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
46750 if (serial_table[i] && (serial_table[i]->interface == iface)) {
46751 - if (dev2ser(serial_table[i])->port.count) {
46752 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
46753 result =
46754 hso_start_serial_device(serial_table[i], GFP_NOIO);
46755 hso_kick_transmit(dev2ser(serial_table[i]));
46756 diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
46757 index d2c0070..3c3da43 100644
46758 --- a/drivers/net/usb/r8152.c
46759 +++ b/drivers/net/usb/r8152.c
46760 @@ -567,7 +567,7 @@ struct r8152 {
46761 void (*up)(struct r8152 *);
46762 void (*down)(struct r8152 *);
46763 void (*unload)(struct r8152 *);
46764 - } rtl_ops;
46765 + } __no_const rtl_ops;
46766
46767 int intr_interval;
46768 u32 saved_wolopts;
46769 diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
46770 index a2515887..6d13233 100644
46771 --- a/drivers/net/usb/sierra_net.c
46772 +++ b/drivers/net/usb/sierra_net.c
46773 @@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
46774 /* atomic counter partially included in MAC address to make sure 2 devices
46775 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
46776 */
46777 -static atomic_t iface_counter = ATOMIC_INIT(0);
46778 +static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
46779
46780 /*
46781 * SYNC Timer Delay definition used to set the expiry time
46782 @@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
46783 dev->net->netdev_ops = &sierra_net_device_ops;
46784
46785 /* change MAC addr to include, ifacenum, and to be unique */
46786 - dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
46787 + dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
46788 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
46789
46790 /* we will have to manufacture ethernet headers, prepare template */
46791 diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
46792 index 8a852b5..668a4b6 100644
46793 --- a/drivers/net/virtio_net.c
46794 +++ b/drivers/net/virtio_net.c
46795 @@ -47,7 +47,7 @@ module_param(gso, bool, 0444);
46796 #define RECEIVE_AVG_WEIGHT 64
46797
46798 /* Minimum alignment for mergeable packet buffers. */
46799 -#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256)
46800 +#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256UL)
46801
46802 #define VIRTNET_DRIVER_VERSION "1.0.0"
46803
46804 diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
46805 index 77dcf92..549924a 100644
46806 --- a/drivers/net/vxlan.c
46807 +++ b/drivers/net/vxlan.c
46808 @@ -2839,7 +2839,7 @@ nla_put_failure:
46809 return -EMSGSIZE;
46810 }
46811
46812 -static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
46813 +static struct rtnl_link_ops vxlan_link_ops = {
46814 .kind = "vxlan",
46815 .maxtype = IFLA_VXLAN_MAX,
46816 .policy = vxlan_policy,
46817 @@ -2886,7 +2886,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
46818 return NOTIFY_DONE;
46819 }
46820
46821 -static struct notifier_block vxlan_notifier_block __read_mostly = {
46822 +static struct notifier_block vxlan_notifier_block = {
46823 .notifier_call = vxlan_lowerdev_event,
46824 };
46825
46826 diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
46827 index 5920c99..ff2e4a5 100644
46828 --- a/drivers/net/wan/lmc/lmc_media.c
46829 +++ b/drivers/net/wan/lmc/lmc_media.c
46830 @@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
46831 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
46832
46833 lmc_media_t lmc_ds3_media = {
46834 - lmc_ds3_init, /* special media init stuff */
46835 - lmc_ds3_default, /* reset to default state */
46836 - lmc_ds3_set_status, /* reset status to state provided */
46837 - lmc_dummy_set_1, /* set clock source */
46838 - lmc_dummy_set2_1, /* set line speed */
46839 - lmc_ds3_set_100ft, /* set cable length */
46840 - lmc_ds3_set_scram, /* set scrambler */
46841 - lmc_ds3_get_link_status, /* get link status */
46842 - lmc_dummy_set_1, /* set link status */
46843 - lmc_ds3_set_crc_length, /* set CRC length */
46844 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
46845 - lmc_ds3_watchdog
46846 + .init = lmc_ds3_init, /* special media init stuff */
46847 + .defaults = lmc_ds3_default, /* reset to default state */
46848 + .set_status = lmc_ds3_set_status, /* reset status to state provided */
46849 + .set_clock_source = lmc_dummy_set_1, /* set clock source */
46850 + .set_speed = lmc_dummy_set2_1, /* set line speed */
46851 + .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
46852 + .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
46853 + .get_link_status = lmc_ds3_get_link_status, /* get link status */
46854 + .set_link_status = lmc_dummy_set_1, /* set link status */
46855 + .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
46856 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46857 + .watchdog = lmc_ds3_watchdog
46858 };
46859
46860 lmc_media_t lmc_hssi_media = {
46861 - lmc_hssi_init, /* special media init stuff */
46862 - lmc_hssi_default, /* reset to default state */
46863 - lmc_hssi_set_status, /* reset status to state provided */
46864 - lmc_hssi_set_clock, /* set clock source */
46865 - lmc_dummy_set2_1, /* set line speed */
46866 - lmc_dummy_set_1, /* set cable length */
46867 - lmc_dummy_set_1, /* set scrambler */
46868 - lmc_hssi_get_link_status, /* get link status */
46869 - lmc_hssi_set_link_status, /* set link status */
46870 - lmc_hssi_set_crc_length, /* set CRC length */
46871 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
46872 - lmc_hssi_watchdog
46873 + .init = lmc_hssi_init, /* special media init stuff */
46874 + .defaults = lmc_hssi_default, /* reset to default state */
46875 + .set_status = lmc_hssi_set_status, /* reset status to state provided */
46876 + .set_clock_source = lmc_hssi_set_clock, /* set clock source */
46877 + .set_speed = lmc_dummy_set2_1, /* set line speed */
46878 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
46879 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46880 + .get_link_status = lmc_hssi_get_link_status, /* get link status */
46881 + .set_link_status = lmc_hssi_set_link_status, /* set link status */
46882 + .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
46883 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46884 + .watchdog = lmc_hssi_watchdog
46885 };
46886
46887 -lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
46888 - lmc_ssi_default, /* reset to default state */
46889 - lmc_ssi_set_status, /* reset status to state provided */
46890 - lmc_ssi_set_clock, /* set clock source */
46891 - lmc_ssi_set_speed, /* set line speed */
46892 - lmc_dummy_set_1, /* set cable length */
46893 - lmc_dummy_set_1, /* set scrambler */
46894 - lmc_ssi_get_link_status, /* get link status */
46895 - lmc_ssi_set_link_status, /* set link status */
46896 - lmc_ssi_set_crc_length, /* set CRC length */
46897 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
46898 - lmc_ssi_watchdog
46899 +lmc_media_t lmc_ssi_media = {
46900 + .init = lmc_ssi_init, /* special media init stuff */
46901 + .defaults = lmc_ssi_default, /* reset to default state */
46902 + .set_status = lmc_ssi_set_status, /* reset status to state provided */
46903 + .set_clock_source = lmc_ssi_set_clock, /* set clock source */
46904 + .set_speed = lmc_ssi_set_speed, /* set line speed */
46905 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
46906 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46907 + .get_link_status = lmc_ssi_get_link_status, /* get link status */
46908 + .set_link_status = lmc_ssi_set_link_status, /* set link status */
46909 + .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
46910 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46911 + .watchdog = lmc_ssi_watchdog
46912 };
46913
46914 lmc_media_t lmc_t1_media = {
46915 - lmc_t1_init, /* special media init stuff */
46916 - lmc_t1_default, /* reset to default state */
46917 - lmc_t1_set_status, /* reset status to state provided */
46918 - lmc_t1_set_clock, /* set clock source */
46919 - lmc_dummy_set2_1, /* set line speed */
46920 - lmc_dummy_set_1, /* set cable length */
46921 - lmc_dummy_set_1, /* set scrambler */
46922 - lmc_t1_get_link_status, /* get link status */
46923 - lmc_dummy_set_1, /* set link status */
46924 - lmc_t1_set_crc_length, /* set CRC length */
46925 - lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46926 - lmc_t1_watchdog
46927 + .init = lmc_t1_init, /* special media init stuff */
46928 + .defaults = lmc_t1_default, /* reset to default state */
46929 + .set_status = lmc_t1_set_status, /* reset status to state provided */
46930 + .set_clock_source = lmc_t1_set_clock, /* set clock source */
46931 + .set_speed = lmc_dummy_set2_1, /* set line speed */
46932 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
46933 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46934 + .get_link_status = lmc_t1_get_link_status, /* get link status */
46935 + .set_link_status = lmc_dummy_set_1, /* set link status */
46936 + .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
46937 + .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46938 + .watchdog = lmc_t1_watchdog
46939 };
46940
46941 static void
46942 diff --git a/drivers/net/wan/x25_asy.c b/drivers/net/wan/x25_asy.c
46943 index 5895f19..fa9fdfa 100644
46944 --- a/drivers/net/wan/x25_asy.c
46945 +++ b/drivers/net/wan/x25_asy.c
46946 @@ -122,8 +122,12 @@ static int x25_asy_change_mtu(struct net_device *dev, int newmtu)
46947 {
46948 struct x25_asy *sl = netdev_priv(dev);
46949 unsigned char *xbuff, *rbuff;
46950 - int len = 2 * newmtu;
46951 + int len;
46952
46953 + if (newmtu > 65534)
46954 + return -EINVAL;
46955 +
46956 + len = 2 * newmtu;
46957 xbuff = kmalloc(len + 4, GFP_ATOMIC);
46958 rbuff = kmalloc(len + 4, GFP_ATOMIC);
46959
46960 diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
46961 index feacc3b..5bac0de 100644
46962 --- a/drivers/net/wan/z85230.c
46963 +++ b/drivers/net/wan/z85230.c
46964 @@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
46965
46966 struct z8530_irqhandler z8530_sync =
46967 {
46968 - z8530_rx,
46969 - z8530_tx,
46970 - z8530_status
46971 + .rx = z8530_rx,
46972 + .tx = z8530_tx,
46973 + .status = z8530_status
46974 };
46975
46976 EXPORT_SYMBOL(z8530_sync);
46977 @@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
46978 }
46979
46980 static struct z8530_irqhandler z8530_dma_sync = {
46981 - z8530_dma_rx,
46982 - z8530_dma_tx,
46983 - z8530_dma_status
46984 + .rx = z8530_dma_rx,
46985 + .tx = z8530_dma_tx,
46986 + .status = z8530_dma_status
46987 };
46988
46989 static struct z8530_irqhandler z8530_txdma_sync = {
46990 - z8530_rx,
46991 - z8530_dma_tx,
46992 - z8530_dma_status
46993 + .rx = z8530_rx,
46994 + .tx = z8530_dma_tx,
46995 + .status = z8530_dma_status
46996 };
46997
46998 /**
46999 @@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
47000
47001 struct z8530_irqhandler z8530_nop=
47002 {
47003 - z8530_rx_clear,
47004 - z8530_tx_clear,
47005 - z8530_status_clear
47006 + .rx = z8530_rx_clear,
47007 + .tx = z8530_tx_clear,
47008 + .status = z8530_status_clear
47009 };
47010
47011
47012 diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
47013 index 0b60295..b8bfa5b 100644
47014 --- a/drivers/net/wimax/i2400m/rx.c
47015 +++ b/drivers/net/wimax/i2400m/rx.c
47016 @@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
47017 if (i2400m->rx_roq == NULL)
47018 goto error_roq_alloc;
47019
47020 - rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
47021 + rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
47022 GFP_KERNEL);
47023 if (rd == NULL) {
47024 result = -ENOMEM;
47025 diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
47026 index 64747d4..17c4cf3 100644
47027 --- a/drivers/net/wireless/airo.c
47028 +++ b/drivers/net/wireless/airo.c
47029 @@ -7846,7 +7846,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
47030 struct airo_info *ai = dev->ml_priv;
47031 int ridcode;
47032 int enabled;
47033 - static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
47034 + int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
47035 unsigned char *iobuf;
47036
47037 /* Only super-user can write RIDs */
47038 diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
47039 index 99b3bfa..9559372 100644
47040 --- a/drivers/net/wireless/at76c50x-usb.c
47041 +++ b/drivers/net/wireless/at76c50x-usb.c
47042 @@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
47043 }
47044
47045 /* Convert timeout from the DFU status to jiffies */
47046 -static inline unsigned long at76_get_timeout(struct dfu_status *s)
47047 +static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
47048 {
47049 return msecs_to_jiffies((s->poll_timeout[2] << 16)
47050 | (s->poll_timeout[1] << 8)
47051 diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
47052 index 7f1bccd..ca2ffca 100644
47053 --- a/drivers/net/wireless/ath/ath10k/htc.c
47054 +++ b/drivers/net/wireless/ath/ath10k/htc.c
47055 @@ -840,7 +840,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
47056 /* registered target arrival callback from the HIF layer */
47057 int ath10k_htc_init(struct ath10k *ar)
47058 {
47059 - struct ath10k_hif_cb htc_callbacks;
47060 + static struct ath10k_hif_cb htc_callbacks = {
47061 + .rx_completion = ath10k_htc_rx_completion_handler,
47062 + .tx_completion = ath10k_htc_tx_completion_handler,
47063 + };
47064 struct ath10k_htc_ep *ep = NULL;
47065 struct ath10k_htc *htc = &ar->htc;
47066
47067 @@ -850,8 +853,6 @@ int ath10k_htc_init(struct ath10k *ar)
47068 ath10k_htc_reset_endpoint_states(htc);
47069
47070 /* setup HIF layer callbacks */
47071 - htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
47072 - htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
47073 htc->ar = ar;
47074
47075 /* Get HIF default pipe for HTC message exchange */
47076 diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
47077 index 4716d33..a688310 100644
47078 --- a/drivers/net/wireless/ath/ath10k/htc.h
47079 +++ b/drivers/net/wireless/ath/ath10k/htc.h
47080 @@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
47081
47082 struct ath10k_htc_ops {
47083 void (*target_send_suspend_complete)(struct ath10k *ar);
47084 -};
47085 +} __no_const;
47086
47087 struct ath10k_htc_ep_ops {
47088 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
47089 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
47090 void (*ep_tx_credits)(struct ath10k *);
47091 -};
47092 +} __no_const;
47093
47094 /* service connection information */
47095 struct ath10k_htc_svc_conn_req {
47096 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
47097 index 741b38d..b7ae41b 100644
47098 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
47099 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
47100 @@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47101 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
47102 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
47103
47104 - ACCESS_ONCE(ads->ds_link) = i->link;
47105 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
47106 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
47107 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
47108
47109 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
47110 ctl6 = SM(i->keytype, AR_EncrType);
47111 @@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47112
47113 if ((i->is_first || i->is_last) &&
47114 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
47115 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
47116 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
47117 | set11nTries(i->rates, 1)
47118 | set11nTries(i->rates, 2)
47119 | set11nTries(i->rates, 3)
47120 | (i->dur_update ? AR_DurUpdateEna : 0)
47121 | SM(0, AR_BurstDur);
47122
47123 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
47124 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
47125 | set11nRate(i->rates, 1)
47126 | set11nRate(i->rates, 2)
47127 | set11nRate(i->rates, 3);
47128 } else {
47129 - ACCESS_ONCE(ads->ds_ctl2) = 0;
47130 - ACCESS_ONCE(ads->ds_ctl3) = 0;
47131 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
47132 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
47133 }
47134
47135 if (!i->is_first) {
47136 - ACCESS_ONCE(ads->ds_ctl0) = 0;
47137 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
47138 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
47139 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
47140 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
47141 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
47142 return;
47143 }
47144
47145 @@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47146 break;
47147 }
47148
47149 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
47150 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
47151 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
47152 | SM(i->txpower, AR_XmitPower)
47153 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
47154 @@ -289,19 +289,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47155 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
47156 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
47157
47158 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
47159 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
47160 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
47161 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
47162
47163 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
47164 return;
47165
47166 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
47167 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
47168 | set11nPktDurRTSCTS(i->rates, 1);
47169
47170 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
47171 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
47172 | set11nPktDurRTSCTS(i->rates, 3);
47173
47174 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
47175 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
47176 | set11nRateFlags(i->rates, 1)
47177 | set11nRateFlags(i->rates, 2)
47178 | set11nRateFlags(i->rates, 3)
47179 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
47180 index 729ffbf..49f50e3 100644
47181 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
47182 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
47183 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47184 (i->qcu << AR_TxQcuNum_S) | desc_len;
47185
47186 checksum += val;
47187 - ACCESS_ONCE(ads->info) = val;
47188 + ACCESS_ONCE_RW(ads->info) = val;
47189
47190 checksum += i->link;
47191 - ACCESS_ONCE(ads->link) = i->link;
47192 + ACCESS_ONCE_RW(ads->link) = i->link;
47193
47194 checksum += i->buf_addr[0];
47195 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
47196 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
47197 checksum += i->buf_addr[1];
47198 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
47199 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
47200 checksum += i->buf_addr[2];
47201 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
47202 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
47203 checksum += i->buf_addr[3];
47204 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
47205 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
47206
47207 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
47208 - ACCESS_ONCE(ads->ctl3) = val;
47209 + ACCESS_ONCE_RW(ads->ctl3) = val;
47210 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
47211 - ACCESS_ONCE(ads->ctl5) = val;
47212 + ACCESS_ONCE_RW(ads->ctl5) = val;
47213 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
47214 - ACCESS_ONCE(ads->ctl7) = val;
47215 + ACCESS_ONCE_RW(ads->ctl7) = val;
47216 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
47217 - ACCESS_ONCE(ads->ctl9) = val;
47218 + ACCESS_ONCE_RW(ads->ctl9) = val;
47219
47220 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
47221 - ACCESS_ONCE(ads->ctl10) = checksum;
47222 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
47223
47224 if (i->is_first || i->is_last) {
47225 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
47226 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
47227 | set11nTries(i->rates, 1)
47228 | set11nTries(i->rates, 2)
47229 | set11nTries(i->rates, 3)
47230 | (i->dur_update ? AR_DurUpdateEna : 0)
47231 | SM(0, AR_BurstDur);
47232
47233 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
47234 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
47235 | set11nRate(i->rates, 1)
47236 | set11nRate(i->rates, 2)
47237 | set11nRate(i->rates, 3);
47238 } else {
47239 - ACCESS_ONCE(ads->ctl13) = 0;
47240 - ACCESS_ONCE(ads->ctl14) = 0;
47241 + ACCESS_ONCE_RW(ads->ctl13) = 0;
47242 + ACCESS_ONCE_RW(ads->ctl14) = 0;
47243 }
47244
47245 ads->ctl20 = 0;
47246 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47247
47248 ctl17 = SM(i->keytype, AR_EncrType);
47249 if (!i->is_first) {
47250 - ACCESS_ONCE(ads->ctl11) = 0;
47251 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
47252 - ACCESS_ONCE(ads->ctl15) = 0;
47253 - ACCESS_ONCE(ads->ctl16) = 0;
47254 - ACCESS_ONCE(ads->ctl17) = ctl17;
47255 - ACCESS_ONCE(ads->ctl18) = 0;
47256 - ACCESS_ONCE(ads->ctl19) = 0;
47257 + ACCESS_ONCE_RW(ads->ctl11) = 0;
47258 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
47259 + ACCESS_ONCE_RW(ads->ctl15) = 0;
47260 + ACCESS_ONCE_RW(ads->ctl16) = 0;
47261 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
47262 + ACCESS_ONCE_RW(ads->ctl18) = 0;
47263 + ACCESS_ONCE_RW(ads->ctl19) = 0;
47264 return;
47265 }
47266
47267 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
47268 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
47269 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
47270 | SM(i->txpower, AR_XmitPower)
47271 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
47272 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47273 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
47274 ctl12 |= SM(val, AR_PAPRDChainMask);
47275
47276 - ACCESS_ONCE(ads->ctl12) = ctl12;
47277 - ACCESS_ONCE(ads->ctl17) = ctl17;
47278 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
47279 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
47280
47281 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
47282 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
47283 | set11nPktDurRTSCTS(i->rates, 1);
47284
47285 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
47286 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
47287 | set11nPktDurRTSCTS(i->rates, 3);
47288
47289 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
47290 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
47291 | set11nRateFlags(i->rates, 1)
47292 | set11nRateFlags(i->rates, 2)
47293 | set11nRateFlags(i->rates, 3)
47294 | SM(i->rtscts_rate, AR_RTSCTSRate);
47295
47296 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
47297 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
47298 }
47299
47300 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
47301 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
47302 index 0acd4b5..0591c91 100644
47303 --- a/drivers/net/wireless/ath/ath9k/hw.h
47304 +++ b/drivers/net/wireless/ath/ath9k/hw.h
47305 @@ -629,7 +629,7 @@ struct ath_hw_private_ops {
47306
47307 /* ANI */
47308 void (*ani_cache_ini_regs)(struct ath_hw *ah);
47309 -};
47310 +} __no_const;
47311
47312 /**
47313 * struct ath_spec_scan - parameters for Atheros spectral scan
47314 @@ -706,7 +706,7 @@ struct ath_hw_ops {
47315 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
47316 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
47317 #endif
47318 -};
47319 +} __no_const;
47320
47321 struct ath_nf_limits {
47322 s16 max;
47323 diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
47324 index 92190da..f3a4c4c 100644
47325 --- a/drivers/net/wireless/b43/phy_lp.c
47326 +++ b/drivers/net/wireless/b43/phy_lp.c
47327 @@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
47328 {
47329 struct ssb_bus *bus = dev->dev->sdev->bus;
47330
47331 - static const struct b206x_channel *chandata = NULL;
47332 + const struct b206x_channel *chandata = NULL;
47333 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
47334 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
47335 u16 old_comm15, scale;
47336 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
47337 index dc1d20c..f7a4f06 100644
47338 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
47339 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
47340 @@ -3633,7 +3633,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
47341 */
47342 if (il3945_mod_params.disable_hw_scan) {
47343 D_INFO("Disabling hw_scan\n");
47344 - il3945_mac_ops.hw_scan = NULL;
47345 + pax_open_kernel();
47346 + *(void **)&il3945_mac_ops.hw_scan = NULL;
47347 + pax_close_kernel();
47348 }
47349
47350 D_INFO("*** LOAD DRIVER ***\n");
47351 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47352 index d2fe259..0c4c682 100644
47353 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47354 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47355 @@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
47356 {
47357 struct iwl_priv *priv = file->private_data;
47358 char buf[64];
47359 - int buf_size;
47360 + size_t buf_size;
47361 u32 offset, len;
47362
47363 memset(buf, 0, sizeof(buf));
47364 @@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
47365 struct iwl_priv *priv = file->private_data;
47366
47367 char buf[8];
47368 - int buf_size;
47369 + size_t buf_size;
47370 u32 reset_flag;
47371
47372 memset(buf, 0, sizeof(buf));
47373 @@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
47374 {
47375 struct iwl_priv *priv = file->private_data;
47376 char buf[8];
47377 - int buf_size;
47378 + size_t buf_size;
47379 int ht40;
47380
47381 memset(buf, 0, sizeof(buf));
47382 @@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
47383 {
47384 struct iwl_priv *priv = file->private_data;
47385 char buf[8];
47386 - int buf_size;
47387 + size_t buf_size;
47388 int value;
47389
47390 memset(buf, 0, sizeof(buf));
47391 @@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
47392 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
47393 DEBUGFS_READ_FILE_OPS(current_sleep_command);
47394
47395 -static const char *fmt_value = " %-30s %10u\n";
47396 -static const char *fmt_hex = " %-30s 0x%02X\n";
47397 -static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
47398 -static const char *fmt_header =
47399 +static const char fmt_value[] = " %-30s %10u\n";
47400 +static const char fmt_hex[] = " %-30s 0x%02X\n";
47401 +static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
47402 +static const char fmt_header[] =
47403 "%-32s current cumulative delta max\n";
47404
47405 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
47406 @@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
47407 {
47408 struct iwl_priv *priv = file->private_data;
47409 char buf[8];
47410 - int buf_size;
47411 + size_t buf_size;
47412 int clear;
47413
47414 memset(buf, 0, sizeof(buf));
47415 @@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
47416 {
47417 struct iwl_priv *priv = file->private_data;
47418 char buf[8];
47419 - int buf_size;
47420 + size_t buf_size;
47421 int trace;
47422
47423 memset(buf, 0, sizeof(buf));
47424 @@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
47425 {
47426 struct iwl_priv *priv = file->private_data;
47427 char buf[8];
47428 - int buf_size;
47429 + size_t buf_size;
47430 int missed;
47431
47432 memset(buf, 0, sizeof(buf));
47433 @@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
47434
47435 struct iwl_priv *priv = file->private_data;
47436 char buf[8];
47437 - int buf_size;
47438 + size_t buf_size;
47439 int plcp;
47440
47441 memset(buf, 0, sizeof(buf));
47442 @@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
47443
47444 struct iwl_priv *priv = file->private_data;
47445 char buf[8];
47446 - int buf_size;
47447 + size_t buf_size;
47448 int flush;
47449
47450 memset(buf, 0, sizeof(buf));
47451 @@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
47452
47453 struct iwl_priv *priv = file->private_data;
47454 char buf[8];
47455 - int buf_size;
47456 + size_t buf_size;
47457 int rts;
47458
47459 if (!priv->cfg->ht_params)
47460 @@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
47461 {
47462 struct iwl_priv *priv = file->private_data;
47463 char buf[8];
47464 - int buf_size;
47465 + size_t buf_size;
47466
47467 memset(buf, 0, sizeof(buf));
47468 buf_size = min(count, sizeof(buf) - 1);
47469 @@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
47470 struct iwl_priv *priv = file->private_data;
47471 u32 event_log_flag;
47472 char buf[8];
47473 - int buf_size;
47474 + size_t buf_size;
47475
47476 /* check that the interface is up */
47477 if (!iwl_is_ready(priv))
47478 @@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
47479 struct iwl_priv *priv = file->private_data;
47480 char buf[8];
47481 u32 calib_disabled;
47482 - int buf_size;
47483 + size_t buf_size;
47484
47485 memset(buf, 0, sizeof(buf));
47486 buf_size = min(count, sizeof(buf) - 1);
47487 diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
47488 index 6a6df71..eb5c93a 100644
47489 --- a/drivers/net/wireless/iwlwifi/dvm/main.c
47490 +++ b/drivers/net/wireless/iwlwifi/dvm/main.c
47491 @@ -1127,7 +1127,7 @@ static void iwl_option_config(struct iwl_priv *priv)
47492 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47493 {
47494 struct iwl_nvm_data *data = priv->nvm_data;
47495 - char *debug_msg;
47496 + static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47497
47498 if (data->sku_cap_11n_enable &&
47499 !priv->cfg->ht_params) {
47500 @@ -1141,7 +1141,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47501 return -EINVAL;
47502 }
47503
47504 - debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47505 IWL_DEBUG_INFO(priv, debug_msg,
47506 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
47507 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
47508 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
47509 index 295b24c..cb4f823 100644
47510 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
47511 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
47512 @@ -1558,7 +1558,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
47513 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
47514
47515 char buf[8];
47516 - int buf_size;
47517 + size_t buf_size;
47518 u32 reset_flag;
47519
47520 memset(buf, 0, sizeof(buf));
47521 @@ -1579,7 +1579,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
47522 {
47523 struct iwl_trans *trans = file->private_data;
47524 char buf[8];
47525 - int buf_size;
47526 + size_t buf_size;
47527 int csr;
47528
47529 memset(buf, 0, sizeof(buf));
47530 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
47531 index 9d7a52f..2729a99 100644
47532 --- a/drivers/net/wireless/mac80211_hwsim.c
47533 +++ b/drivers/net/wireless/mac80211_hwsim.c
47534 @@ -2570,20 +2570,20 @@ static int __init init_mac80211_hwsim(void)
47535 if (channels < 1)
47536 return -EINVAL;
47537
47538 - mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
47539 - mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47540 - mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47541 - mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47542 - mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47543 - mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47544 - mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47545 - mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47546 - mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47547 - mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47548 - mac80211_hwsim_mchan_ops.assign_vif_chanctx =
47549 - mac80211_hwsim_assign_vif_chanctx;
47550 - mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
47551 - mac80211_hwsim_unassign_vif_chanctx;
47552 + pax_open_kernel();
47553 + memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
47554 + *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47555 + *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47556 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47557 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47558 + *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47559 + *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47560 + *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47561 + *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47562 + *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47563 + *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
47564 + *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
47565 + pax_close_kernel();
47566
47567 spin_lock_init(&hwsim_radio_lock);
47568 INIT_LIST_HEAD(&hwsim_radios);
47569 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
47570 index 39d22a1..4ec8612 100644
47571 --- a/drivers/net/wireless/rndis_wlan.c
47572 +++ b/drivers/net/wireless/rndis_wlan.c
47573 @@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
47574
47575 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
47576
47577 - if (rts_threshold < 0 || rts_threshold > 2347)
47578 + if (rts_threshold > 2347)
47579 rts_threshold = 2347;
47580
47581 tmp = cpu_to_le32(rts_threshold);
47582 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
47583 index 5d45a1a..6f5f041 100644
47584 --- a/drivers/net/wireless/rt2x00/rt2x00.h
47585 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
47586 @@ -375,7 +375,7 @@ struct rt2x00_intf {
47587 * for hardware which doesn't support hardware
47588 * sequence counting.
47589 */
47590 - atomic_t seqno;
47591 + atomic_unchecked_t seqno;
47592 };
47593
47594 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
47595 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
47596 index 5642ccc..01f03eb 100644
47597 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
47598 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
47599 @@ -250,9 +250,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
47600 * sequence counter given by mac80211.
47601 */
47602 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
47603 - seqno = atomic_add_return(0x10, &intf->seqno);
47604 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
47605 else
47606 - seqno = atomic_read(&intf->seqno);
47607 + seqno = atomic_read_unchecked(&intf->seqno);
47608
47609 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
47610 hdr->seq_ctrl |= cpu_to_le16(seqno);
47611 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
47612 index b661f896..ddf7d2b 100644
47613 --- a/drivers/net/wireless/ti/wl1251/sdio.c
47614 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
47615 @@ -282,13 +282,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
47616
47617 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
47618
47619 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47620 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47621 + pax_open_kernel();
47622 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47623 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47624 + pax_close_kernel();
47625
47626 wl1251_info("using dedicated interrupt line");
47627 } else {
47628 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47629 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47630 + pax_open_kernel();
47631 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47632 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47633 + pax_close_kernel();
47634
47635 wl1251_info("using SDIO interrupt");
47636 }
47637 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
47638 index d50dfac..0a6f5be3 100644
47639 --- a/drivers/net/wireless/ti/wl12xx/main.c
47640 +++ b/drivers/net/wireless/ti/wl12xx/main.c
47641 @@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47642 sizeof(wl->conf.mem));
47643
47644 /* read data preparation is only needed by wl127x */
47645 - wl->ops->prepare_read = wl127x_prepare_read;
47646 + pax_open_kernel();
47647 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47648 + pax_close_kernel();
47649
47650 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47651 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47652 @@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47653 sizeof(wl->conf.mem));
47654
47655 /* read data preparation is only needed by wl127x */
47656 - wl->ops->prepare_read = wl127x_prepare_read;
47657 + pax_open_kernel();
47658 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47659 + pax_close_kernel();
47660
47661 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47662 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47663 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
47664 index de5b4fa..7996ec6 100644
47665 --- a/drivers/net/wireless/ti/wl18xx/main.c
47666 +++ b/drivers/net/wireless/ti/wl18xx/main.c
47667 @@ -1900,8 +1900,10 @@ static int wl18xx_setup(struct wl1271 *wl)
47668 }
47669
47670 if (!checksum_param) {
47671 - wl18xx_ops.set_rx_csum = NULL;
47672 - wl18xx_ops.init_vif = NULL;
47673 + pax_open_kernel();
47674 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
47675 + *(void **)&wl18xx_ops.init_vif = NULL;
47676 + pax_close_kernel();
47677 }
47678
47679 /* Enable 11a Band only if we have 5G antennas */
47680 diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
47681 index a912dc0..a8225ba 100644
47682 --- a/drivers/net/wireless/zd1211rw/zd_usb.c
47683 +++ b/drivers/net/wireless/zd1211rw/zd_usb.c
47684 @@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
47685 {
47686 struct zd_usb *usb = urb->context;
47687 struct zd_usb_interrupt *intr = &usb->intr;
47688 - int len;
47689 + unsigned int len;
47690 u16 int_num;
47691
47692 ZD_ASSERT(in_interrupt());
47693 diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
47694 index 683671a..4519fc2 100644
47695 --- a/drivers/nfc/nfcwilink.c
47696 +++ b/drivers/nfc/nfcwilink.c
47697 @@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
47698
47699 static int nfcwilink_probe(struct platform_device *pdev)
47700 {
47701 - static struct nfcwilink *drv;
47702 + struct nfcwilink *drv;
47703 int rc;
47704 __u32 protocols;
47705
47706 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
47707 index d93b2b6..ae50401 100644
47708 --- a/drivers/oprofile/buffer_sync.c
47709 +++ b/drivers/oprofile/buffer_sync.c
47710 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
47711 if (cookie == NO_COOKIE)
47712 offset = pc;
47713 if (cookie == INVALID_COOKIE) {
47714 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47715 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47716 offset = pc;
47717 }
47718 if (cookie != last_cookie) {
47719 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
47720 /* add userspace sample */
47721
47722 if (!mm) {
47723 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
47724 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
47725 return 0;
47726 }
47727
47728 cookie = lookup_dcookie(mm, s->eip, &offset);
47729
47730 if (cookie == INVALID_COOKIE) {
47731 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47732 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47733 return 0;
47734 }
47735
47736 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
47737 /* ignore backtraces if failed to add a sample */
47738 if (state == sb_bt_start) {
47739 state = sb_bt_ignore;
47740 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
47741 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
47742 }
47743 }
47744 release_mm(mm);
47745 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
47746 index c0cc4e7..44d4e54 100644
47747 --- a/drivers/oprofile/event_buffer.c
47748 +++ b/drivers/oprofile/event_buffer.c
47749 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
47750 }
47751
47752 if (buffer_pos == buffer_size) {
47753 - atomic_inc(&oprofile_stats.event_lost_overflow);
47754 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
47755 return;
47756 }
47757
47758 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
47759 index ed2c3ec..deda85a 100644
47760 --- a/drivers/oprofile/oprof.c
47761 +++ b/drivers/oprofile/oprof.c
47762 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
47763 if (oprofile_ops.switch_events())
47764 return;
47765
47766 - atomic_inc(&oprofile_stats.multiplex_counter);
47767 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
47768 start_switch_worker();
47769 }
47770
47771 diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
47772 index ee2cfce..7f8f699 100644
47773 --- a/drivers/oprofile/oprofile_files.c
47774 +++ b/drivers/oprofile/oprofile_files.c
47775 @@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
47776
47777 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
47778
47779 -static ssize_t timeout_read(struct file *file, char __user *buf,
47780 +static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
47781 size_t count, loff_t *offset)
47782 {
47783 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
47784 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
47785 index 59659ce..6c860a0 100644
47786 --- a/drivers/oprofile/oprofile_stats.c
47787 +++ b/drivers/oprofile/oprofile_stats.c
47788 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
47789 cpu_buf->sample_invalid_eip = 0;
47790 }
47791
47792 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
47793 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
47794 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
47795 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
47796 - atomic_set(&oprofile_stats.multiplex_counter, 0);
47797 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
47798 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
47799 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
47800 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
47801 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
47802 }
47803
47804
47805 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
47806 index 1fc622b..8c48fc3 100644
47807 --- a/drivers/oprofile/oprofile_stats.h
47808 +++ b/drivers/oprofile/oprofile_stats.h
47809 @@ -13,11 +13,11 @@
47810 #include <linux/atomic.h>
47811
47812 struct oprofile_stat_struct {
47813 - atomic_t sample_lost_no_mm;
47814 - atomic_t sample_lost_no_mapping;
47815 - atomic_t bt_lost_no_mapping;
47816 - atomic_t event_lost_overflow;
47817 - atomic_t multiplex_counter;
47818 + atomic_unchecked_t sample_lost_no_mm;
47819 + atomic_unchecked_t sample_lost_no_mapping;
47820 + atomic_unchecked_t bt_lost_no_mapping;
47821 + atomic_unchecked_t event_lost_overflow;
47822 + atomic_unchecked_t multiplex_counter;
47823 };
47824
47825 extern struct oprofile_stat_struct oprofile_stats;
47826 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
47827 index 3f49345..c750d0b 100644
47828 --- a/drivers/oprofile/oprofilefs.c
47829 +++ b/drivers/oprofile/oprofilefs.c
47830 @@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
47831
47832 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
47833 {
47834 - atomic_t *val = file->private_data;
47835 - return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
47836 + atomic_unchecked_t *val = file->private_data;
47837 + return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
47838 }
47839
47840
47841 @@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
47842
47843
47844 int oprofilefs_create_ro_atomic(struct dentry *root,
47845 - char const *name, atomic_t *val)
47846 + char const *name, atomic_unchecked_t *val)
47847 {
47848 return __oprofilefs_create_file(root, name,
47849 &atomic_ro_fops, 0444, val);
47850 diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
47851 index 61be1d9..dec05d7 100644
47852 --- a/drivers/oprofile/timer_int.c
47853 +++ b/drivers/oprofile/timer_int.c
47854 @@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
47855 return NOTIFY_OK;
47856 }
47857
47858 -static struct notifier_block __refdata oprofile_cpu_notifier = {
47859 +static struct notifier_block oprofile_cpu_notifier = {
47860 .notifier_call = oprofile_cpu_notify,
47861 };
47862
47863 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
47864 index 92ed045..62d39bd7 100644
47865 --- a/drivers/parport/procfs.c
47866 +++ b/drivers/parport/procfs.c
47867 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
47868
47869 *ppos += len;
47870
47871 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
47872 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
47873 }
47874
47875 #ifdef CONFIG_PARPORT_1284
47876 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
47877
47878 *ppos += len;
47879
47880 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
47881 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
47882 }
47883 #endif /* IEEE1284.3 support. */
47884
47885 diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
47886 index 8dcccff..35d701d 100644
47887 --- a/drivers/pci/hotplug/acpiphp_ibm.c
47888 +++ b/drivers/pci/hotplug/acpiphp_ibm.c
47889 @@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
47890 goto init_cleanup;
47891 }
47892
47893 - ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47894 + pax_open_kernel();
47895 + *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47896 + pax_close_kernel();
47897 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
47898
47899 return retval;
47900 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
47901 index 7536eef..52dc8fa 100644
47902 --- a/drivers/pci/hotplug/cpcihp_generic.c
47903 +++ b/drivers/pci/hotplug/cpcihp_generic.c
47904 @@ -73,7 +73,6 @@ static u16 port;
47905 static unsigned int enum_bit;
47906 static u8 enum_mask;
47907
47908 -static struct cpci_hp_controller_ops generic_hpc_ops;
47909 static struct cpci_hp_controller generic_hpc;
47910
47911 static int __init validate_parameters(void)
47912 @@ -139,6 +138,10 @@ static int query_enum(void)
47913 return ((value & enum_mask) == enum_mask);
47914 }
47915
47916 +static struct cpci_hp_controller_ops generic_hpc_ops = {
47917 + .query_enum = query_enum,
47918 +};
47919 +
47920 static int __init cpcihp_generic_init(void)
47921 {
47922 int status;
47923 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
47924 pci_dev_put(dev);
47925
47926 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
47927 - generic_hpc_ops.query_enum = query_enum;
47928 generic_hpc.ops = &generic_hpc_ops;
47929
47930 status = cpci_hp_register_controller(&generic_hpc);
47931 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
47932 index e8c4a7c..7046f5c 100644
47933 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
47934 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
47935 @@ -59,7 +59,6 @@
47936 /* local variables */
47937 static bool debug;
47938 static bool poll;
47939 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
47940 static struct cpci_hp_controller zt5550_hpc;
47941
47942 /* Primary cPCI bus bridge device */
47943 @@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
47944 return 0;
47945 }
47946
47947 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
47948 + .query_enum = zt5550_hc_query_enum,
47949 +};
47950 +
47951 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
47952 {
47953 int status;
47954 @@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
47955 dbg("returned from zt5550_hc_config");
47956
47957 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
47958 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
47959 zt5550_hpc.ops = &zt5550_hpc_ops;
47960 if(!poll) {
47961 zt5550_hpc.irq = hc_dev->irq;
47962 zt5550_hpc.irq_flags = IRQF_SHARED;
47963 zt5550_hpc.dev_id = hc_dev;
47964
47965 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47966 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47967 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47968 + pax_open_kernel();
47969 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47970 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47971 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47972 + pax_open_kernel();
47973 } else {
47974 info("using ENUM# polling mode");
47975 }
47976 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
47977 index 76ba8a1..20ca857 100644
47978 --- a/drivers/pci/hotplug/cpqphp_nvram.c
47979 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
47980 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
47981
47982 void compaq_nvram_init (void __iomem *rom_start)
47983 {
47984 +
47985 +#ifndef CONFIG_PAX_KERNEXEC
47986 if (rom_start) {
47987 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
47988 }
47989 +#endif
47990 +
47991 dbg("int15 entry = %p\n", compaq_int15_entry_point);
47992
47993 /* initialize our int15 lock */
47994 diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
47995 index cfa92a9..29539c5 100644
47996 --- a/drivers/pci/hotplug/pci_hotplug_core.c
47997 +++ b/drivers/pci/hotplug/pci_hotplug_core.c
47998 @@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
47999 return -EINVAL;
48000 }
48001
48002 - slot->ops->owner = owner;
48003 - slot->ops->mod_name = mod_name;
48004 + pax_open_kernel();
48005 + *(struct module **)&slot->ops->owner = owner;
48006 + *(const char **)&slot->ops->mod_name = mod_name;
48007 + pax_close_kernel();
48008
48009 mutex_lock(&pci_hp_mutex);
48010 /*
48011 diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
48012 index 0e0a2ff..29dff57 100644
48013 --- a/drivers/pci/hotplug/pciehp_core.c
48014 +++ b/drivers/pci/hotplug/pciehp_core.c
48015 @@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
48016 struct slot *slot = ctrl->slot;
48017 struct hotplug_slot *hotplug = NULL;
48018 struct hotplug_slot_info *info = NULL;
48019 - struct hotplug_slot_ops *ops = NULL;
48020 + hotplug_slot_ops_no_const *ops = NULL;
48021 char name[SLOT_NAME_SIZE];
48022 int retval = -ENOMEM;
48023
48024 diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
48025 index fb02fc2..83dc2c3 100644
48026 --- a/drivers/pci/msi.c
48027 +++ b/drivers/pci/msi.c
48028 @@ -524,8 +524,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
48029 {
48030 struct attribute **msi_attrs;
48031 struct attribute *msi_attr;
48032 - struct device_attribute *msi_dev_attr;
48033 - struct attribute_group *msi_irq_group;
48034 + device_attribute_no_const *msi_dev_attr;
48035 + attribute_group_no_const *msi_irq_group;
48036 const struct attribute_group **msi_irq_groups;
48037 struct msi_desc *entry;
48038 int ret = -ENOMEM;
48039 @@ -589,7 +589,7 @@ error_attrs:
48040 count = 0;
48041 msi_attr = msi_attrs[count];
48042 while (msi_attr) {
48043 - msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
48044 + msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
48045 kfree(msi_attr->name);
48046 kfree(msi_dev_attr);
48047 ++count;
48048 diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
48049 index 4e0acef..bd98e31 100644
48050 --- a/drivers/pci/pci-sysfs.c
48051 +++ b/drivers/pci/pci-sysfs.c
48052 @@ -1101,7 +1101,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
48053 {
48054 /* allocate attribute structure, piggyback attribute name */
48055 int name_len = write_combine ? 13 : 10;
48056 - struct bin_attribute *res_attr;
48057 + bin_attribute_no_const *res_attr;
48058 int retval;
48059
48060 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
48061 @@ -1286,7 +1286,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
48062 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
48063 {
48064 int retval;
48065 - struct bin_attribute *attr;
48066 + bin_attribute_no_const *attr;
48067
48068 /* If the device has VPD, try to expose it in sysfs. */
48069 if (dev->vpd) {
48070 @@ -1333,7 +1333,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
48071 {
48072 int retval;
48073 int rom_size = 0;
48074 - struct bin_attribute *attr;
48075 + bin_attribute_no_const *attr;
48076
48077 if (!sysfs_initialized)
48078 return -EACCES;
48079 diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
48080 index 6bd0822..35bc2b3 100644
48081 --- a/drivers/pci/pci.h
48082 +++ b/drivers/pci/pci.h
48083 @@ -91,7 +91,7 @@ struct pci_vpd_ops {
48084 struct pci_vpd {
48085 unsigned int len;
48086 const struct pci_vpd_ops *ops;
48087 - struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
48088 + bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
48089 };
48090
48091 int pci_vpd_pci22_init(struct pci_dev *dev);
48092 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
48093 index e1e7026..d28dd33 100644
48094 --- a/drivers/pci/pcie/aspm.c
48095 +++ b/drivers/pci/pcie/aspm.c
48096 @@ -27,9 +27,9 @@
48097 #define MODULE_PARAM_PREFIX "pcie_aspm."
48098
48099 /* Note: those are not register definitions */
48100 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
48101 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
48102 -#define ASPM_STATE_L1 (4) /* L1 state */
48103 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
48104 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
48105 +#define ASPM_STATE_L1 (4U) /* L1 state */
48106 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
48107 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
48108
48109 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
48110 index ef09f5f..49ac62f 100644
48111 --- a/drivers/pci/probe.c
48112 +++ b/drivers/pci/probe.c
48113 @@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
48114 struct pci_bus_region region, inverted_region;
48115 bool bar_too_big = false, bar_disabled = false;
48116
48117 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
48118 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
48119
48120 /* No printks while decoding is disabled! */
48121 if (!dev->mmio_always_on) {
48122 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
48123 index 46d1378..30e452b 100644
48124 --- a/drivers/pci/proc.c
48125 +++ b/drivers/pci/proc.c
48126 @@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
48127 static int __init pci_proc_init(void)
48128 {
48129 struct pci_dev *dev = NULL;
48130 +
48131 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48132 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48133 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
48134 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48135 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
48136 +#endif
48137 +#else
48138 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
48139 +#endif
48140 proc_create("devices", 0, proc_bus_pci_dir,
48141 &proc_bus_pci_dev_operations);
48142 proc_initialized = 1;
48143 diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
48144 index 7f3aad0..7d604bb 100644
48145 --- a/drivers/platform/chrome/chromeos_laptop.c
48146 +++ b/drivers/platform/chrome/chromeos_laptop.c
48147 @@ -406,7 +406,7 @@ static struct chromeos_laptop cr48 = {
48148 .callback = chromeos_laptop_dmi_matched, \
48149 .driver_data = (void *)&board_
48150
48151 -static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
48152 +static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
48153 {
48154 .ident = "Samsung Series 5 550",
48155 .matches = {
48156 diff --git a/drivers/platform/x86/alienware-wmi.c b/drivers/platform/x86/alienware-wmi.c
48157 index 541f951..4dfd598 100644
48158 --- a/drivers/platform/x86/alienware-wmi.c
48159 +++ b/drivers/platform/x86/alienware-wmi.c
48160 @@ -132,7 +132,7 @@ struct wmax_led_args {
48161 } __packed;
48162
48163 static struct platform_device *platform_device;
48164 -static struct device_attribute *zone_dev_attrs;
48165 +static device_attribute_no_const *zone_dev_attrs;
48166 static struct attribute **zone_attrs;
48167 static struct platform_zone *zone_data;
48168
48169 @@ -143,7 +143,7 @@ static struct platform_driver platform_driver = {
48170 }
48171 };
48172
48173 -static struct attribute_group zone_attribute_group = {
48174 +static attribute_group_no_const zone_attribute_group = {
48175 .name = "rgb_zones",
48176 };
48177
48178 diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
48179 index c5e082f..d6307a0 100644
48180 --- a/drivers/platform/x86/asus-wmi.c
48181 +++ b/drivers/platform/x86/asus-wmi.c
48182 @@ -1595,6 +1595,10 @@ static int show_dsts(struct seq_file *m, void *data)
48183 int err;
48184 u32 retval = -1;
48185
48186 +#ifdef CONFIG_GRKERNSEC_KMEM
48187 + return -EPERM;
48188 +#endif
48189 +
48190 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
48191
48192 if (err < 0)
48193 @@ -1611,6 +1615,10 @@ static int show_devs(struct seq_file *m, void *data)
48194 int err;
48195 u32 retval = -1;
48196
48197 +#ifdef CONFIG_GRKERNSEC_KMEM
48198 + return -EPERM;
48199 +#endif
48200 +
48201 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
48202 &retval);
48203
48204 @@ -1635,6 +1643,10 @@ static int show_call(struct seq_file *m, void *data)
48205 union acpi_object *obj;
48206 acpi_status status;
48207
48208 +#ifdef CONFIG_GRKERNSEC_KMEM
48209 + return -EPERM;
48210 +#endif
48211 +
48212 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
48213 1, asus->debug.method_id,
48214 &input, &output);
48215 diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
48216 index 62f8030..c7f2a45 100644
48217 --- a/drivers/platform/x86/msi-laptop.c
48218 +++ b/drivers/platform/x86/msi-laptop.c
48219 @@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
48220
48221 if (!quirks->ec_read_only) {
48222 /* allow userland write sysfs file */
48223 - dev_attr_bluetooth.store = store_bluetooth;
48224 - dev_attr_wlan.store = store_wlan;
48225 - dev_attr_threeg.store = store_threeg;
48226 - dev_attr_bluetooth.attr.mode |= S_IWUSR;
48227 - dev_attr_wlan.attr.mode |= S_IWUSR;
48228 - dev_attr_threeg.attr.mode |= S_IWUSR;
48229 + pax_open_kernel();
48230 + *(void **)&dev_attr_bluetooth.store = store_bluetooth;
48231 + *(void **)&dev_attr_wlan.store = store_wlan;
48232 + *(void **)&dev_attr_threeg.store = store_threeg;
48233 + *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
48234 + *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
48235 + *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
48236 + pax_close_kernel();
48237 }
48238
48239 /* disable hardware control by fn key */
48240 diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
48241 index 70222f2..8c8ce66 100644
48242 --- a/drivers/platform/x86/msi-wmi.c
48243 +++ b/drivers/platform/x86/msi-wmi.c
48244 @@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
48245 static void msi_wmi_notify(u32 value, void *context)
48246 {
48247 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
48248 - static struct key_entry *key;
48249 + struct key_entry *key;
48250 union acpi_object *obj;
48251 acpi_status status;
48252
48253 diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
48254 index 9c5a074..06c976a 100644
48255 --- a/drivers/platform/x86/sony-laptop.c
48256 +++ b/drivers/platform/x86/sony-laptop.c
48257 @@ -2527,7 +2527,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
48258 }
48259
48260 /* High speed charging function */
48261 -static struct device_attribute *hsc_handle;
48262 +static device_attribute_no_const *hsc_handle;
48263
48264 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
48265 struct device_attribute *attr,
48266 @@ -2601,7 +2601,7 @@ static void sony_nc_highspeed_charging_cleanup(struct platform_device *pd)
48267 }
48268
48269 /* low battery function */
48270 -static struct device_attribute *lowbatt_handle;
48271 +static device_attribute_no_const *lowbatt_handle;
48272
48273 static ssize_t sony_nc_lowbatt_store(struct device *dev,
48274 struct device_attribute *attr,
48275 @@ -2667,7 +2667,7 @@ static void sony_nc_lowbatt_cleanup(struct platform_device *pd)
48276 }
48277
48278 /* fan speed function */
48279 -static struct device_attribute *fan_handle, *hsf_handle;
48280 +static device_attribute_no_const *fan_handle, *hsf_handle;
48281
48282 static ssize_t sony_nc_hsfan_store(struct device *dev,
48283 struct device_attribute *attr,
48284 @@ -2774,7 +2774,7 @@ static void sony_nc_fanspeed_cleanup(struct platform_device *pd)
48285 }
48286
48287 /* USB charge function */
48288 -static struct device_attribute *uc_handle;
48289 +static device_attribute_no_const *uc_handle;
48290
48291 static ssize_t sony_nc_usb_charge_store(struct device *dev,
48292 struct device_attribute *attr,
48293 @@ -2848,7 +2848,7 @@ static void sony_nc_usb_charge_cleanup(struct platform_device *pd)
48294 }
48295
48296 /* Panel ID function */
48297 -static struct device_attribute *panel_handle;
48298 +static device_attribute_no_const *panel_handle;
48299
48300 static ssize_t sony_nc_panelid_show(struct device *dev,
48301 struct device_attribute *attr, char *buffer)
48302 @@ -2895,7 +2895,7 @@ static void sony_nc_panelid_cleanup(struct platform_device *pd)
48303 }
48304
48305 /* smart connect function */
48306 -static struct device_attribute *sc_handle;
48307 +static device_attribute_no_const *sc_handle;
48308
48309 static ssize_t sony_nc_smart_conn_store(struct device *dev,
48310 struct device_attribute *attr,
48311 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
48312 index 15e61c1..40a39c7 100644
48313 --- a/drivers/platform/x86/thinkpad_acpi.c
48314 +++ b/drivers/platform/x86/thinkpad_acpi.c
48315 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
48316 return 0;
48317 }
48318
48319 -void static hotkey_mask_warn_incomplete_mask(void)
48320 +static void hotkey_mask_warn_incomplete_mask(void)
48321 {
48322 /* log only what the user can fix... */
48323 const u32 wantedmask = hotkey_driver_mask &
48324 @@ -2438,10 +2438,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48325 && !tp_features.bright_unkfw)
48326 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
48327 }
48328 +}
48329
48330 #undef TPACPI_COMPARE_KEY
48331 #undef TPACPI_MAY_SEND_KEY
48332 -}
48333
48334 /*
48335 * Polling driver
48336 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
48337 index 438d4c7..ca8a2fb 100644
48338 --- a/drivers/pnp/pnpbios/bioscalls.c
48339 +++ b/drivers/pnp/pnpbios/bioscalls.c
48340 @@ -59,7 +59,7 @@ do { \
48341 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
48342 } while(0)
48343
48344 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
48345 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
48346 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
48347
48348 /*
48349 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
48350
48351 cpu = get_cpu();
48352 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
48353 +
48354 + pax_open_kernel();
48355 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
48356 + pax_close_kernel();
48357
48358 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
48359 spin_lock_irqsave(&pnp_bios_lock, flags);
48360 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
48361 :"memory");
48362 spin_unlock_irqrestore(&pnp_bios_lock, flags);
48363
48364 + pax_open_kernel();
48365 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
48366 + pax_close_kernel();
48367 +
48368 put_cpu();
48369
48370 /* If we get here and this is set then the PnP BIOS faulted on us. */
48371 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
48372 return status;
48373 }
48374
48375 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
48376 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
48377 {
48378 int i;
48379
48380 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
48381 pnp_bios_callpoint.offset = header->fields.pm16offset;
48382 pnp_bios_callpoint.segment = PNP_CS16;
48383
48384 + pax_open_kernel();
48385 +
48386 for_each_possible_cpu(i) {
48387 struct desc_struct *gdt = get_cpu_gdt_table(i);
48388 if (!gdt)
48389 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
48390 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
48391 (unsigned long)__va(header->fields.pm16dseg));
48392 }
48393 +
48394 + pax_close_kernel();
48395 }
48396 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
48397 index 01712cb..782e822 100644
48398 --- a/drivers/pnp/resource.c
48399 +++ b/drivers/pnp/resource.c
48400 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
48401 return 1;
48402
48403 /* check if the resource is valid */
48404 - if (*irq < 0 || *irq > 15)
48405 + if (*irq > 15)
48406 return 0;
48407
48408 /* check if the resource is reserved */
48409 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
48410 return 1;
48411
48412 /* check if the resource is valid */
48413 - if (*dma < 0 || *dma == 4 || *dma > 7)
48414 + if (*dma == 4 || *dma > 7)
48415 return 0;
48416
48417 /* check if the resource is reserved */
48418 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
48419 index 0c52e2a..3421ab7 100644
48420 --- a/drivers/power/pda_power.c
48421 +++ b/drivers/power/pda_power.c
48422 @@ -37,7 +37,11 @@ static int polling;
48423
48424 #if IS_ENABLED(CONFIG_USB_PHY)
48425 static struct usb_phy *transceiver;
48426 -static struct notifier_block otg_nb;
48427 +static int otg_handle_notification(struct notifier_block *nb,
48428 + unsigned long event, void *unused);
48429 +static struct notifier_block otg_nb = {
48430 + .notifier_call = otg_handle_notification
48431 +};
48432 #endif
48433
48434 static struct regulator *ac_draw;
48435 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
48436
48437 #if IS_ENABLED(CONFIG_USB_PHY)
48438 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
48439 - otg_nb.notifier_call = otg_handle_notification;
48440 ret = usb_register_notifier(transceiver, &otg_nb);
48441 if (ret) {
48442 dev_err(dev, "failure to register otg notifier\n");
48443 diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
48444 index cc439fd..8fa30df 100644
48445 --- a/drivers/power/power_supply.h
48446 +++ b/drivers/power/power_supply.h
48447 @@ -16,12 +16,12 @@ struct power_supply;
48448
48449 #ifdef CONFIG_SYSFS
48450
48451 -extern void power_supply_init_attrs(struct device_type *dev_type);
48452 +extern void power_supply_init_attrs(void);
48453 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
48454
48455 #else
48456
48457 -static inline void power_supply_init_attrs(struct device_type *dev_type) {}
48458 +static inline void power_supply_init_attrs(void) {}
48459 #define power_supply_uevent NULL
48460
48461 #endif /* CONFIG_SYSFS */
48462 diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
48463 index 2660664..75fcb04 100644
48464 --- a/drivers/power/power_supply_core.c
48465 +++ b/drivers/power/power_supply_core.c
48466 @@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
48467 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
48468 EXPORT_SYMBOL_GPL(power_supply_notifier);
48469
48470 -static struct device_type power_supply_dev_type;
48471 +extern const struct attribute_group *power_supply_attr_groups[];
48472 +static struct device_type power_supply_dev_type = {
48473 + .groups = power_supply_attr_groups,
48474 +};
48475
48476 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
48477 struct power_supply *supply)
48478 @@ -628,7 +631,7 @@ static int __init power_supply_class_init(void)
48479 return PTR_ERR(power_supply_class);
48480
48481 power_supply_class->dev_uevent = power_supply_uevent;
48482 - power_supply_init_attrs(&power_supply_dev_type);
48483 + power_supply_init_attrs();
48484
48485 return 0;
48486 }
48487 diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
48488 index 44420d1..967126e 100644
48489 --- a/drivers/power/power_supply_sysfs.c
48490 +++ b/drivers/power/power_supply_sysfs.c
48491 @@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
48492 .is_visible = power_supply_attr_is_visible,
48493 };
48494
48495 -static const struct attribute_group *power_supply_attr_groups[] = {
48496 +const struct attribute_group *power_supply_attr_groups[] = {
48497 &power_supply_attr_group,
48498 NULL,
48499 };
48500
48501 -void power_supply_init_attrs(struct device_type *dev_type)
48502 +void power_supply_init_attrs(void)
48503 {
48504 int i;
48505
48506 - dev_type->groups = power_supply_attr_groups;
48507 -
48508 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
48509 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
48510 }
48511 diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
48512 index 84419af..268ede8 100644
48513 --- a/drivers/powercap/powercap_sys.c
48514 +++ b/drivers/powercap/powercap_sys.c
48515 @@ -154,8 +154,77 @@ struct powercap_constraint_attr {
48516 struct device_attribute name_attr;
48517 };
48518
48519 +static ssize_t show_constraint_name(struct device *dev,
48520 + struct device_attribute *dev_attr,
48521 + char *buf);
48522 +
48523 static struct powercap_constraint_attr
48524 - constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
48525 + constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
48526 + [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
48527 + .power_limit_attr = {
48528 + .attr = {
48529 + .name = NULL,
48530 + .mode = S_IWUSR | S_IRUGO
48531 + },
48532 + .show = show_constraint_power_limit_uw,
48533 + .store = store_constraint_power_limit_uw
48534 + },
48535 +
48536 + .time_window_attr = {
48537 + .attr = {
48538 + .name = NULL,
48539 + .mode = S_IWUSR | S_IRUGO
48540 + },
48541 + .show = show_constraint_time_window_us,
48542 + .store = store_constraint_time_window_us
48543 + },
48544 +
48545 + .max_power_attr = {
48546 + .attr = {
48547 + .name = NULL,
48548 + .mode = S_IRUGO
48549 + },
48550 + .show = show_constraint_max_power_uw,
48551 + .store = NULL
48552 + },
48553 +
48554 + .min_power_attr = {
48555 + .attr = {
48556 + .name = NULL,
48557 + .mode = S_IRUGO
48558 + },
48559 + .show = show_constraint_min_power_uw,
48560 + .store = NULL
48561 + },
48562 +
48563 + .max_time_window_attr = {
48564 + .attr = {
48565 + .name = NULL,
48566 + .mode = S_IRUGO
48567 + },
48568 + .show = show_constraint_max_time_window_us,
48569 + .store = NULL
48570 + },
48571 +
48572 + .min_time_window_attr = {
48573 + .attr = {
48574 + .name = NULL,
48575 + .mode = S_IRUGO
48576 + },
48577 + .show = show_constraint_min_time_window_us,
48578 + .store = NULL
48579 + },
48580 +
48581 + .name_attr = {
48582 + .attr = {
48583 + .name = NULL,
48584 + .mode = S_IRUGO
48585 + },
48586 + .show = show_constraint_name,
48587 + .store = NULL
48588 + }
48589 + }
48590 +};
48591
48592 /* A list of powercap control_types */
48593 static LIST_HEAD(powercap_cntrl_list);
48594 @@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
48595 }
48596
48597 static int create_constraint_attribute(int id, const char *name,
48598 - int mode,
48599 - struct device_attribute *dev_attr,
48600 - ssize_t (*show)(struct device *,
48601 - struct device_attribute *, char *),
48602 - ssize_t (*store)(struct device *,
48603 - struct device_attribute *,
48604 - const char *, size_t)
48605 - )
48606 + struct device_attribute *dev_attr)
48607 {
48608 + name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
48609
48610 - dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
48611 - id, name);
48612 - if (!dev_attr->attr.name)
48613 + if (!name)
48614 return -ENOMEM;
48615 - dev_attr->attr.mode = mode;
48616 - dev_attr->show = show;
48617 - dev_attr->store = store;
48618 +
48619 + pax_open_kernel();
48620 + *(const char **)&dev_attr->attr.name = name;
48621 + pax_close_kernel();
48622
48623 return 0;
48624 }
48625 @@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
48626
48627 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
48628 ret = create_constraint_attribute(i, "power_limit_uw",
48629 - S_IWUSR | S_IRUGO,
48630 - &constraint_attrs[i].power_limit_attr,
48631 - show_constraint_power_limit_uw,
48632 - store_constraint_power_limit_uw);
48633 + &constraint_attrs[i].power_limit_attr);
48634 if (ret)
48635 goto err_alloc;
48636 ret = create_constraint_attribute(i, "time_window_us",
48637 - S_IWUSR | S_IRUGO,
48638 - &constraint_attrs[i].time_window_attr,
48639 - show_constraint_time_window_us,
48640 - store_constraint_time_window_us);
48641 + &constraint_attrs[i].time_window_attr);
48642 if (ret)
48643 goto err_alloc;
48644 - ret = create_constraint_attribute(i, "name", S_IRUGO,
48645 - &constraint_attrs[i].name_attr,
48646 - show_constraint_name,
48647 - NULL);
48648 + ret = create_constraint_attribute(i, "name",
48649 + &constraint_attrs[i].name_attr);
48650 if (ret)
48651 goto err_alloc;
48652 - ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
48653 - &constraint_attrs[i].max_power_attr,
48654 - show_constraint_max_power_uw,
48655 - NULL);
48656 + ret = create_constraint_attribute(i, "max_power_uw",
48657 + &constraint_attrs[i].max_power_attr);
48658 if (ret)
48659 goto err_alloc;
48660 - ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
48661 - &constraint_attrs[i].min_power_attr,
48662 - show_constraint_min_power_uw,
48663 - NULL);
48664 + ret = create_constraint_attribute(i, "min_power_uw",
48665 + &constraint_attrs[i].min_power_attr);
48666 if (ret)
48667 goto err_alloc;
48668 ret = create_constraint_attribute(i, "max_time_window_us",
48669 - S_IRUGO,
48670 - &constraint_attrs[i].max_time_window_attr,
48671 - show_constraint_max_time_window_us,
48672 - NULL);
48673 + &constraint_attrs[i].max_time_window_attr);
48674 if (ret)
48675 goto err_alloc;
48676 ret = create_constraint_attribute(i, "min_time_window_us",
48677 - S_IRUGO,
48678 - &constraint_attrs[i].min_time_window_attr,
48679 - show_constraint_min_time_window_us,
48680 - NULL);
48681 + &constraint_attrs[i].min_time_window_attr);
48682 if (ret)
48683 goto err_alloc;
48684
48685 @@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
48686 power_zone->zone_dev_attrs[count++] =
48687 &dev_attr_max_energy_range_uj.attr;
48688 if (power_zone->ops->get_energy_uj) {
48689 + pax_open_kernel();
48690 if (power_zone->ops->reset_energy_uj)
48691 - dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48692 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48693 else
48694 - dev_attr_energy_uj.attr.mode = S_IRUGO;
48695 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
48696 + pax_close_kernel();
48697 power_zone->zone_dev_attrs[count++] =
48698 &dev_attr_energy_uj.attr;
48699 }
48700 diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h
48701 index 9c5d414..c7900ce 100644
48702 --- a/drivers/ptp/ptp_private.h
48703 +++ b/drivers/ptp/ptp_private.h
48704 @@ -51,7 +51,7 @@ struct ptp_clock {
48705 struct mutex pincfg_mux; /* protect concurrent info->pin_config access */
48706 wait_queue_head_t tsev_wq;
48707 int defunct; /* tells readers to go away when clock is being removed */
48708 - struct device_attribute *pin_dev_attr;
48709 + device_attribute_no_const *pin_dev_attr;
48710 struct attribute **pin_attr;
48711 struct attribute_group pin_attr_group;
48712 };
48713 diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c
48714 index 302e626..12579af 100644
48715 --- a/drivers/ptp/ptp_sysfs.c
48716 +++ b/drivers/ptp/ptp_sysfs.c
48717 @@ -280,7 +280,7 @@ static int ptp_populate_pins(struct ptp_clock *ptp)
48718 goto no_pin_attr;
48719
48720 for (i = 0; i < n_pins; i++) {
48721 - struct device_attribute *da = &ptp->pin_dev_attr[i];
48722 + device_attribute_no_const *da = &ptp->pin_dev_attr[i];
48723 sysfs_attr_init(&da->attr);
48724 da->attr.name = info->pin_config[i].name;
48725 da->attr.mode = 0644;
48726 diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
48727 index 9a09f3c..450b523 100644
48728 --- a/drivers/regulator/core.c
48729 +++ b/drivers/regulator/core.c
48730 @@ -3380,7 +3380,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48731 {
48732 const struct regulation_constraints *constraints = NULL;
48733 const struct regulator_init_data *init_data;
48734 - static atomic_t regulator_no = ATOMIC_INIT(0);
48735 + static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
48736 struct regulator_dev *rdev;
48737 struct device *dev;
48738 int ret, i;
48739 @@ -3450,7 +3450,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48740 rdev->dev.of_node = config->of_node;
48741 rdev->dev.parent = dev;
48742 dev_set_name(&rdev->dev, "regulator.%d",
48743 - atomic_inc_return(&regulator_no) - 1);
48744 + atomic_inc_return_unchecked(&regulator_no) - 1);
48745 ret = device_register(&rdev->dev);
48746 if (ret != 0) {
48747 put_device(&rdev->dev);
48748 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
48749 index 2fc4111..6aa88ca 100644
48750 --- a/drivers/regulator/max8660.c
48751 +++ b/drivers/regulator/max8660.c
48752 @@ -424,8 +424,10 @@ static int max8660_probe(struct i2c_client *client,
48753 max8660->shadow_regs[MAX8660_OVER1] = 5;
48754 } else {
48755 /* Otherwise devices can be toggled via software */
48756 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
48757 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
48758 + pax_open_kernel();
48759 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
48760 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
48761 + pax_close_kernel();
48762 }
48763
48764 /*
48765 diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
48766 index dbedf17..18ff6b7 100644
48767 --- a/drivers/regulator/max8973-regulator.c
48768 +++ b/drivers/regulator/max8973-regulator.c
48769 @@ -403,9 +403,11 @@ static int max8973_probe(struct i2c_client *client,
48770 if (!pdata || !pdata->enable_ext_control) {
48771 max->desc.enable_reg = MAX8973_VOUT;
48772 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
48773 - max->ops.enable = regulator_enable_regmap;
48774 - max->ops.disable = regulator_disable_regmap;
48775 - max->ops.is_enabled = regulator_is_enabled_regmap;
48776 + pax_open_kernel();
48777 + *(void **)&max->ops.enable = regulator_enable_regmap;
48778 + *(void **)&max->ops.disable = regulator_disable_regmap;
48779 + *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
48780 + pax_close_kernel();
48781 }
48782
48783 if (pdata) {
48784 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
48785 index f374fa5..26f0683 100644
48786 --- a/drivers/regulator/mc13892-regulator.c
48787 +++ b/drivers/regulator/mc13892-regulator.c
48788 @@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
48789 }
48790 mc13xxx_unlock(mc13892);
48791
48792 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48793 + pax_open_kernel();
48794 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48795 = mc13892_vcam_set_mode;
48796 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48797 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48798 = mc13892_vcam_get_mode;
48799 + pax_close_kernel();
48800
48801 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
48802 ARRAY_SIZE(mc13892_regulators));
48803 diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
48804 index 0963c93..ea29cce 100644
48805 --- a/drivers/rtc/rtc-cmos.c
48806 +++ b/drivers/rtc/rtc-cmos.c
48807 @@ -777,7 +777,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
48808 hpet_rtc_timer_init();
48809
48810 /* export at least the first block of NVRAM */
48811 - nvram.size = address_space - NVRAM_OFFSET;
48812 + pax_open_kernel();
48813 + *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
48814 + pax_close_kernel();
48815 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
48816 if (retval < 0) {
48817 dev_dbg(dev, "can't create nvram file? %d\n", retval);
48818 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
48819 index d049393..bb20be0 100644
48820 --- a/drivers/rtc/rtc-dev.c
48821 +++ b/drivers/rtc/rtc-dev.c
48822 @@ -16,6 +16,7 @@
48823 #include <linux/module.h>
48824 #include <linux/rtc.h>
48825 #include <linux/sched.h>
48826 +#include <linux/grsecurity.h>
48827 #include "rtc-core.h"
48828
48829 static dev_t rtc_devt;
48830 @@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
48831 if (copy_from_user(&tm, uarg, sizeof(tm)))
48832 return -EFAULT;
48833
48834 + gr_log_timechange();
48835 +
48836 return rtc_set_time(rtc, &tm);
48837
48838 case RTC_PIE_ON:
48839 diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
48840 index f03d5ba..8325bf6 100644
48841 --- a/drivers/rtc/rtc-ds1307.c
48842 +++ b/drivers/rtc/rtc-ds1307.c
48843 @@ -107,7 +107,7 @@ struct ds1307 {
48844 u8 offset; /* register's offset */
48845 u8 regs[11];
48846 u16 nvram_offset;
48847 - struct bin_attribute *nvram;
48848 + bin_attribute_no_const *nvram;
48849 enum ds_type type;
48850 unsigned long flags;
48851 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
48852 diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
48853 index 11880c1..b823aa4 100644
48854 --- a/drivers/rtc/rtc-m48t59.c
48855 +++ b/drivers/rtc/rtc-m48t59.c
48856 @@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
48857 if (IS_ERR(m48t59->rtc))
48858 return PTR_ERR(m48t59->rtc);
48859
48860 - m48t59_nvram_attr.size = pdata->offset;
48861 + pax_open_kernel();
48862 + *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
48863 + pax_close_kernel();
48864
48865 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
48866 if (ret)
48867 diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
48868 index 14b5f8d..cc9bd26 100644
48869 --- a/drivers/scsi/aic7xxx/aic79xx_pci.c
48870 +++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
48871 @@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
48872 for (bit = 0; bit < 8; bit++) {
48873
48874 if ((pci_status[i] & (0x1 << bit)) != 0) {
48875 - static const char *s;
48876 + const char *s;
48877
48878 s = pci_status_strings[bit];
48879 if (i == 7/*TARG*/ && bit == 3)
48880 @@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
48881
48882 for (bit = 0; bit < 8; bit++) {
48883
48884 - if ((split_status[i] & (0x1 << bit)) != 0) {
48885 - static const char *s;
48886 -
48887 - s = split_status_strings[bit];
48888 - printk(s, ahd_name(ahd),
48889 + if ((split_status[i] & (0x1 << bit)) != 0)
48890 + printk(split_status_strings[bit], ahd_name(ahd),
48891 split_status_source[i]);
48892 - }
48893
48894 if (i > 1)
48895 continue;
48896
48897 - if ((sg_split_status[i] & (0x1 << bit)) != 0) {
48898 - static const char *s;
48899 -
48900 - s = split_status_strings[bit];
48901 - printk(s, ahd_name(ahd), "SG");
48902 - }
48903 + if ((sg_split_status[i] & (0x1 << bit)) != 0)
48904 + printk(split_status_strings[bit], ahd_name(ahd), "SG");
48905 }
48906 }
48907 /*
48908 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
48909 index e693af6..2e525b6 100644
48910 --- a/drivers/scsi/bfa/bfa_fcpim.h
48911 +++ b/drivers/scsi/bfa/bfa_fcpim.h
48912 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
48913
48914 struct bfa_itn_s {
48915 bfa_isr_func_t isr;
48916 -};
48917 +} __no_const;
48918
48919 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
48920 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
48921 diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
48922 index a3ab5cc..8143622 100644
48923 --- a/drivers/scsi/bfa/bfa_fcs.c
48924 +++ b/drivers/scsi/bfa/bfa_fcs.c
48925 @@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
48926 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
48927
48928 static struct bfa_fcs_mod_s fcs_modules[] = {
48929 - { bfa_fcs_port_attach, NULL, NULL },
48930 - { bfa_fcs_uf_attach, NULL, NULL },
48931 - { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
48932 - bfa_fcs_fabric_modexit },
48933 + {
48934 + .attach = bfa_fcs_port_attach,
48935 + .modinit = NULL,
48936 + .modexit = NULL
48937 + },
48938 + {
48939 + .attach = bfa_fcs_uf_attach,
48940 + .modinit = NULL,
48941 + .modexit = NULL
48942 + },
48943 + {
48944 + .attach = bfa_fcs_fabric_attach,
48945 + .modinit = bfa_fcs_fabric_modinit,
48946 + .modexit = bfa_fcs_fabric_modexit
48947 + },
48948 };
48949
48950 /*
48951 diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
48952 index ff75ef8..2dfe00a 100644
48953 --- a/drivers/scsi/bfa/bfa_fcs_lport.c
48954 +++ b/drivers/scsi/bfa/bfa_fcs_lport.c
48955 @@ -89,15 +89,26 @@ static struct {
48956 void (*offline) (struct bfa_fcs_lport_s *port);
48957 } __port_action[] = {
48958 {
48959 - bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
48960 - bfa_fcs_lport_unknown_offline}, {
48961 - bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
48962 - bfa_fcs_lport_fab_offline}, {
48963 - bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
48964 - bfa_fcs_lport_n2n_offline}, {
48965 - bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
48966 - bfa_fcs_lport_loop_offline},
48967 - };
48968 + .init = bfa_fcs_lport_unknown_init,
48969 + .online = bfa_fcs_lport_unknown_online,
48970 + .offline = bfa_fcs_lport_unknown_offline
48971 + },
48972 + {
48973 + .init = bfa_fcs_lport_fab_init,
48974 + .online = bfa_fcs_lport_fab_online,
48975 + .offline = bfa_fcs_lport_fab_offline
48976 + },
48977 + {
48978 + .init = bfa_fcs_lport_n2n_init,
48979 + .online = bfa_fcs_lport_n2n_online,
48980 + .offline = bfa_fcs_lport_n2n_offline
48981 + },
48982 + {
48983 + .init = bfa_fcs_lport_loop_init,
48984 + .online = bfa_fcs_lport_loop_online,
48985 + .offline = bfa_fcs_lport_loop_offline
48986 + },
48987 +};
48988
48989 /*
48990 * fcs_port_sm FCS logical port state machine
48991 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
48992 index 2e28392..9d865b6 100644
48993 --- a/drivers/scsi/bfa/bfa_ioc.h
48994 +++ b/drivers/scsi/bfa/bfa_ioc.h
48995 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
48996 bfa_ioc_disable_cbfn_t disable_cbfn;
48997 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
48998 bfa_ioc_reset_cbfn_t reset_cbfn;
48999 -};
49000 +} __no_const;
49001
49002 /*
49003 * IOC event notification mechanism.
49004 @@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
49005 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
49006 enum bfi_ioc_state fwstate);
49007 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
49008 -};
49009 +} __no_const;
49010
49011 /*
49012 * Queue element to wait for room in request queue. FIFO order is
49013 diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
49014 index a14c784..6de6790 100644
49015 --- a/drivers/scsi/bfa/bfa_modules.h
49016 +++ b/drivers/scsi/bfa/bfa_modules.h
49017 @@ -78,12 +78,12 @@ enum {
49018 \
49019 extern struct bfa_module_s hal_mod_ ## __mod; \
49020 struct bfa_module_s hal_mod_ ## __mod = { \
49021 - bfa_ ## __mod ## _meminfo, \
49022 - bfa_ ## __mod ## _attach, \
49023 - bfa_ ## __mod ## _detach, \
49024 - bfa_ ## __mod ## _start, \
49025 - bfa_ ## __mod ## _stop, \
49026 - bfa_ ## __mod ## _iocdisable, \
49027 + .meminfo = bfa_ ## __mod ## _meminfo, \
49028 + .attach = bfa_ ## __mod ## _attach, \
49029 + .detach = bfa_ ## __mod ## _detach, \
49030 + .start = bfa_ ## __mod ## _start, \
49031 + .stop = bfa_ ## __mod ## _stop, \
49032 + .iocdisable = bfa_ ## __mod ## _iocdisable, \
49033 }
49034
49035 #define BFA_CACHELINE_SZ (256)
49036 diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
49037 index 045c4e1..13de803 100644
49038 --- a/drivers/scsi/fcoe/fcoe_sysfs.c
49039 +++ b/drivers/scsi/fcoe/fcoe_sysfs.c
49040 @@ -33,8 +33,8 @@
49041 */
49042 #include "libfcoe.h"
49043
49044 -static atomic_t ctlr_num;
49045 -static atomic_t fcf_num;
49046 +static atomic_unchecked_t ctlr_num;
49047 +static atomic_unchecked_t fcf_num;
49048
49049 /*
49050 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
49051 @@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
49052 if (!ctlr)
49053 goto out;
49054
49055 - ctlr->id = atomic_inc_return(&ctlr_num) - 1;
49056 + ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
49057 ctlr->f = f;
49058 ctlr->mode = FIP_CONN_TYPE_FABRIC;
49059 INIT_LIST_HEAD(&ctlr->fcfs);
49060 @@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
49061 fcf->dev.parent = &ctlr->dev;
49062 fcf->dev.bus = &fcoe_bus_type;
49063 fcf->dev.type = &fcoe_fcf_device_type;
49064 - fcf->id = atomic_inc_return(&fcf_num) - 1;
49065 + fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
49066 fcf->state = FCOE_FCF_STATE_UNKNOWN;
49067
49068 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
49069 @@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
49070 {
49071 int error;
49072
49073 - atomic_set(&ctlr_num, 0);
49074 - atomic_set(&fcf_num, 0);
49075 + atomic_set_unchecked(&ctlr_num, 0);
49076 + atomic_set_unchecked(&fcf_num, 0);
49077
49078 error = bus_register(&fcoe_bus_type);
49079 if (error)
49080 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
49081 index 3cbb57a..95e47a3 100644
49082 --- a/drivers/scsi/hosts.c
49083 +++ b/drivers/scsi/hosts.c
49084 @@ -42,7 +42,7 @@
49085 #include "scsi_logging.h"
49086
49087
49088 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
49089 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
49090
49091
49092 static void scsi_host_cls_release(struct device *dev)
49093 @@ -369,7 +369,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
49094 * subtract one because we increment first then return, but we need to
49095 * know what the next host number was before increment
49096 */
49097 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
49098 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
49099 shost->dma_channel = 0xff;
49100
49101 /* These three are default values which can be overridden */
49102 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
49103 index fda6cf1..7a6b5d8 100644
49104 --- a/drivers/scsi/hpsa.c
49105 +++ b/drivers/scsi/hpsa.c
49106 @@ -699,10 +699,10 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
49107 unsigned long flags;
49108
49109 if (h->transMethod & CFGTBL_Trans_io_accel1)
49110 - return h->access.command_completed(h, q);
49111 + return h->access->command_completed(h, q);
49112
49113 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
49114 - return h->access.command_completed(h, q);
49115 + return h->access->command_completed(h, q);
49116
49117 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
49118 a = rq->head[rq->current_entry];
49119 @@ -5460,7 +5460,7 @@ static void start_io(struct ctlr_info *h)
49120 while (!list_empty(&h->reqQ)) {
49121 c = list_entry(h->reqQ.next, struct CommandList, list);
49122 /* can't do anything if fifo is full */
49123 - if ((h->access.fifo_full(h))) {
49124 + if ((h->access->fifo_full(h))) {
49125 h->fifo_recently_full = 1;
49126 dev_warn(&h->pdev->dev, "fifo full\n");
49127 break;
49128 @@ -5484,7 +5484,7 @@ static void start_io(struct ctlr_info *h)
49129
49130 /* Tell the controller execute command */
49131 spin_unlock_irqrestore(&h->lock, flags);
49132 - h->access.submit_command(h, c);
49133 + h->access->submit_command(h, c);
49134 spin_lock_irqsave(&h->lock, flags);
49135 }
49136 spin_unlock_irqrestore(&h->lock, flags);
49137 @@ -5492,17 +5492,17 @@ static void start_io(struct ctlr_info *h)
49138
49139 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
49140 {
49141 - return h->access.command_completed(h, q);
49142 + return h->access->command_completed(h, q);
49143 }
49144
49145 static inline bool interrupt_pending(struct ctlr_info *h)
49146 {
49147 - return h->access.intr_pending(h);
49148 + return h->access->intr_pending(h);
49149 }
49150
49151 static inline long interrupt_not_for_us(struct ctlr_info *h)
49152 {
49153 - return (h->access.intr_pending(h) == 0) ||
49154 + return (h->access->intr_pending(h) == 0) ||
49155 (h->interrupts_enabled == 0);
49156 }
49157
49158 @@ -6456,7 +6456,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
49159 if (prod_index < 0)
49160 return -ENODEV;
49161 h->product_name = products[prod_index].product_name;
49162 - h->access = *(products[prod_index].access);
49163 + h->access = products[prod_index].access;
49164
49165 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
49166 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
49167 @@ -6735,7 +6735,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
49168 {
49169 unsigned long flags;
49170
49171 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
49172 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
49173 spin_lock_irqsave(&h->lock, flags);
49174 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
49175 spin_unlock_irqrestore(&h->lock, flags);
49176 @@ -6963,7 +6963,7 @@ reinit_after_soft_reset:
49177 }
49178
49179 /* make sure the board interrupts are off */
49180 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
49181 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
49182
49183 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
49184 goto clean2;
49185 @@ -6998,7 +6998,7 @@ reinit_after_soft_reset:
49186 * fake ones to scoop up any residual completions.
49187 */
49188 spin_lock_irqsave(&h->lock, flags);
49189 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
49190 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
49191 spin_unlock_irqrestore(&h->lock, flags);
49192 free_irqs(h);
49193 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
49194 @@ -7017,9 +7017,9 @@ reinit_after_soft_reset:
49195 dev_info(&h->pdev->dev, "Board READY.\n");
49196 dev_info(&h->pdev->dev,
49197 "Waiting for stale completions to drain.\n");
49198 - h->access.set_intr_mask(h, HPSA_INTR_ON);
49199 + h->access->set_intr_mask(h, HPSA_INTR_ON);
49200 msleep(10000);
49201 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
49202 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
49203
49204 rc = controller_reset_failed(h->cfgtable);
49205 if (rc)
49206 @@ -7045,7 +7045,7 @@ reinit_after_soft_reset:
49207 h->drv_req_rescan = 0;
49208
49209 /* Turn the interrupts on so we can service requests */
49210 - h->access.set_intr_mask(h, HPSA_INTR_ON);
49211 + h->access->set_intr_mask(h, HPSA_INTR_ON);
49212
49213 hpsa_hba_inquiry(h);
49214 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
49215 @@ -7114,7 +7114,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
49216 * To write all data in the battery backed cache to disks
49217 */
49218 hpsa_flush_cache(h);
49219 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
49220 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
49221 hpsa_free_irqs_and_disable_msix(h);
49222 }
49223
49224 @@ -7232,7 +7232,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
49225 CFGTBL_Trans_enable_directed_msix |
49226 (trans_support & (CFGTBL_Trans_io_accel1 |
49227 CFGTBL_Trans_io_accel2));
49228 - struct access_method access = SA5_performant_access;
49229 + struct access_method *access = &SA5_performant_access;
49230
49231 /* This is a bit complicated. There are 8 registers on
49232 * the controller which we write to to tell it 8 different
49233 @@ -7297,12 +7297,12 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
49234 * enable outbound interrupt coalescing in accelerator mode;
49235 */
49236 if (trans_support & CFGTBL_Trans_io_accel1) {
49237 - access = SA5_ioaccel_mode1_access;
49238 + access = &SA5_ioaccel_mode1_access;
49239 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
49240 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
49241 } else {
49242 if (trans_support & CFGTBL_Trans_io_accel2) {
49243 - access = SA5_ioaccel_mode2_access;
49244 + access = &SA5_ioaccel_mode2_access;
49245 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
49246 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
49247 }
49248 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
49249 index 44235a2..962e91b 100644
49250 --- a/drivers/scsi/hpsa.h
49251 +++ b/drivers/scsi/hpsa.h
49252 @@ -128,7 +128,7 @@ struct ctlr_info {
49253 unsigned int msix_vector;
49254 unsigned int msi_vector;
49255 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
49256 - struct access_method access;
49257 + struct access_method *access;
49258 char hba_mode_enabled;
49259
49260 /* queue and queue Info */
49261 @@ -541,35 +541,35 @@ static unsigned long SA5_ioaccel_mode1_completed(struct ctlr_info *h, u8 q)
49262 }
49263
49264 static struct access_method SA5_access = {
49265 - SA5_submit_command,
49266 - SA5_intr_mask,
49267 - SA5_fifo_full,
49268 - SA5_intr_pending,
49269 - SA5_completed,
49270 + .submit_command = SA5_submit_command,
49271 + .set_intr_mask = SA5_intr_mask,
49272 + .fifo_full = SA5_fifo_full,
49273 + .intr_pending = SA5_intr_pending,
49274 + .command_completed = SA5_completed,
49275 };
49276
49277 static struct access_method SA5_ioaccel_mode1_access = {
49278 - SA5_submit_command,
49279 - SA5_performant_intr_mask,
49280 - SA5_fifo_full,
49281 - SA5_ioaccel_mode1_intr_pending,
49282 - SA5_ioaccel_mode1_completed,
49283 + .submit_command = SA5_submit_command,
49284 + .set_intr_mask = SA5_performant_intr_mask,
49285 + .fifo_full = SA5_fifo_full,
49286 + .intr_pending = SA5_ioaccel_mode1_intr_pending,
49287 + .command_completed = SA5_ioaccel_mode1_completed,
49288 };
49289
49290 static struct access_method SA5_ioaccel_mode2_access = {
49291 - SA5_submit_command_ioaccel2,
49292 - SA5_performant_intr_mask,
49293 - SA5_fifo_full,
49294 - SA5_performant_intr_pending,
49295 - SA5_performant_completed,
49296 + .submit_command = SA5_submit_command_ioaccel2,
49297 + .set_intr_mask = SA5_performant_intr_mask,
49298 + .fifo_full = SA5_fifo_full,
49299 + .intr_pending = SA5_performant_intr_pending,
49300 + .command_completed = SA5_performant_completed,
49301 };
49302
49303 static struct access_method SA5_performant_access = {
49304 - SA5_submit_command,
49305 - SA5_performant_intr_mask,
49306 - SA5_fifo_full,
49307 - SA5_performant_intr_pending,
49308 - SA5_performant_completed,
49309 + .submit_command = SA5_submit_command,
49310 + .set_intr_mask = SA5_performant_intr_mask,
49311 + .fifo_full = SA5_fifo_full,
49312 + .intr_pending = SA5_performant_intr_pending,
49313 + .command_completed = SA5_performant_completed,
49314 };
49315
49316 struct board_type {
49317 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
49318 index 1b3a094..068e683 100644
49319 --- a/drivers/scsi/libfc/fc_exch.c
49320 +++ b/drivers/scsi/libfc/fc_exch.c
49321 @@ -101,12 +101,12 @@ struct fc_exch_mgr {
49322 u16 pool_max_index;
49323
49324 struct {
49325 - atomic_t no_free_exch;
49326 - atomic_t no_free_exch_xid;
49327 - atomic_t xid_not_found;
49328 - atomic_t xid_busy;
49329 - atomic_t seq_not_found;
49330 - atomic_t non_bls_resp;
49331 + atomic_unchecked_t no_free_exch;
49332 + atomic_unchecked_t no_free_exch_xid;
49333 + atomic_unchecked_t xid_not_found;
49334 + atomic_unchecked_t xid_busy;
49335 + atomic_unchecked_t seq_not_found;
49336 + atomic_unchecked_t non_bls_resp;
49337 } stats;
49338 };
49339
49340 @@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
49341 /* allocate memory for exchange */
49342 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
49343 if (!ep) {
49344 - atomic_inc(&mp->stats.no_free_exch);
49345 + atomic_inc_unchecked(&mp->stats.no_free_exch);
49346 goto out;
49347 }
49348 memset(ep, 0, sizeof(*ep));
49349 @@ -874,7 +874,7 @@ out:
49350 return ep;
49351 err:
49352 spin_unlock_bh(&pool->lock);
49353 - atomic_inc(&mp->stats.no_free_exch_xid);
49354 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
49355 mempool_free(ep, mp->ep_pool);
49356 return NULL;
49357 }
49358 @@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49359 xid = ntohs(fh->fh_ox_id); /* we originated exch */
49360 ep = fc_exch_find(mp, xid);
49361 if (!ep) {
49362 - atomic_inc(&mp->stats.xid_not_found);
49363 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49364 reject = FC_RJT_OX_ID;
49365 goto out;
49366 }
49367 @@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49368 ep = fc_exch_find(mp, xid);
49369 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
49370 if (ep) {
49371 - atomic_inc(&mp->stats.xid_busy);
49372 + atomic_inc_unchecked(&mp->stats.xid_busy);
49373 reject = FC_RJT_RX_ID;
49374 goto rel;
49375 }
49376 @@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49377 }
49378 xid = ep->xid; /* get our XID */
49379 } else if (!ep) {
49380 - atomic_inc(&mp->stats.xid_not_found);
49381 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49382 reject = FC_RJT_RX_ID; /* XID not found */
49383 goto out;
49384 }
49385 @@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49386 } else {
49387 sp = &ep->seq;
49388 if (sp->id != fh->fh_seq_id) {
49389 - atomic_inc(&mp->stats.seq_not_found);
49390 + atomic_inc_unchecked(&mp->stats.seq_not_found);
49391 if (f_ctl & FC_FC_END_SEQ) {
49392 /*
49393 * Update sequence_id based on incoming last
49394 @@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49395
49396 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
49397 if (!ep) {
49398 - atomic_inc(&mp->stats.xid_not_found);
49399 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49400 goto out;
49401 }
49402 if (ep->esb_stat & ESB_ST_COMPLETE) {
49403 - atomic_inc(&mp->stats.xid_not_found);
49404 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49405 goto rel;
49406 }
49407 if (ep->rxid == FC_XID_UNKNOWN)
49408 ep->rxid = ntohs(fh->fh_rx_id);
49409 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
49410 - atomic_inc(&mp->stats.xid_not_found);
49411 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49412 goto rel;
49413 }
49414 if (ep->did != ntoh24(fh->fh_s_id) &&
49415 ep->did != FC_FID_FLOGI) {
49416 - atomic_inc(&mp->stats.xid_not_found);
49417 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49418 goto rel;
49419 }
49420 sof = fr_sof(fp);
49421 @@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49422 sp->ssb_stat |= SSB_ST_RESP;
49423 sp->id = fh->fh_seq_id;
49424 } else if (sp->id != fh->fh_seq_id) {
49425 - atomic_inc(&mp->stats.seq_not_found);
49426 + atomic_inc_unchecked(&mp->stats.seq_not_found);
49427 goto rel;
49428 }
49429
49430 @@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49431 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
49432
49433 if (!sp)
49434 - atomic_inc(&mp->stats.xid_not_found);
49435 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49436 else
49437 - atomic_inc(&mp->stats.non_bls_resp);
49438 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
49439
49440 fc_frame_free(fp);
49441 }
49442 @@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
49443
49444 list_for_each_entry(ema, &lport->ema_list, ema_list) {
49445 mp = ema->mp;
49446 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
49447 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
49448 st->fc_no_free_exch_xid +=
49449 - atomic_read(&mp->stats.no_free_exch_xid);
49450 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
49451 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
49452 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
49453 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
49454 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
49455 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
49456 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
49457 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
49458 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
49459 }
49460 }
49461 EXPORT_SYMBOL(fc_exch_update_stats);
49462 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
49463 index 766098a..1c6c971 100644
49464 --- a/drivers/scsi/libsas/sas_ata.c
49465 +++ b/drivers/scsi/libsas/sas_ata.c
49466 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
49467 .postreset = ata_std_postreset,
49468 .error_handler = ata_std_error_handler,
49469 .post_internal_cmd = sas_ata_post_internal,
49470 - .qc_defer = ata_std_qc_defer,
49471 + .qc_defer = ata_std_qc_defer,
49472 .qc_prep = ata_noop_qc_prep,
49473 .qc_issue = sas_ata_qc_issue,
49474 .qc_fill_rtf = sas_ata_qc_fill_rtf,
49475 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
49476 index 94a3caf..a118dec 100644
49477 --- a/drivers/scsi/lpfc/lpfc.h
49478 +++ b/drivers/scsi/lpfc/lpfc.h
49479 @@ -430,7 +430,7 @@ struct lpfc_vport {
49480 struct dentry *debug_nodelist;
49481 struct dentry *vport_debugfs_root;
49482 struct lpfc_debugfs_trc *disc_trc;
49483 - atomic_t disc_trc_cnt;
49484 + atomic_unchecked_t disc_trc_cnt;
49485 #endif
49486 uint8_t stat_data_enabled;
49487 uint8_t stat_data_blocked;
49488 @@ -879,8 +879,8 @@ struct lpfc_hba {
49489 struct timer_list fabric_block_timer;
49490 unsigned long bit_flags;
49491 #define FABRIC_COMANDS_BLOCKED 0
49492 - atomic_t num_rsrc_err;
49493 - atomic_t num_cmd_success;
49494 + atomic_unchecked_t num_rsrc_err;
49495 + atomic_unchecked_t num_cmd_success;
49496 unsigned long last_rsrc_error_time;
49497 unsigned long last_ramp_down_time;
49498 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
49499 @@ -915,7 +915,7 @@ struct lpfc_hba {
49500
49501 struct dentry *debug_slow_ring_trc;
49502 struct lpfc_debugfs_trc *slow_ring_trc;
49503 - atomic_t slow_ring_trc_cnt;
49504 + atomic_unchecked_t slow_ring_trc_cnt;
49505 /* iDiag debugfs sub-directory */
49506 struct dentry *idiag_root;
49507 struct dentry *idiag_pci_cfg;
49508 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
49509 index 828c08e..e3378e0 100644
49510 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
49511 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
49512 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
49513
49514 #include <linux/debugfs.h>
49515
49516 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49517 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49518 static unsigned long lpfc_debugfs_start_time = 0L;
49519
49520 /* iDiag */
49521 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
49522 lpfc_debugfs_enable = 0;
49523
49524 len = 0;
49525 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
49526 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
49527 (lpfc_debugfs_max_disc_trc - 1);
49528 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
49529 dtp = vport->disc_trc + i;
49530 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
49531 lpfc_debugfs_enable = 0;
49532
49533 len = 0;
49534 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
49535 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
49536 (lpfc_debugfs_max_slow_ring_trc - 1);
49537 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
49538 dtp = phba->slow_ring_trc + i;
49539 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
49540 !vport || !vport->disc_trc)
49541 return;
49542
49543 - index = atomic_inc_return(&vport->disc_trc_cnt) &
49544 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
49545 (lpfc_debugfs_max_disc_trc - 1);
49546 dtp = vport->disc_trc + index;
49547 dtp->fmt = fmt;
49548 dtp->data1 = data1;
49549 dtp->data2 = data2;
49550 dtp->data3 = data3;
49551 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49552 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49553 dtp->jif = jiffies;
49554 #endif
49555 return;
49556 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
49557 !phba || !phba->slow_ring_trc)
49558 return;
49559
49560 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
49561 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
49562 (lpfc_debugfs_max_slow_ring_trc - 1);
49563 dtp = phba->slow_ring_trc + index;
49564 dtp->fmt = fmt;
49565 dtp->data1 = data1;
49566 dtp->data2 = data2;
49567 dtp->data3 = data3;
49568 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49569 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49570 dtp->jif = jiffies;
49571 #endif
49572 return;
49573 @@ -4268,7 +4268,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49574 "slow_ring buffer\n");
49575 goto debug_failed;
49576 }
49577 - atomic_set(&phba->slow_ring_trc_cnt, 0);
49578 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
49579 memset(phba->slow_ring_trc, 0,
49580 (sizeof(struct lpfc_debugfs_trc) *
49581 lpfc_debugfs_max_slow_ring_trc));
49582 @@ -4314,7 +4314,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49583 "buffer\n");
49584 goto debug_failed;
49585 }
49586 - atomic_set(&vport->disc_trc_cnt, 0);
49587 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
49588
49589 snprintf(name, sizeof(name), "discovery_trace");
49590 vport->debug_disc_trc =
49591 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
49592 index 635eeb3..038aef6 100644
49593 --- a/drivers/scsi/lpfc/lpfc_init.c
49594 +++ b/drivers/scsi/lpfc/lpfc_init.c
49595 @@ -11194,8 +11194,10 @@ lpfc_init(void)
49596 "misc_register returned with status %d", error);
49597
49598 if (lpfc_enable_npiv) {
49599 - lpfc_transport_functions.vport_create = lpfc_vport_create;
49600 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49601 + pax_open_kernel();
49602 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
49603 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49604 + pax_close_kernel();
49605 }
49606 lpfc_transport_template =
49607 fc_attach_transport(&lpfc_transport_functions);
49608 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
49609 index 462453e..c0023a6 100644
49610 --- a/drivers/scsi/lpfc/lpfc_scsi.c
49611 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
49612 @@ -382,7 +382,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
49613 uint32_t evt_posted;
49614
49615 spin_lock_irqsave(&phba->hbalock, flags);
49616 - atomic_inc(&phba->num_rsrc_err);
49617 + atomic_inc_unchecked(&phba->num_rsrc_err);
49618 phba->last_rsrc_error_time = jiffies;
49619
49620 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
49621 @@ -423,8 +423,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49622 unsigned long num_rsrc_err, num_cmd_success;
49623 int i;
49624
49625 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
49626 - num_cmd_success = atomic_read(&phba->num_cmd_success);
49627 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
49628 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
49629
49630 /*
49631 * The error and success command counters are global per
49632 @@ -452,8 +452,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49633 }
49634 }
49635 lpfc_destroy_vport_work_array(phba, vports);
49636 - atomic_set(&phba->num_rsrc_err, 0);
49637 - atomic_set(&phba->num_cmd_success, 0);
49638 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
49639 + atomic_set_unchecked(&phba->num_cmd_success, 0);
49640 }
49641
49642 /**
49643 diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49644 index 6fd7d40..b444223 100644
49645 --- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49646 +++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49647 @@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
49648 {
49649 struct scsi_device *sdev = to_scsi_device(dev);
49650 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49651 - static struct _raid_device *raid_device;
49652 + struct _raid_device *raid_device;
49653 unsigned long flags;
49654 Mpi2RaidVolPage0_t vol_pg0;
49655 Mpi2ConfigReply_t mpi_reply;
49656 @@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
49657 {
49658 struct scsi_device *sdev = to_scsi_device(dev);
49659 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49660 - static struct _raid_device *raid_device;
49661 + struct _raid_device *raid_device;
49662 unsigned long flags;
49663 Mpi2RaidVolPage0_t vol_pg0;
49664 Mpi2ConfigReply_t mpi_reply;
49665 @@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
49666 struct fw_event_work *fw_event)
49667 {
49668 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
49669 - static struct _raid_device *raid_device;
49670 + struct _raid_device *raid_device;
49671 unsigned long flags;
49672 u16 handle;
49673
49674 @@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
49675 u64 sas_address;
49676 struct _sas_device *sas_device;
49677 struct _sas_node *expander_device;
49678 - static struct _raid_device *raid_device;
49679 + struct _raid_device *raid_device;
49680 u8 retry_count;
49681 unsigned long flags;
49682
49683 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
49684 index be8ce54..94ed33a 100644
49685 --- a/drivers/scsi/pmcraid.c
49686 +++ b/drivers/scsi/pmcraid.c
49687 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
49688 res->scsi_dev = scsi_dev;
49689 scsi_dev->hostdata = res;
49690 res->change_detected = 0;
49691 - atomic_set(&res->read_failures, 0);
49692 - atomic_set(&res->write_failures, 0);
49693 + atomic_set_unchecked(&res->read_failures, 0);
49694 + atomic_set_unchecked(&res->write_failures, 0);
49695 rc = 0;
49696 }
49697 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
49698 @@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
49699
49700 /* If this was a SCSI read/write command keep count of errors */
49701 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
49702 - atomic_inc(&res->read_failures);
49703 + atomic_inc_unchecked(&res->read_failures);
49704 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
49705 - atomic_inc(&res->write_failures);
49706 + atomic_inc_unchecked(&res->write_failures);
49707
49708 if (!RES_IS_GSCSI(res->cfg_entry) &&
49709 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
49710 @@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
49711 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49712 * hrrq_id assigned here in queuecommand
49713 */
49714 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49715 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49716 pinstance->num_hrrq;
49717 cmd->cmd_done = pmcraid_io_done;
49718
49719 @@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
49720 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49721 * hrrq_id assigned here in queuecommand
49722 */
49723 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49724 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49725 pinstance->num_hrrq;
49726
49727 if (request_size) {
49728 @@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
49729
49730 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
49731 /* add resources only after host is added into system */
49732 - if (!atomic_read(&pinstance->expose_resources))
49733 + if (!atomic_read_unchecked(&pinstance->expose_resources))
49734 return;
49735
49736 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
49737 @@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
49738 init_waitqueue_head(&pinstance->reset_wait_q);
49739
49740 atomic_set(&pinstance->outstanding_cmds, 0);
49741 - atomic_set(&pinstance->last_message_id, 0);
49742 - atomic_set(&pinstance->expose_resources, 0);
49743 + atomic_set_unchecked(&pinstance->last_message_id, 0);
49744 + atomic_set_unchecked(&pinstance->expose_resources, 0);
49745
49746 INIT_LIST_HEAD(&pinstance->free_res_q);
49747 INIT_LIST_HEAD(&pinstance->used_res_q);
49748 @@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
49749 /* Schedule worker thread to handle CCN and take care of adding and
49750 * removing devices to OS
49751 */
49752 - atomic_set(&pinstance->expose_resources, 1);
49753 + atomic_set_unchecked(&pinstance->expose_resources, 1);
49754 schedule_work(&pinstance->worker_q);
49755 return rc;
49756
49757 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
49758 index e1d150f..6c6df44 100644
49759 --- a/drivers/scsi/pmcraid.h
49760 +++ b/drivers/scsi/pmcraid.h
49761 @@ -748,7 +748,7 @@ struct pmcraid_instance {
49762 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
49763
49764 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
49765 - atomic_t last_message_id;
49766 + atomic_unchecked_t last_message_id;
49767
49768 /* configuration table */
49769 struct pmcraid_config_table *cfg_table;
49770 @@ -777,7 +777,7 @@ struct pmcraid_instance {
49771 atomic_t outstanding_cmds;
49772
49773 /* should add/delete resources to mid-layer now ?*/
49774 - atomic_t expose_resources;
49775 + atomic_unchecked_t expose_resources;
49776
49777
49778
49779 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
49780 struct pmcraid_config_table_entry_ext cfg_entry_ext;
49781 };
49782 struct scsi_device *scsi_dev; /* Link scsi_device structure */
49783 - atomic_t read_failures; /* count of failed READ commands */
49784 - atomic_t write_failures; /* count of failed WRITE commands */
49785 + atomic_unchecked_t read_failures; /* count of failed READ commands */
49786 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
49787
49788 /* To indicate add/delete/modify during CCN */
49789 u8 change_detected;
49790 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
49791 index 07befcf..c0bff13 100644
49792 --- a/drivers/scsi/qla2xxx/qla_attr.c
49793 +++ b/drivers/scsi/qla2xxx/qla_attr.c
49794 @@ -2188,7 +2188,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
49795 return 0;
49796 }
49797
49798 -struct fc_function_template qla2xxx_transport_functions = {
49799 +fc_function_template_no_const qla2xxx_transport_functions = {
49800
49801 .show_host_node_name = 1,
49802 .show_host_port_name = 1,
49803 @@ -2236,7 +2236,7 @@ struct fc_function_template qla2xxx_transport_functions = {
49804 .bsg_timeout = qla24xx_bsg_timeout,
49805 };
49806
49807 -struct fc_function_template qla2xxx_transport_vport_functions = {
49808 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
49809
49810 .show_host_node_name = 1,
49811 .show_host_port_name = 1,
49812 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
49813 index e665e81..16e84e6 100644
49814 --- a/drivers/scsi/qla2xxx/qla_gbl.h
49815 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
49816 @@ -557,8 +557,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
49817 struct device_attribute;
49818 extern struct device_attribute *qla2x00_host_attrs[];
49819 struct fc_function_template;
49820 -extern struct fc_function_template qla2xxx_transport_functions;
49821 -extern struct fc_function_template qla2xxx_transport_vport_functions;
49822 +extern fc_function_template_no_const qla2xxx_transport_functions;
49823 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
49824 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
49825 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
49826 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
49827 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
49828 index 19e99cc..b3c0b7b 100644
49829 --- a/drivers/scsi/qla2xxx/qla_os.c
49830 +++ b/drivers/scsi/qla2xxx/qla_os.c
49831 @@ -1493,8 +1493,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
49832 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
49833 /* Ok, a 64bit DMA mask is applicable. */
49834 ha->flags.enable_64bit_addressing = 1;
49835 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49836 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49837 + pax_open_kernel();
49838 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49839 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49840 + pax_close_kernel();
49841 return;
49842 }
49843 }
49844 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
49845 index 73a5022..4e0797c 100644
49846 --- a/drivers/scsi/qla4xxx/ql4_def.h
49847 +++ b/drivers/scsi/qla4xxx/ql4_def.h
49848 @@ -305,7 +305,7 @@ struct ddb_entry {
49849 * (4000 only) */
49850 atomic_t relogin_timer; /* Max Time to wait for
49851 * relogin to complete */
49852 - atomic_t relogin_retry_count; /* Num of times relogin has been
49853 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
49854 * retried */
49855 uint32_t default_time2wait; /* Default Min time between
49856 * relogins (+aens) */
49857 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
49858 index 459b9f7..2930a68 100644
49859 --- a/drivers/scsi/qla4xxx/ql4_os.c
49860 +++ b/drivers/scsi/qla4xxx/ql4_os.c
49861 @@ -4499,12 +4499,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
49862 */
49863 if (!iscsi_is_session_online(cls_sess)) {
49864 /* Reset retry relogin timer */
49865 - atomic_inc(&ddb_entry->relogin_retry_count);
49866 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
49867 DEBUG2(ql4_printk(KERN_INFO, ha,
49868 "%s: index[%d] relogin timed out-retrying"
49869 " relogin (%d), retry (%d)\n", __func__,
49870 ddb_entry->fw_ddb_index,
49871 - atomic_read(&ddb_entry->relogin_retry_count),
49872 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
49873 ddb_entry->default_time2wait + 4));
49874 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
49875 atomic_set(&ddb_entry->retry_relogin_timer,
49876 @@ -6609,7 +6609,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
49877
49878 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
49879 atomic_set(&ddb_entry->relogin_timer, 0);
49880 - atomic_set(&ddb_entry->relogin_retry_count, 0);
49881 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
49882 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
49883 ddb_entry->default_relogin_timeout =
49884 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
49885 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
49886 index 88d46fe..7351be5 100644
49887 --- a/drivers/scsi/scsi.c
49888 +++ b/drivers/scsi/scsi.c
49889 @@ -640,7 +640,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
49890 struct Scsi_Host *host = cmd->device->host;
49891 int rtn = 0;
49892
49893 - atomic_inc(&cmd->device->iorequest_cnt);
49894 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49895
49896 /* check if the device is still usable */
49897 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
49898 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
49899 index d99ab3b..c4ccdef 100644
49900 --- a/drivers/scsi/scsi_lib.c
49901 +++ b/drivers/scsi/scsi_lib.c
49902 @@ -1472,7 +1472,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
49903 shost = sdev->host;
49904 scsi_init_cmd_errh(cmd);
49905 cmd->result = DID_NO_CONNECT << 16;
49906 - atomic_inc(&cmd->device->iorequest_cnt);
49907 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49908
49909 /*
49910 * SCSI request completion path will do scsi_device_unbusy(),
49911 @@ -1498,9 +1498,9 @@ static void scsi_softirq_done(struct request *rq)
49912
49913 INIT_LIST_HEAD(&cmd->eh_entry);
49914
49915 - atomic_inc(&cmd->device->iodone_cnt);
49916 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
49917 if (cmd->result)
49918 - atomic_inc(&cmd->device->ioerr_cnt);
49919 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
49920
49921 disposition = scsi_decide_disposition(cmd);
49922 if (disposition != SUCCESS &&
49923 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
49924 index 074e8cc..f612e5c 100644
49925 --- a/drivers/scsi/scsi_sysfs.c
49926 +++ b/drivers/scsi/scsi_sysfs.c
49927 @@ -780,7 +780,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
49928 char *buf) \
49929 { \
49930 struct scsi_device *sdev = to_scsi_device(dev); \
49931 - unsigned long long count = atomic_read(&sdev->field); \
49932 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
49933 return snprintf(buf, 20, "0x%llx\n", count); \
49934 } \
49935 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
49936 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
49937 index e51add0..1e06a96 100644
49938 --- a/drivers/scsi/scsi_tgt_lib.c
49939 +++ b/drivers/scsi/scsi_tgt_lib.c
49940 @@ -363,7 +363,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
49941 int err;
49942
49943 dprintk("%lx %u\n", uaddr, len);
49944 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
49945 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
49946 if (err) {
49947 /*
49948 * TODO: need to fixup sg_tablesize, max_segment_size,
49949 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
49950 index f80908f..22aba76 100644
49951 --- a/drivers/scsi/scsi_transport_fc.c
49952 +++ b/drivers/scsi/scsi_transport_fc.c
49953 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
49954 * Netlink Infrastructure
49955 */
49956
49957 -static atomic_t fc_event_seq;
49958 +static atomic_unchecked_t fc_event_seq;
49959
49960 /**
49961 * fc_get_event_number - Obtain the next sequential FC event number
49962 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
49963 u32
49964 fc_get_event_number(void)
49965 {
49966 - return atomic_add_return(1, &fc_event_seq);
49967 + return atomic_add_return_unchecked(1, &fc_event_seq);
49968 }
49969 EXPORT_SYMBOL(fc_get_event_number);
49970
49971 @@ -655,7 +655,7 @@ static __init int fc_transport_init(void)
49972 {
49973 int error;
49974
49975 - atomic_set(&fc_event_seq, 0);
49976 + atomic_set_unchecked(&fc_event_seq, 0);
49977
49978 error = transport_class_register(&fc_host_class);
49979 if (error)
49980 @@ -845,7 +845,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
49981 char *cp;
49982
49983 *val = simple_strtoul(buf, &cp, 0);
49984 - if ((*cp && (*cp != '\n')) || (*val < 0))
49985 + if (*cp && (*cp != '\n'))
49986 return -EINVAL;
49987 /*
49988 * Check for overflow; dev_loss_tmo is u32
49989 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
49990 index 0102a2d..cc3f8e9 100644
49991 --- a/drivers/scsi/scsi_transport_iscsi.c
49992 +++ b/drivers/scsi/scsi_transport_iscsi.c
49993 @@ -79,7 +79,7 @@ struct iscsi_internal {
49994 struct transport_container session_cont;
49995 };
49996
49997 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
49998 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
49999 static struct workqueue_struct *iscsi_eh_timer_workq;
50000
50001 static DEFINE_IDA(iscsi_sess_ida);
50002 @@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
50003 int err;
50004
50005 ihost = shost->shost_data;
50006 - session->sid = atomic_add_return(1, &iscsi_session_nr);
50007 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
50008
50009 if (target_id == ISCSI_MAX_TARGET) {
50010 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
50011 @@ -4511,7 +4511,7 @@ static __init int iscsi_transport_init(void)
50012 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
50013 ISCSI_TRANSPORT_VERSION);
50014
50015 - atomic_set(&iscsi_session_nr, 0);
50016 + atomic_set_unchecked(&iscsi_session_nr, 0);
50017
50018 err = class_register(&iscsi_transport_class);
50019 if (err)
50020 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
50021 index 13e8983..d306a68 100644
50022 --- a/drivers/scsi/scsi_transport_srp.c
50023 +++ b/drivers/scsi/scsi_transport_srp.c
50024 @@ -36,7 +36,7 @@
50025 #include "scsi_transport_srp_internal.h"
50026
50027 struct srp_host_attrs {
50028 - atomic_t next_port_id;
50029 + atomic_unchecked_t next_port_id;
50030 };
50031 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
50032
50033 @@ -101,7 +101,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
50034 struct Scsi_Host *shost = dev_to_shost(dev);
50035 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
50036
50037 - atomic_set(&srp_host->next_port_id, 0);
50038 + atomic_set_unchecked(&srp_host->next_port_id, 0);
50039 return 0;
50040 }
50041
50042 @@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
50043 rport_fast_io_fail_timedout);
50044 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
50045
50046 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
50047 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
50048 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
50049
50050 transport_setup_device(&rport->dev);
50051 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
50052 index bffbd4b..cb1b68a 100644
50053 --- a/drivers/scsi/sd.c
50054 +++ b/drivers/scsi/sd.c
50055 @@ -2971,7 +2971,7 @@ static int sd_probe(struct device *dev)
50056 sdkp->disk = gd;
50057 sdkp->index = index;
50058 atomic_set(&sdkp->openers, 0);
50059 - atomic_set(&sdkp->device->ioerr_cnt, 0);
50060 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
50061
50062 if (!sdp->request_queue->rq_timeout) {
50063 if (sdp->type != TYPE_MOD)
50064 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
50065 index df5e961..df6b97f 100644
50066 --- a/drivers/scsi/sg.c
50067 +++ b/drivers/scsi/sg.c
50068 @@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
50069 sdp->disk->disk_name,
50070 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
50071 NULL,
50072 - (char *)arg);
50073 + (char __user *)arg);
50074 case BLKTRACESTART:
50075 return blk_trace_startstop(sdp->device->request_queue, 1);
50076 case BLKTRACESTOP:
50077 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
50078 index 939edf4..3f50423 100644
50079 --- a/drivers/spi/spi.c
50080 +++ b/drivers/spi/spi.c
50081 @@ -2204,7 +2204,7 @@ int spi_bus_unlock(struct spi_master *master)
50082 EXPORT_SYMBOL_GPL(spi_bus_unlock);
50083
50084 /* portable code must never pass more than 32 bytes */
50085 -#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
50086 +#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
50087
50088 static u8 *buf;
50089
50090 diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
50091 index 2c61783..4d49e4e 100644
50092 --- a/drivers/staging/android/timed_output.c
50093 +++ b/drivers/staging/android/timed_output.c
50094 @@ -25,7 +25,7 @@
50095 #include "timed_output.h"
50096
50097 static struct class *timed_output_class;
50098 -static atomic_t device_count;
50099 +static atomic_unchecked_t device_count;
50100
50101 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
50102 char *buf)
50103 @@ -63,7 +63,7 @@ static int create_timed_output_class(void)
50104 timed_output_class = class_create(THIS_MODULE, "timed_output");
50105 if (IS_ERR(timed_output_class))
50106 return PTR_ERR(timed_output_class);
50107 - atomic_set(&device_count, 0);
50108 + atomic_set_unchecked(&device_count, 0);
50109 timed_output_class->dev_groups = timed_output_groups;
50110 }
50111
50112 @@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
50113 if (ret < 0)
50114 return ret;
50115
50116 - tdev->index = atomic_inc_return(&device_count);
50117 + tdev->index = atomic_inc_return_unchecked(&device_count);
50118 tdev->dev = device_create(timed_output_class, NULL,
50119 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
50120 if (IS_ERR(tdev->dev))
50121 diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
50122 index fe47cd3..19a1bd1 100644
50123 --- a/drivers/staging/gdm724x/gdm_tty.c
50124 +++ b/drivers/staging/gdm724x/gdm_tty.c
50125 @@ -44,7 +44,7 @@
50126 #define gdm_tty_send_control(n, r, v, d, l) (\
50127 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
50128
50129 -#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
50130 +#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
50131
50132 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
50133 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
50134 diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
50135 index c270c9a..94ddf82 100644
50136 --- a/drivers/staging/imx-drm/imx-drm-core.c
50137 +++ b/drivers/staging/imx-drm/imx-drm-core.c
50138 @@ -362,7 +362,7 @@ int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc,
50139 if (imxdrm->pipes >= MAX_CRTC)
50140 return -EINVAL;
50141
50142 - if (imxdrm->drm->open_count)
50143 + if (local_read(&imxdrm->drm->open_count))
50144 return -EBUSY;
50145
50146 imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL);
50147 diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
50148 index 3f8020c..649fded 100644
50149 --- a/drivers/staging/lustre/lnet/selftest/brw_test.c
50150 +++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
50151 @@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
50152 return 0;
50153 }
50154
50155 -sfw_test_client_ops_t brw_test_client;
50156 -void brw_init_test_client(void)
50157 -{
50158 - brw_test_client.tso_init = brw_client_init;
50159 - brw_test_client.tso_fini = brw_client_fini;
50160 - brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
50161 - brw_test_client.tso_done_rpc = brw_client_done_rpc;
50162 +sfw_test_client_ops_t brw_test_client = {
50163 + .tso_init = brw_client_init,
50164 + .tso_fini = brw_client_fini,
50165 + .tso_prep_rpc = brw_client_prep_rpc,
50166 + .tso_done_rpc = brw_client_done_rpc,
50167 };
50168
50169 srpc_service_t brw_test_service;
50170 diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
50171 index 050723a..fa6fdf1 100644
50172 --- a/drivers/staging/lustre/lnet/selftest/framework.c
50173 +++ b/drivers/staging/lustre/lnet/selftest/framework.c
50174 @@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
50175
50176 extern sfw_test_client_ops_t ping_test_client;
50177 extern srpc_service_t ping_test_service;
50178 -extern void ping_init_test_client(void);
50179 extern void ping_init_test_service(void);
50180
50181 extern sfw_test_client_ops_t brw_test_client;
50182 extern srpc_service_t brw_test_service;
50183 -extern void brw_init_test_client(void);
50184 extern void brw_init_test_service(void);
50185
50186
50187 @@ -1684,12 +1682,10 @@ sfw_startup (void)
50188 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
50189 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
50190
50191 - brw_init_test_client();
50192 brw_init_test_service();
50193 rc = sfw_register_test(&brw_test_service, &brw_test_client);
50194 LASSERT (rc == 0);
50195
50196 - ping_init_test_client();
50197 ping_init_test_service();
50198 rc = sfw_register_test(&ping_test_service, &ping_test_client);
50199 LASSERT (rc == 0);
50200 diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
50201 index 750cac4..e4d751f 100644
50202 --- a/drivers/staging/lustre/lnet/selftest/ping_test.c
50203 +++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
50204 @@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
50205 return 0;
50206 }
50207
50208 -sfw_test_client_ops_t ping_test_client;
50209 -void ping_init_test_client(void)
50210 -{
50211 - ping_test_client.tso_init = ping_client_init;
50212 - ping_test_client.tso_fini = ping_client_fini;
50213 - ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
50214 - ping_test_client.tso_done_rpc = ping_client_done_rpc;
50215 -}
50216 +sfw_test_client_ops_t ping_test_client = {
50217 + .tso_init = ping_client_init,
50218 + .tso_fini = ping_client_fini,
50219 + .tso_prep_rpc = ping_client_prep_rpc,
50220 + .tso_done_rpc = ping_client_done_rpc,
50221 +};
50222
50223 srpc_service_t ping_test_service;
50224 void ping_init_test_service(void)
50225 diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
50226 index 3e25f00..0d59cf5 100644
50227 --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
50228 +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
50229 @@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
50230 ldlm_completion_callback lcs_completion;
50231 ldlm_blocking_callback lcs_blocking;
50232 ldlm_glimpse_callback lcs_glimpse;
50233 -};
50234 +} __no_const;
50235
50236 /* ldlm_lockd.c */
50237 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
50238 diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
50239 index 72cf3fe..4beac19 100644
50240 --- a/drivers/staging/lustre/lustre/include/obd.h
50241 +++ b/drivers/staging/lustre/lustre/include/obd.h
50242 @@ -1427,7 +1427,7 @@ struct md_ops {
50243 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
50244 * wrapper function in include/linux/obd_class.h.
50245 */
50246 -};
50247 +} __no_const;
50248
50249 struct lsm_operations {
50250 void (*lsm_free)(struct lov_stripe_md *);
50251 diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
50252 index 986bf38..eab2558f 100644
50253 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
50254 +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
50255 @@ -259,7 +259,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
50256 int added = (mode == LCK_NL);
50257 int overlaps = 0;
50258 int splitted = 0;
50259 - const struct ldlm_callback_suite null_cbs = { NULL };
50260 + const struct ldlm_callback_suite null_cbs = { };
50261
50262 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
50263 LPU64" end "LPU64"\n", *flags,
50264 diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
50265 index e947b91..f408990 100644
50266 --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
50267 +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
50268 @@ -217,7 +217,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
50269 int LL_PROC_PROTO(proc_console_max_delay_cs)
50270 {
50271 int rc, max_delay_cs;
50272 - ctl_table_t dummy = *table;
50273 + ctl_table_no_const dummy = *table;
50274 cfs_duration_t d;
50275
50276 dummy.data = &max_delay_cs;
50277 @@ -248,7 +248,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
50278 int LL_PROC_PROTO(proc_console_min_delay_cs)
50279 {
50280 int rc, min_delay_cs;
50281 - ctl_table_t dummy = *table;
50282 + ctl_table_no_const dummy = *table;
50283 cfs_duration_t d;
50284
50285 dummy.data = &min_delay_cs;
50286 @@ -279,7 +279,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
50287 int LL_PROC_PROTO(proc_console_backoff)
50288 {
50289 int rc, backoff;
50290 - ctl_table_t dummy = *table;
50291 + ctl_table_no_const dummy = *table;
50292
50293 dummy.data = &backoff;
50294 dummy.proc_handler = &proc_dointvec;
50295 diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
50296 index 24ae26d..9d09cab 100644
50297 --- a/drivers/staging/lustre/lustre/libcfs/module.c
50298 +++ b/drivers/staging/lustre/lustre/libcfs/module.c
50299 @@ -313,11 +313,11 @@ out:
50300
50301
50302 struct cfs_psdev_ops libcfs_psdev_ops = {
50303 - libcfs_psdev_open,
50304 - libcfs_psdev_release,
50305 - NULL,
50306 - NULL,
50307 - libcfs_ioctl
50308 + .p_open = libcfs_psdev_open,
50309 + .p_close = libcfs_psdev_release,
50310 + .p_read = NULL,
50311 + .p_write = NULL,
50312 + .p_ioctl = libcfs_ioctl
50313 };
50314
50315 extern int insert_proc(void);
50316 diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
50317 index 7fbc18e..f982071 100644
50318 --- a/drivers/staging/lustre/lustre/llite/dir.c
50319 +++ b/drivers/staging/lustre/lustre/llite/dir.c
50320 @@ -660,7 +660,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
50321 int mode;
50322 int err;
50323
50324 - mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
50325 + mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
50326 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
50327 strlen(filename), mode, LUSTRE_OPC_MKDIR,
50328 lump);
50329 diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
50330 index f670469..03b7438 100644
50331 --- a/drivers/staging/media/solo6x10/solo6x10-core.c
50332 +++ b/drivers/staging/media/solo6x10/solo6x10-core.c
50333 @@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
50334
50335 static int solo_sysfs_init(struct solo_dev *solo_dev)
50336 {
50337 - struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
50338 + bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
50339 struct device *dev = &solo_dev->dev;
50340 const char *driver;
50341 int i;
50342 diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
50343 index 74f037b..5b5bb76 100644
50344 --- a/drivers/staging/media/solo6x10/solo6x10-g723.c
50345 +++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
50346 @@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
50347
50348 int solo_g723_init(struct solo_dev *solo_dev)
50349 {
50350 - static struct snd_device_ops ops = { NULL };
50351 + static struct snd_device_ops ops = { };
50352 struct snd_card *card;
50353 struct snd_kcontrol_new kctl;
50354 char name[32];
50355 diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
50356 index 7f2f247..d999137 100644
50357 --- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
50358 +++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
50359 @@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
50360
50361 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
50362 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
50363 - p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
50364 + p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
50365 if (p2m_id < 0)
50366 p2m_id = -p2m_id;
50367 }
50368 diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
50369 index 8964f8b..36eb087 100644
50370 --- a/drivers/staging/media/solo6x10/solo6x10.h
50371 +++ b/drivers/staging/media/solo6x10/solo6x10.h
50372 @@ -237,7 +237,7 @@ struct solo_dev {
50373
50374 /* P2M DMA Engine */
50375 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
50376 - atomic_t p2m_count;
50377 + atomic_unchecked_t p2m_count;
50378 int p2m_jiffies;
50379 unsigned int p2m_timeouts;
50380
50381 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
50382 index a0f4868..139f1fb 100644
50383 --- a/drivers/staging/octeon/ethernet-rx.c
50384 +++ b/drivers/staging/octeon/ethernet-rx.c
50385 @@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
50386 /* Increment RX stats for virtual ports */
50387 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
50388 #ifdef CONFIG_64BIT
50389 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
50390 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
50391 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
50392 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
50393 #else
50394 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
50395 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
50396 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
50397 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
50398 #endif
50399 }
50400 netif_receive_skb(skb);
50401 @@ -432,9 +432,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
50402 dev->name);
50403 */
50404 #ifdef CONFIG_64BIT
50405 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
50406 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
50407 #else
50408 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
50409 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
50410 #endif
50411 dev_kfree_skb_irq(skb);
50412 }
50413 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
50414 index ff7214a..6dd90f0 100644
50415 --- a/drivers/staging/octeon/ethernet.c
50416 +++ b/drivers/staging/octeon/ethernet.c
50417 @@ -247,11 +247,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
50418 * since the RX tasklet also increments it.
50419 */
50420 #ifdef CONFIG_64BIT
50421 - atomic64_add(rx_status.dropped_packets,
50422 - (atomic64_t *)&priv->stats.rx_dropped);
50423 + atomic64_add_unchecked(rx_status.dropped_packets,
50424 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
50425 #else
50426 - atomic_add(rx_status.dropped_packets,
50427 - (atomic_t *)&priv->stats.rx_dropped);
50428 + atomic_add_unchecked(rx_status.dropped_packets,
50429 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
50430 #endif
50431 }
50432
50433 diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
50434 index c274b34..f84de76 100644
50435 --- a/drivers/staging/rtl8188eu/include/hal_intf.h
50436 +++ b/drivers/staging/rtl8188eu/include/hal_intf.h
50437 @@ -271,7 +271,7 @@ struct hal_ops {
50438 s32 (*c2h_handler)(struct adapter *padapter,
50439 struct c2h_evt_hdr *c2h_evt);
50440 c2h_id_filter c2h_id_filter_ccx;
50441 -};
50442 +} __no_const;
50443
50444 enum rt_eeprom_type {
50445 EEPROM_93C46,
50446 diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
50447 index e8790f8..b4a5980 100644
50448 --- a/drivers/staging/rtl8188eu/include/rtw_io.h
50449 +++ b/drivers/staging/rtl8188eu/include/rtw_io.h
50450 @@ -124,7 +124,7 @@ struct _io_ops {
50451 u32 (*_write_scsi)(struct intf_hdl *pintfhdl, u32 cnt, u8 *pmem);
50452 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
50453 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
50454 -};
50455 +} __no_const;
50456
50457 struct io_req {
50458 struct list_head list;
50459 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
50460 index dc23395..cf7e9b1 100644
50461 --- a/drivers/staging/rtl8712/rtl871x_io.h
50462 +++ b/drivers/staging/rtl8712/rtl871x_io.h
50463 @@ -108,7 +108,7 @@ struct _io_ops {
50464 u8 *pmem);
50465 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
50466 u8 *pmem);
50467 -};
50468 +} __no_const;
50469
50470 struct io_req {
50471 struct list_head list;
50472 diff --git a/drivers/staging/rtl8723au/include/hal_intf.h b/drivers/staging/rtl8723au/include/hal_intf.h
50473 index d183f4b..3f4903d 100644
50474 --- a/drivers/staging/rtl8723au/include/hal_intf.h
50475 +++ b/drivers/staging/rtl8723au/include/hal_intf.h
50476 @@ -251,7 +251,7 @@ struct hal_ops {
50477 void (*hal_reset_security_engine)(struct rtw_adapter *adapter);
50478 s32 (*c2h_handler)(struct rtw_adapter *padapter, struct c2h_evt_hdr *c2h_evt);
50479 c2h_id_filter c2h_id_filter_ccx;
50480 -};
50481 +} __no_const;
50482
50483 enum rt_eeprom_type {
50484 EEPROM_93C46,
50485 diff --git a/drivers/staging/rtl8723au/include/rtw_io.h b/drivers/staging/rtl8723au/include/rtw_io.h
50486 index 8d39d800..3f21c0c 100644
50487 --- a/drivers/staging/rtl8723au/include/rtw_io.h
50488 +++ b/drivers/staging/rtl8723au/include/rtw_io.h
50489 @@ -130,7 +130,7 @@ struct _io_ops
50490 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
50491 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
50492
50493 -};
50494 +} __no_const;
50495
50496 struct io_req {
50497 struct list_head list;
50498 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
50499 index fe6c951..72935ba 100644
50500 --- a/drivers/staging/sbe-2t3e3/netdev.c
50501 +++ b/drivers/staging/sbe-2t3e3/netdev.c
50502 @@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50503 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
50504
50505 if (rlen)
50506 - if (copy_to_user(data, &resp, rlen))
50507 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
50508 return -EFAULT;
50509
50510 return 0;
50511 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
50512 index a863a98..d272795 100644
50513 --- a/drivers/staging/usbip/vhci.h
50514 +++ b/drivers/staging/usbip/vhci.h
50515 @@ -83,7 +83,7 @@ struct vhci_hcd {
50516 unsigned resuming:1;
50517 unsigned long re_timeout;
50518
50519 - atomic_t seqnum;
50520 + atomic_unchecked_t seqnum;
50521
50522 /*
50523 * NOTE:
50524 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
50525 index 70e1755..de41855 100644
50526 --- a/drivers/staging/usbip/vhci_hcd.c
50527 +++ b/drivers/staging/usbip/vhci_hcd.c
50528 @@ -439,7 +439,7 @@ static void vhci_tx_urb(struct urb *urb)
50529
50530 spin_lock(&vdev->priv_lock);
50531
50532 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
50533 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50534 if (priv->seqnum == 0xffff)
50535 dev_info(&urb->dev->dev, "seqnum max\n");
50536
50537 @@ -685,7 +685,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
50538 return -ENOMEM;
50539 }
50540
50541 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
50542 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50543 if (unlink->seqnum == 0xffff)
50544 pr_info("seqnum max\n");
50545
50546 @@ -889,7 +889,7 @@ static int vhci_start(struct usb_hcd *hcd)
50547 vdev->rhport = rhport;
50548 }
50549
50550 - atomic_set(&vhci->seqnum, 0);
50551 + atomic_set_unchecked(&vhci->seqnum, 0);
50552 spin_lock_init(&vhci->lock);
50553
50554 hcd->power_budget = 0; /* no limit */
50555 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
50556 index d07fcb5..358e1e1 100644
50557 --- a/drivers/staging/usbip/vhci_rx.c
50558 +++ b/drivers/staging/usbip/vhci_rx.c
50559 @@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
50560 if (!urb) {
50561 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
50562 pr_info("max seqnum %d\n",
50563 - atomic_read(&the_controller->seqnum));
50564 + atomic_read_unchecked(&the_controller->seqnum));
50565 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
50566 return;
50567 }
50568 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
50569 index 6eecd53..29317c6 100644
50570 --- a/drivers/staging/vt6655/hostap.c
50571 +++ b/drivers/staging/vt6655/hostap.c
50572 @@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
50573 *
50574 */
50575
50576 +static net_device_ops_no_const apdev_netdev_ops;
50577 +
50578 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50579 {
50580 PSDevice apdev_priv;
50581 struct net_device *dev = pDevice->dev;
50582 int ret;
50583 - const struct net_device_ops apdev_netdev_ops = {
50584 - .ndo_start_xmit = pDevice->tx_80211,
50585 - };
50586
50587 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50588
50589 @@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50590 *apdev_priv = *pDevice;
50591 eth_hw_addr_inherit(pDevice->apdev, dev);
50592
50593 + /* only half broken now */
50594 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50595 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50596
50597 pDevice->apdev->type = ARPHRD_IEEE80211;
50598 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
50599 index 67ba48b..24e602f 100644
50600 --- a/drivers/staging/vt6656/hostap.c
50601 +++ b/drivers/staging/vt6656/hostap.c
50602 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
50603 *
50604 */
50605
50606 +static net_device_ops_no_const apdev_netdev_ops;
50607 +
50608 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50609 {
50610 struct vnt_private *apdev_priv;
50611 struct net_device *dev = pDevice->dev;
50612 int ret;
50613 - const struct net_device_ops apdev_netdev_ops = {
50614 - .ndo_start_xmit = pDevice->tx_80211,
50615 - };
50616
50617 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50618
50619 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50620 *apdev_priv = *pDevice;
50621 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
50622
50623 + /* only half broken now */
50624 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50625 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50626
50627 pDevice->apdev->type = ARPHRD_IEEE80211;
50628 diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
50629 index e7e9372..161f530 100644
50630 --- a/drivers/target/sbp/sbp_target.c
50631 +++ b/drivers/target/sbp/sbp_target.c
50632 @@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
50633
50634 #define SESSION_MAINTENANCE_INTERVAL HZ
50635
50636 -static atomic_t login_id = ATOMIC_INIT(0);
50637 +static atomic_unchecked_t login_id = ATOMIC_INIT(0);
50638
50639 static void session_maintenance_work(struct work_struct *);
50640 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
50641 @@ -444,7 +444,7 @@ static void sbp_management_request_login(
50642 login->lun = se_lun;
50643 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
50644 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
50645 - login->login_id = atomic_inc_return(&login_id);
50646 + login->login_id = atomic_inc_return_unchecked(&login_id);
50647
50648 login->tgt_agt = sbp_target_agent_register(login);
50649 if (IS_ERR(login->tgt_agt)) {
50650 diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
50651 index 6ea95d2..88607b4 100644
50652 --- a/drivers/target/target_core_device.c
50653 +++ b/drivers/target/target_core_device.c
50654 @@ -1525,7 +1525,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
50655 spin_lock_init(&dev->se_tmr_lock);
50656 spin_lock_init(&dev->qf_cmd_lock);
50657 sema_init(&dev->caw_sem, 1);
50658 - atomic_set(&dev->dev_ordered_id, 0);
50659 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
50660 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
50661 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
50662 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
50663 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
50664 index 14772e9..42d9f63 100644
50665 --- a/drivers/target/target_core_transport.c
50666 +++ b/drivers/target/target_core_transport.c
50667 @@ -1165,7 +1165,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
50668 * Used to determine when ORDERED commands should go from
50669 * Dormant to Active status.
50670 */
50671 - cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
50672 + cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
50673 smp_mb__after_atomic_inc();
50674 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
50675 cmd->se_ordered_id, cmd->sam_task_attr,
50676 diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
50677 index 04b1be7..5eff86d 100644
50678 --- a/drivers/thermal/of-thermal.c
50679 +++ b/drivers/thermal/of-thermal.c
50680 @@ -30,6 +30,7 @@
50681 #include <linux/err.h>
50682 #include <linux/export.h>
50683 #include <linux/string.h>
50684 +#include <linux/mm.h>
50685
50686 #include "thermal_core.h"
50687
50688 @@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
50689 tz->get_trend = get_trend;
50690 tz->sensor_data = data;
50691
50692 - tzd->ops->get_temp = of_thermal_get_temp;
50693 - tzd->ops->get_trend = of_thermal_get_trend;
50694 + pax_open_kernel();
50695 + *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
50696 + *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
50697 + pax_close_kernel();
50698 mutex_unlock(&tzd->lock);
50699
50700 return tzd;
50701 @@ -461,8 +464,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
50702 return;
50703
50704 mutex_lock(&tzd->lock);
50705 - tzd->ops->get_temp = NULL;
50706 - tzd->ops->get_trend = NULL;
50707 + pax_open_kernel();
50708 + *(void **)&tzd->ops->get_temp = NULL;
50709 + *(void **)&tzd->ops->get_trend = NULL;
50710 + pax_close_kernel();
50711
50712 tz->get_temp = NULL;
50713 tz->get_trend = NULL;
50714 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
50715 index a57bb5a..1f727d33 100644
50716 --- a/drivers/tty/cyclades.c
50717 +++ b/drivers/tty/cyclades.c
50718 @@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
50719 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
50720 info->port.count);
50721 #endif
50722 - info->port.count++;
50723 + atomic_inc(&info->port.count);
50724 #ifdef CY_DEBUG_COUNT
50725 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
50726 - current->pid, info->port.count);
50727 + current->pid, atomic_read(&info->port.count));
50728 #endif
50729
50730 /*
50731 @@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
50732 for (j = 0; j < cy_card[i].nports; j++) {
50733 info = &cy_card[i].ports[j];
50734
50735 - if (info->port.count) {
50736 + if (atomic_read(&info->port.count)) {
50737 /* XXX is the ldisc num worth this? */
50738 struct tty_struct *tty;
50739 struct tty_ldisc *ld;
50740 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
50741 index 0ff7fda..dbc7d52 100644
50742 --- a/drivers/tty/hvc/hvc_console.c
50743 +++ b/drivers/tty/hvc/hvc_console.c
50744 @@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
50745
50746 spin_lock_irqsave(&hp->port.lock, flags);
50747 /* Check and then increment for fast path open. */
50748 - if (hp->port.count++ > 0) {
50749 + if (atomic_inc_return(&hp->port.count) > 1) {
50750 spin_unlock_irqrestore(&hp->port.lock, flags);
50751 hvc_kick();
50752 return 0;
50753 @@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50754
50755 spin_lock_irqsave(&hp->port.lock, flags);
50756
50757 - if (--hp->port.count == 0) {
50758 + if (atomic_dec_return(&hp->port.count) == 0) {
50759 spin_unlock_irqrestore(&hp->port.lock, flags);
50760 /* We are done with the tty pointer now. */
50761 tty_port_tty_set(&hp->port, NULL);
50762 @@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50763 */
50764 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
50765 } else {
50766 - if (hp->port.count < 0)
50767 + if (atomic_read(&hp->port.count) < 0)
50768 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
50769 - hp->vtermno, hp->port.count);
50770 + hp->vtermno, atomic_read(&hp->port.count));
50771 spin_unlock_irqrestore(&hp->port.lock, flags);
50772 }
50773 }
50774 @@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
50775 * open->hangup case this can be called after the final close so prevent
50776 * that from happening for now.
50777 */
50778 - if (hp->port.count <= 0) {
50779 + if (atomic_read(&hp->port.count) <= 0) {
50780 spin_unlock_irqrestore(&hp->port.lock, flags);
50781 return;
50782 }
50783
50784 - hp->port.count = 0;
50785 + atomic_set(&hp->port.count, 0);
50786 spin_unlock_irqrestore(&hp->port.lock, flags);
50787 tty_port_tty_set(&hp->port, NULL);
50788
50789 @@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
50790 return -EPIPE;
50791
50792 /* FIXME what's this (unprotected) check for? */
50793 - if (hp->port.count <= 0)
50794 + if (atomic_read(&hp->port.count) <= 0)
50795 return -EIO;
50796
50797 spin_lock_irqsave(&hp->lock, flags);
50798 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
50799 index 81e939e..95ead10 100644
50800 --- a/drivers/tty/hvc/hvcs.c
50801 +++ b/drivers/tty/hvc/hvcs.c
50802 @@ -83,6 +83,7 @@
50803 #include <asm/hvcserver.h>
50804 #include <asm/uaccess.h>
50805 #include <asm/vio.h>
50806 +#include <asm/local.h>
50807
50808 /*
50809 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
50810 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
50811
50812 spin_lock_irqsave(&hvcsd->lock, flags);
50813
50814 - if (hvcsd->port.count > 0) {
50815 + if (atomic_read(&hvcsd->port.count) > 0) {
50816 spin_unlock_irqrestore(&hvcsd->lock, flags);
50817 printk(KERN_INFO "HVCS: vterm state unchanged. "
50818 "The hvcs device node is still in use.\n");
50819 @@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
50820 }
50821 }
50822
50823 - hvcsd->port.count = 0;
50824 + atomic_set(&hvcsd->port.count, 0);
50825 hvcsd->port.tty = tty;
50826 tty->driver_data = hvcsd;
50827
50828 @@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
50829 unsigned long flags;
50830
50831 spin_lock_irqsave(&hvcsd->lock, flags);
50832 - hvcsd->port.count++;
50833 + atomic_inc(&hvcsd->port.count);
50834 hvcsd->todo_mask |= HVCS_SCHED_READ;
50835 spin_unlock_irqrestore(&hvcsd->lock, flags);
50836
50837 @@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50838 hvcsd = tty->driver_data;
50839
50840 spin_lock_irqsave(&hvcsd->lock, flags);
50841 - if (--hvcsd->port.count == 0) {
50842 + if (atomic_dec_and_test(&hvcsd->port.count)) {
50843
50844 vio_disable_interrupts(hvcsd->vdev);
50845
50846 @@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50847
50848 free_irq(irq, hvcsd);
50849 return;
50850 - } else if (hvcsd->port.count < 0) {
50851 + } else if (atomic_read(&hvcsd->port.count) < 0) {
50852 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
50853 " is missmanaged.\n",
50854 - hvcsd->vdev->unit_address, hvcsd->port.count);
50855 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
50856 }
50857
50858 spin_unlock_irqrestore(&hvcsd->lock, flags);
50859 @@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50860
50861 spin_lock_irqsave(&hvcsd->lock, flags);
50862 /* Preserve this so that we know how many kref refs to put */
50863 - temp_open_count = hvcsd->port.count;
50864 + temp_open_count = atomic_read(&hvcsd->port.count);
50865
50866 /*
50867 * Don't kref put inside the spinlock because the destruction
50868 @@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50869 tty->driver_data = NULL;
50870 hvcsd->port.tty = NULL;
50871
50872 - hvcsd->port.count = 0;
50873 + atomic_set(&hvcsd->port.count, 0);
50874
50875 /* This will drop any buffered data on the floor which is OK in a hangup
50876 * scenario. */
50877 @@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
50878 * the middle of a write operation? This is a crummy place to do this
50879 * but we want to keep it all in the spinlock.
50880 */
50881 - if (hvcsd->port.count <= 0) {
50882 + if (atomic_read(&hvcsd->port.count) <= 0) {
50883 spin_unlock_irqrestore(&hvcsd->lock, flags);
50884 return -ENODEV;
50885 }
50886 @@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
50887 {
50888 struct hvcs_struct *hvcsd = tty->driver_data;
50889
50890 - if (!hvcsd || hvcsd->port.count <= 0)
50891 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
50892 return 0;
50893
50894 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
50895 diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
50896 index 4190199..06d5bfa 100644
50897 --- a/drivers/tty/hvc/hvsi.c
50898 +++ b/drivers/tty/hvc/hvsi.c
50899 @@ -85,7 +85,7 @@ struct hvsi_struct {
50900 int n_outbuf;
50901 uint32_t vtermno;
50902 uint32_t virq;
50903 - atomic_t seqno; /* HVSI packet sequence number */
50904 + atomic_unchecked_t seqno; /* HVSI packet sequence number */
50905 uint16_t mctrl;
50906 uint8_t state; /* HVSI protocol state */
50907 uint8_t flags;
50908 @@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
50909
50910 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
50911 packet.hdr.len = sizeof(struct hvsi_query_response);
50912 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50913 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50914 packet.verb = VSV_SEND_VERSION_NUMBER;
50915 packet.u.version = HVSI_VERSION;
50916 packet.query_seqno = query_seqno+1;
50917 @@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
50918
50919 packet.hdr.type = VS_QUERY_PACKET_HEADER;
50920 packet.hdr.len = sizeof(struct hvsi_query);
50921 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50922 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50923 packet.verb = verb;
50924
50925 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
50926 @@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
50927 int wrote;
50928
50929 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
50930 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50931 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50932 packet.hdr.len = sizeof(struct hvsi_control);
50933 packet.verb = VSV_SET_MODEM_CTL;
50934 packet.mask = HVSI_TSDTR;
50935 @@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
50936 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
50937
50938 packet.hdr.type = VS_DATA_PACKET_HEADER;
50939 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50940 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50941 packet.hdr.len = count + sizeof(struct hvsi_header);
50942 memcpy(&packet.data, buf, count);
50943
50944 @@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
50945 struct hvsi_control packet __ALIGNED__;
50946
50947 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
50948 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50949 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50950 packet.hdr.len = 6;
50951 packet.verb = VSV_CLOSE_PROTOCOL;
50952
50953 @@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
50954
50955 tty_port_tty_set(&hp->port, tty);
50956 spin_lock_irqsave(&hp->lock, flags);
50957 - hp->port.count++;
50958 + atomic_inc(&hp->port.count);
50959 atomic_set(&hp->seqno, 0);
50960 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
50961 spin_unlock_irqrestore(&hp->lock, flags);
50962 @@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50963
50964 spin_lock_irqsave(&hp->lock, flags);
50965
50966 - if (--hp->port.count == 0) {
50967 + if (atomic_dec_return(&hp->port.count) == 0) {
50968 tty_port_tty_set(&hp->port, NULL);
50969 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
50970
50971 @@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50972
50973 spin_lock_irqsave(&hp->lock, flags);
50974 }
50975 - } else if (hp->port.count < 0)
50976 + } else if (atomic_read(&hp->port.count) < 0)
50977 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
50978 - hp - hvsi_ports, hp->port.count);
50979 + hp - hvsi_ports, atomic_read(&hp->port.count));
50980
50981 spin_unlock_irqrestore(&hp->lock, flags);
50982 }
50983 @@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
50984 tty_port_tty_set(&hp->port, NULL);
50985
50986 spin_lock_irqsave(&hp->lock, flags);
50987 - hp->port.count = 0;
50988 + atomic_set(&hp->port.count, 0);
50989 hp->n_outbuf = 0;
50990 spin_unlock_irqrestore(&hp->lock, flags);
50991 }
50992 diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
50993 index 7ae6c29..05c6dba 100644
50994 --- a/drivers/tty/hvc/hvsi_lib.c
50995 +++ b/drivers/tty/hvc/hvsi_lib.c
50996 @@ -8,7 +8,7 @@
50997
50998 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
50999 {
51000 - packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
51001 + packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
51002
51003 /* Assumes that always succeeds, works in practice */
51004 return pv->put_chars(pv->termno, (char *)packet, packet->len);
51005 @@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
51006
51007 /* Reset state */
51008 pv->established = 0;
51009 - atomic_set(&pv->seqno, 0);
51010 + atomic_set_unchecked(&pv->seqno, 0);
51011
51012 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
51013
51014 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
51015 index 17ee3bf..8d2520d 100644
51016 --- a/drivers/tty/ipwireless/tty.c
51017 +++ b/drivers/tty/ipwireless/tty.c
51018 @@ -28,6 +28,7 @@
51019 #include <linux/tty_driver.h>
51020 #include <linux/tty_flip.h>
51021 #include <linux/uaccess.h>
51022 +#include <asm/local.h>
51023
51024 #include "tty.h"
51025 #include "network.h"
51026 @@ -98,10 +99,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
51027 mutex_unlock(&tty->ipw_tty_mutex);
51028 return -ENODEV;
51029 }
51030 - if (tty->port.count == 0)
51031 + if (atomic_read(&tty->port.count) == 0)
51032 tty->tx_bytes_queued = 0;
51033
51034 - tty->port.count++;
51035 + atomic_inc(&tty->port.count);
51036
51037 tty->port.tty = linux_tty;
51038 linux_tty->driver_data = tty;
51039 @@ -117,9 +118,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
51040
51041 static void do_ipw_close(struct ipw_tty *tty)
51042 {
51043 - tty->port.count--;
51044 -
51045 - if (tty->port.count == 0) {
51046 + if (atomic_dec_return(&tty->port.count) == 0) {
51047 struct tty_struct *linux_tty = tty->port.tty;
51048
51049 if (linux_tty != NULL) {
51050 @@ -140,7 +139,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
51051 return;
51052
51053 mutex_lock(&tty->ipw_tty_mutex);
51054 - if (tty->port.count == 0) {
51055 + if (atomic_read(&tty->port.count) == 0) {
51056 mutex_unlock(&tty->ipw_tty_mutex);
51057 return;
51058 }
51059 @@ -163,7 +162,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
51060
51061 mutex_lock(&tty->ipw_tty_mutex);
51062
51063 - if (!tty->port.count) {
51064 + if (!atomic_read(&tty->port.count)) {
51065 mutex_unlock(&tty->ipw_tty_mutex);
51066 return;
51067 }
51068 @@ -202,7 +201,7 @@ static int ipw_write(struct tty_struct *linux_tty,
51069 return -ENODEV;
51070
51071 mutex_lock(&tty->ipw_tty_mutex);
51072 - if (!tty->port.count) {
51073 + if (!atomic_read(&tty->port.count)) {
51074 mutex_unlock(&tty->ipw_tty_mutex);
51075 return -EINVAL;
51076 }
51077 @@ -242,7 +241,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
51078 if (!tty)
51079 return -ENODEV;
51080
51081 - if (!tty->port.count)
51082 + if (!atomic_read(&tty->port.count))
51083 return -EINVAL;
51084
51085 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
51086 @@ -284,7 +283,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
51087 if (!tty)
51088 return 0;
51089
51090 - if (!tty->port.count)
51091 + if (!atomic_read(&tty->port.count))
51092 return 0;
51093
51094 return tty->tx_bytes_queued;
51095 @@ -365,7 +364,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
51096 if (!tty)
51097 return -ENODEV;
51098
51099 - if (!tty->port.count)
51100 + if (!atomic_read(&tty->port.count))
51101 return -EINVAL;
51102
51103 return get_control_lines(tty);
51104 @@ -381,7 +380,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
51105 if (!tty)
51106 return -ENODEV;
51107
51108 - if (!tty->port.count)
51109 + if (!atomic_read(&tty->port.count))
51110 return -EINVAL;
51111
51112 return set_control_lines(tty, set, clear);
51113 @@ -395,7 +394,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
51114 if (!tty)
51115 return -ENODEV;
51116
51117 - if (!tty->port.count)
51118 + if (!atomic_read(&tty->port.count))
51119 return -EINVAL;
51120
51121 /* FIXME: Exactly how is the tty object locked here .. */
51122 @@ -551,7 +550,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
51123 * are gone */
51124 mutex_lock(&ttyj->ipw_tty_mutex);
51125 }
51126 - while (ttyj->port.count)
51127 + while (atomic_read(&ttyj->port.count))
51128 do_ipw_close(ttyj);
51129 ipwireless_disassociate_network_ttys(network,
51130 ttyj->channel_idx);
51131 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
51132 index 1deaca4..c8582d4 100644
51133 --- a/drivers/tty/moxa.c
51134 +++ b/drivers/tty/moxa.c
51135 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
51136 }
51137
51138 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
51139 - ch->port.count++;
51140 + atomic_inc(&ch->port.count);
51141 tty->driver_data = ch;
51142 tty_port_tty_set(&ch->port, tty);
51143 mutex_lock(&ch->port.mutex);
51144 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
51145 index 2ebe47b..3205833 100644
51146 --- a/drivers/tty/n_gsm.c
51147 +++ b/drivers/tty/n_gsm.c
51148 @@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
51149 spin_lock_init(&dlci->lock);
51150 mutex_init(&dlci->mutex);
51151 dlci->fifo = &dlci->_fifo;
51152 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
51153 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
51154 kfree(dlci);
51155 return NULL;
51156 }
51157 @@ -2954,7 +2954,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
51158 struct gsm_dlci *dlci = tty->driver_data;
51159 struct tty_port *port = &dlci->port;
51160
51161 - port->count++;
51162 + atomic_inc(&port->count);
51163 tty_port_tty_set(port, tty);
51164
51165 dlci->modem_rx = 0;
51166 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
51167 index 0391f17..31fa586 100644
51168 --- a/drivers/tty/n_tty.c
51169 +++ b/drivers/tty/n_tty.c
51170 @@ -115,7 +115,7 @@ struct n_tty_data {
51171 int minimum_to_wake;
51172
51173 /* consumer-published */
51174 - size_t read_tail;
51175 + size_t read_tail __intentional_overflow(-1);
51176 size_t line_start;
51177
51178 /* protected by output lock */
51179 @@ -2517,6 +2517,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
51180 {
51181 *ops = tty_ldisc_N_TTY;
51182 ops->owner = NULL;
51183 - ops->refcount = ops->flags = 0;
51184 + atomic_set(&ops->refcount, 0);
51185 + ops->flags = 0;
51186 }
51187 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
51188 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
51189 index 25c9bc7..24077b7 100644
51190 --- a/drivers/tty/pty.c
51191 +++ b/drivers/tty/pty.c
51192 @@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
51193 panic("Couldn't register Unix98 pts driver");
51194
51195 /* Now create the /dev/ptmx special device */
51196 + pax_open_kernel();
51197 tty_default_fops(&ptmx_fops);
51198 - ptmx_fops.open = ptmx_open;
51199 + *(void **)&ptmx_fops.open = ptmx_open;
51200 + pax_close_kernel();
51201
51202 cdev_init(&ptmx_cdev, &ptmx_fops);
51203 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
51204 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
51205 index 383c4c7..d408e21 100644
51206 --- a/drivers/tty/rocket.c
51207 +++ b/drivers/tty/rocket.c
51208 @@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
51209 tty->driver_data = info;
51210 tty_port_tty_set(port, tty);
51211
51212 - if (port->count++ == 0) {
51213 + if (atomic_inc_return(&port->count) == 1) {
51214 atomic_inc(&rp_num_ports_open);
51215
51216 #ifdef ROCKET_DEBUG_OPEN
51217 @@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
51218 #endif
51219 }
51220 #ifdef ROCKET_DEBUG_OPEN
51221 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
51222 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
51223 #endif
51224
51225 /*
51226 @@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
51227 spin_unlock_irqrestore(&info->port.lock, flags);
51228 return;
51229 }
51230 - if (info->port.count)
51231 + if (atomic_read(&info->port.count))
51232 atomic_dec(&rp_num_ports_open);
51233 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
51234 spin_unlock_irqrestore(&info->port.lock, flags);
51235 diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
51236 index 1274499..f541382 100644
51237 --- a/drivers/tty/serial/ioc4_serial.c
51238 +++ b/drivers/tty/serial/ioc4_serial.c
51239 @@ -437,7 +437,7 @@ struct ioc4_soft {
51240 } is_intr_info[MAX_IOC4_INTR_ENTS];
51241
51242 /* Number of entries active in the above array */
51243 - atomic_t is_num_intrs;
51244 + atomic_unchecked_t is_num_intrs;
51245 } is_intr_type[IOC4_NUM_INTR_TYPES];
51246
51247 /* is_ir_lock must be held while
51248 @@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
51249 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
51250 || (type == IOC4_OTHER_INTR_TYPE)));
51251
51252 - i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
51253 + i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
51254 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
51255
51256 /* Save off the lower level interrupt handler */
51257 @@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
51258
51259 soft = arg;
51260 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
51261 - num_intrs = (int)atomic_read(
51262 + num_intrs = (int)atomic_read_unchecked(
51263 &soft->is_intr_type[intr_type].is_num_intrs);
51264
51265 this_mir = this_ir = pending_intrs(soft, intr_type);
51266 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
51267 index a260cde..6b2b5ce 100644
51268 --- a/drivers/tty/serial/kgdboc.c
51269 +++ b/drivers/tty/serial/kgdboc.c
51270 @@ -24,8 +24,9 @@
51271 #define MAX_CONFIG_LEN 40
51272
51273 static struct kgdb_io kgdboc_io_ops;
51274 +static struct kgdb_io kgdboc_io_ops_console;
51275
51276 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
51277 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
51278 static int configured = -1;
51279
51280 static char config[MAX_CONFIG_LEN];
51281 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
51282 kgdboc_unregister_kbd();
51283 if (configured == 1)
51284 kgdb_unregister_io_module(&kgdboc_io_ops);
51285 + else if (configured == 2)
51286 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
51287 }
51288
51289 static int configure_kgdboc(void)
51290 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
51291 int err;
51292 char *cptr = config;
51293 struct console *cons;
51294 + int is_console = 0;
51295
51296 err = kgdboc_option_setup(config);
51297 if (err || !strlen(config) || isspace(config[0]))
51298 goto noconfig;
51299
51300 err = -ENODEV;
51301 - kgdboc_io_ops.is_console = 0;
51302 kgdb_tty_driver = NULL;
51303
51304 kgdboc_use_kms = 0;
51305 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
51306 int idx;
51307 if (cons->device && cons->device(cons, &idx) == p &&
51308 idx == tty_line) {
51309 - kgdboc_io_ops.is_console = 1;
51310 + is_console = 1;
51311 break;
51312 }
51313 cons = cons->next;
51314 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
51315 kgdb_tty_line = tty_line;
51316
51317 do_register:
51318 - err = kgdb_register_io_module(&kgdboc_io_ops);
51319 + if (is_console) {
51320 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
51321 + configured = 2;
51322 + } else {
51323 + err = kgdb_register_io_module(&kgdboc_io_ops);
51324 + configured = 1;
51325 + }
51326 if (err)
51327 goto noconfig;
51328
51329 @@ -205,8 +214,6 @@ do_register:
51330 if (err)
51331 goto nmi_con_failed;
51332
51333 - configured = 1;
51334 -
51335 return 0;
51336
51337 nmi_con_failed:
51338 @@ -223,7 +230,7 @@ noconfig:
51339 static int __init init_kgdboc(void)
51340 {
51341 /* Already configured? */
51342 - if (configured == 1)
51343 + if (configured >= 1)
51344 return 0;
51345
51346 return configure_kgdboc();
51347 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
51348 if (config[len - 1] == '\n')
51349 config[len - 1] = '\0';
51350
51351 - if (configured == 1)
51352 + if (configured >= 1)
51353 cleanup_kgdboc();
51354
51355 /* Go and configure with the new params. */
51356 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
51357 .post_exception = kgdboc_post_exp_handler,
51358 };
51359
51360 +static struct kgdb_io kgdboc_io_ops_console = {
51361 + .name = "kgdboc",
51362 + .read_char = kgdboc_get_char,
51363 + .write_char = kgdboc_put_char,
51364 + .pre_exception = kgdboc_pre_exp_handler,
51365 + .post_exception = kgdboc_post_exp_handler,
51366 + .is_console = 1
51367 +};
51368 +
51369 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
51370 /* This is only available if kgdboc is a built in for early debugging */
51371 static int __init kgdboc_early_init(char *opt)
51372 diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
51373 index 7307dc4..ce4fe90 100644
51374 --- a/drivers/tty/serial/msm_serial.c
51375 +++ b/drivers/tty/serial/msm_serial.c
51376 @@ -1026,7 +1026,7 @@ static struct uart_driver msm_uart_driver = {
51377 .cons = MSM_CONSOLE,
51378 };
51379
51380 -static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
51381 +static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
51382
51383 static const struct of_device_id msm_uartdm_table[] = {
51384 { .compatible = "qcom,msm-uartdm-v1.1", .data = (void *)UARTDM_1P1 },
51385 @@ -1045,7 +1045,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
51386 int irq;
51387
51388 if (pdev->id == -1)
51389 - pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
51390 + pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
51391
51392 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
51393 return -ENXIO;
51394 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
51395 index 1f5505e..a1a767d 100644
51396 --- a/drivers/tty/serial/samsung.c
51397 +++ b/drivers/tty/serial/samsung.c
51398 @@ -463,11 +463,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
51399 }
51400 }
51401
51402 +static int s3c64xx_serial_startup(struct uart_port *port);
51403 static int s3c24xx_serial_startup(struct uart_port *port)
51404 {
51405 struct s3c24xx_uart_port *ourport = to_ourport(port);
51406 int ret;
51407
51408 + /* Startup sequence is different for s3c64xx and higher SoC's */
51409 + if (s3c24xx_serial_has_interrupt_mask(port))
51410 + return s3c64xx_serial_startup(port);
51411 +
51412 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
51413 port->mapbase, port->membase);
51414
51415 @@ -1141,10 +1146,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
51416 /* setup info for port */
51417 port->dev = &platdev->dev;
51418
51419 - /* Startup sequence is different for s3c64xx and higher SoC's */
51420 - if (s3c24xx_serial_has_interrupt_mask(port))
51421 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
51422 -
51423 port->uartclk = 1;
51424
51425 if (cfg->uart_flags & UPF_CONS_FLOW) {
51426 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
51427 index b68550d..a62d7f8 100644
51428 --- a/drivers/tty/serial/serial_core.c
51429 +++ b/drivers/tty/serial/serial_core.c
51430 @@ -1329,7 +1329,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
51431
51432 pr_debug("uart_close(%d) called\n", uport ? uport->line : -1);
51433
51434 - if (!port->count || tty_port_close_start(port, tty, filp) == 0)
51435 + if (!atomic_read(&port->count) || tty_port_close_start(port, tty, filp) == 0)
51436 return;
51437
51438 /*
51439 @@ -1456,7 +1456,7 @@ static void uart_hangup(struct tty_struct *tty)
51440 uart_flush_buffer(tty);
51441 uart_shutdown(tty, state);
51442 spin_lock_irqsave(&port->lock, flags);
51443 - port->count = 0;
51444 + atomic_set(&port->count, 0);
51445 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
51446 spin_unlock_irqrestore(&port->lock, flags);
51447 tty_port_tty_set(port, NULL);
51448 @@ -1554,7 +1554,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51449 goto end;
51450 }
51451
51452 - port->count++;
51453 + atomic_inc(&port->count);
51454 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
51455 retval = -ENXIO;
51456 goto err_dec_count;
51457 @@ -1594,7 +1594,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51458 end:
51459 return retval;
51460 err_dec_count:
51461 - port->count--;
51462 + atomic_inc(&port->count);
51463 mutex_unlock(&port->mutex);
51464 goto end;
51465 }
51466 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
51467 index d48e040..0f52764 100644
51468 --- a/drivers/tty/synclink.c
51469 +++ b/drivers/tty/synclink.c
51470 @@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51471
51472 if (debug_level >= DEBUG_LEVEL_INFO)
51473 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
51474 - __FILE__,__LINE__, info->device_name, info->port.count);
51475 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51476
51477 if (tty_port_close_start(&info->port, tty, filp) == 0)
51478 goto cleanup;
51479 @@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51480 cleanup:
51481 if (debug_level >= DEBUG_LEVEL_INFO)
51482 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
51483 - tty->driver->name, info->port.count);
51484 + tty->driver->name, atomic_read(&info->port.count));
51485
51486 } /* end of mgsl_close() */
51487
51488 @@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
51489
51490 mgsl_flush_buffer(tty);
51491 shutdown(info);
51492 -
51493 - info->port.count = 0;
51494 +
51495 + atomic_set(&info->port.count, 0);
51496 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51497 info->port.tty = NULL;
51498
51499 @@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51500
51501 if (debug_level >= DEBUG_LEVEL_INFO)
51502 printk("%s(%d):block_til_ready before block on %s count=%d\n",
51503 - __FILE__,__LINE__, tty->driver->name, port->count );
51504 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51505
51506 spin_lock_irqsave(&info->irq_spinlock, flags);
51507 if (!tty_hung_up_p(filp)) {
51508 extra_count = true;
51509 - port->count--;
51510 + atomic_dec(&port->count);
51511 }
51512 spin_unlock_irqrestore(&info->irq_spinlock, flags);
51513 port->blocked_open++;
51514 @@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51515
51516 if (debug_level >= DEBUG_LEVEL_INFO)
51517 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
51518 - __FILE__,__LINE__, tty->driver->name, port->count );
51519 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51520
51521 tty_unlock(tty);
51522 schedule();
51523 @@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51524
51525 /* FIXME: Racy on hangup during close wait */
51526 if (extra_count)
51527 - port->count++;
51528 + atomic_inc(&port->count);
51529 port->blocked_open--;
51530
51531 if (debug_level >= DEBUG_LEVEL_INFO)
51532 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
51533 - __FILE__,__LINE__, tty->driver->name, port->count );
51534 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51535
51536 if (!retval)
51537 port->flags |= ASYNC_NORMAL_ACTIVE;
51538 @@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51539
51540 if (debug_level >= DEBUG_LEVEL_INFO)
51541 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
51542 - __FILE__,__LINE__,tty->driver->name, info->port.count);
51543 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51544
51545 /* If port is closing, signal caller to try again */
51546 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51547 @@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51548 spin_unlock_irqrestore(&info->netlock, flags);
51549 goto cleanup;
51550 }
51551 - info->port.count++;
51552 + atomic_inc(&info->port.count);
51553 spin_unlock_irqrestore(&info->netlock, flags);
51554
51555 - if (info->port.count == 1) {
51556 + if (atomic_read(&info->port.count) == 1) {
51557 /* 1st open on this device, init hardware */
51558 retval = startup(info);
51559 if (retval < 0)
51560 @@ -3446,8 +3446,8 @@ cleanup:
51561 if (retval) {
51562 if (tty->count == 1)
51563 info->port.tty = NULL; /* tty layer will release tty struct */
51564 - if(info->port.count)
51565 - info->port.count--;
51566 + if (atomic_read(&info->port.count))
51567 + atomic_dec(&info->port.count);
51568 }
51569
51570 return retval;
51571 @@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51572 unsigned short new_crctype;
51573
51574 /* return error if TTY interface open */
51575 - if (info->port.count)
51576 + if (atomic_read(&info->port.count))
51577 return -EBUSY;
51578
51579 switch (encoding)
51580 @@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
51581
51582 /* arbitrate between network and tty opens */
51583 spin_lock_irqsave(&info->netlock, flags);
51584 - if (info->port.count != 0 || info->netcount != 0) {
51585 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51586 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51587 spin_unlock_irqrestore(&info->netlock, flags);
51588 return -EBUSY;
51589 @@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51590 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51591
51592 /* return error if TTY interface open */
51593 - if (info->port.count)
51594 + if (atomic_read(&info->port.count))
51595 return -EBUSY;
51596
51597 if (cmd != SIOCWANDEV)
51598 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
51599 index c359a91..959fc26 100644
51600 --- a/drivers/tty/synclink_gt.c
51601 +++ b/drivers/tty/synclink_gt.c
51602 @@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51603 tty->driver_data = info;
51604 info->port.tty = tty;
51605
51606 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
51607 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
51608
51609 /* If port is closing, signal caller to try again */
51610 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51611 @@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51612 mutex_unlock(&info->port.mutex);
51613 goto cleanup;
51614 }
51615 - info->port.count++;
51616 + atomic_inc(&info->port.count);
51617 spin_unlock_irqrestore(&info->netlock, flags);
51618
51619 - if (info->port.count == 1) {
51620 + if (atomic_read(&info->port.count) == 1) {
51621 /* 1st open on this device, init hardware */
51622 retval = startup(info);
51623 if (retval < 0) {
51624 @@ -715,8 +715,8 @@ cleanup:
51625 if (retval) {
51626 if (tty->count == 1)
51627 info->port.tty = NULL; /* tty layer will release tty struct */
51628 - if(info->port.count)
51629 - info->port.count--;
51630 + if(atomic_read(&info->port.count))
51631 + atomic_dec(&info->port.count);
51632 }
51633
51634 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
51635 @@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51636
51637 if (sanity_check(info, tty->name, "close"))
51638 return;
51639 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
51640 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
51641
51642 if (tty_port_close_start(&info->port, tty, filp) == 0)
51643 goto cleanup;
51644 @@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51645 tty_port_close_end(&info->port, tty);
51646 info->port.tty = NULL;
51647 cleanup:
51648 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
51649 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
51650 }
51651
51652 static void hangup(struct tty_struct *tty)
51653 @@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
51654 shutdown(info);
51655
51656 spin_lock_irqsave(&info->port.lock, flags);
51657 - info->port.count = 0;
51658 + atomic_set(&info->port.count, 0);
51659 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51660 info->port.tty = NULL;
51661 spin_unlock_irqrestore(&info->port.lock, flags);
51662 @@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51663 unsigned short new_crctype;
51664
51665 /* return error if TTY interface open */
51666 - if (info->port.count)
51667 + if (atomic_read(&info->port.count))
51668 return -EBUSY;
51669
51670 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
51671 @@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
51672
51673 /* arbitrate between network and tty opens */
51674 spin_lock_irqsave(&info->netlock, flags);
51675 - if (info->port.count != 0 || info->netcount != 0) {
51676 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51677 DBGINFO(("%s hdlc_open busy\n", dev->name));
51678 spin_unlock_irqrestore(&info->netlock, flags);
51679 return -EBUSY;
51680 @@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51681 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
51682
51683 /* return error if TTY interface open */
51684 - if (info->port.count)
51685 + if (atomic_read(&info->port.count))
51686 return -EBUSY;
51687
51688 if (cmd != SIOCWANDEV)
51689 @@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
51690 if (port == NULL)
51691 continue;
51692 spin_lock(&port->lock);
51693 - if ((port->port.count || port->netcount) &&
51694 + if ((atomic_read(&port->port.count) || port->netcount) &&
51695 port->pending_bh && !port->bh_running &&
51696 !port->bh_requested) {
51697 DBGISR(("%s bh queued\n", port->device_name));
51698 @@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51699 spin_lock_irqsave(&info->lock, flags);
51700 if (!tty_hung_up_p(filp)) {
51701 extra_count = true;
51702 - port->count--;
51703 + atomic_dec(&port->count);
51704 }
51705 spin_unlock_irqrestore(&info->lock, flags);
51706 port->blocked_open++;
51707 @@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51708 remove_wait_queue(&port->open_wait, &wait);
51709
51710 if (extra_count)
51711 - port->count++;
51712 + atomic_inc(&port->count);
51713 port->blocked_open--;
51714
51715 if (!retval)
51716 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
51717 index 53ba853..3c30f6d 100644
51718 --- a/drivers/tty/synclinkmp.c
51719 +++ b/drivers/tty/synclinkmp.c
51720 @@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51721
51722 if (debug_level >= DEBUG_LEVEL_INFO)
51723 printk("%s(%d):%s open(), old ref count = %d\n",
51724 - __FILE__,__LINE__,tty->driver->name, info->port.count);
51725 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51726
51727 /* If port is closing, signal caller to try again */
51728 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51729 @@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51730 spin_unlock_irqrestore(&info->netlock, flags);
51731 goto cleanup;
51732 }
51733 - info->port.count++;
51734 + atomic_inc(&info->port.count);
51735 spin_unlock_irqrestore(&info->netlock, flags);
51736
51737 - if (info->port.count == 1) {
51738 + if (atomic_read(&info->port.count) == 1) {
51739 /* 1st open on this device, init hardware */
51740 retval = startup(info);
51741 if (retval < 0)
51742 @@ -796,8 +796,8 @@ cleanup:
51743 if (retval) {
51744 if (tty->count == 1)
51745 info->port.tty = NULL; /* tty layer will release tty struct */
51746 - if(info->port.count)
51747 - info->port.count--;
51748 + if(atomic_read(&info->port.count))
51749 + atomic_dec(&info->port.count);
51750 }
51751
51752 return retval;
51753 @@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51754
51755 if (debug_level >= DEBUG_LEVEL_INFO)
51756 printk("%s(%d):%s close() entry, count=%d\n",
51757 - __FILE__,__LINE__, info->device_name, info->port.count);
51758 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51759
51760 if (tty_port_close_start(&info->port, tty, filp) == 0)
51761 goto cleanup;
51762 @@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51763 cleanup:
51764 if (debug_level >= DEBUG_LEVEL_INFO)
51765 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
51766 - tty->driver->name, info->port.count);
51767 + tty->driver->name, atomic_read(&info->port.count));
51768 }
51769
51770 /* Called by tty_hangup() when a hangup is signaled.
51771 @@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
51772 shutdown(info);
51773
51774 spin_lock_irqsave(&info->port.lock, flags);
51775 - info->port.count = 0;
51776 + atomic_set(&info->port.count, 0);
51777 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51778 info->port.tty = NULL;
51779 spin_unlock_irqrestore(&info->port.lock, flags);
51780 @@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51781 unsigned short new_crctype;
51782
51783 /* return error if TTY interface open */
51784 - if (info->port.count)
51785 + if (atomic_read(&info->port.count))
51786 return -EBUSY;
51787
51788 switch (encoding)
51789 @@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
51790
51791 /* arbitrate between network and tty opens */
51792 spin_lock_irqsave(&info->netlock, flags);
51793 - if (info->port.count != 0 || info->netcount != 0) {
51794 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51795 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51796 spin_unlock_irqrestore(&info->netlock, flags);
51797 return -EBUSY;
51798 @@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51799 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51800
51801 /* return error if TTY interface open */
51802 - if (info->port.count)
51803 + if (atomic_read(&info->port.count))
51804 return -EBUSY;
51805
51806 if (cmd != SIOCWANDEV)
51807 @@ -2621,7 +2621,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
51808 * do not request bottom half processing if the
51809 * device is not open in a normal mode.
51810 */
51811 - if ( port && (port->port.count || port->netcount) &&
51812 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
51813 port->pending_bh && !port->bh_running &&
51814 !port->bh_requested ) {
51815 if ( debug_level >= DEBUG_LEVEL_ISR )
51816 @@ -3319,12 +3319,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51817
51818 if (debug_level >= DEBUG_LEVEL_INFO)
51819 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
51820 - __FILE__,__LINE__, tty->driver->name, port->count );
51821 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51822
51823 spin_lock_irqsave(&info->lock, flags);
51824 if (!tty_hung_up_p(filp)) {
51825 extra_count = true;
51826 - port->count--;
51827 + atomic_dec(&port->count);
51828 }
51829 spin_unlock_irqrestore(&info->lock, flags);
51830 port->blocked_open++;
51831 @@ -3353,7 +3353,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51832
51833 if (debug_level >= DEBUG_LEVEL_INFO)
51834 printk("%s(%d):%s block_til_ready() count=%d\n",
51835 - __FILE__,__LINE__, tty->driver->name, port->count );
51836 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51837
51838 tty_unlock(tty);
51839 schedule();
51840 @@ -3364,12 +3364,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51841 remove_wait_queue(&port->open_wait, &wait);
51842
51843 if (extra_count)
51844 - port->count++;
51845 + atomic_inc(&port->count);
51846 port->blocked_open--;
51847
51848 if (debug_level >= DEBUG_LEVEL_INFO)
51849 printk("%s(%d):%s block_til_ready() after, count=%d\n",
51850 - __FILE__,__LINE__, tty->driver->name, port->count );
51851 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51852
51853 if (!retval)
51854 port->flags |= ASYNC_NORMAL_ACTIVE;
51855 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
51856 index ce396ec..04a37be 100644
51857 --- a/drivers/tty/sysrq.c
51858 +++ b/drivers/tty/sysrq.c
51859 @@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
51860 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
51861 size_t count, loff_t *ppos)
51862 {
51863 - if (count) {
51864 + if (count && capable(CAP_SYS_ADMIN)) {
51865 char c;
51866
51867 if (get_user(c, buf))
51868 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
51869 index 3411071..86f2cf2 100644
51870 --- a/drivers/tty/tty_io.c
51871 +++ b/drivers/tty/tty_io.c
51872 @@ -3475,7 +3475,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
51873
51874 void tty_default_fops(struct file_operations *fops)
51875 {
51876 - *fops = tty_fops;
51877 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
51878 }
51879
51880 /*
51881 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
51882 index 2d822aa..a566234 100644
51883 --- a/drivers/tty/tty_ldisc.c
51884 +++ b/drivers/tty/tty_ldisc.c
51885 @@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
51886 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51887 tty_ldiscs[disc] = new_ldisc;
51888 new_ldisc->num = disc;
51889 - new_ldisc->refcount = 0;
51890 + atomic_set(&new_ldisc->refcount, 0);
51891 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51892
51893 return ret;
51894 @@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
51895 return -EINVAL;
51896
51897 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51898 - if (tty_ldiscs[disc]->refcount)
51899 + if (atomic_read(&tty_ldiscs[disc]->refcount))
51900 ret = -EBUSY;
51901 else
51902 tty_ldiscs[disc] = NULL;
51903 @@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
51904 if (ldops) {
51905 ret = ERR_PTR(-EAGAIN);
51906 if (try_module_get(ldops->owner)) {
51907 - ldops->refcount++;
51908 + atomic_inc(&ldops->refcount);
51909 ret = ldops;
51910 }
51911 }
51912 @@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
51913 unsigned long flags;
51914
51915 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51916 - ldops->refcount--;
51917 + atomic_dec(&ldops->refcount);
51918 module_put(ldops->owner);
51919 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51920 }
51921 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
51922 index 3f746c8..2f2fcaa 100644
51923 --- a/drivers/tty/tty_port.c
51924 +++ b/drivers/tty/tty_port.c
51925 @@ -235,7 +235,7 @@ void tty_port_hangup(struct tty_port *port)
51926 unsigned long flags;
51927
51928 spin_lock_irqsave(&port->lock, flags);
51929 - port->count = 0;
51930 + atomic_set(&port->count, 0);
51931 port->flags &= ~ASYNC_NORMAL_ACTIVE;
51932 tty = port->tty;
51933 if (tty)
51934 @@ -393,7 +393,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51935 /* The port lock protects the port counts */
51936 spin_lock_irqsave(&port->lock, flags);
51937 if (!tty_hung_up_p(filp))
51938 - port->count--;
51939 + atomic_dec(&port->count);
51940 port->blocked_open++;
51941 spin_unlock_irqrestore(&port->lock, flags);
51942
51943 @@ -435,7 +435,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51944 we must not mess that up further */
51945 spin_lock_irqsave(&port->lock, flags);
51946 if (!tty_hung_up_p(filp))
51947 - port->count++;
51948 + atomic_inc(&port->count);
51949 port->blocked_open--;
51950 if (retval == 0)
51951 port->flags |= ASYNC_NORMAL_ACTIVE;
51952 @@ -469,19 +469,19 @@ int tty_port_close_start(struct tty_port *port,
51953 return 0;
51954 }
51955
51956 - if (tty->count == 1 && port->count != 1) {
51957 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
51958 printk(KERN_WARNING
51959 "tty_port_close_start: tty->count = 1 port count = %d.\n",
51960 - port->count);
51961 - port->count = 1;
51962 + atomic_read(&port->count));
51963 + atomic_set(&port->count, 1);
51964 }
51965 - if (--port->count < 0) {
51966 + if (atomic_dec_return(&port->count) < 0) {
51967 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
51968 - port->count);
51969 - port->count = 0;
51970 + atomic_read(&port->count));
51971 + atomic_set(&port->count, 0);
51972 }
51973
51974 - if (port->count) {
51975 + if (atomic_read(&port->count)) {
51976 spin_unlock_irqrestore(&port->lock, flags);
51977 return 0;
51978 }
51979 @@ -563,7 +563,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
51980 {
51981 spin_lock_irq(&port->lock);
51982 if (!tty_hung_up_p(filp))
51983 - ++port->count;
51984 + atomic_inc(&port->count);
51985 spin_unlock_irq(&port->lock);
51986 tty_port_tty_set(port, tty);
51987
51988 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
51989 index d0e3a44..5f8b754 100644
51990 --- a/drivers/tty/vt/keyboard.c
51991 +++ b/drivers/tty/vt/keyboard.c
51992 @@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
51993 kbd->kbdmode == VC_OFF) &&
51994 value != KVAL(K_SAK))
51995 return; /* SAK is allowed even in raw mode */
51996 +
51997 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51998 + {
51999 + void *func = fn_handler[value];
52000 + if (func == fn_show_state || func == fn_show_ptregs ||
52001 + func == fn_show_mem)
52002 + return;
52003 + }
52004 +#endif
52005 +
52006 fn_handler[value](vc);
52007 }
52008
52009 @@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
52010 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
52011 return -EFAULT;
52012
52013 - if (!capable(CAP_SYS_TTY_CONFIG))
52014 - perm = 0;
52015 -
52016 switch (cmd) {
52017 case KDGKBENT:
52018 /* Ensure another thread doesn't free it under us */
52019 @@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
52020 spin_unlock_irqrestore(&kbd_event_lock, flags);
52021 return put_user(val, &user_kbe->kb_value);
52022 case KDSKBENT:
52023 + if (!capable(CAP_SYS_TTY_CONFIG))
52024 + perm = 0;
52025 +
52026 if (!perm)
52027 return -EPERM;
52028 if (!i && v == K_NOSUCHMAP) {
52029 @@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
52030 int i, j, k;
52031 int ret;
52032
52033 - if (!capable(CAP_SYS_TTY_CONFIG))
52034 - perm = 0;
52035 -
52036 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
52037 if (!kbs) {
52038 ret = -ENOMEM;
52039 @@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
52040 kfree(kbs);
52041 return ((p && *p) ? -EOVERFLOW : 0);
52042 case KDSKBSENT:
52043 + if (!capable(CAP_SYS_TTY_CONFIG))
52044 + perm = 0;
52045 +
52046 if (!perm) {
52047 ret = -EPERM;
52048 goto reterr;
52049 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
52050 index a673e5b..36e5d32 100644
52051 --- a/drivers/uio/uio.c
52052 +++ b/drivers/uio/uio.c
52053 @@ -25,6 +25,7 @@
52054 #include <linux/kobject.h>
52055 #include <linux/cdev.h>
52056 #include <linux/uio_driver.h>
52057 +#include <asm/local.h>
52058
52059 #define UIO_MAX_DEVICES (1U << MINORBITS)
52060
52061 @@ -32,7 +33,7 @@ struct uio_device {
52062 struct module *owner;
52063 struct device *dev;
52064 int minor;
52065 - atomic_t event;
52066 + atomic_unchecked_t event;
52067 struct fasync_struct *async_queue;
52068 wait_queue_head_t wait;
52069 struct uio_info *info;
52070 @@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
52071 struct device_attribute *attr, char *buf)
52072 {
52073 struct uio_device *idev = dev_get_drvdata(dev);
52074 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
52075 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
52076 }
52077 static DEVICE_ATTR_RO(event);
52078
52079 @@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
52080 {
52081 struct uio_device *idev = info->uio_dev;
52082
52083 - atomic_inc(&idev->event);
52084 + atomic_inc_unchecked(&idev->event);
52085 wake_up_interruptible(&idev->wait);
52086 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
52087 }
52088 @@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
52089 }
52090
52091 listener->dev = idev;
52092 - listener->event_count = atomic_read(&idev->event);
52093 + listener->event_count = atomic_read_unchecked(&idev->event);
52094 filep->private_data = listener;
52095
52096 if (idev->info->open) {
52097 @@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
52098 return -EIO;
52099
52100 poll_wait(filep, &idev->wait, wait);
52101 - if (listener->event_count != atomic_read(&idev->event))
52102 + if (listener->event_count != atomic_read_unchecked(&idev->event))
52103 return POLLIN | POLLRDNORM;
52104 return 0;
52105 }
52106 @@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
52107 do {
52108 set_current_state(TASK_INTERRUPTIBLE);
52109
52110 - event_count = atomic_read(&idev->event);
52111 + event_count = atomic_read_unchecked(&idev->event);
52112 if (event_count != listener->event_count) {
52113 if (copy_to_user(buf, &event_count, count))
52114 retval = -EFAULT;
52115 @@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
52116 static int uio_find_mem_index(struct vm_area_struct *vma)
52117 {
52118 struct uio_device *idev = vma->vm_private_data;
52119 + unsigned long size;
52120
52121 if (vma->vm_pgoff < MAX_UIO_MAPS) {
52122 - if (idev->info->mem[vma->vm_pgoff].size == 0)
52123 + size = idev->info->mem[vma->vm_pgoff].size;
52124 + if (size == 0)
52125 + return -1;
52126 + if (vma->vm_end - vma->vm_start > size)
52127 return -1;
52128 return (int)vma->vm_pgoff;
52129 }
52130 @@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
52131 idev->owner = owner;
52132 idev->info = info;
52133 init_waitqueue_head(&idev->wait);
52134 - atomic_set(&idev->event, 0);
52135 + atomic_set_unchecked(&idev->event, 0);
52136
52137 ret = uio_get_minor(idev);
52138 if (ret)
52139 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
52140 index 813d4d3..a71934f 100644
52141 --- a/drivers/usb/atm/cxacru.c
52142 +++ b/drivers/usb/atm/cxacru.c
52143 @@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
52144 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
52145 if (ret < 2)
52146 return -EINVAL;
52147 - if (index < 0 || index > 0x7f)
52148 + if (index > 0x7f)
52149 return -EINVAL;
52150 pos += tmp;
52151
52152 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
52153 index dada014..1d0d517 100644
52154 --- a/drivers/usb/atm/usbatm.c
52155 +++ b/drivers/usb/atm/usbatm.c
52156 @@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52157 if (printk_ratelimit())
52158 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
52159 __func__, vpi, vci);
52160 - atomic_inc(&vcc->stats->rx_err);
52161 + atomic_inc_unchecked(&vcc->stats->rx_err);
52162 return;
52163 }
52164
52165 @@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52166 if (length > ATM_MAX_AAL5_PDU) {
52167 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
52168 __func__, length, vcc);
52169 - atomic_inc(&vcc->stats->rx_err);
52170 + atomic_inc_unchecked(&vcc->stats->rx_err);
52171 goto out;
52172 }
52173
52174 @@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52175 if (sarb->len < pdu_length) {
52176 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
52177 __func__, pdu_length, sarb->len, vcc);
52178 - atomic_inc(&vcc->stats->rx_err);
52179 + atomic_inc_unchecked(&vcc->stats->rx_err);
52180 goto out;
52181 }
52182
52183 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
52184 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
52185 __func__, vcc);
52186 - atomic_inc(&vcc->stats->rx_err);
52187 + atomic_inc_unchecked(&vcc->stats->rx_err);
52188 goto out;
52189 }
52190
52191 @@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52192 if (printk_ratelimit())
52193 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
52194 __func__, length);
52195 - atomic_inc(&vcc->stats->rx_drop);
52196 + atomic_inc_unchecked(&vcc->stats->rx_drop);
52197 goto out;
52198 }
52199
52200 @@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52201
52202 vcc->push(vcc, skb);
52203
52204 - atomic_inc(&vcc->stats->rx);
52205 + atomic_inc_unchecked(&vcc->stats->rx);
52206 out:
52207 skb_trim(sarb, 0);
52208 }
52209 @@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
52210 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
52211
52212 usbatm_pop(vcc, skb);
52213 - atomic_inc(&vcc->stats->tx);
52214 + atomic_inc_unchecked(&vcc->stats->tx);
52215
52216 skb = skb_dequeue(&instance->sndqueue);
52217 }
52218 @@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
52219 if (!left--)
52220 return sprintf(page,
52221 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
52222 - atomic_read(&atm_dev->stats.aal5.tx),
52223 - atomic_read(&atm_dev->stats.aal5.tx_err),
52224 - atomic_read(&atm_dev->stats.aal5.rx),
52225 - atomic_read(&atm_dev->stats.aal5.rx_err),
52226 - atomic_read(&atm_dev->stats.aal5.rx_drop));
52227 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
52228 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
52229 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
52230 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
52231 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
52232
52233 if (!left--) {
52234 if (instance->disconnected)
52235 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
52236 index 2a3bbdf..91d72cf 100644
52237 --- a/drivers/usb/core/devices.c
52238 +++ b/drivers/usb/core/devices.c
52239 @@ -126,7 +126,7 @@ static const char format_endpt[] =
52240 * time it gets called.
52241 */
52242 static struct device_connect_event {
52243 - atomic_t count;
52244 + atomic_unchecked_t count;
52245 wait_queue_head_t wait;
52246 } device_event = {
52247 .count = ATOMIC_INIT(1),
52248 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
52249
52250 void usbfs_conn_disc_event(void)
52251 {
52252 - atomic_add(2, &device_event.count);
52253 + atomic_add_unchecked(2, &device_event.count);
52254 wake_up(&device_event.wait);
52255 }
52256
52257 @@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
52258
52259 poll_wait(file, &device_event.wait, wait);
52260
52261 - event_count = atomic_read(&device_event.count);
52262 + event_count = atomic_read_unchecked(&device_event.count);
52263 if (file->f_version != event_count) {
52264 file->f_version = event_count;
52265 return POLLIN | POLLRDNORM;
52266 diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
52267 index 257876e..4304364 100644
52268 --- a/drivers/usb/core/devio.c
52269 +++ b/drivers/usb/core/devio.c
52270 @@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
52271 struct usb_dev_state *ps = file->private_data;
52272 struct usb_device *dev = ps->dev;
52273 ssize_t ret = 0;
52274 - unsigned len;
52275 + size_t len;
52276 loff_t pos;
52277 int i;
52278
52279 @@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
52280 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
52281 struct usb_config_descriptor *config =
52282 (struct usb_config_descriptor *)dev->rawdescriptors[i];
52283 - unsigned int length = le16_to_cpu(config->wTotalLength);
52284 + size_t length = le16_to_cpu(config->wTotalLength);
52285
52286 if (*ppos < pos + length) {
52287
52288 /* The descriptor may claim to be longer than it
52289 * really is. Here is the actual allocated length. */
52290 - unsigned alloclen =
52291 + size_t alloclen =
52292 le16_to_cpu(dev->config[i].desc.wTotalLength);
52293
52294 - len = length - (*ppos - pos);
52295 + len = length + pos - *ppos;
52296 if (len > nbytes)
52297 len = nbytes;
52298
52299 /* Simply don't write (skip over) unallocated parts */
52300 if (alloclen > (*ppos - pos)) {
52301 - alloclen -= (*ppos - pos);
52302 + alloclen = alloclen + pos - *ppos;
52303 if (copy_to_user(buf,
52304 dev->rawdescriptors[i] + (*ppos - pos),
52305 min(len, alloclen))) {
52306 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
52307 index 9c4e292..b89877f 100644
52308 --- a/drivers/usb/core/hcd.c
52309 +++ b/drivers/usb/core/hcd.c
52310 @@ -1550,7 +1550,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
52311 */
52312 usb_get_urb(urb);
52313 atomic_inc(&urb->use_count);
52314 - atomic_inc(&urb->dev->urbnum);
52315 + atomic_inc_unchecked(&urb->dev->urbnum);
52316 usbmon_urb_submit(&hcd->self, urb);
52317
52318 /* NOTE requirements on root-hub callers (usbfs and the hub
52319 @@ -1577,7 +1577,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
52320 urb->hcpriv = NULL;
52321 INIT_LIST_HEAD(&urb->urb_list);
52322 atomic_dec(&urb->use_count);
52323 - atomic_dec(&urb->dev->urbnum);
52324 + atomic_dec_unchecked(&urb->dev->urbnum);
52325 if (atomic_read(&urb->reject))
52326 wake_up(&usb_kill_urb_queue);
52327 usb_put_urb(urb);
52328 diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
52329 index 00c4b96..b4498c8 100644
52330 --- a/drivers/usb/core/hub.c
52331 +++ b/drivers/usb/core/hub.c
52332 @@ -27,6 +27,7 @@
52333 #include <linux/freezer.h>
52334 #include <linux/random.h>
52335 #include <linux/pm_qos.h>
52336 +#include <linux/grsecurity.h>
52337
52338 #include <asm/uaccess.h>
52339 #include <asm/byteorder.h>
52340 @@ -4531,6 +4532,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
52341 goto done;
52342 return;
52343 }
52344 +
52345 + if (gr_handle_new_usb())
52346 + goto done;
52347 +
52348 if (hub_is_superspeed(hub->hdev))
52349 unit_load = 150;
52350 else
52351 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
52352 index 0c8a7fc..c45b40a 100644
52353 --- a/drivers/usb/core/message.c
52354 +++ b/drivers/usb/core/message.c
52355 @@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
52356 * Return: If successful, the number of bytes transferred. Otherwise, a negative
52357 * error number.
52358 */
52359 -int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
52360 +int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
52361 __u8 requesttype, __u16 value, __u16 index, void *data,
52362 __u16 size, int timeout)
52363 {
52364 @@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
52365 * If successful, 0. Otherwise a negative error number. The number of actual
52366 * bytes transferred will be stored in the @actual_length parameter.
52367 */
52368 -int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
52369 +int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
52370 void *data, int len, int *actual_length, int timeout)
52371 {
52372 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
52373 @@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
52374 * bytes transferred will be stored in the @actual_length parameter.
52375 *
52376 */
52377 -int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
52378 +int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
52379 void *data, int len, int *actual_length, int timeout)
52380 {
52381 struct urb *urb;
52382 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
52383 index 1236c60..d47a51c 100644
52384 --- a/drivers/usb/core/sysfs.c
52385 +++ b/drivers/usb/core/sysfs.c
52386 @@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
52387 struct usb_device *udev;
52388
52389 udev = to_usb_device(dev);
52390 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
52391 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
52392 }
52393 static DEVICE_ATTR_RO(urbnum);
52394
52395 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
52396 index 4d11449..f4ccabf 100644
52397 --- a/drivers/usb/core/usb.c
52398 +++ b/drivers/usb/core/usb.c
52399 @@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
52400 set_dev_node(&dev->dev, dev_to_node(bus->controller));
52401 dev->state = USB_STATE_ATTACHED;
52402 dev->lpm_disable_count = 1;
52403 - atomic_set(&dev->urbnum, 0);
52404 + atomic_set_unchecked(&dev->urbnum, 0);
52405
52406 INIT_LIST_HEAD(&dev->ep0.urb_list);
52407 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
52408 diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
52409 index 85f398d..d375bbe 100644
52410 --- a/drivers/usb/dwc3/gadget.c
52411 +++ b/drivers/usb/dwc3/gadget.c
52412 @@ -550,8 +550,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
52413 if (!usb_endpoint_xfer_isoc(desc))
52414 return 0;
52415
52416 - memset(&trb_link, 0, sizeof(trb_link));
52417 -
52418 /* Link TRB for ISOC. The HWO bit is never reset */
52419 trb_st_hw = &dep->trb_pool[0];
52420
52421 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
52422 index 8cfc319..4868255 100644
52423 --- a/drivers/usb/early/ehci-dbgp.c
52424 +++ b/drivers/usb/early/ehci-dbgp.c
52425 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
52426
52427 #ifdef CONFIG_KGDB
52428 static struct kgdb_io kgdbdbgp_io_ops;
52429 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
52430 +static struct kgdb_io kgdbdbgp_io_ops_console;
52431 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
52432 #else
52433 #define dbgp_kgdb_mode (0)
52434 #endif
52435 @@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
52436 .write_char = kgdbdbgp_write_char,
52437 };
52438
52439 +static struct kgdb_io kgdbdbgp_io_ops_console = {
52440 + .name = "kgdbdbgp",
52441 + .read_char = kgdbdbgp_read_char,
52442 + .write_char = kgdbdbgp_write_char,
52443 + .is_console = 1
52444 +};
52445 +
52446 static int kgdbdbgp_wait_time;
52447
52448 static int __init kgdbdbgp_parse_config(char *str)
52449 @@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
52450 ptr++;
52451 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
52452 }
52453 - kgdb_register_io_module(&kgdbdbgp_io_ops);
52454 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
52455 + if (early_dbgp_console.index != -1)
52456 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
52457 + else
52458 + kgdb_register_io_module(&kgdbdbgp_io_ops);
52459
52460 return 0;
52461 }
52462 diff --git a/drivers/usb/gadget/f_uac1.c b/drivers/usb/gadget/f_uac1.c
52463 index 2b4c82d..06a8ee6 100644
52464 --- a/drivers/usb/gadget/f_uac1.c
52465 +++ b/drivers/usb/gadget/f_uac1.c
52466 @@ -13,6 +13,7 @@
52467 #include <linux/kernel.h>
52468 #include <linux/device.h>
52469 #include <linux/atomic.h>
52470 +#include <linux/module.h>
52471
52472 #include "u_uac1.h"
52473
52474 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
52475 index ad0aca8..8ff84865 100644
52476 --- a/drivers/usb/gadget/u_serial.c
52477 +++ b/drivers/usb/gadget/u_serial.c
52478 @@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52479 spin_lock_irq(&port->port_lock);
52480
52481 /* already open? Great. */
52482 - if (port->port.count) {
52483 + if (atomic_read(&port->port.count)) {
52484 status = 0;
52485 - port->port.count++;
52486 + atomic_inc(&port->port.count);
52487
52488 /* currently opening/closing? wait ... */
52489 } else if (port->openclose) {
52490 @@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52491 tty->driver_data = port;
52492 port->port.tty = tty;
52493
52494 - port->port.count = 1;
52495 + atomic_set(&port->port.count, 1);
52496 port->openclose = false;
52497
52498 /* if connected, start the I/O stream */
52499 @@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52500
52501 spin_lock_irq(&port->port_lock);
52502
52503 - if (port->port.count != 1) {
52504 - if (port->port.count == 0)
52505 + if (atomic_read(&port->port.count) != 1) {
52506 + if (atomic_read(&port->port.count) == 0)
52507 WARN_ON(1);
52508 else
52509 - --port->port.count;
52510 + atomic_dec(&port->port.count);
52511 goto exit;
52512 }
52513
52514 @@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52515 * and sleep if necessary
52516 */
52517 port->openclose = true;
52518 - port->port.count = 0;
52519 + atomic_set(&port->port.count, 0);
52520
52521 gser = port->port_usb;
52522 if (gser && gser->disconnect)
52523 @@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
52524 int cond;
52525
52526 spin_lock_irq(&port->port_lock);
52527 - cond = (port->port.count == 0) && !port->openclose;
52528 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
52529 spin_unlock_irq(&port->port_lock);
52530 return cond;
52531 }
52532 @@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
52533 /* if it's already open, start I/O ... and notify the serial
52534 * protocol about open/close status (connect/disconnect).
52535 */
52536 - if (port->port.count) {
52537 + if (atomic_read(&port->port.count)) {
52538 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
52539 gs_start_io(port);
52540 if (gser->connect)
52541 @@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
52542
52543 port->port_usb = NULL;
52544 gser->ioport = NULL;
52545 - if (port->port.count > 0 || port->openclose) {
52546 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
52547 wake_up_interruptible(&port->drain_wait);
52548 if (port->port.tty)
52549 tty_hangup(port->port.tty);
52550 @@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
52551
52552 /* finally, free any unused/unusable I/O buffers */
52553 spin_lock_irqsave(&port->port_lock, flags);
52554 - if (port->port.count == 0 && !port->openclose)
52555 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
52556 gs_buf_free(&port->port_write_buf);
52557 gs_free_requests(gser->out, &port->read_pool, NULL);
52558 gs_free_requests(gser->out, &port->read_queue, NULL);
52559 diff --git a/drivers/usb/gadget/u_uac1.c b/drivers/usb/gadget/u_uac1.c
52560 index 7a55fea..cc0ed4f 100644
52561 --- a/drivers/usb/gadget/u_uac1.c
52562 +++ b/drivers/usb/gadget/u_uac1.c
52563 @@ -16,6 +16,7 @@
52564 #include <linux/ctype.h>
52565 #include <linux/random.h>
52566 #include <linux/syscalls.h>
52567 +#include <linux/module.h>
52568
52569 #include "u_uac1.h"
52570
52571 diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
52572 index 7ae0c4d..35521b7 100644
52573 --- a/drivers/usb/host/ehci-hub.c
52574 +++ b/drivers/usb/host/ehci-hub.c
52575 @@ -780,7 +780,7 @@ static struct urb *request_single_step_set_feature_urb(
52576 urb->transfer_flags = URB_DIR_IN;
52577 usb_get_urb(urb);
52578 atomic_inc(&urb->use_count);
52579 - atomic_inc(&urb->dev->urbnum);
52580 + atomic_inc_unchecked(&urb->dev->urbnum);
52581 urb->setup_dma = dma_map_single(
52582 hcd->self.controller,
52583 urb->setup_packet,
52584 @@ -847,7 +847,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
52585 urb->status = -EINPROGRESS;
52586 usb_get_urb(urb);
52587 atomic_inc(&urb->use_count);
52588 - atomic_inc(&urb->dev->urbnum);
52589 + atomic_inc_unchecked(&urb->dev->urbnum);
52590 retval = submit_single_step_set_feature(hcd, urb, 0);
52591 if (!retval && !wait_for_completion_timeout(&done,
52592 msecs_to_jiffies(2000))) {
52593 diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c
52594 index d0d8fad..668ef7b 100644
52595 --- a/drivers/usb/host/hwa-hc.c
52596 +++ b/drivers/usb/host/hwa-hc.c
52597 @@ -337,7 +337,10 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
52598 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
52599 struct wahc *wa = &hwahc->wa;
52600 struct device *dev = &wa->usb_iface->dev;
52601 - u8 mas_le[UWB_NUM_MAS/8];
52602 + u8 *mas_le = kmalloc(UWB_NUM_MAS/8, GFP_KERNEL);
52603 +
52604 + if (mas_le == NULL)
52605 + return -ENOMEM;
52606
52607 /* Set the stream index */
52608 result = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
52609 @@ -356,10 +359,12 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
52610 WUSB_REQ_SET_WUSB_MAS,
52611 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
52612 0, wa->usb_iface->cur_altsetting->desc.bInterfaceNumber,
52613 - mas_le, 32, USB_CTRL_SET_TIMEOUT);
52614 + mas_le, UWB_NUM_MAS/8, USB_CTRL_SET_TIMEOUT);
52615 if (result < 0)
52616 dev_err(dev, "Cannot set WUSB MAS allocation: %d\n", result);
52617 out:
52618 + kfree(mas_le);
52619 +
52620 return result;
52621 }
52622
52623 diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
52624 index ba6a5d6..f88f7f3 100644
52625 --- a/drivers/usb/misc/appledisplay.c
52626 +++ b/drivers/usb/misc/appledisplay.c
52627 @@ -83,7 +83,7 @@ struct appledisplay {
52628 spinlock_t lock;
52629 };
52630
52631 -static atomic_t count_displays = ATOMIC_INIT(0);
52632 +static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
52633 static struct workqueue_struct *wq;
52634
52635 static void appledisplay_complete(struct urb *urb)
52636 @@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
52637
52638 /* Register backlight device */
52639 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
52640 - atomic_inc_return(&count_displays) - 1);
52641 + atomic_inc_return_unchecked(&count_displays) - 1);
52642 memset(&props, 0, sizeof(struct backlight_properties));
52643 props.type = BACKLIGHT_RAW;
52644 props.max_brightness = 0xff;
52645 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
52646 index 8d7fc48..01c4986 100644
52647 --- a/drivers/usb/serial/console.c
52648 +++ b/drivers/usb/serial/console.c
52649 @@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
52650
52651 info->port = port;
52652
52653 - ++port->port.count;
52654 + atomic_inc(&port->port.count);
52655 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
52656 if (serial->type->set_termios) {
52657 /*
52658 @@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
52659 }
52660 /* Now that any required fake tty operations are completed restore
52661 * the tty port count */
52662 - --port->port.count;
52663 + atomic_dec(&port->port.count);
52664 /* The console is special in terms of closing the device so
52665 * indicate this port is now acting as a system console. */
52666 port->port.console = 1;
52667 @@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
52668 free_tty:
52669 kfree(tty);
52670 reset_open_count:
52671 - port->port.count = 0;
52672 + atomic_set(&port->port.count, 0);
52673 usb_autopm_put_interface(serial->interface);
52674 error_get_interface:
52675 usb_serial_put(serial);
52676 @@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
52677 static void usb_console_write(struct console *co,
52678 const char *buf, unsigned count)
52679 {
52680 - static struct usbcons_info *info = &usbcons_info;
52681 + struct usbcons_info *info = &usbcons_info;
52682 struct usb_serial_port *port = info->port;
52683 struct usb_serial *serial;
52684 int retval = -ENODEV;
52685 diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
52686 index 307e339..6aa97cb 100644
52687 --- a/drivers/usb/storage/usb.h
52688 +++ b/drivers/usb/storage/usb.h
52689 @@ -63,7 +63,7 @@ struct us_unusual_dev {
52690 __u8 useProtocol;
52691 __u8 useTransport;
52692 int (*initFunction)(struct us_data *);
52693 -};
52694 +} __do_const;
52695
52696
52697 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
52698 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
52699 index f2a8d29..7bc3fe7 100644
52700 --- a/drivers/usb/wusbcore/wa-hc.h
52701 +++ b/drivers/usb/wusbcore/wa-hc.h
52702 @@ -240,7 +240,7 @@ struct wahc {
52703 spinlock_t xfer_list_lock;
52704 struct work_struct xfer_enqueue_work;
52705 struct work_struct xfer_error_work;
52706 - atomic_t xfer_id_count;
52707 + atomic_unchecked_t xfer_id_count;
52708
52709 kernel_ulong_t quirks;
52710 };
52711 @@ -305,7 +305,7 @@ static inline void wa_init(struct wahc *wa)
52712 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
52713 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
52714 wa->dto_in_use = 0;
52715 - atomic_set(&wa->xfer_id_count, 1);
52716 + atomic_set_unchecked(&wa->xfer_id_count, 1);
52717 /* init the buf in URBs */
52718 for (index = 0; index < WA_MAX_BUF_IN_URBS; ++index)
52719 usb_init_urb(&(wa->buf_in_urbs[index]));
52720 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
52721 index 3e2e4ed..060c9b8 100644
52722 --- a/drivers/usb/wusbcore/wa-xfer.c
52723 +++ b/drivers/usb/wusbcore/wa-xfer.c
52724 @@ -314,7 +314,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
52725 */
52726 static void wa_xfer_id_init(struct wa_xfer *xfer)
52727 {
52728 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
52729 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
52730 }
52731
52732 /* Return the xfer's ID. */
52733 diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
52734 index 512f479..7e041d0 100644
52735 --- a/drivers/vfio/vfio.c
52736 +++ b/drivers/vfio/vfio.c
52737 @@ -487,7 +487,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
52738 return 0;
52739
52740 /* TODO Prevent device auto probing */
52741 - WARN("Device %s added to live group %d!\n", dev_name(dev),
52742 + WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
52743 iommu_group_id(group->iommu_group));
52744
52745 return 0;
52746 diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
52747 index 5174eba..451e6bc 100644
52748 --- a/drivers/vhost/vringh.c
52749 +++ b/drivers/vhost/vringh.c
52750 @@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
52751 /* Userspace access helpers: in this case, addresses are really userspace. */
52752 static inline int getu16_user(u16 *val, const u16 *p)
52753 {
52754 - return get_user(*val, (__force u16 __user *)p);
52755 + return get_user(*val, (u16 __force_user *)p);
52756 }
52757
52758 static inline int putu16_user(u16 *p, u16 val)
52759 {
52760 - return put_user(val, (__force u16 __user *)p);
52761 + return put_user(val, (u16 __force_user *)p);
52762 }
52763
52764 static inline int copydesc_user(void *dst, const void *src, size_t len)
52765 {
52766 - return copy_from_user(dst, (__force void __user *)src, len) ?
52767 + return copy_from_user(dst, (void __force_user *)src, len) ?
52768 -EFAULT : 0;
52769 }
52770
52771 @@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
52772 const struct vring_used_elem *src,
52773 unsigned int num)
52774 {
52775 - return copy_to_user((__force void __user *)dst, src,
52776 + return copy_to_user((void __force_user *)dst, src,
52777 sizeof(*dst) * num) ? -EFAULT : 0;
52778 }
52779
52780 static inline int xfer_from_user(void *src, void *dst, size_t len)
52781 {
52782 - return copy_from_user(dst, (__force void __user *)src, len) ?
52783 + return copy_from_user(dst, (void __force_user *)src, len) ?
52784 -EFAULT : 0;
52785 }
52786
52787 static inline int xfer_to_user(void *dst, void *src, size_t len)
52788 {
52789 - return copy_to_user((__force void __user *)dst, src, len) ?
52790 + return copy_to_user((void __force_user *)dst, src, len) ?
52791 -EFAULT : 0;
52792 }
52793
52794 @@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
52795 vrh->last_used_idx = 0;
52796 vrh->vring.num = num;
52797 /* vring expects kernel addresses, but only used via accessors. */
52798 - vrh->vring.desc = (__force struct vring_desc *)desc;
52799 - vrh->vring.avail = (__force struct vring_avail *)avail;
52800 - vrh->vring.used = (__force struct vring_used *)used;
52801 + vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
52802 + vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
52803 + vrh->vring.used = (__force_kernel struct vring_used *)used;
52804 return 0;
52805 }
52806 EXPORT_SYMBOL(vringh_init_user);
52807 @@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
52808
52809 static inline int putu16_kern(u16 *p, u16 val)
52810 {
52811 - ACCESS_ONCE(*p) = val;
52812 + ACCESS_ONCE_RW(*p) = val;
52813 return 0;
52814 }
52815
52816 diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
52817 index 84a110a..96312c3 100644
52818 --- a/drivers/video/backlight/kb3886_bl.c
52819 +++ b/drivers/video/backlight/kb3886_bl.c
52820 @@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
52821 static unsigned long kb3886bl_flags;
52822 #define KB3886BL_SUSPENDED 0x01
52823
52824 -static struct dmi_system_id kb3886bl_device_table[] __initdata = {
52825 +static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
52826 {
52827 .ident = "Sahara Touch-iT",
52828 .matches = {
52829 diff --git a/drivers/video/fbdev/arcfb.c b/drivers/video/fbdev/arcfb.c
52830 index 1b0b233..6f34c2c 100644
52831 --- a/drivers/video/fbdev/arcfb.c
52832 +++ b/drivers/video/fbdev/arcfb.c
52833 @@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
52834 return -ENOSPC;
52835
52836 err = 0;
52837 - if ((count + p) > fbmemlength) {
52838 + if (count > (fbmemlength - p)) {
52839 count = fbmemlength - p;
52840 err = -ENOSPC;
52841 }
52842 diff --git a/drivers/video/fbdev/aty/aty128fb.c b/drivers/video/fbdev/aty/aty128fb.c
52843 index 52108be..c7c110d 100644
52844 --- a/drivers/video/fbdev/aty/aty128fb.c
52845 +++ b/drivers/video/fbdev/aty/aty128fb.c
52846 @@ -149,7 +149,7 @@ enum {
52847 };
52848
52849 /* Must match above enum */
52850 -static char * const r128_family[] = {
52851 +static const char * const r128_family[] = {
52852 "AGP",
52853 "PCI",
52854 "PRO AGP",
52855 diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c
52856 index c3d0074..0b9077e 100644
52857 --- a/drivers/video/fbdev/aty/atyfb_base.c
52858 +++ b/drivers/video/fbdev/aty/atyfb_base.c
52859 @@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
52860 par->accel_flags = var->accel_flags; /* hack */
52861
52862 if (var->accel_flags) {
52863 - info->fbops->fb_sync = atyfb_sync;
52864 + pax_open_kernel();
52865 + *(void **)&info->fbops->fb_sync = atyfb_sync;
52866 + pax_close_kernel();
52867 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52868 } else {
52869 - info->fbops->fb_sync = NULL;
52870 + pax_open_kernel();
52871 + *(void **)&info->fbops->fb_sync = NULL;
52872 + pax_close_kernel();
52873 info->flags |= FBINFO_HWACCEL_DISABLED;
52874 }
52875
52876 diff --git a/drivers/video/fbdev/aty/mach64_cursor.c b/drivers/video/fbdev/aty/mach64_cursor.c
52877 index 2fa0317..4983f2a 100644
52878 --- a/drivers/video/fbdev/aty/mach64_cursor.c
52879 +++ b/drivers/video/fbdev/aty/mach64_cursor.c
52880 @@ -8,6 +8,7 @@
52881 #include "../core/fb_draw.h"
52882
52883 #include <asm/io.h>
52884 +#include <asm/pgtable.h>
52885
52886 #ifdef __sparc__
52887 #include <asm/fbio.h>
52888 @@ -218,7 +219,9 @@ int aty_init_cursor(struct fb_info *info)
52889 info->sprite.buf_align = 16; /* and 64 lines tall. */
52890 info->sprite.flags = FB_PIXMAP_IO;
52891
52892 - info->fbops->fb_cursor = atyfb_cursor;
52893 + pax_open_kernel();
52894 + *(void **)&info->fbops->fb_cursor = atyfb_cursor;
52895 + pax_close_kernel();
52896
52897 return 0;
52898 }
52899 diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
52900 index 900aa4e..6d49418 100644
52901 --- a/drivers/video/fbdev/core/fb_defio.c
52902 +++ b/drivers/video/fbdev/core/fb_defio.c
52903 @@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
52904
52905 BUG_ON(!fbdefio);
52906 mutex_init(&fbdefio->lock);
52907 - info->fbops->fb_mmap = fb_deferred_io_mmap;
52908 + pax_open_kernel();
52909 + *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
52910 + pax_close_kernel();
52911 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
52912 INIT_LIST_HEAD(&fbdefio->pagelist);
52913 if (fbdefio->delay == 0) /* set a default of 1 s */
52914 @@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
52915 page->mapping = NULL;
52916 }
52917
52918 - info->fbops->fb_mmap = NULL;
52919 + *(void **)&info->fbops->fb_mmap = NULL;
52920 mutex_destroy(&fbdefio->lock);
52921 }
52922 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
52923 diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
52924 index b6d5008..5bca7bf 100644
52925 --- a/drivers/video/fbdev/core/fbmem.c
52926 +++ b/drivers/video/fbdev/core/fbmem.c
52927 @@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52928 image->dx += image->width + 8;
52929 }
52930 } else if (rotate == FB_ROTATE_UD) {
52931 - for (x = 0; x < num && image->dx >= 0; x++) {
52932 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
52933 info->fbops->fb_imageblit(info, image);
52934 image->dx -= image->width + 8;
52935 }
52936 @@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52937 image->dy += image->height + 8;
52938 }
52939 } else if (rotate == FB_ROTATE_CCW) {
52940 - for (x = 0; x < num && image->dy >= 0; x++) {
52941 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
52942 info->fbops->fb_imageblit(info, image);
52943 image->dy -= image->height + 8;
52944 }
52945 @@ -1179,7 +1179,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
52946 return -EFAULT;
52947 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
52948 return -EINVAL;
52949 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
52950 + if (con2fb.framebuffer >= FB_MAX)
52951 return -EINVAL;
52952 if (!registered_fb[con2fb.framebuffer])
52953 request_module("fb%d", con2fb.framebuffer);
52954 @@ -1300,7 +1300,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
52955 __u32 data;
52956 int err;
52957
52958 - err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
52959 + err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
52960
52961 data = (__u32) (unsigned long) fix->smem_start;
52962 err |= put_user(data, &fix32->smem_start);
52963 diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
52964 index e23392e..8a77540 100644
52965 --- a/drivers/video/fbdev/hyperv_fb.c
52966 +++ b/drivers/video/fbdev/hyperv_fb.c
52967 @@ -235,7 +235,7 @@ static uint screen_fb_size;
52968 static inline int synthvid_send(struct hv_device *hdev,
52969 struct synthvid_msg *msg)
52970 {
52971 - static atomic64_t request_id = ATOMIC64_INIT(0);
52972 + static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
52973 int ret;
52974
52975 msg->pipe_hdr.type = PIPE_MSG_DATA;
52976 @@ -243,7 +243,7 @@ static inline int synthvid_send(struct hv_device *hdev,
52977
52978 ret = vmbus_sendpacket(hdev->channel, msg,
52979 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
52980 - atomic64_inc_return(&request_id),
52981 + atomic64_inc_return_unchecked(&request_id),
52982 VM_PKT_DATA_INBAND, 0);
52983
52984 if (ret)
52985 diff --git a/drivers/video/fbdev/i810/i810_accel.c b/drivers/video/fbdev/i810/i810_accel.c
52986 index 7672d2e..b56437f 100644
52987 --- a/drivers/video/fbdev/i810/i810_accel.c
52988 +++ b/drivers/video/fbdev/i810/i810_accel.c
52989 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
52990 }
52991 }
52992 printk("ringbuffer lockup!!!\n");
52993 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
52994 i810_report_error(mmio);
52995 par->dev_flags |= LOCKUP;
52996 info->pixmap.scan_align = 1;
52997 diff --git a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
52998 index a01147f..5d896f8 100644
52999 --- a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
53000 +++ b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
53001 @@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
53002
53003 #ifdef CONFIG_FB_MATROX_MYSTIQUE
53004 struct matrox_switch matrox_mystique = {
53005 - MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
53006 + .preinit = MGA1064_preinit,
53007 + .reset = MGA1064_reset,
53008 + .init = MGA1064_init,
53009 + .restore = MGA1064_restore,
53010 };
53011 EXPORT_SYMBOL(matrox_mystique);
53012 #endif
53013
53014 #ifdef CONFIG_FB_MATROX_G
53015 struct matrox_switch matrox_G100 = {
53016 - MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
53017 + .preinit = MGAG100_preinit,
53018 + .reset = MGAG100_reset,
53019 + .init = MGAG100_init,
53020 + .restore = MGAG100_restore,
53021 };
53022 EXPORT_SYMBOL(matrox_G100);
53023 #endif
53024 diff --git a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
53025 index 195ad7c..09743fc 100644
53026 --- a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
53027 +++ b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
53028 @@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
53029 }
53030
53031 struct matrox_switch matrox_millennium = {
53032 - Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
53033 + .preinit = Ti3026_preinit,
53034 + .reset = Ti3026_reset,
53035 + .init = Ti3026_init,
53036 + .restore = Ti3026_restore
53037 };
53038 EXPORT_SYMBOL(matrox_millennium);
53039 #endif
53040 diff --git a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
53041 index fe92eed..106e085 100644
53042 --- a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
53043 +++ b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
53044 @@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
53045 struct mb862xxfb_par *par = info->par;
53046
53047 if (info->var.bits_per_pixel == 32) {
53048 - info->fbops->fb_fillrect = cfb_fillrect;
53049 - info->fbops->fb_copyarea = cfb_copyarea;
53050 - info->fbops->fb_imageblit = cfb_imageblit;
53051 + pax_open_kernel();
53052 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
53053 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
53054 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
53055 + pax_close_kernel();
53056 } else {
53057 outreg(disp, GC_L0EM, 3);
53058 - info->fbops->fb_fillrect = mb86290fb_fillrect;
53059 - info->fbops->fb_copyarea = mb86290fb_copyarea;
53060 - info->fbops->fb_imageblit = mb86290fb_imageblit;
53061 + pax_open_kernel();
53062 + *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
53063 + *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
53064 + *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
53065 + pax_close_kernel();
53066 }
53067 outreg(draw, GDC_REG_DRAW_BASE, 0);
53068 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
53069 diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
53070 index def0412..fed6529 100644
53071 --- a/drivers/video/fbdev/nvidia/nvidia.c
53072 +++ b/drivers/video/fbdev/nvidia/nvidia.c
53073 @@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
53074 info->fix.line_length = (info->var.xres_virtual *
53075 info->var.bits_per_pixel) >> 3;
53076 if (info->var.accel_flags) {
53077 - info->fbops->fb_imageblit = nvidiafb_imageblit;
53078 - info->fbops->fb_fillrect = nvidiafb_fillrect;
53079 - info->fbops->fb_copyarea = nvidiafb_copyarea;
53080 - info->fbops->fb_sync = nvidiafb_sync;
53081 + pax_open_kernel();
53082 + *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
53083 + *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
53084 + *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
53085 + *(void **)&info->fbops->fb_sync = nvidiafb_sync;
53086 + pax_close_kernel();
53087 info->pixmap.scan_align = 4;
53088 info->flags &= ~FBINFO_HWACCEL_DISABLED;
53089 info->flags |= FBINFO_READS_FAST;
53090 NVResetGraphics(info);
53091 } else {
53092 - info->fbops->fb_imageblit = cfb_imageblit;
53093 - info->fbops->fb_fillrect = cfb_fillrect;
53094 - info->fbops->fb_copyarea = cfb_copyarea;
53095 - info->fbops->fb_sync = NULL;
53096 + pax_open_kernel();
53097 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
53098 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
53099 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
53100 + *(void **)&info->fbops->fb_sync = NULL;
53101 + pax_close_kernel();
53102 info->pixmap.scan_align = 1;
53103 info->flags |= FBINFO_HWACCEL_DISABLED;
53104 info->flags &= ~FBINFO_READS_FAST;
53105 @@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
53106 info->pixmap.size = 8 * 1024;
53107 info->pixmap.flags = FB_PIXMAP_SYSTEM;
53108
53109 - if (!hwcur)
53110 - info->fbops->fb_cursor = NULL;
53111 + if (!hwcur) {
53112 + pax_open_kernel();
53113 + *(void **)&info->fbops->fb_cursor = NULL;
53114 + pax_close_kernel();
53115 + }
53116
53117 info->var.accel_flags = (!noaccel);
53118
53119 diff --git a/drivers/video/fbdev/omap2/dss/display.c b/drivers/video/fbdev/omap2/dss/display.c
53120 index 2412a0d..294215b 100644
53121 --- a/drivers/video/fbdev/omap2/dss/display.c
53122 +++ b/drivers/video/fbdev/omap2/dss/display.c
53123 @@ -161,12 +161,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
53124 if (dssdev->name == NULL)
53125 dssdev->name = dssdev->alias;
53126
53127 + pax_open_kernel();
53128 if (drv && drv->get_resolution == NULL)
53129 - drv->get_resolution = omapdss_default_get_resolution;
53130 + *(void **)&drv->get_resolution = omapdss_default_get_resolution;
53131 if (drv && drv->get_recommended_bpp == NULL)
53132 - drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
53133 + *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
53134 if (drv && drv->get_timings == NULL)
53135 - drv->get_timings = omapdss_default_get_timings;
53136 + *(void **)&drv->get_timings = omapdss_default_get_timings;
53137 + pax_close_kernel();
53138
53139 mutex_lock(&panel_list_mutex);
53140 list_add_tail(&dssdev->panel_list, &panel_list);
53141 diff --git a/drivers/video/fbdev/s1d13xxxfb.c b/drivers/video/fbdev/s1d13xxxfb.c
53142 index 83433cb..71e9b98 100644
53143 --- a/drivers/video/fbdev/s1d13xxxfb.c
53144 +++ b/drivers/video/fbdev/s1d13xxxfb.c
53145 @@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
53146
53147 switch(prod_id) {
53148 case S1D13506_PROD_ID: /* activate acceleration */
53149 - s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
53150 - s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
53151 + pax_open_kernel();
53152 + *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
53153 + *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
53154 + pax_close_kernel();
53155 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
53156 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
53157 break;
53158 diff --git a/drivers/video/fbdev/sh_mobile_lcdcfb.c b/drivers/video/fbdev/sh_mobile_lcdcfb.c
53159 index 2bcc84a..29dd1ea 100644
53160 --- a/drivers/video/fbdev/sh_mobile_lcdcfb.c
53161 +++ b/drivers/video/fbdev/sh_mobile_lcdcfb.c
53162 @@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
53163 }
53164
53165 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
53166 - lcdc_sys_write_index,
53167 - lcdc_sys_write_data,
53168 - lcdc_sys_read_data,
53169 + .write_index = lcdc_sys_write_index,
53170 + .write_data = lcdc_sys_write_data,
53171 + .read_data = lcdc_sys_read_data,
53172 };
53173
53174 static int sh_mobile_lcdc_sginit(struct fb_info *info,
53175 diff --git a/drivers/video/fbdev/smscufx.c b/drivers/video/fbdev/smscufx.c
53176 index d513ed6..90b0de9 100644
53177 --- a/drivers/video/fbdev/smscufx.c
53178 +++ b/drivers/video/fbdev/smscufx.c
53179 @@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
53180 fb_deferred_io_cleanup(info);
53181 kfree(info->fbdefio);
53182 info->fbdefio = NULL;
53183 - info->fbops->fb_mmap = ufx_ops_mmap;
53184 + pax_open_kernel();
53185 + *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
53186 + pax_close_kernel();
53187 }
53188
53189 pr_debug("released /dev/fb%d user=%d count=%d",
53190 diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c
53191 index 77b890e..458e666 100644
53192 --- a/drivers/video/fbdev/udlfb.c
53193 +++ b/drivers/video/fbdev/udlfb.c
53194 @@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
53195 dlfb_urb_completion(urb);
53196
53197 error:
53198 - atomic_add(bytes_sent, &dev->bytes_sent);
53199 - atomic_add(bytes_identical, &dev->bytes_identical);
53200 - atomic_add(width*height*2, &dev->bytes_rendered);
53201 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
53202 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
53203 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
53204 end_cycles = get_cycles();
53205 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
53206 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
53207 >> 10)), /* Kcycles */
53208 &dev->cpu_kcycles_used);
53209
53210 @@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
53211 dlfb_urb_completion(urb);
53212
53213 error:
53214 - atomic_add(bytes_sent, &dev->bytes_sent);
53215 - atomic_add(bytes_identical, &dev->bytes_identical);
53216 - atomic_add(bytes_rendered, &dev->bytes_rendered);
53217 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
53218 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
53219 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
53220 end_cycles = get_cycles();
53221 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
53222 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
53223 >> 10)), /* Kcycles */
53224 &dev->cpu_kcycles_used);
53225 }
53226 @@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
53227 fb_deferred_io_cleanup(info);
53228 kfree(info->fbdefio);
53229 info->fbdefio = NULL;
53230 - info->fbops->fb_mmap = dlfb_ops_mmap;
53231 + pax_open_kernel();
53232 + *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
53233 + pax_close_kernel();
53234 }
53235
53236 pr_warn("released /dev/fb%d user=%d count=%d\n",
53237 @@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
53238 struct fb_info *fb_info = dev_get_drvdata(fbdev);
53239 struct dlfb_data *dev = fb_info->par;
53240 return snprintf(buf, PAGE_SIZE, "%u\n",
53241 - atomic_read(&dev->bytes_rendered));
53242 + atomic_read_unchecked(&dev->bytes_rendered));
53243 }
53244
53245 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
53246 @@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
53247 struct fb_info *fb_info = dev_get_drvdata(fbdev);
53248 struct dlfb_data *dev = fb_info->par;
53249 return snprintf(buf, PAGE_SIZE, "%u\n",
53250 - atomic_read(&dev->bytes_identical));
53251 + atomic_read_unchecked(&dev->bytes_identical));
53252 }
53253
53254 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
53255 @@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
53256 struct fb_info *fb_info = dev_get_drvdata(fbdev);
53257 struct dlfb_data *dev = fb_info->par;
53258 return snprintf(buf, PAGE_SIZE, "%u\n",
53259 - atomic_read(&dev->bytes_sent));
53260 + atomic_read_unchecked(&dev->bytes_sent));
53261 }
53262
53263 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
53264 @@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
53265 struct fb_info *fb_info = dev_get_drvdata(fbdev);
53266 struct dlfb_data *dev = fb_info->par;
53267 return snprintf(buf, PAGE_SIZE, "%u\n",
53268 - atomic_read(&dev->cpu_kcycles_used));
53269 + atomic_read_unchecked(&dev->cpu_kcycles_used));
53270 }
53271
53272 static ssize_t edid_show(
53273 @@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
53274 struct fb_info *fb_info = dev_get_drvdata(fbdev);
53275 struct dlfb_data *dev = fb_info->par;
53276
53277 - atomic_set(&dev->bytes_rendered, 0);
53278 - atomic_set(&dev->bytes_identical, 0);
53279 - atomic_set(&dev->bytes_sent, 0);
53280 - atomic_set(&dev->cpu_kcycles_used, 0);
53281 + atomic_set_unchecked(&dev->bytes_rendered, 0);
53282 + atomic_set_unchecked(&dev->bytes_identical, 0);
53283 + atomic_set_unchecked(&dev->bytes_sent, 0);
53284 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
53285
53286 return count;
53287 }
53288 diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c
53289 index 509d452..7c9d2de 100644
53290 --- a/drivers/video/fbdev/uvesafb.c
53291 +++ b/drivers/video/fbdev/uvesafb.c
53292 @@ -19,6 +19,7 @@
53293 #include <linux/io.h>
53294 #include <linux/mutex.h>
53295 #include <linux/slab.h>
53296 +#include <linux/moduleloader.h>
53297 #include <video/edid.h>
53298 #include <video/uvesafb.h>
53299 #ifdef CONFIG_X86
53300 @@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
53301 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
53302 par->pmi_setpal = par->ypan = 0;
53303 } else {
53304 +
53305 +#ifdef CONFIG_PAX_KERNEXEC
53306 +#ifdef CONFIG_MODULES
53307 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
53308 +#endif
53309 + if (!par->pmi_code) {
53310 + par->pmi_setpal = par->ypan = 0;
53311 + return 0;
53312 + }
53313 +#endif
53314 +
53315 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
53316 + task->t.regs.edi);
53317 +
53318 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53319 + pax_open_kernel();
53320 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
53321 + pax_close_kernel();
53322 +
53323 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
53324 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
53325 +#else
53326 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
53327 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
53328 +#endif
53329 +
53330 printk(KERN_INFO "uvesafb: protected mode interface info at "
53331 "%04x:%04x\n",
53332 (u16)task->t.regs.es, (u16)task->t.regs.edi);
53333 @@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
53334 par->ypan = ypan;
53335
53336 if (par->pmi_setpal || par->ypan) {
53337 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
53338 if (__supported_pte_mask & _PAGE_NX) {
53339 par->pmi_setpal = par->ypan = 0;
53340 printk(KERN_WARNING "uvesafb: NX protection is active, "
53341 "better not use the PMI.\n");
53342 - } else {
53343 + } else
53344 +#endif
53345 uvesafb_vbe_getpmi(task, par);
53346 - }
53347 }
53348 #else
53349 /* The protected mode interface is not available on non-x86. */
53350 @@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
53351 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
53352
53353 /* Disable blanking if the user requested so. */
53354 - if (!blank)
53355 - info->fbops->fb_blank = NULL;
53356 + if (!blank) {
53357 + pax_open_kernel();
53358 + *(void **)&info->fbops->fb_blank = NULL;
53359 + pax_close_kernel();
53360 + }
53361
53362 /*
53363 * Find out how much IO memory is required for the mode with
53364 @@ -1525,8 +1552,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
53365 info->flags = FBINFO_FLAG_DEFAULT |
53366 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
53367
53368 - if (!par->ypan)
53369 - info->fbops->fb_pan_display = NULL;
53370 + if (!par->ypan) {
53371 + pax_open_kernel();
53372 + *(void **)&info->fbops->fb_pan_display = NULL;
53373 + pax_close_kernel();
53374 + }
53375 }
53376
53377 static void uvesafb_init_mtrr(struct fb_info *info)
53378 @@ -1787,6 +1817,11 @@ out_mode:
53379 out:
53380 kfree(par->vbe_modes);
53381
53382 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53383 + if (par->pmi_code)
53384 + module_free_exec(NULL, par->pmi_code);
53385 +#endif
53386 +
53387 framebuffer_release(info);
53388 return err;
53389 }
53390 @@ -1811,6 +1846,11 @@ static int uvesafb_remove(struct platform_device *dev)
53391 kfree(par->vbe_state_orig);
53392 kfree(par->vbe_state_saved);
53393
53394 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53395 + if (par->pmi_code)
53396 + module_free_exec(NULL, par->pmi_code);
53397 +#endif
53398 +
53399 framebuffer_release(info);
53400 }
53401 return 0;
53402 diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
53403 index 6170e7f..dd63031 100644
53404 --- a/drivers/video/fbdev/vesafb.c
53405 +++ b/drivers/video/fbdev/vesafb.c
53406 @@ -9,6 +9,7 @@
53407 */
53408
53409 #include <linux/module.h>
53410 +#include <linux/moduleloader.h>
53411 #include <linux/kernel.h>
53412 #include <linux/errno.h>
53413 #include <linux/string.h>
53414 @@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
53415 static int vram_total; /* Set total amount of memory */
53416 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
53417 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
53418 -static void (*pmi_start)(void) __read_mostly;
53419 -static void (*pmi_pal) (void) __read_mostly;
53420 +static void (*pmi_start)(void) __read_only;
53421 +static void (*pmi_pal) (void) __read_only;
53422 static int depth __read_mostly;
53423 static int vga_compat __read_mostly;
53424 /* --------------------------------------------------------------------- */
53425 @@ -233,6 +234,7 @@ static int vesafb_probe(struct platform_device *dev)
53426 unsigned int size_remap;
53427 unsigned int size_total;
53428 char *option = NULL;
53429 + void *pmi_code = NULL;
53430
53431 /* ignore error return of fb_get_options */
53432 fb_get_options("vesafb", &option);
53433 @@ -279,10 +281,6 @@ static int vesafb_probe(struct platform_device *dev)
53434 size_remap = size_total;
53435 vesafb_fix.smem_len = size_remap;
53436
53437 -#ifndef __i386__
53438 - screen_info.vesapm_seg = 0;
53439 -#endif
53440 -
53441 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
53442 printk(KERN_WARNING
53443 "vesafb: cannot reserve video memory at 0x%lx\n",
53444 @@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
53445 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
53446 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
53447
53448 +#ifdef __i386__
53449 +
53450 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53451 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
53452 + if (!pmi_code)
53453 +#elif !defined(CONFIG_PAX_KERNEXEC)
53454 + if (0)
53455 +#endif
53456 +
53457 +#endif
53458 + screen_info.vesapm_seg = 0;
53459 +
53460 if (screen_info.vesapm_seg) {
53461 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
53462 - screen_info.vesapm_seg,screen_info.vesapm_off);
53463 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
53464 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
53465 }
53466
53467 if (screen_info.vesapm_seg < 0xc000)
53468 @@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
53469
53470 if (ypan || pmi_setpal) {
53471 unsigned short *pmi_base;
53472 +
53473 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
53474 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
53475 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
53476 +
53477 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53478 + pax_open_kernel();
53479 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
53480 +#else
53481 + pmi_code = pmi_base;
53482 +#endif
53483 +
53484 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
53485 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
53486 +
53487 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53488 + pmi_start = ktva_ktla(pmi_start);
53489 + pmi_pal = ktva_ktla(pmi_pal);
53490 + pax_close_kernel();
53491 +#endif
53492 +
53493 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
53494 if (pmi_base[3]) {
53495 printk(KERN_INFO "vesafb: pmi: ports = ");
53496 @@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
53497 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
53498 (ypan ? FBINFO_HWACCEL_YPAN : 0);
53499
53500 - if (!ypan)
53501 - info->fbops->fb_pan_display = NULL;
53502 + if (!ypan) {
53503 + pax_open_kernel();
53504 + *(void **)&info->fbops->fb_pan_display = NULL;
53505 + pax_close_kernel();
53506 + }
53507
53508 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
53509 err = -ENOMEM;
53510 @@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
53511 fb_info(info, "%s frame buffer device\n", info->fix.id);
53512 return 0;
53513 err:
53514 +
53515 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53516 + module_free_exec(NULL, pmi_code);
53517 +#endif
53518 +
53519 if (info->screen_base)
53520 iounmap(info->screen_base);
53521 framebuffer_release(info);
53522 diff --git a/drivers/video/fbdev/via/via_clock.h b/drivers/video/fbdev/via/via_clock.h
53523 index 88714ae..16c2e11 100644
53524 --- a/drivers/video/fbdev/via/via_clock.h
53525 +++ b/drivers/video/fbdev/via/via_clock.h
53526 @@ -56,7 +56,7 @@ struct via_clock {
53527
53528 void (*set_engine_pll_state)(u8 state);
53529 void (*set_engine_pll)(struct via_pll_config config);
53530 -};
53531 +} __no_const;
53532
53533
53534 static inline u32 get_pll_internal_frequency(u32 ref_freq,
53535 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
53536 index 3c14e43..2630570 100644
53537 --- a/drivers/video/logo/logo_linux_clut224.ppm
53538 +++ b/drivers/video/logo/logo_linux_clut224.ppm
53539 @@ -2,1603 +2,1123 @@ P3
53540 # Standard 224-color Linux logo
53541 80 80
53542 255
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 0 0 0 0 0 0 0 0 0 0
53549 - 0 0 0 0 0 0 0 0 0 0 0 0
53550 - 0 0 0 0 0 0 0 0 0 0 0 0
53551 - 0 0 0 0 0 0 0 0 0 0 0 0
53552 - 6 6 6 6 6 6 10 10 10 10 10 10
53553 - 10 10 10 6 6 6 6 6 6 6 6 6
53554 - 0 0 0 0 0 0 0 0 0 0 0 0
53555 - 0 0 0 0 0 0 0 0 0 0 0 0
53556 - 0 0 0 0 0 0 0 0 0 0 0 0
53557 - 0 0 0 0 0 0 0 0 0 0 0 0
53558 - 0 0 0 0 0 0 0 0 0 0 0 0
53559 - 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0 0
53569 - 0 0 0 0 0 0 0 0 0 0 0 0
53570 - 0 0 0 0 0 0 0 0 0 0 0 0
53571 - 0 0 0 6 6 6 10 10 10 14 14 14
53572 - 22 22 22 26 26 26 30 30 30 34 34 34
53573 - 30 30 30 30 30 30 26 26 26 18 18 18
53574 - 14 14 14 10 10 10 6 6 6 0 0 0
53575 - 0 0 0 0 0 0 0 0 0 0 0 0
53576 - 0 0 0 0 0 0 0 0 0 0 0 0
53577 - 0 0 0 0 0 0 0 0 0 0 0 0
53578 - 0 0 0 0 0 0 0 0 0 0 0 0
53579 - 0 0 0 0 0 0 0 0 0 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 1 0 0 1 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 - 6 6 6 14 14 14 26 26 26 42 42 42
53592 - 54 54 54 66 66 66 78 78 78 78 78 78
53593 - 78 78 78 74 74 74 66 66 66 54 54 54
53594 - 42 42 42 26 26 26 18 18 18 10 10 10
53595 - 6 6 6 0 0 0 0 0 0 0 0 0
53596 - 0 0 0 0 0 0 0 0 0 0 0 0
53597 - 0 0 0 0 0 0 0 0 0 0 0 0
53598 - 0 0 0 0 0 0 0 0 0 0 0 0
53599 - 0 0 0 0 0 0 0 0 0 0 0 0
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 1 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 0 0 0 0 0 0 0 0 0 0
53609 - 0 0 0 0 0 0 0 0 0 0 0 0
53610 - 0 0 0 0 0 0 0 0 0 10 10 10
53611 - 22 22 22 42 42 42 66 66 66 86 86 86
53612 - 66 66 66 38 38 38 38 38 38 22 22 22
53613 - 26 26 26 34 34 34 54 54 54 66 66 66
53614 - 86 86 86 70 70 70 46 46 46 26 26 26
53615 - 14 14 14 6 6 6 0 0 0 0 0 0
53616 - 0 0 0 0 0 0 0 0 0 0 0 0
53617 - 0 0 0 0 0 0 0 0 0 0 0 0
53618 - 0 0 0 0 0 0 0 0 0 0 0 0
53619 - 0 0 0 0 0 0 0 0 0 0 0 0
53620 - 0 0 0 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 1 0 0 1 0 0 1 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 0 0 0 0 0 0 0 0 0 0
53629 - 0 0 0 0 0 0 0 0 0 0 0 0
53630 - 0 0 0 0 0 0 10 10 10 26 26 26
53631 - 50 50 50 82 82 82 58 58 58 6 6 6
53632 - 2 2 6 2 2 6 2 2 6 2 2 6
53633 - 2 2 6 2 2 6 2 2 6 2 2 6
53634 - 6 6 6 54 54 54 86 86 86 66 66 66
53635 - 38 38 38 18 18 18 6 6 6 0 0 0
53636 - 0 0 0 0 0 0 0 0 0 0 0 0
53637 - 0 0 0 0 0 0 0 0 0 0 0 0
53638 - 0 0 0 0 0 0 0 0 0 0 0 0
53639 - 0 0 0 0 0 0 0 0 0 0 0 0
53640 - 0 0 0 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 0 0 0 0 0 0 0 0 0 0
53649 - 0 0 0 0 0 0 0 0 0 0 0 0
53650 - 0 0 0 6 6 6 22 22 22 50 50 50
53651 - 78 78 78 34 34 34 2 2 6 2 2 6
53652 - 2 2 6 2 2 6 2 2 6 2 2 6
53653 - 2 2 6 2 2 6 2 2 6 2 2 6
53654 - 2 2 6 2 2 6 6 6 6 70 70 70
53655 - 78 78 78 46 46 46 22 22 22 6 6 6
53656 - 0 0 0 0 0 0 0 0 0 0 0 0
53657 - 0 0 0 0 0 0 0 0 0 0 0 0
53658 - 0 0 0 0 0 0 0 0 0 0 0 0
53659 - 0 0 0 0 0 0 0 0 0 0 0 0
53660 - 0 0 0 0 0 0 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 1 0 0 1 0 0 1 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 - 6 6 6 18 18 18 42 42 42 82 82 82
53671 - 26 26 26 2 2 6 2 2 6 2 2 6
53672 - 2 2 6 2 2 6 2 2 6 2 2 6
53673 - 2 2 6 2 2 6 2 2 6 14 14 14
53674 - 46 46 46 34 34 34 6 6 6 2 2 6
53675 - 42 42 42 78 78 78 42 42 42 18 18 18
53676 - 6 6 6 0 0 0 0 0 0 0 0 0
53677 - 0 0 0 0 0 0 0 0 0 0 0 0
53678 - 0 0 0 0 0 0 0 0 0 0 0 0
53679 - 0 0 0 0 0 0 0 0 0 0 0 0
53680 - 0 0 0 0 0 0 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 1 0 0 0 0 0 1 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 0 0 0 0 0 0 0
53689 - 0 0 0 0 0 0 0 0 0 0 0 0
53690 - 10 10 10 30 30 30 66 66 66 58 58 58
53691 - 2 2 6 2 2 6 2 2 6 2 2 6
53692 - 2 2 6 2 2 6 2 2 6 2 2 6
53693 - 2 2 6 2 2 6 2 2 6 26 26 26
53694 - 86 86 86 101 101 101 46 46 46 10 10 10
53695 - 2 2 6 58 58 58 70 70 70 34 34 34
53696 - 10 10 10 0 0 0 0 0 0 0 0 0
53697 - 0 0 0 0 0 0 0 0 0 0 0 0
53698 - 0 0 0 0 0 0 0 0 0 0 0 0
53699 - 0 0 0 0 0 0 0 0 0 0 0 0
53700 - 0 0 0 0 0 0 0 0 0 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 1 0 0 1 0 0 1 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 0 0 0 0 0 0 0 0 0 0
53709 - 0 0 0 0 0 0 0 0 0 0 0 0
53710 - 14 14 14 42 42 42 86 86 86 10 10 10
53711 - 2 2 6 2 2 6 2 2 6 2 2 6
53712 - 2 2 6 2 2 6 2 2 6 2 2 6
53713 - 2 2 6 2 2 6 2 2 6 30 30 30
53714 - 94 94 94 94 94 94 58 58 58 26 26 26
53715 - 2 2 6 6 6 6 78 78 78 54 54 54
53716 - 22 22 22 6 6 6 0 0 0 0 0 0
53717 - 0 0 0 0 0 0 0 0 0 0 0 0
53718 - 0 0 0 0 0 0 0 0 0 0 0 0
53719 - 0 0 0 0 0 0 0 0 0 0 0 0
53720 - 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0
53729 - 0 0 0 0 0 0 0 0 0 6 6 6
53730 - 22 22 22 62 62 62 62 62 62 2 2 6
53731 - 2 2 6 2 2 6 2 2 6 2 2 6
53732 - 2 2 6 2 2 6 2 2 6 2 2 6
53733 - 2 2 6 2 2 6 2 2 6 26 26 26
53734 - 54 54 54 38 38 38 18 18 18 10 10 10
53735 - 2 2 6 2 2 6 34 34 34 82 82 82
53736 - 38 38 38 14 14 14 0 0 0 0 0 0
53737 - 0 0 0 0 0 0 0 0 0 0 0 0
53738 - 0 0 0 0 0 0 0 0 0 0 0 0
53739 - 0 0 0 0 0 0 0 0 0 0 0 0
53740 - 0 0 0 0 0 0 0 0 0 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 1 0 0 1 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 0 0 0 0 0 0 0 0 0 0
53749 - 0 0 0 0 0 0 0 0 0 6 6 6
53750 - 30 30 30 78 78 78 30 30 30 2 2 6
53751 - 2 2 6 2 2 6 2 2 6 2 2 6
53752 - 2 2 6 2 2 6 2 2 6 2 2 6
53753 - 2 2 6 2 2 6 2 2 6 10 10 10
53754 - 10 10 10 2 2 6 2 2 6 2 2 6
53755 - 2 2 6 2 2 6 2 2 6 78 78 78
53756 - 50 50 50 18 18 18 6 6 6 0 0 0
53757 - 0 0 0 0 0 0 0 0 0 0 0 0
53758 - 0 0 0 0 0 0 0 0 0 0 0 0
53759 - 0 0 0 0 0 0 0 0 0 0 0 0
53760 - 0 0 0 0 0 0 0 0 0 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 1 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 0 0 0 0 0 0 0 0 0 0
53769 - 0 0 0 0 0 0 0 0 0 10 10 10
53770 - 38 38 38 86 86 86 14 14 14 2 2 6
53771 - 2 2 6 2 2 6 2 2 6 2 2 6
53772 - 2 2 6 2 2 6 2 2 6 2 2 6
53773 - 2 2 6 2 2 6 2 2 6 2 2 6
53774 - 2 2 6 2 2 6 2 2 6 2 2 6
53775 - 2 2 6 2 2 6 2 2 6 54 54 54
53776 - 66 66 66 26 26 26 6 6 6 0 0 0
53777 - 0 0 0 0 0 0 0 0 0 0 0 0
53778 - 0 0 0 0 0 0 0 0 0 0 0 0
53779 - 0 0 0 0 0 0 0 0 0 0 0 0
53780 - 0 0 0 0 0 0 0 0 0 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 1 0 0 1 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 14 14 14
53790 - 42 42 42 82 82 82 2 2 6 2 2 6
53791 - 2 2 6 6 6 6 10 10 10 2 2 6
53792 - 2 2 6 2 2 6 2 2 6 2 2 6
53793 - 2 2 6 2 2 6 2 2 6 6 6 6
53794 - 14 14 14 10 10 10 2 2 6 2 2 6
53795 - 2 2 6 2 2 6 2 2 6 18 18 18
53796 - 82 82 82 34 34 34 10 10 10 0 0 0
53797 - 0 0 0 0 0 0 0 0 0 0 0 0
53798 - 0 0 0 0 0 0 0 0 0 0 0 0
53799 - 0 0 0 0 0 0 0 0 0 0 0 0
53800 - 0 0 0 0 0 0 0 0 0 0 0 0
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 1 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 0 0 0 0
53808 - 0 0 0 0 0 0 0 0 0 0 0 0
53809 - 0 0 0 0 0 0 0 0 0 14 14 14
53810 - 46 46 46 86 86 86 2 2 6 2 2 6
53811 - 6 6 6 6 6 6 22 22 22 34 34 34
53812 - 6 6 6 2 2 6 2 2 6 2 2 6
53813 - 2 2 6 2 2 6 18 18 18 34 34 34
53814 - 10 10 10 50 50 50 22 22 22 2 2 6
53815 - 2 2 6 2 2 6 2 2 6 10 10 10
53816 - 86 86 86 42 42 42 14 14 14 0 0 0
53817 - 0 0 0 0 0 0 0 0 0 0 0 0
53818 - 0 0 0 0 0 0 0 0 0 0 0 0
53819 - 0 0 0 0 0 0 0 0 0 0 0 0
53820 - 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 1 0 0 1 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 14 14 14
53830 - 46 46 46 86 86 86 2 2 6 2 2 6
53831 - 38 38 38 116 116 116 94 94 94 22 22 22
53832 - 22 22 22 2 2 6 2 2 6 2 2 6
53833 - 14 14 14 86 86 86 138 138 138 162 162 162
53834 -154 154 154 38 38 38 26 26 26 6 6 6
53835 - 2 2 6 2 2 6 2 2 6 2 2 6
53836 - 86 86 86 46 46 46 14 14 14 0 0 0
53837 - 0 0 0 0 0 0 0 0 0 0 0 0
53838 - 0 0 0 0 0 0 0 0 0 0 0 0
53839 - 0 0 0 0 0 0 0 0 0 0 0 0
53840 - 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0 0
53848 - 0 0 0 0 0 0 0 0 0 0 0 0
53849 - 0 0 0 0 0 0 0 0 0 14 14 14
53850 - 46 46 46 86 86 86 2 2 6 14 14 14
53851 -134 134 134 198 198 198 195 195 195 116 116 116
53852 - 10 10 10 2 2 6 2 2 6 6 6 6
53853 -101 98 89 187 187 187 210 210 210 218 218 218
53854 -214 214 214 134 134 134 14 14 14 6 6 6
53855 - 2 2 6 2 2 6 2 2 6 2 2 6
53856 - 86 86 86 50 50 50 18 18 18 6 6 6
53857 - 0 0 0 0 0 0 0 0 0 0 0 0
53858 - 0 0 0 0 0 0 0 0 0 0 0 0
53859 - 0 0 0 0 0 0 0 0 0 0 0 0
53860 - 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 0
53864 - 0 0 1 0 0 1 0 0 1 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 0 0 0 0
53868 - 0 0 0 0 0 0 0 0 0 0 0 0
53869 - 0 0 0 0 0 0 0 0 0 14 14 14
53870 - 46 46 46 86 86 86 2 2 6 54 54 54
53871 -218 218 218 195 195 195 226 226 226 246 246 246
53872 - 58 58 58 2 2 6 2 2 6 30 30 30
53873 -210 210 210 253 253 253 174 174 174 123 123 123
53874 -221 221 221 234 234 234 74 74 74 2 2 6
53875 - 2 2 6 2 2 6 2 2 6 2 2 6
53876 - 70 70 70 58 58 58 22 22 22 6 6 6
53877 - 0 0 0 0 0 0 0 0 0 0 0 0
53878 - 0 0 0 0 0 0 0 0 0 0 0 0
53879 - 0 0 0 0 0 0 0 0 0 0 0 0
53880 - 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0 0
53888 - 0 0 0 0 0 0 0 0 0 0 0 0
53889 - 0 0 0 0 0 0 0 0 0 14 14 14
53890 - 46 46 46 82 82 82 2 2 6 106 106 106
53891 -170 170 170 26 26 26 86 86 86 226 226 226
53892 -123 123 123 10 10 10 14 14 14 46 46 46
53893 -231 231 231 190 190 190 6 6 6 70 70 70
53894 - 90 90 90 238 238 238 158 158 158 2 2 6
53895 - 2 2 6 2 2 6 2 2 6 2 2 6
53896 - 70 70 70 58 58 58 22 22 22 6 6 6
53897 - 0 0 0 0 0 0 0 0 0 0 0 0
53898 - 0 0 0 0 0 0 0 0 0 0 0 0
53899 - 0 0 0 0 0 0 0 0 0 0 0 0
53900 - 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 0
53904 - 0 0 1 0 0 1 0 0 1 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 14 14 14
53910 - 42 42 42 86 86 86 6 6 6 116 116 116
53911 -106 106 106 6 6 6 70 70 70 149 149 149
53912 -128 128 128 18 18 18 38 38 38 54 54 54
53913 -221 221 221 106 106 106 2 2 6 14 14 14
53914 - 46 46 46 190 190 190 198 198 198 2 2 6
53915 - 2 2 6 2 2 6 2 2 6 2 2 6
53916 - 74 74 74 62 62 62 22 22 22 6 6 6
53917 - 0 0 0 0 0 0 0 0 0 0 0 0
53918 - 0 0 0 0 0 0 0 0 0 0 0 0
53919 - 0 0 0 0 0 0 0 0 0 0 0 0
53920 - 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 0
53924 - 0 0 1 0 0 0 0 0 1 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 14 14 14
53930 - 42 42 42 94 94 94 14 14 14 101 101 101
53931 -128 128 128 2 2 6 18 18 18 116 116 116
53932 -118 98 46 121 92 8 121 92 8 98 78 10
53933 -162 162 162 106 106 106 2 2 6 2 2 6
53934 - 2 2 6 195 195 195 195 195 195 6 6 6
53935 - 2 2 6 2 2 6 2 2 6 2 2 6
53936 - 74 74 74 62 62 62 22 22 22 6 6 6
53937 - 0 0 0 0 0 0 0 0 0 0 0 0
53938 - 0 0 0 0 0 0 0 0 0 0 0 0
53939 - 0 0 0 0 0 0 0 0 0 0 0 0
53940 - 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 1
53944 - 0 0 1 0 0 0 0 0 1 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 10 10 10
53950 - 38 38 38 90 90 90 14 14 14 58 58 58
53951 -210 210 210 26 26 26 54 38 6 154 114 10
53952 -226 170 11 236 186 11 225 175 15 184 144 12
53953 -215 174 15 175 146 61 37 26 9 2 2 6
53954 - 70 70 70 246 246 246 138 138 138 2 2 6
53955 - 2 2 6 2 2 6 2 2 6 2 2 6
53956 - 70 70 70 66 66 66 26 26 26 6 6 6
53957 - 0 0 0 0 0 0 0 0 0 0 0 0
53958 - 0 0 0 0 0 0 0 0 0 0 0 0
53959 - 0 0 0 0 0 0 0 0 0 0 0 0
53960 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
53970 - 38 38 38 86 86 86 14 14 14 10 10 10
53971 -195 195 195 188 164 115 192 133 9 225 175 15
53972 -239 182 13 234 190 10 232 195 16 232 200 30
53973 -245 207 45 241 208 19 232 195 16 184 144 12
53974 -218 194 134 211 206 186 42 42 42 2 2 6
53975 - 2 2 6 2 2 6 2 2 6 2 2 6
53976 - 50 50 50 74 74 74 30 30 30 6 6 6
53977 - 0 0 0 0 0 0 0 0 0 0 0 0
53978 - 0 0 0 0 0 0 0 0 0 0 0 0
53979 - 0 0 0 0 0 0 0 0 0 0 0 0
53980 - 0 0 0 0 0 0 0 0 0 0 0 0
53981 - 0 0 0 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 10 10 10
53990 - 34 34 34 86 86 86 14 14 14 2 2 6
53991 -121 87 25 192 133 9 219 162 10 239 182 13
53992 -236 186 11 232 195 16 241 208 19 244 214 54
53993 -246 218 60 246 218 38 246 215 20 241 208 19
53994 -241 208 19 226 184 13 121 87 25 2 2 6
53995 - 2 2 6 2 2 6 2 2 6 2 2 6
53996 - 50 50 50 82 82 82 34 34 34 10 10 10
53997 - 0 0 0 0 0 0 0 0 0 0 0 0
53998 - 0 0 0 0 0 0 0 0 0 0 0 0
53999 - 0 0 0 0 0 0 0 0 0 0 0 0
54000 - 0 0 0 0 0 0 0 0 0 0 0 0
54001 - 0 0 0 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 10 10 10
54010 - 34 34 34 82 82 82 30 30 30 61 42 6
54011 -180 123 7 206 145 10 230 174 11 239 182 13
54012 -234 190 10 238 202 15 241 208 19 246 218 74
54013 -246 218 38 246 215 20 246 215 20 246 215 20
54014 -226 184 13 215 174 15 184 144 12 6 6 6
54015 - 2 2 6 2 2 6 2 2 6 2 2 6
54016 - 26 26 26 94 94 94 42 42 42 14 14 14
54017 - 0 0 0 0 0 0 0 0 0 0 0 0
54018 - 0 0 0 0 0 0 0 0 0 0 0 0
54019 - 0 0 0 0 0 0 0 0 0 0 0 0
54020 - 0 0 0 0 0 0 0 0 0 0 0 0
54021 - 0 0 0 0 0 0 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 10 10 10
54030 - 30 30 30 78 78 78 50 50 50 104 69 6
54031 -192 133 9 216 158 10 236 178 12 236 186 11
54032 -232 195 16 241 208 19 244 214 54 245 215 43
54033 -246 215 20 246 215 20 241 208 19 198 155 10
54034 -200 144 11 216 158 10 156 118 10 2 2 6
54035 - 2 2 6 2 2 6 2 2 6 2 2 6
54036 - 6 6 6 90 90 90 54 54 54 18 18 18
54037 - 6 6 6 0 0 0 0 0 0 0 0 0
54038 - 0 0 0 0 0 0 0 0 0 0 0 0
54039 - 0 0 0 0 0 0 0 0 0 0 0 0
54040 - 0 0 0 0 0 0 0 0 0 0 0 0
54041 - 0 0 0 0 0 0 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 10 10 10
54050 - 30 30 30 78 78 78 46 46 46 22 22 22
54051 -137 92 6 210 162 10 239 182 13 238 190 10
54052 -238 202 15 241 208 19 246 215 20 246 215 20
54053 -241 208 19 203 166 17 185 133 11 210 150 10
54054 -216 158 10 210 150 10 102 78 10 2 2 6
54055 - 6 6 6 54 54 54 14 14 14 2 2 6
54056 - 2 2 6 62 62 62 74 74 74 30 30 30
54057 - 10 10 10 0 0 0 0 0 0 0 0 0
54058 - 0 0 0 0 0 0 0 0 0 0 0 0
54059 - 0 0 0 0 0 0 0 0 0 0 0 0
54060 - 0 0 0 0 0 0 0 0 0 0 0 0
54061 - 0 0 0 0 0 0 0 0 0 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 10 10 10
54070 - 34 34 34 78 78 78 50 50 50 6 6 6
54071 - 94 70 30 139 102 15 190 146 13 226 184 13
54072 -232 200 30 232 195 16 215 174 15 190 146 13
54073 -168 122 10 192 133 9 210 150 10 213 154 11
54074 -202 150 34 182 157 106 101 98 89 2 2 6
54075 - 2 2 6 78 78 78 116 116 116 58 58 58
54076 - 2 2 6 22 22 22 90 90 90 46 46 46
54077 - 18 18 18 6 6 6 0 0 0 0 0 0
54078 - 0 0 0 0 0 0 0 0 0 0 0 0
54079 - 0 0 0 0 0 0 0 0 0 0 0 0
54080 - 0 0 0 0 0 0 0 0 0 0 0 0
54081 - 0 0 0 0 0 0 0 0 0 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 10 10 10
54090 - 38 38 38 86 86 86 50 50 50 6 6 6
54091 -128 128 128 174 154 114 156 107 11 168 122 10
54092 -198 155 10 184 144 12 197 138 11 200 144 11
54093 -206 145 10 206 145 10 197 138 11 188 164 115
54094 -195 195 195 198 198 198 174 174 174 14 14 14
54095 - 2 2 6 22 22 22 116 116 116 116 116 116
54096 - 22 22 22 2 2 6 74 74 74 70 70 70
54097 - 30 30 30 10 10 10 0 0 0 0 0 0
54098 - 0 0 0 0 0 0 0 0 0 0 0 0
54099 - 0 0 0 0 0 0 0 0 0 0 0 0
54100 - 0 0 0 0 0 0 0 0 0 0 0 0
54101 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 18 18 18
54110 - 50 50 50 101 101 101 26 26 26 10 10 10
54111 -138 138 138 190 190 190 174 154 114 156 107 11
54112 -197 138 11 200 144 11 197 138 11 192 133 9
54113 -180 123 7 190 142 34 190 178 144 187 187 187
54114 -202 202 202 221 221 221 214 214 214 66 66 66
54115 - 2 2 6 2 2 6 50 50 50 62 62 62
54116 - 6 6 6 2 2 6 10 10 10 90 90 90
54117 - 50 50 50 18 18 18 6 6 6 0 0 0
54118 - 0 0 0 0 0 0 0 0 0 0 0 0
54119 - 0 0 0 0 0 0 0 0 0 0 0 0
54120 - 0 0 0 0 0 0 0 0 0 0 0 0
54121 - 0 0 0 0 0 0 0 0 0 0 0 0
54122 - 0 0 0 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 10 10 10 34 34 34
54130 - 74 74 74 74 74 74 2 2 6 6 6 6
54131 -144 144 144 198 198 198 190 190 190 178 166 146
54132 -154 121 60 156 107 11 156 107 11 168 124 44
54133 -174 154 114 187 187 187 190 190 190 210 210 210
54134 -246 246 246 253 253 253 253 253 253 182 182 182
54135 - 6 6 6 2 2 6 2 2 6 2 2 6
54136 - 2 2 6 2 2 6 2 2 6 62 62 62
54137 - 74 74 74 34 34 34 14 14 14 0 0 0
54138 - 0 0 0 0 0 0 0 0 0 0 0 0
54139 - 0 0 0 0 0 0 0 0 0 0 0 0
54140 - 0 0 0 0 0 0 0 0 0 0 0 0
54141 - 0 0 0 0 0 0 0 0 0 0 0 0
54142 - 0 0 0 0 0 0 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 10 10 10 22 22 22 54 54 54
54150 - 94 94 94 18 18 18 2 2 6 46 46 46
54151 -234 234 234 221 221 221 190 190 190 190 190 190
54152 -190 190 190 187 187 187 187 187 187 190 190 190
54153 -190 190 190 195 195 195 214 214 214 242 242 242
54154 -253 253 253 253 253 253 253 253 253 253 253 253
54155 - 82 82 82 2 2 6 2 2 6 2 2 6
54156 - 2 2 6 2 2 6 2 2 6 14 14 14
54157 - 86 86 86 54 54 54 22 22 22 6 6 6
54158 - 0 0 0 0 0 0 0 0 0 0 0 0
54159 - 0 0 0 0 0 0 0 0 0 0 0 0
54160 - 0 0 0 0 0 0 0 0 0 0 0 0
54161 - 0 0 0 0 0 0 0 0 0 0 0 0
54162 - 0 0 0 0 0 0 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 - 6 6 6 18 18 18 46 46 46 90 90 90
54170 - 46 46 46 18 18 18 6 6 6 182 182 182
54171 -253 253 253 246 246 246 206 206 206 190 190 190
54172 -190 190 190 190 190 190 190 190 190 190 190 190
54173 -206 206 206 231 231 231 250 250 250 253 253 253
54174 -253 253 253 253 253 253 253 253 253 253 253 253
54175 -202 202 202 14 14 14 2 2 6 2 2 6
54176 - 2 2 6 2 2 6 2 2 6 2 2 6
54177 - 42 42 42 86 86 86 42 42 42 18 18 18
54178 - 6 6 6 0 0 0 0 0 0 0 0 0
54179 - 0 0 0 0 0 0 0 0 0 0 0 0
54180 - 0 0 0 0 0 0 0 0 0 0 0 0
54181 - 0 0 0 0 0 0 0 0 0 0 0 0
54182 - 0 0 0 0 0 0 0 0 0 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 6 6 6
54189 - 14 14 14 38 38 38 74 74 74 66 66 66
54190 - 2 2 6 6 6 6 90 90 90 250 250 250
54191 -253 253 253 253 253 253 238 238 238 198 198 198
54192 -190 190 190 190 190 190 195 195 195 221 221 221
54193 -246 246 246 253 253 253 253 253 253 253 253 253
54194 -253 253 253 253 253 253 253 253 253 253 253 253
54195 -253 253 253 82 82 82 2 2 6 2 2 6
54196 - 2 2 6 2 2 6 2 2 6 2 2 6
54197 - 2 2 6 78 78 78 70 70 70 34 34 34
54198 - 14 14 14 6 6 6 0 0 0 0 0 0
54199 - 0 0 0 0 0 0 0 0 0 0 0 0
54200 - 0 0 0 0 0 0 0 0 0 0 0 0
54201 - 0 0 0 0 0 0 0 0 0 0 0 0
54202 - 0 0 0 0 0 0 0 0 0 0 0 0
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 14 14 14
54209 - 34 34 34 66 66 66 78 78 78 6 6 6
54210 - 2 2 6 18 18 18 218 218 218 253 253 253
54211 -253 253 253 253 253 253 253 253 253 246 246 246
54212 -226 226 226 231 231 231 246 246 246 253 253 253
54213 -253 253 253 253 253 253 253 253 253 253 253 253
54214 -253 253 253 253 253 253 253 253 253 253 253 253
54215 -253 253 253 178 178 178 2 2 6 2 2 6
54216 - 2 2 6 2 2 6 2 2 6 2 2 6
54217 - 2 2 6 18 18 18 90 90 90 62 62 62
54218 - 30 30 30 10 10 10 0 0 0 0 0 0
54219 - 0 0 0 0 0 0 0 0 0 0 0 0
54220 - 0 0 0 0 0 0 0 0 0 0 0 0
54221 - 0 0 0 0 0 0 0 0 0 0 0 0
54222 - 0 0 0 0 0 0 0 0 0 0 0 0
54223 - 0 0 0 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 10 10 10 26 26 26
54229 - 58 58 58 90 90 90 18 18 18 2 2 6
54230 - 2 2 6 110 110 110 253 253 253 253 253 253
54231 -253 253 253 253 253 253 253 253 253 253 253 253
54232 -250 250 250 253 253 253 253 253 253 253 253 253
54233 -253 253 253 253 253 253 253 253 253 253 253 253
54234 -253 253 253 253 253 253 253 253 253 253 253 253
54235 -253 253 253 231 231 231 18 18 18 2 2 6
54236 - 2 2 6 2 2 6 2 2 6 2 2 6
54237 - 2 2 6 2 2 6 18 18 18 94 94 94
54238 - 54 54 54 26 26 26 10 10 10 0 0 0
54239 - 0 0 0 0 0 0 0 0 0 0 0 0
54240 - 0 0 0 0 0 0 0 0 0 0 0 0
54241 - 0 0 0 0 0 0 0 0 0 0 0 0
54242 - 0 0 0 0 0 0 0 0 0 0 0 0
54243 - 0 0 0 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 6 6 6 22 22 22 50 50 50
54249 - 90 90 90 26 26 26 2 2 6 2 2 6
54250 - 14 14 14 195 195 195 250 250 250 253 253 253
54251 -253 253 253 253 253 253 253 253 253 253 253 253
54252 -253 253 253 253 253 253 253 253 253 253 253 253
54253 -253 253 253 253 253 253 253 253 253 253 253 253
54254 -253 253 253 253 253 253 253 253 253 253 253 253
54255 -250 250 250 242 242 242 54 54 54 2 2 6
54256 - 2 2 6 2 2 6 2 2 6 2 2 6
54257 - 2 2 6 2 2 6 2 2 6 38 38 38
54258 - 86 86 86 50 50 50 22 22 22 6 6 6
54259 - 0 0 0 0 0 0 0 0 0 0 0 0
54260 - 0 0 0 0 0 0 0 0 0 0 0 0
54261 - 0 0 0 0 0 0 0 0 0 0 0 0
54262 - 0 0 0 0 0 0 0 0 0 0 0 0
54263 - 0 0 0 0 0 0 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 - 6 6 6 14 14 14 38 38 38 82 82 82
54269 - 34 34 34 2 2 6 2 2 6 2 2 6
54270 - 42 42 42 195 195 195 246 246 246 253 253 253
54271 -253 253 253 253 253 253 253 253 253 250 250 250
54272 -242 242 242 242 242 242 250 250 250 253 253 253
54273 -253 253 253 253 253 253 253 253 253 253 253 253
54274 -253 253 253 250 250 250 246 246 246 238 238 238
54275 -226 226 226 231 231 231 101 101 101 6 6 6
54276 - 2 2 6 2 2 6 2 2 6 2 2 6
54277 - 2 2 6 2 2 6 2 2 6 2 2 6
54278 - 38 38 38 82 82 82 42 42 42 14 14 14
54279 - 6 6 6 0 0 0 0 0 0 0 0 0
54280 - 0 0 0 0 0 0 0 0 0 0 0 0
54281 - 0 0 0 0 0 0 0 0 0 0 0 0
54282 - 0 0 0 0 0 0 0 0 0 0 0 0
54283 - 0 0 0 0 0 0 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 - 10 10 10 26 26 26 62 62 62 66 66 66
54289 - 2 2 6 2 2 6 2 2 6 6 6 6
54290 - 70 70 70 170 170 170 206 206 206 234 234 234
54291 -246 246 246 250 250 250 250 250 250 238 238 238
54292 -226 226 226 231 231 231 238 238 238 250 250 250
54293 -250 250 250 250 250 250 246 246 246 231 231 231
54294 -214 214 214 206 206 206 202 202 202 202 202 202
54295 -198 198 198 202 202 202 182 182 182 18 18 18
54296 - 2 2 6 2 2 6 2 2 6 2 2 6
54297 - 2 2 6 2 2 6 2 2 6 2 2 6
54298 - 2 2 6 62 62 62 66 66 66 30 30 30
54299 - 10 10 10 0 0 0 0 0 0 0 0 0
54300 - 0 0 0 0 0 0 0 0 0 0 0 0
54301 - 0 0 0 0 0 0 0 0 0 0 0 0
54302 - 0 0 0 0 0 0 0 0 0 0 0 0
54303 - 0 0 0 0 0 0 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 - 14 14 14 42 42 42 82 82 82 18 18 18
54309 - 2 2 6 2 2 6 2 2 6 10 10 10
54310 - 94 94 94 182 182 182 218 218 218 242 242 242
54311 -250 250 250 253 253 253 253 253 253 250 250 250
54312 -234 234 234 253 253 253 253 253 253 253 253 253
54313 -253 253 253 253 253 253 253 253 253 246 246 246
54314 -238 238 238 226 226 226 210 210 210 202 202 202
54315 -195 195 195 195 195 195 210 210 210 158 158 158
54316 - 6 6 6 14 14 14 50 50 50 14 14 14
54317 - 2 2 6 2 2 6 2 2 6 2 2 6
54318 - 2 2 6 6 6 6 86 86 86 46 46 46
54319 - 18 18 18 6 6 6 0 0 0 0 0 0
54320 - 0 0 0 0 0 0 0 0 0 0 0 0
54321 - 0 0 0 0 0 0 0 0 0 0 0 0
54322 - 0 0 0 0 0 0 0 0 0 0 0 0
54323 - 0 0 0 0 0 0 0 0 0 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 6 6 6
54328 - 22 22 22 54 54 54 70 70 70 2 2 6
54329 - 2 2 6 10 10 10 2 2 6 22 22 22
54330 -166 166 166 231 231 231 250 250 250 253 253 253
54331 -253 253 253 253 253 253 253 253 253 250 250 250
54332 -242 242 242 253 253 253 253 253 253 253 253 253
54333 -253 253 253 253 253 253 253 253 253 253 253 253
54334 -253 253 253 253 253 253 253 253 253 246 246 246
54335 -231 231 231 206 206 206 198 198 198 226 226 226
54336 - 94 94 94 2 2 6 6 6 6 38 38 38
54337 - 30 30 30 2 2 6 2 2 6 2 2 6
54338 - 2 2 6 2 2 6 62 62 62 66 66 66
54339 - 26 26 26 10 10 10 0 0 0 0 0 0
54340 - 0 0 0 0 0 0 0 0 0 0 0 0
54341 - 0 0 0 0 0 0 0 0 0 0 0 0
54342 - 0 0 0 0 0 0 0 0 0 0 0 0
54343 - 0 0 0 0 0 0 0 0 0 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 10 10 10
54348 - 30 30 30 74 74 74 50 50 50 2 2 6
54349 - 26 26 26 26 26 26 2 2 6 106 106 106
54350 -238 238 238 253 253 253 253 253 253 253 253 253
54351 -253 253 253 253 253 253 253 253 253 253 253 253
54352 -253 253 253 253 253 253 253 253 253 253 253 253
54353 -253 253 253 253 253 253 253 253 253 253 253 253
54354 -253 253 253 253 253 253 253 253 253 253 253 253
54355 -253 253 253 246 246 246 218 218 218 202 202 202
54356 -210 210 210 14 14 14 2 2 6 2 2 6
54357 - 30 30 30 22 22 22 2 2 6 2 2 6
54358 - 2 2 6 2 2 6 18 18 18 86 86 86
54359 - 42 42 42 14 14 14 0 0 0 0 0 0
54360 - 0 0 0 0 0 0 0 0 0 0 0 0
54361 - 0 0 0 0 0 0 0 0 0 0 0 0
54362 - 0 0 0 0 0 0 0 0 0 0 0 0
54363 - 0 0 0 0 0 0 0 0 0 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 14 14 14
54368 - 42 42 42 90 90 90 22 22 22 2 2 6
54369 - 42 42 42 2 2 6 18 18 18 218 218 218
54370 -253 253 253 253 253 253 253 253 253 253 253 253
54371 -253 253 253 253 253 253 253 253 253 253 253 253
54372 -253 253 253 253 253 253 253 253 253 253 253 253
54373 -253 253 253 253 253 253 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 221 221 221
54376 -218 218 218 101 101 101 2 2 6 14 14 14
54377 - 18 18 18 38 38 38 10 10 10 2 2 6
54378 - 2 2 6 2 2 6 2 2 6 78 78 78
54379 - 58 58 58 22 22 22 6 6 6 0 0 0
54380 - 0 0 0 0 0 0 0 0 0 0 0 0
54381 - 0 0 0 0 0 0 0 0 0 0 0 0
54382 - 0 0 0 0 0 0 0 0 0 0 0 0
54383 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 18 18 18
54388 - 54 54 54 82 82 82 2 2 6 26 26 26
54389 - 22 22 22 2 2 6 123 123 123 253 253 253
54390 -253 253 253 253 253 253 253 253 253 253 253 253
54391 -253 253 253 253 253 253 253 253 253 253 253 253
54392 -253 253 253 253 253 253 253 253 253 253 253 253
54393 -253 253 253 253 253 253 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 253 253 253 250 250 250
54396 -238 238 238 198 198 198 6 6 6 38 38 38
54397 - 58 58 58 26 26 26 38 38 38 2 2 6
54398 - 2 2 6 2 2 6 2 2 6 46 46 46
54399 - 78 78 78 30 30 30 10 10 10 0 0 0
54400 - 0 0 0 0 0 0 0 0 0 0 0 0
54401 - 0 0 0 0 0 0 0 0 0 0 0 0
54402 - 0 0 0 0 0 0 0 0 0 0 0 0
54403 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10 30 30 30
54408 - 74 74 74 58 58 58 2 2 6 42 42 42
54409 - 2 2 6 22 22 22 231 231 231 253 253 253
54410 -253 253 253 253 253 253 253 253 253 253 253 253
54411 -253 253 253 253 253 253 253 253 253 250 250 250
54412 -253 253 253 253 253 253 253 253 253 253 253 253
54413 -253 253 253 253 253 253 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 253 253 253 253 253 253
54416 -253 253 253 246 246 246 46 46 46 38 38 38
54417 - 42 42 42 14 14 14 38 38 38 14 14 14
54418 - 2 2 6 2 2 6 2 2 6 6 6 6
54419 - 86 86 86 46 46 46 14 14 14 0 0 0
54420 - 0 0 0 0 0 0 0 0 0 0 0 0
54421 - 0 0 0 0 0 0 0 0 0 0 0 0
54422 - 0 0 0 0 0 0 0 0 0 0 0 0
54423 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 14 14 14 42 42 42
54428 - 90 90 90 18 18 18 18 18 18 26 26 26
54429 - 2 2 6 116 116 116 253 253 253 253 253 253
54430 -253 253 253 253 253 253 253 253 253 253 253 253
54431 -253 253 253 253 253 253 250 250 250 238 238 238
54432 -253 253 253 253 253 253 253 253 253 253 253 253
54433 -253 253 253 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 253 253 253 253 253 253
54436 -253 253 253 253 253 253 94 94 94 6 6 6
54437 - 2 2 6 2 2 6 10 10 10 34 34 34
54438 - 2 2 6 2 2 6 2 2 6 2 2 6
54439 - 74 74 74 58 58 58 22 22 22 6 6 6
54440 - 0 0 0 0 0 0 0 0 0 0 0 0
54441 - 0 0 0 0 0 0 0 0 0 0 0 0
54442 - 0 0 0 0 0 0 0 0 0 0 0 0
54443 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10 26 26 26 66 66 66
54448 - 82 82 82 2 2 6 38 38 38 6 6 6
54449 - 14 14 14 210 210 210 253 253 253 253 253 253
54450 -253 253 253 253 253 253 253 253 253 253 253 253
54451 -253 253 253 253 253 253 246 246 246 242 242 242
54452 -253 253 253 253 253 253 253 253 253 253 253 253
54453 -253 253 253 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 253 253 253 253 253 253
54456 -253 253 253 253 253 253 144 144 144 2 2 6
54457 - 2 2 6 2 2 6 2 2 6 46 46 46
54458 - 2 2 6 2 2 6 2 2 6 2 2 6
54459 - 42 42 42 74 74 74 30 30 30 10 10 10
54460 - 0 0 0 0 0 0 0 0 0 0 0 0
54461 - 0 0 0 0 0 0 0 0 0 0 0 0
54462 - 0 0 0 0 0 0 0 0 0 0 0 0
54463 - 0 0 0 0 0 0 0 0 0 0 0 0
54464 - 0 0 0 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 - 6 6 6 14 14 14 42 42 42 90 90 90
54468 - 26 26 26 6 6 6 42 42 42 2 2 6
54469 - 74 74 74 250 250 250 253 253 253 253 253 253
54470 -253 253 253 253 253 253 253 253 253 253 253 253
54471 -253 253 253 253 253 253 242 242 242 242 242 242
54472 -253 253 253 253 253 253 253 253 253 253 253 253
54473 -253 253 253 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 253 253 253 253 253 253
54476 -253 253 253 253 253 253 182 182 182 2 2 6
54477 - 2 2 6 2 2 6 2 2 6 46 46 46
54478 - 2 2 6 2 2 6 2 2 6 2 2 6
54479 - 10 10 10 86 86 86 38 38 38 10 10 10
54480 - 0 0 0 0 0 0 0 0 0 0 0 0
54481 - 0 0 0 0 0 0 0 0 0 0 0 0
54482 - 0 0 0 0 0 0 0 0 0 0 0 0
54483 - 0 0 0 0 0 0 0 0 0 0 0 0
54484 - 0 0 0 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 - 10 10 10 26 26 26 66 66 66 82 82 82
54488 - 2 2 6 22 22 22 18 18 18 2 2 6
54489 -149 149 149 253 253 253 253 253 253 253 253 253
54490 -253 253 253 253 253 253 253 253 253 253 253 253
54491 -253 253 253 253 253 253 234 234 234 242 242 242
54492 -253 253 253 253 253 253 253 253 253 253 253 253
54493 -253 253 253 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 253 253 253 253 253 253
54496 -253 253 253 253 253 253 206 206 206 2 2 6
54497 - 2 2 6 2 2 6 2 2 6 38 38 38
54498 - 2 2 6 2 2 6 2 2 6 2 2 6
54499 - 6 6 6 86 86 86 46 46 46 14 14 14
54500 - 0 0 0 0 0 0 0 0 0 0 0 0
54501 - 0 0 0 0 0 0 0 0 0 0 0 0
54502 - 0 0 0 0 0 0 0 0 0 0 0 0
54503 - 0 0 0 0 0 0 0 0 0 0 0 0
54504 - 0 0 0 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 6 6 6
54507 - 18 18 18 46 46 46 86 86 86 18 18 18
54508 - 2 2 6 34 34 34 10 10 10 6 6 6
54509 -210 210 210 253 253 253 253 253 253 253 253 253
54510 -253 253 253 253 253 253 253 253 253 253 253 253
54511 -253 253 253 253 253 253 234 234 234 242 242 242
54512 -253 253 253 253 253 253 253 253 253 253 253 253
54513 -253 253 253 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 253 253 253 253 253 253
54516 -253 253 253 253 253 253 221 221 221 6 6 6
54517 - 2 2 6 2 2 6 6 6 6 30 30 30
54518 - 2 2 6 2 2 6 2 2 6 2 2 6
54519 - 2 2 6 82 82 82 54 54 54 18 18 18
54520 - 6 6 6 0 0 0 0 0 0 0 0 0
54521 - 0 0 0 0 0 0 0 0 0 0 0 0
54522 - 0 0 0 0 0 0 0 0 0 0 0 0
54523 - 0 0 0 0 0 0 0 0 0 0 0 0
54524 - 0 0 0 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 10 10 10
54527 - 26 26 26 66 66 66 62 62 62 2 2 6
54528 - 2 2 6 38 38 38 10 10 10 26 26 26
54529 -238 238 238 253 253 253 253 253 253 253 253 253
54530 -253 253 253 253 253 253 253 253 253 253 253 253
54531 -253 253 253 253 253 253 231 231 231 238 238 238
54532 -253 253 253 253 253 253 253 253 253 253 253 253
54533 -253 253 253 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 253 253 253 253 253 253
54536 -253 253 253 253 253 253 231 231 231 6 6 6
54537 - 2 2 6 2 2 6 10 10 10 30 30 30
54538 - 2 2 6 2 2 6 2 2 6 2 2 6
54539 - 2 2 6 66 66 66 58 58 58 22 22 22
54540 - 6 6 6 0 0 0 0 0 0 0 0 0
54541 - 0 0 0 0 0 0 0 0 0 0 0 0
54542 - 0 0 0 0 0 0 0 0 0 0 0 0
54543 - 0 0 0 0 0 0 0 0 0 0 0 0
54544 - 0 0 0 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 10 10 10
54547 - 38 38 38 78 78 78 6 6 6 2 2 6
54548 - 2 2 6 46 46 46 14 14 14 42 42 42
54549 -246 246 246 253 253 253 253 253 253 253 253 253
54550 -253 253 253 253 253 253 253 253 253 253 253 253
54551 -253 253 253 253 253 253 231 231 231 242 242 242
54552 -253 253 253 253 253 253 253 253 253 253 253 253
54553 -253 253 253 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 253 253 253 253 253 253
54556 -253 253 253 253 253 253 234 234 234 10 10 10
54557 - 2 2 6 2 2 6 22 22 22 14 14 14
54558 - 2 2 6 2 2 6 2 2 6 2 2 6
54559 - 2 2 6 66 66 66 62 62 62 22 22 22
54560 - 6 6 6 0 0 0 0 0 0 0 0 0
54561 - 0 0 0 0 0 0 0 0 0 0 0 0
54562 - 0 0 0 0 0 0 0 0 0 0 0 0
54563 - 0 0 0 0 0 0 0 0 0 0 0 0
54564 - 0 0 0 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 6 6 6 18 18 18
54567 - 50 50 50 74 74 74 2 2 6 2 2 6
54568 - 14 14 14 70 70 70 34 34 34 62 62 62
54569 -250 250 250 253 253 253 253 253 253 253 253 253
54570 -253 253 253 253 253 253 253 253 253 253 253 253
54571 -253 253 253 253 253 253 231 231 231 246 246 246
54572 -253 253 253 253 253 253 253 253 253 253 253 253
54573 -253 253 253 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 253 253 253 253 253 253
54576 -253 253 253 253 253 253 234 234 234 14 14 14
54577 - 2 2 6 2 2 6 30 30 30 2 2 6
54578 - 2 2 6 2 2 6 2 2 6 2 2 6
54579 - 2 2 6 66 66 66 62 62 62 22 22 22
54580 - 6 6 6 0 0 0 0 0 0 0 0 0
54581 - 0 0 0 0 0 0 0 0 0 0 0 0
54582 - 0 0 0 0 0 0 0 0 0 0 0 0
54583 - 0 0 0 0 0 0 0 0 0 0 0 0
54584 - 0 0 0 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 6 6 6 18 18 18
54587 - 54 54 54 62 62 62 2 2 6 2 2 6
54588 - 2 2 6 30 30 30 46 46 46 70 70 70
54589 -250 250 250 253 253 253 253 253 253 253 253 253
54590 -253 253 253 253 253 253 253 253 253 253 253 253
54591 -253 253 253 253 253 253 231 231 231 246 246 246
54592 -253 253 253 253 253 253 253 253 253 253 253 253
54593 -253 253 253 253 253 253 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 253 253 253 253 253 253
54596 -253 253 253 253 253 253 226 226 226 10 10 10
54597 - 2 2 6 6 6 6 30 30 30 2 2 6
54598 - 2 2 6 2 2 6 2 2 6 2 2 6
54599 - 2 2 6 66 66 66 58 58 58 22 22 22
54600 - 6 6 6 0 0 0 0 0 0 0 0 0
54601 - 0 0 0 0 0 0 0 0 0 0 0 0
54602 - 0 0 0 0 0 0 0 0 0 0 0 0
54603 - 0 0 0 0 0 0 0 0 0 0 0 0
54604 - 0 0 0 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 6 6 6 22 22 22
54607 - 58 58 58 62 62 62 2 2 6 2 2 6
54608 - 2 2 6 2 2 6 30 30 30 78 78 78
54609 -250 250 250 253 253 253 253 253 253 253 253 253
54610 -253 253 253 253 253 253 253 253 253 253 253 253
54611 -253 253 253 253 253 253 231 231 231 246 246 246
54612 -253 253 253 253 253 253 253 253 253 253 253 253
54613 -253 253 253 253 253 253 253 253 253 253 253 253
54614 -253 253 253 253 253 253 253 253 253 253 253 253
54615 -253 253 253 253 253 253 253 253 253 253 253 253
54616 -253 253 253 253 253 253 206 206 206 2 2 6
54617 - 22 22 22 34 34 34 18 14 6 22 22 22
54618 - 26 26 26 18 18 18 6 6 6 2 2 6
54619 - 2 2 6 82 82 82 54 54 54 18 18 18
54620 - 6 6 6 0 0 0 0 0 0 0 0 0
54621 - 0 0 0 0 0 0 0 0 0 0 0 0
54622 - 0 0 0 0 0 0 0 0 0 0 0 0
54623 - 0 0 0 0 0 0 0 0 0 0 0 0
54624 - 0 0 0 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 6 6 6 26 26 26
54627 - 62 62 62 106 106 106 74 54 14 185 133 11
54628 -210 162 10 121 92 8 6 6 6 62 62 62
54629 -238 238 238 253 253 253 253 253 253 253 253 253
54630 -253 253 253 253 253 253 253 253 253 253 253 253
54631 -253 253 253 253 253 253 231 231 231 246 246 246
54632 -253 253 253 253 253 253 253 253 253 253 253 253
54633 -253 253 253 253 253 253 253 253 253 253 253 253
54634 -253 253 253 253 253 253 253 253 253 253 253 253
54635 -253 253 253 253 253 253 253 253 253 253 253 253
54636 -253 253 253 253 253 253 158 158 158 18 18 18
54637 - 14 14 14 2 2 6 2 2 6 2 2 6
54638 - 6 6 6 18 18 18 66 66 66 38 38 38
54639 - 6 6 6 94 94 94 50 50 50 18 18 18
54640 - 6 6 6 0 0 0 0 0 0 0 0 0
54641 - 0 0 0 0 0 0 0 0 0 0 0 0
54642 - 0 0 0 0 0 0 0 0 0 0 0 0
54643 - 0 0 0 0 0 0 0 0 0 0 0 0
54644 - 0 0 0 0 0 0 0 0 0 0 0 0
54645 - 0 0 0 0 0 0 0 0 0 6 6 6
54646 - 10 10 10 10 10 10 18 18 18 38 38 38
54647 - 78 78 78 142 134 106 216 158 10 242 186 14
54648 -246 190 14 246 190 14 156 118 10 10 10 10
54649 - 90 90 90 238 238 238 253 253 253 253 253 253
54650 -253 253 253 253 253 253 253 253 253 253 253 253
54651 -253 253 253 253 253 253 231 231 231 250 250 250
54652 -253 253 253 253 253 253 253 253 253 253 253 253
54653 -253 253 253 253 253 253 253 253 253 253 253 253
54654 -253 253 253 253 253 253 253 253 253 253 253 253
54655 -253 253 253 253 253 253 253 253 253 246 230 190
54656 -238 204 91 238 204 91 181 142 44 37 26 9
54657 - 2 2 6 2 2 6 2 2 6 2 2 6
54658 - 2 2 6 2 2 6 38 38 38 46 46 46
54659 - 26 26 26 106 106 106 54 54 54 18 18 18
54660 - 6 6 6 0 0 0 0 0 0 0 0 0
54661 - 0 0 0 0 0 0 0 0 0 0 0 0
54662 - 0 0 0 0 0 0 0 0 0 0 0 0
54663 - 0 0 0 0 0 0 0 0 0 0 0 0
54664 - 0 0 0 0 0 0 0 0 0 0 0 0
54665 - 0 0 0 6 6 6 14 14 14 22 22 22
54666 - 30 30 30 38 38 38 50 50 50 70 70 70
54667 -106 106 106 190 142 34 226 170 11 242 186 14
54668 -246 190 14 246 190 14 246 190 14 154 114 10
54669 - 6 6 6 74 74 74 226 226 226 253 253 253
54670 -253 253 253 253 253 253 253 253 253 253 253 253
54671 -253 253 253 253 253 253 231 231 231 250 250 250
54672 -253 253 253 253 253 253 253 253 253 253 253 253
54673 -253 253 253 253 253 253 253 253 253 253 253 253
54674 -253 253 253 253 253 253 253 253 253 253 253 253
54675 -253 253 253 253 253 253 253 253 253 228 184 62
54676 -241 196 14 241 208 19 232 195 16 38 30 10
54677 - 2 2 6 2 2 6 2 2 6 2 2 6
54678 - 2 2 6 6 6 6 30 30 30 26 26 26
54679 -203 166 17 154 142 90 66 66 66 26 26 26
54680 - 6 6 6 0 0 0 0 0 0 0 0 0
54681 - 0 0 0 0 0 0 0 0 0 0 0 0
54682 - 0 0 0 0 0 0 0 0 0 0 0 0
54683 - 0 0 0 0 0 0 0 0 0 0 0 0
54684 - 0 0 0 0 0 0 0 0 0 0 0 0
54685 - 6 6 6 18 18 18 38 38 38 58 58 58
54686 - 78 78 78 86 86 86 101 101 101 123 123 123
54687 -175 146 61 210 150 10 234 174 13 246 186 14
54688 -246 190 14 246 190 14 246 190 14 238 190 10
54689 -102 78 10 2 2 6 46 46 46 198 198 198
54690 -253 253 253 253 253 253 253 253 253 253 253 253
54691 -253 253 253 253 253 253 234 234 234 242 242 242
54692 -253 253 253 253 253 253 253 253 253 253 253 253
54693 -253 253 253 253 253 253 253 253 253 253 253 253
54694 -253 253 253 253 253 253 253 253 253 253 253 253
54695 -253 253 253 253 253 253 253 253 253 224 178 62
54696 -242 186 14 241 196 14 210 166 10 22 18 6
54697 - 2 2 6 2 2 6 2 2 6 2 2 6
54698 - 2 2 6 2 2 6 6 6 6 121 92 8
54699 -238 202 15 232 195 16 82 82 82 34 34 34
54700 - 10 10 10 0 0 0 0 0 0 0 0 0
54701 - 0 0 0 0 0 0 0 0 0 0 0 0
54702 - 0 0 0 0 0 0 0 0 0 0 0 0
54703 - 0 0 0 0 0 0 0 0 0 0 0 0
54704 - 0 0 0 0 0 0 0 0 0 0 0 0
54705 - 14 14 14 38 38 38 70 70 70 154 122 46
54706 -190 142 34 200 144 11 197 138 11 197 138 11
54707 -213 154 11 226 170 11 242 186 14 246 190 14
54708 -246 190 14 246 190 14 246 190 14 246 190 14
54709 -225 175 15 46 32 6 2 2 6 22 22 22
54710 -158 158 158 250 250 250 253 253 253 253 253 253
54711 -253 253 253 253 253 253 253 253 253 253 253 253
54712 -253 253 253 253 253 253 253 253 253 253 253 253
54713 -253 253 253 253 253 253 253 253 253 253 253 253
54714 -253 253 253 253 253 253 253 253 253 253 253 253
54715 -253 253 253 250 250 250 242 242 242 224 178 62
54716 -239 182 13 236 186 11 213 154 11 46 32 6
54717 - 2 2 6 2 2 6 2 2 6 2 2 6
54718 - 2 2 6 2 2 6 61 42 6 225 175 15
54719 -238 190 10 236 186 11 112 100 78 42 42 42
54720 - 14 14 14 0 0 0 0 0 0 0 0 0
54721 - 0 0 0 0 0 0 0 0 0 0 0 0
54722 - 0 0 0 0 0 0 0 0 0 0 0 0
54723 - 0 0 0 0 0 0 0 0 0 0 0 0
54724 - 0 0 0 0 0 0 0 0 0 6 6 6
54725 - 22 22 22 54 54 54 154 122 46 213 154 11
54726 -226 170 11 230 174 11 226 170 11 226 170 11
54727 -236 178 12 242 186 14 246 190 14 246 190 14
54728 -246 190 14 246 190 14 246 190 14 246 190 14
54729 -241 196 14 184 144 12 10 10 10 2 2 6
54730 - 6 6 6 116 116 116 242 242 242 253 253 253
54731 -253 253 253 253 253 253 253 253 253 253 253 253
54732 -253 253 253 253 253 253 253 253 253 253 253 253
54733 -253 253 253 253 253 253 253 253 253 253 253 253
54734 -253 253 253 253 253 253 253 253 253 253 253 253
54735 -253 253 253 231 231 231 198 198 198 214 170 54
54736 -236 178 12 236 178 12 210 150 10 137 92 6
54737 - 18 14 6 2 2 6 2 2 6 2 2 6
54738 - 6 6 6 70 47 6 200 144 11 236 178 12
54739 -239 182 13 239 182 13 124 112 88 58 58 58
54740 - 22 22 22 6 6 6 0 0 0 0 0 0
54741 - 0 0 0 0 0 0 0 0 0 0 0 0
54742 - 0 0 0 0 0 0 0 0 0 0 0 0
54743 - 0 0 0 0 0 0 0 0 0 0 0 0
54744 - 0 0 0 0 0 0 0 0 0 10 10 10
54745 - 30 30 30 70 70 70 180 133 36 226 170 11
54746 -239 182 13 242 186 14 242 186 14 246 186 14
54747 -246 190 14 246 190 14 246 190 14 246 190 14
54748 -246 190 14 246 190 14 246 190 14 246 190 14
54749 -246 190 14 232 195 16 98 70 6 2 2 6
54750 - 2 2 6 2 2 6 66 66 66 221 221 221
54751 -253 253 253 253 253 253 253 253 253 253 253 253
54752 -253 253 253 253 253 253 253 253 253 253 253 253
54753 -253 253 253 253 253 253 253 253 253 253 253 253
54754 -253 253 253 253 253 253 253 253 253 253 253 253
54755 -253 253 253 206 206 206 198 198 198 214 166 58
54756 -230 174 11 230 174 11 216 158 10 192 133 9
54757 -163 110 8 116 81 8 102 78 10 116 81 8
54758 -167 114 7 197 138 11 226 170 11 239 182 13
54759 -242 186 14 242 186 14 162 146 94 78 78 78
54760 - 34 34 34 14 14 14 6 6 6 0 0 0
54761 - 0 0 0 0 0 0 0 0 0 0 0 0
54762 - 0 0 0 0 0 0 0 0 0 0 0 0
54763 - 0 0 0 0 0 0 0 0 0 0 0 0
54764 - 0 0 0 0 0 0 0 0 0 6 6 6
54765 - 30 30 30 78 78 78 190 142 34 226 170 11
54766 -239 182 13 246 190 14 246 190 14 246 190 14
54767 -246 190 14 246 190 14 246 190 14 246 190 14
54768 -246 190 14 246 190 14 246 190 14 246 190 14
54769 -246 190 14 241 196 14 203 166 17 22 18 6
54770 - 2 2 6 2 2 6 2 2 6 38 38 38
54771 -218 218 218 253 253 253 253 253 253 253 253 253
54772 -253 253 253 253 253 253 253 253 253 253 253 253
54773 -253 253 253 253 253 253 253 253 253 253 253 253
54774 -253 253 253 253 253 253 253 253 253 253 253 253
54775 -250 250 250 206 206 206 198 198 198 202 162 69
54776 -226 170 11 236 178 12 224 166 10 210 150 10
54777 -200 144 11 197 138 11 192 133 9 197 138 11
54778 -210 150 10 226 170 11 242 186 14 246 190 14
54779 -246 190 14 246 186 14 225 175 15 124 112 88
54780 - 62 62 62 30 30 30 14 14 14 6 6 6
54781 - 0 0 0 0 0 0 0 0 0 0 0 0
54782 - 0 0 0 0 0 0 0 0 0 0 0 0
54783 - 0 0 0 0 0 0 0 0 0 0 0 0
54784 - 0 0 0 0 0 0 0 0 0 10 10 10
54785 - 30 30 30 78 78 78 174 135 50 224 166 10
54786 -239 182 13 246 190 14 246 190 14 246 190 14
54787 -246 190 14 246 190 14 246 190 14 246 190 14
54788 -246 190 14 246 190 14 246 190 14 246 190 14
54789 -246 190 14 246 190 14 241 196 14 139 102 15
54790 - 2 2 6 2 2 6 2 2 6 2 2 6
54791 - 78 78 78 250 250 250 253 253 253 253 253 253
54792 -253 253 253 253 253 253 253 253 253 253 253 253
54793 -253 253 253 253 253 253 253 253 253 253 253 253
54794 -253 253 253 253 253 253 253 253 253 253 253 253
54795 -250 250 250 214 214 214 198 198 198 190 150 46
54796 -219 162 10 236 178 12 234 174 13 224 166 10
54797 -216 158 10 213 154 11 213 154 11 216 158 10
54798 -226 170 11 239 182 13 246 190 14 246 190 14
54799 -246 190 14 246 190 14 242 186 14 206 162 42
54800 -101 101 101 58 58 58 30 30 30 14 14 14
54801 - 6 6 6 0 0 0 0 0 0 0 0 0
54802 - 0 0 0 0 0 0 0 0 0 0 0 0
54803 - 0 0 0 0 0 0 0 0 0 0 0 0
54804 - 0 0 0 0 0 0 0 0 0 10 10 10
54805 - 30 30 30 74 74 74 174 135 50 216 158 10
54806 -236 178 12 246 190 14 246 190 14 246 190 14
54807 -246 190 14 246 190 14 246 190 14 246 190 14
54808 -246 190 14 246 190 14 246 190 14 246 190 14
54809 -246 190 14 246 190 14 241 196 14 226 184 13
54810 - 61 42 6 2 2 6 2 2 6 2 2 6
54811 - 22 22 22 238 238 238 253 253 253 253 253 253
54812 -253 253 253 253 253 253 253 253 253 253 253 253
54813 -253 253 253 253 253 253 253 253 253 253 253 253
54814 -253 253 253 253 253 253 253 253 253 253 253 253
54815 -253 253 253 226 226 226 187 187 187 180 133 36
54816 -216 158 10 236 178 12 239 182 13 236 178 12
54817 -230 174 11 226 170 11 226 170 11 230 174 11
54818 -236 178 12 242 186 14 246 190 14 246 190 14
54819 -246 190 14 246 190 14 246 186 14 239 182 13
54820 -206 162 42 106 106 106 66 66 66 34 34 34
54821 - 14 14 14 6 6 6 0 0 0 0 0 0
54822 - 0 0 0 0 0 0 0 0 0 0 0 0
54823 - 0 0 0 0 0 0 0 0 0 0 0 0
54824 - 0 0 0 0 0 0 0 0 0 6 6 6
54825 - 26 26 26 70 70 70 163 133 67 213 154 11
54826 -236 178 12 246 190 14 246 190 14 246 190 14
54827 -246 190 14 246 190 14 246 190 14 246 190 14
54828 -246 190 14 246 190 14 246 190 14 246 190 14
54829 -246 190 14 246 190 14 246 190 14 241 196 14
54830 -190 146 13 18 14 6 2 2 6 2 2 6
54831 - 46 46 46 246 246 246 253 253 253 253 253 253
54832 -253 253 253 253 253 253 253 253 253 253 253 253
54833 -253 253 253 253 253 253 253 253 253 253 253 253
54834 -253 253 253 253 253 253 253 253 253 253 253 253
54835 -253 253 253 221 221 221 86 86 86 156 107 11
54836 -216 158 10 236 178 12 242 186 14 246 186 14
54837 -242 186 14 239 182 13 239 182 13 242 186 14
54838 -242 186 14 246 186 14 246 190 14 246 190 14
54839 -246 190 14 246 190 14 246 190 14 246 190 14
54840 -242 186 14 225 175 15 142 122 72 66 66 66
54841 - 30 30 30 10 10 10 0 0 0 0 0 0
54842 - 0 0 0 0 0 0 0 0 0 0 0 0
54843 - 0 0 0 0 0 0 0 0 0 0 0 0
54844 - 0 0 0 0 0 0 0 0 0 6 6 6
54845 - 26 26 26 70 70 70 163 133 67 210 150 10
54846 -236 178 12 246 190 14 246 190 14 246 190 14
54847 -246 190 14 246 190 14 246 190 14 246 190 14
54848 -246 190 14 246 190 14 246 190 14 246 190 14
54849 -246 190 14 246 190 14 246 190 14 246 190 14
54850 -232 195 16 121 92 8 34 34 34 106 106 106
54851 -221 221 221 253 253 253 253 253 253 253 253 253
54852 -253 253 253 253 253 253 253 253 253 253 253 253
54853 -253 253 253 253 253 253 253 253 253 253 253 253
54854 -253 253 253 253 253 253 253 253 253 253 253 253
54855 -242 242 242 82 82 82 18 14 6 163 110 8
54856 -216 158 10 236 178 12 242 186 14 246 190 14
54857 -246 190 14 246 190 14 246 190 14 246 190 14
54858 -246 190 14 246 190 14 246 190 14 246 190 14
54859 -246 190 14 246 190 14 246 190 14 246 190 14
54860 -246 190 14 246 190 14 242 186 14 163 133 67
54861 - 46 46 46 18 18 18 6 6 6 0 0 0
54862 - 0 0 0 0 0 0 0 0 0 0 0 0
54863 - 0 0 0 0 0 0 0 0 0 0 0 0
54864 - 0 0 0 0 0 0 0 0 0 10 10 10
54865 - 30 30 30 78 78 78 163 133 67 210 150 10
54866 -236 178 12 246 186 14 246 190 14 246 190 14
54867 -246 190 14 246 190 14 246 190 14 246 190 14
54868 -246 190 14 246 190 14 246 190 14 246 190 14
54869 -246 190 14 246 190 14 246 190 14 246 190 14
54870 -241 196 14 215 174 15 190 178 144 253 253 253
54871 -253 253 253 253 253 253 253 253 253 253 253 253
54872 -253 253 253 253 253 253 253 253 253 253 253 253
54873 -253 253 253 253 253 253 253 253 253 253 253 253
54874 -253 253 253 253 253 253 253 253 253 218 218 218
54875 - 58 58 58 2 2 6 22 18 6 167 114 7
54876 -216 158 10 236 178 12 246 186 14 246 190 14
54877 -246 190 14 246 190 14 246 190 14 246 190 14
54878 -246 190 14 246 190 14 246 190 14 246 190 14
54879 -246 190 14 246 190 14 246 190 14 246 190 14
54880 -246 190 14 246 186 14 242 186 14 190 150 46
54881 - 54 54 54 22 22 22 6 6 6 0 0 0
54882 - 0 0 0 0 0 0 0 0 0 0 0 0
54883 - 0 0 0 0 0 0 0 0 0 0 0 0
54884 - 0 0 0 0 0 0 0 0 0 14 14 14
54885 - 38 38 38 86 86 86 180 133 36 213 154 11
54886 -236 178 12 246 186 14 246 190 14 246 190 14
54887 -246 190 14 246 190 14 246 190 14 246 190 14
54888 -246 190 14 246 190 14 246 190 14 246 190 14
54889 -246 190 14 246 190 14 246 190 14 246 190 14
54890 -246 190 14 232 195 16 190 146 13 214 214 214
54891 -253 253 253 253 253 253 253 253 253 253 253 253
54892 -253 253 253 253 253 253 253 253 253 253 253 253
54893 -253 253 253 253 253 253 253 253 253 253 253 253
54894 -253 253 253 250 250 250 170 170 170 26 26 26
54895 - 2 2 6 2 2 6 37 26 9 163 110 8
54896 -219 162 10 239 182 13 246 186 14 246 190 14
54897 -246 190 14 246 190 14 246 190 14 246 190 14
54898 -246 190 14 246 190 14 246 190 14 246 190 14
54899 -246 190 14 246 190 14 246 190 14 246 190 14
54900 -246 186 14 236 178 12 224 166 10 142 122 72
54901 - 46 46 46 18 18 18 6 6 6 0 0 0
54902 - 0 0 0 0 0 0 0 0 0 0 0 0
54903 - 0 0 0 0 0 0 0 0 0 0 0 0
54904 - 0 0 0 0 0 0 6 6 6 18 18 18
54905 - 50 50 50 109 106 95 192 133 9 224 166 10
54906 -242 186 14 246 190 14 246 190 14 246 190 14
54907 -246 190 14 246 190 14 246 190 14 246 190 14
54908 -246 190 14 246 190 14 246 190 14 246 190 14
54909 -246 190 14 246 190 14 246 190 14 246 190 14
54910 -242 186 14 226 184 13 210 162 10 142 110 46
54911 -226 226 226 253 253 253 253 253 253 253 253 253
54912 -253 253 253 253 253 253 253 253 253 253 253 253
54913 -253 253 253 253 253 253 253 253 253 253 253 253
54914 -198 198 198 66 66 66 2 2 6 2 2 6
54915 - 2 2 6 2 2 6 50 34 6 156 107 11
54916 -219 162 10 239 182 13 246 186 14 246 190 14
54917 -246 190 14 246 190 14 246 190 14 246 190 14
54918 -246 190 14 246 190 14 246 190 14 246 190 14
54919 -246 190 14 246 190 14 246 190 14 242 186 14
54920 -234 174 13 213 154 11 154 122 46 66 66 66
54921 - 30 30 30 10 10 10 0 0 0 0 0 0
54922 - 0 0 0 0 0 0 0 0 0 0 0 0
54923 - 0 0 0 0 0 0 0 0 0 0 0 0
54924 - 0 0 0 0 0 0 6 6 6 22 22 22
54925 - 58 58 58 154 121 60 206 145 10 234 174 13
54926 -242 186 14 246 186 14 246 190 14 246 190 14
54927 -246 190 14 246 190 14 246 190 14 246 190 14
54928 -246 190 14 246 190 14 246 190 14 246 190 14
54929 -246 190 14 246 190 14 246 190 14 246 190 14
54930 -246 186 14 236 178 12 210 162 10 163 110 8
54931 - 61 42 6 138 138 138 218 218 218 250 250 250
54932 -253 253 253 253 253 253 253 253 253 250 250 250
54933 -242 242 242 210 210 210 144 144 144 66 66 66
54934 - 6 6 6 2 2 6 2 2 6 2 2 6
54935 - 2 2 6 2 2 6 61 42 6 163 110 8
54936 -216 158 10 236 178 12 246 190 14 246 190 14
54937 -246 190 14 246 190 14 246 190 14 246 190 14
54938 -246 190 14 246 190 14 246 190 14 246 190 14
54939 -246 190 14 239 182 13 230 174 11 216 158 10
54940 -190 142 34 124 112 88 70 70 70 38 38 38
54941 - 18 18 18 6 6 6 0 0 0 0 0 0
54942 - 0 0 0 0 0 0 0 0 0 0 0 0
54943 - 0 0 0 0 0 0 0 0 0 0 0 0
54944 - 0 0 0 0 0 0 6 6 6 22 22 22
54945 - 62 62 62 168 124 44 206 145 10 224 166 10
54946 -236 178 12 239 182 13 242 186 14 242 186 14
54947 -246 186 14 246 190 14 246 190 14 246 190 14
54948 -246 190 14 246 190 14 246 190 14 246 190 14
54949 -246 190 14 246 190 14 246 190 14 246 190 14
54950 -246 190 14 236 178 12 216 158 10 175 118 6
54951 - 80 54 7 2 2 6 6 6 6 30 30 30
54952 - 54 54 54 62 62 62 50 50 50 38 38 38
54953 - 14 14 14 2 2 6 2 2 6 2 2 6
54954 - 2 2 6 2 2 6 2 2 6 2 2 6
54955 - 2 2 6 6 6 6 80 54 7 167 114 7
54956 -213 154 11 236 178 12 246 190 14 246 190 14
54957 -246 190 14 246 190 14 246 190 14 246 190 14
54958 -246 190 14 242 186 14 239 182 13 239 182 13
54959 -230 174 11 210 150 10 174 135 50 124 112 88
54960 - 82 82 82 54 54 54 34 34 34 18 18 18
54961 - 6 6 6 0 0 0 0 0 0 0 0 0
54962 - 0 0 0 0 0 0 0 0 0 0 0 0
54963 - 0 0 0 0 0 0 0 0 0 0 0 0
54964 - 0 0 0 0 0 0 6 6 6 18 18 18
54965 - 50 50 50 158 118 36 192 133 9 200 144 11
54966 -216 158 10 219 162 10 224 166 10 226 170 11
54967 -230 174 11 236 178 12 239 182 13 239 182 13
54968 -242 186 14 246 186 14 246 190 14 246 190 14
54969 -246 190 14 246 190 14 246 190 14 246 190 14
54970 -246 186 14 230 174 11 210 150 10 163 110 8
54971 -104 69 6 10 10 10 2 2 6 2 2 6
54972 - 2 2 6 2 2 6 2 2 6 2 2 6
54973 - 2 2 6 2 2 6 2 2 6 2 2 6
54974 - 2 2 6 2 2 6 2 2 6 2 2 6
54975 - 2 2 6 6 6 6 91 60 6 167 114 7
54976 -206 145 10 230 174 11 242 186 14 246 190 14
54977 -246 190 14 246 190 14 246 186 14 242 186 14
54978 -239 182 13 230 174 11 224 166 10 213 154 11
54979 -180 133 36 124 112 88 86 86 86 58 58 58
54980 - 38 38 38 22 22 22 10 10 10 6 6 6
54981 - 0 0 0 0 0 0 0 0 0 0 0 0
54982 - 0 0 0 0 0 0 0 0 0 0 0 0
54983 - 0 0 0 0 0 0 0 0 0 0 0 0
54984 - 0 0 0 0 0 0 0 0 0 14 14 14
54985 - 34 34 34 70 70 70 138 110 50 158 118 36
54986 -167 114 7 180 123 7 192 133 9 197 138 11
54987 -200 144 11 206 145 10 213 154 11 219 162 10
54988 -224 166 10 230 174 11 239 182 13 242 186 14
54989 -246 186 14 246 186 14 246 186 14 246 186 14
54990 -239 182 13 216 158 10 185 133 11 152 99 6
54991 -104 69 6 18 14 6 2 2 6 2 2 6
54992 - 2 2 6 2 2 6 2 2 6 2 2 6
54993 - 2 2 6 2 2 6 2 2 6 2 2 6
54994 - 2 2 6 2 2 6 2 2 6 2 2 6
54995 - 2 2 6 6 6 6 80 54 7 152 99 6
54996 -192 133 9 219 162 10 236 178 12 239 182 13
54997 -246 186 14 242 186 14 239 182 13 236 178 12
54998 -224 166 10 206 145 10 192 133 9 154 121 60
54999 - 94 94 94 62 62 62 42 42 42 22 22 22
55000 - 14 14 14 6 6 6 0 0 0 0 0 0
55001 - 0 0 0 0 0 0 0 0 0 0 0 0
55002 - 0 0 0 0 0 0 0 0 0 0 0 0
55003 - 0 0 0 0 0 0 0 0 0 0 0 0
55004 - 0 0 0 0 0 0 0 0 0 6 6 6
55005 - 18 18 18 34 34 34 58 58 58 78 78 78
55006 -101 98 89 124 112 88 142 110 46 156 107 11
55007 -163 110 8 167 114 7 175 118 6 180 123 7
55008 -185 133 11 197 138 11 210 150 10 219 162 10
55009 -226 170 11 236 178 12 236 178 12 234 174 13
55010 -219 162 10 197 138 11 163 110 8 130 83 6
55011 - 91 60 6 10 10 10 2 2 6 2 2 6
55012 - 18 18 18 38 38 38 38 38 38 38 38 38
55013 - 38 38 38 38 38 38 38 38 38 38 38 38
55014 - 38 38 38 38 38 38 26 26 26 2 2 6
55015 - 2 2 6 6 6 6 70 47 6 137 92 6
55016 -175 118 6 200 144 11 219 162 10 230 174 11
55017 -234 174 13 230 174 11 219 162 10 210 150 10
55018 -192 133 9 163 110 8 124 112 88 82 82 82
55019 - 50 50 50 30 30 30 14 14 14 6 6 6
55020 - 0 0 0 0 0 0 0 0 0 0 0 0
55021 - 0 0 0 0 0 0 0 0 0 0 0 0
55022 - 0 0 0 0 0 0 0 0 0 0 0 0
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 - 6 6 6 14 14 14 22 22 22 34 34 34
55026 - 42 42 42 58 58 58 74 74 74 86 86 86
55027 -101 98 89 122 102 70 130 98 46 121 87 25
55028 -137 92 6 152 99 6 163 110 8 180 123 7
55029 -185 133 11 197 138 11 206 145 10 200 144 11
55030 -180 123 7 156 107 11 130 83 6 104 69 6
55031 - 50 34 6 54 54 54 110 110 110 101 98 89
55032 - 86 86 86 82 82 82 78 78 78 78 78 78
55033 - 78 78 78 78 78 78 78 78 78 78 78 78
55034 - 78 78 78 82 82 82 86 86 86 94 94 94
55035 -106 106 106 101 101 101 86 66 34 124 80 6
55036 -156 107 11 180 123 7 192 133 9 200 144 11
55037 -206 145 10 200 144 11 192 133 9 175 118 6
55038 -139 102 15 109 106 95 70 70 70 42 42 42
55039 - 22 22 22 10 10 10 0 0 0 0 0 0
55040 - 0 0 0 0 0 0 0 0 0 0 0 0
55041 - 0 0 0 0 0 0 0 0 0 0 0 0
55042 - 0 0 0 0 0 0 0 0 0 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 6 6 6 10 10 10
55046 - 14 14 14 22 22 22 30 30 30 38 38 38
55047 - 50 50 50 62 62 62 74 74 74 90 90 90
55048 -101 98 89 112 100 78 121 87 25 124 80 6
55049 -137 92 6 152 99 6 152 99 6 152 99 6
55050 -138 86 6 124 80 6 98 70 6 86 66 30
55051 -101 98 89 82 82 82 58 58 58 46 46 46
55052 - 38 38 38 34 34 34 34 34 34 34 34 34
55053 - 34 34 34 34 34 34 34 34 34 34 34 34
55054 - 34 34 34 34 34 34 38 38 38 42 42 42
55055 - 54 54 54 82 82 82 94 86 76 91 60 6
55056 -134 86 6 156 107 11 167 114 7 175 118 6
55057 -175 118 6 167 114 7 152 99 6 121 87 25
55058 -101 98 89 62 62 62 34 34 34 18 18 18
55059 - 6 6 6 0 0 0 0 0 0 0 0 0
55060 - 0 0 0 0 0 0 0 0 0 0 0 0
55061 - 0 0 0 0 0 0 0 0 0 0 0 0
55062 - 0 0 0 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 6 6 6 6 6 6 10 10 10
55067 - 18 18 18 22 22 22 30 30 30 42 42 42
55068 - 50 50 50 66 66 66 86 86 86 101 98 89
55069 -106 86 58 98 70 6 104 69 6 104 69 6
55070 -104 69 6 91 60 6 82 62 34 90 90 90
55071 - 62 62 62 38 38 38 22 22 22 14 14 14
55072 - 10 10 10 10 10 10 10 10 10 10 10 10
55073 - 10 10 10 10 10 10 6 6 6 10 10 10
55074 - 10 10 10 10 10 10 10 10 10 14 14 14
55075 - 22 22 22 42 42 42 70 70 70 89 81 66
55076 - 80 54 7 104 69 6 124 80 6 137 92 6
55077 -134 86 6 116 81 8 100 82 52 86 86 86
55078 - 58 58 58 30 30 30 14 14 14 6 6 6
55079 - 0 0 0 0 0 0 0 0 0 0 0 0
55080 - 0 0 0 0 0 0 0 0 0 0 0 0
55081 - 0 0 0 0 0 0 0 0 0 0 0 0
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 - 0 0 0 6 6 6 10 10 10 14 14 14
55088 - 18 18 18 26 26 26 38 38 38 54 54 54
55089 - 70 70 70 86 86 86 94 86 76 89 81 66
55090 - 89 81 66 86 86 86 74 74 74 50 50 50
55091 - 30 30 30 14 14 14 6 6 6 0 0 0
55092 - 0 0 0 0 0 0 0 0 0 0 0 0
55093 - 0 0 0 0 0 0 0 0 0 0 0 0
55094 - 0 0 0 0 0 0 0 0 0 0 0 0
55095 - 6 6 6 18 18 18 34 34 34 58 58 58
55096 - 82 82 82 89 81 66 89 81 66 89 81 66
55097 - 94 86 66 94 86 76 74 74 74 50 50 50
55098 - 26 26 26 14 14 14 6 6 6 0 0 0
55099 - 0 0 0 0 0 0 0 0 0 0 0 0
55100 - 0 0 0 0 0 0 0 0 0 0 0 0
55101 - 0 0 0 0 0 0 0 0 0 0 0 0
55102 - 0 0 0 0 0 0 0 0 0 0 0 0
55103 - 0 0 0 0 0 0 0 0 0 0 0 0
55104 - 0 0 0 0 0 0 0 0 0 0 0 0
55105 - 0 0 0 0 0 0 0 0 0 0 0 0
55106 - 0 0 0 0 0 0 0 0 0 0 0 0
55107 - 0 0 0 0 0 0 0 0 0 0 0 0
55108 - 6 6 6 6 6 6 14 14 14 18 18 18
55109 - 30 30 30 38 38 38 46 46 46 54 54 54
55110 - 50 50 50 42 42 42 30 30 30 18 18 18
55111 - 10 10 10 0 0 0 0 0 0 0 0 0
55112 - 0 0 0 0 0 0 0 0 0 0 0 0
55113 - 0 0 0 0 0 0 0 0 0 0 0 0
55114 - 0 0 0 0 0 0 0 0 0 0 0 0
55115 - 0 0 0 6 6 6 14 14 14 26 26 26
55116 - 38 38 38 50 50 50 58 58 58 58 58 58
55117 - 54 54 54 42 42 42 30 30 30 18 18 18
55118 - 10 10 10 0 0 0 0 0 0 0 0 0
55119 - 0 0 0 0 0 0 0 0 0 0 0 0
55120 - 0 0 0 0 0 0 0 0 0 0 0 0
55121 - 0 0 0 0 0 0 0 0 0 0 0 0
55122 - 0 0 0 0 0 0 0 0 0 0 0 0
55123 - 0 0 0 0 0 0 0 0 0 0 0 0
55124 - 0 0 0 0 0 0 0 0 0 0 0 0
55125 - 0 0 0 0 0 0 0 0 0 0 0 0
55126 - 0 0 0 0 0 0 0 0 0 0 0 0
55127 - 0 0 0 0 0 0 0 0 0 0 0 0
55128 - 0 0 0 0 0 0 0 0 0 6 6 6
55129 - 6 6 6 10 10 10 14 14 14 18 18 18
55130 - 18 18 18 14 14 14 10 10 10 6 6 6
55131 - 0 0 0 0 0 0 0 0 0 0 0 0
55132 - 0 0 0 0 0 0 0 0 0 0 0 0
55133 - 0 0 0 0 0 0 0 0 0 0 0 0
55134 - 0 0 0 0 0 0 0 0 0 0 0 0
55135 - 0 0 0 0 0 0 0 0 0 6 6 6
55136 - 14 14 14 18 18 18 22 22 22 22 22 22
55137 - 18 18 18 14 14 14 10 10 10 6 6 6
55138 - 0 0 0 0 0 0 0 0 0 0 0 0
55139 - 0 0 0 0 0 0 0 0 0 0 0 0
55140 - 0 0 0 0 0 0 0 0 0 0 0 0
55141 - 0 0 0 0 0 0 0 0 0 0 0 0
55142 - 0 0 0 0 0 0 0 0 0 0 0 0
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 4 4 4 4 4 4 4 4 4
55176 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
55181 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55182 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
55190 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55191 +4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
55195 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55196 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55197 +4 4 4 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 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55204 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55205 +4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
55209 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55210 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55211 +4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
55217 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55218 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55219 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
55222 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55223 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55224 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55225 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55231 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
55232 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
55233 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55234 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55235 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55236 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
55237 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
55238 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
55239 +4 4 4 4 4 4 4 4 4 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 4 4 4
55244 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55245 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
55246 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
55247 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55248 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55249 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55250 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
55251 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
55252 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
55253 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
55258 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55259 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
55260 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
55261 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
55262 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55263 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55264 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
55265 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
55266 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
55267 +2 2 2 2 1 0 4 4 4 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 4 4 4 4 4 4 4 4 4
55272 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
55273 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
55274 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
55275 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
55276 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55277 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
55278 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
55279 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
55280 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
55281 +37 51 59 2 0 0 1 1 1 4 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55286 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
55287 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
55288 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
55289 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
55290 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55291 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
55292 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
55293 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
55294 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
55295 +64 123 161 14 17 19 0 0 0 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 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55300 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
55301 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
55302 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
55303 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
55304 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
55305 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
55306 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
55307 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
55308 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
55309 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 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 4 4 4 4 4 4
55313 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
55314 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
55315 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
55316 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
55317 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
55318 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
55319 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
55320 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
55321 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
55322 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
55323 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55327 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
55328 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
55329 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
55330 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
55331 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
55332 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
55333 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
55334 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
55335 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
55336 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
55337 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
55338 +4 4 4 4 4 4
55339 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55340 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55341 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
55342 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
55343 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
55344 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
55345 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
55346 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
55347 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
55348 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
55349 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
55350 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
55351 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
55352 +4 4 4 4 4 4
55353 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55354 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55355 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
55356 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
55357 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
55358 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
55359 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
55360 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
55361 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
55362 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
55363 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
55364 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
55365 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
55366 +4 4 4 4 4 4
55367 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55368 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
55369 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
55370 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
55371 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
55372 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
55373 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
55374 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
55375 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
55376 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
55377 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
55378 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
55379 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
55380 +4 4 4 4 4 4
55381 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55382 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
55383 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
55384 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
55385 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
55386 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
55387 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
55388 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
55389 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
55390 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
55391 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
55392 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
55393 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
55394 +0 0 0 4 4 4
55395 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
55396 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
55397 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
55398 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
55399 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
55400 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
55401 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
55402 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
55403 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
55404 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
55405 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
55406 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
55407 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
55408 +2 0 0 0 0 0
55409 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
55410 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
55411 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
55412 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
55413 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
55414 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
55415 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
55416 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
55417 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
55418 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
55419 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
55420 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
55421 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
55422 +37 38 37 0 0 0
55423 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
55424 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
55425 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
55426 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
55427 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
55428 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
55429 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
55430 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
55431 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
55432 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
55433 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
55434 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
55435 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
55436 +85 115 134 4 0 0
55437 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
55438 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
55439 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
55440 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
55441 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
55442 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
55443 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
55444 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
55445 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
55446 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
55447 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
55448 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
55449 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
55450 +60 73 81 4 0 0
55451 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
55452 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
55453 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
55454 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
55455 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
55456 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
55457 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
55458 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
55459 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
55460 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
55461 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
55462 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
55463 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
55464 +16 19 21 4 0 0
55465 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
55466 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
55467 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
55468 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
55469 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
55470 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
55471 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
55472 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
55473 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
55474 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
55475 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
55476 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
55477 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
55478 +4 0 0 4 3 3
55479 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
55480 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
55481 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
55482 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
55483 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
55484 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
55485 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
55486 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
55487 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
55488 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
55489 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
55490 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
55491 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
55492 +3 2 2 4 4 4
55493 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
55494 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
55495 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
55496 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
55497 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
55498 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
55499 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
55500 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
55501 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
55502 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
55503 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
55504 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
55505 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
55506 +4 4 4 4 4 4
55507 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
55508 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
55509 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
55510 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
55511 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
55512 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
55513 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
55514 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
55515 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
55516 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
55517 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
55518 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
55519 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
55520 +4 4 4 4 4 4
55521 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
55522 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
55523 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
55524 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
55525 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
55526 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
55527 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
55528 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
55529 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
55530 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
55531 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
55532 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
55533 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
55534 +5 5 5 5 5 5
55535 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
55536 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
55537 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
55538 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
55539 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
55540 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55541 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
55542 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
55543 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
55544 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
55545 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
55546 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
55547 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
55548 +5 5 5 4 4 4
55549 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
55550 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
55551 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
55552 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
55553 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55554 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
55555 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
55556 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
55557 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
55558 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
55559 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
55560 +4 0 0 4 0 0 5 5 5 5 5 5 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 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
55564 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
55565 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
55566 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
55567 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
55568 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55569 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55570 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
55571 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
55572 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
55573 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
55574 +3 3 3 5 5 5 6 6 6 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 137 136 137 153 152 153 137 136 137
55578 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
55579 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
55580 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
55581 +90 154 193 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 101 161 196 90 154 193 136 185 209
55583 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
55584 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
55585 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
55586 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
55587 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 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 41 54 63 157 156 157 155 154 155 137 136 137
55592 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
55593 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
55594 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
55595 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55596 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55597 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55598 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
55599 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
55600 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
55601 +6 6 6 4 0 0 4 0 0 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 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
55606 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
55607 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
55608 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
55609 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55610 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
55611 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
55612 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
55613 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
55614 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 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 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
55620 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
55621 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
55622 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
55623 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55624 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
55625 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
55626 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
55627 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
55628 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
55629 +6 6 6 4 0 0 6 6 6 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 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
55634 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
55635 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
55636 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
55637 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55638 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
55639 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
55640 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
55641 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
55642 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
55643 +4 0 0 3 2 2 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 165 164 165 174 174 174 158 157 158
55648 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
55649 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
55650 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
55651 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
55652 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
55653 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
55654 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
55655 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
55656 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
55657 +4 0 0 4 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 167 166 167 174 174 174 163 162 163
55662 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
55663 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
55664 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
55665 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55666 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
55667 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
55668 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
55669 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
55670 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
55671 +4 0 0 4 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 167 166 167 174 174 174 166 165 166
55676 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
55677 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
55678 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
55679 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55680 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
55681 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
55682 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
55683 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
55684 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
55685 +4 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 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
55690 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
55691 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
55692 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
55693 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55694 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
55695 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
55696 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
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 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
55704 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
55705 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
55706 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
55707 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
55708 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
55709 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
55710 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
55711 +4 5 5 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 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
55718 +174 174 174 190 197 201 158 157 158 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 18 97 151
55720 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
55721 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55722 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
55723 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
55724 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
55725 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
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 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
55732 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
55733 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
55734 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
55735 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
55736 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
55737 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
55738 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 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 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
55746 +177 184 187 193 200 203 163 162 163 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 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
55749 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
55750 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
55751 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
55752 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
55753 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
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 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
55760 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
55761 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
55762 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
55763 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
55764 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
55765 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
55766 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
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 193 200 203 174 174 174
55774 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
55775 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55776 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
55777 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
55778 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
55779 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
55780 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
55781 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
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 193 200 203 193 200 203 174 174 174
55788 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
55789 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
55790 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
55791 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
55792 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
55793 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
55794 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
55795 +4 4 4 5 5 5 3 3 3 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 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
55803 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55804 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
55805 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
55806 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
55807 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
55808 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
55809 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
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 190 197 201 174 174 174
55816 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
55817 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
55818 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
55819 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
55820 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
55821 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55822 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
55823 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55824 +137 136 137 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 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
55831 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
55832 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
55833 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
55834 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
55835 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55836 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
55837 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55838 +137 136 137 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 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
55844 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
55845 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
55846 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
55847 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
55848 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
55849 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
55850 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
55851 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
55852 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
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 60 73 81 174 174 174 220 221 221 174 174 174
55858 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
55859 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
55860 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
55861 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
55862 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
55863 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
55864 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
55865 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
55866 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55867 +0 0 0 3 3 3 5 5 5 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 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
55872 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
55873 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
55874 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
55875 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
55876 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
55877 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
55878 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
55879 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
55880 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55881 +0 0 0 3 3 3 5 5 5 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 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55886 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
55887 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
55888 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
55889 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
55890 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
55891 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
55892 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
55893 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
55894 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55895 +0 0 0 3 3 3 5 5 5 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 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
55900 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
55901 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
55902 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
55903 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
55904 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
55905 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
55906 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
55907 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
55908 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
55909 +0 0 0 3 3 3 5 5 5 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 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
55914 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
55915 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
55916 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
55917 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
55918 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
55919 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
55920 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
55921 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
55922 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
55923 +0 0 0 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 0 0 4 0 0 60 73 81 193 200 203 220 221 221
55928 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
55929 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
55930 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
55931 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
55932 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
55933 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55934 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
55935 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
55936 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
55937 +4 3 3 5 5 5 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 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
55942 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
55943 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
55944 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
55945 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
55946 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
55947 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
55948 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
55949 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
55950 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
55951 +5 5 5 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 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
55956 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
55957 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
55958 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
55959 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
55960 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
55961 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
55962 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
55963 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
55964 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
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 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55970 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
55971 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
55972 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
55973 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
55974 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
55975 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
55976 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
55977 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
55978 +13 16 17 4 0 0 4 0 0 4 3 3 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 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
55984 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
55985 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
55986 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
55987 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
55988 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
55989 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
55990 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
55991 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
55992 +4 0 0 4 0 0 5 5 5 5 5 5 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 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
55998 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
55999 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
56000 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
56001 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
56002 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
56003 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
56004 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
56005 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
56006 +4 3 3 5 5 5 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 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
56012 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
56013 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
56014 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
56015 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
56016 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
56017 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
56018 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
56019 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
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 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
56026 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
56027 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
56028 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
56029 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
56030 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
56031 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
56032 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
56033 +4 0 0 4 0 0 4 0 0 6 6 6 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 5 5 5 4 3 3 5 5 5 6 6 6
56040 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
56041 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
56042 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
56043 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
56044 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
56045 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
56046 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
56047 +4 0 0 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 5 5 5 5 5 5 4 3 3 6 6 6
56054 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
56055 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
56056 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
56057 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
56058 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
56059 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
56060 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
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 5 5 5 4 3 3
56068 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
56069 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
56070 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
56071 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
56072 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
56073 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
56074 +6 6 6 4 0 0 4 0 0 4 3 3 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 5 5 5
56082 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
56083 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
56084 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
56085 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
56086 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
56087 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
56088 +4 0 0 4 3 3 6 6 6 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 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
56097 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
56098 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
56099 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
56100 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
56101 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
56102 +6 6 6 6 6 6 4 3 3 5 5 5 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 5 5 5 5 5 5 5 5 5
56111 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
56112 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
56113 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
56114 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
56115 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
56116 +5 5 5 5 5 5 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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
56126 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
56127 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
56128 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
56129 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
56130 +4 3 3 5 5 5 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 5 5 5
56140 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
56141 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
56142 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
56143 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
56155 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
56156 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
56157 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
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 5 5 5 4 3 3 5 5 5 6 6 6
56169 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
56170 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
56171 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 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 5 5 5 4 3 3 5 5 5
56183 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
56184 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
56185 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 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 5 5 5
56197 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
56198 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
56199 +6 6 6 4 3 3 5 5 5 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 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56208 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56209 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56210 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56211 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
56212 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
56213 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
56214 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56215 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56216 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56217 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56218 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56219 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56220 +4 4 4 4 4 4
56221 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56222 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56223 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56224 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56225 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
56226 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
56227 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56228 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56229 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56230 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56231 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56232 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56233 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56234 +4 4 4 4 4 4
56235 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56236 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56237 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56238 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56239 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
56240 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
56241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56242 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56243 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56244 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56246 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56247 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56248 +4 4 4 4 4 4
56249 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56250 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56251 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56252 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56253 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
56254 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
56255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56256 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56257 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56258 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56259 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56260 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56261 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56262 +4 4 4 4 4 4
56263 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
56264 index fef20db..d28b1ab 100644
56265 --- a/drivers/xen/xenfs/xenstored.c
56266 +++ b/drivers/xen/xenfs/xenstored.c
56267 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
56268 static int xsd_kva_open(struct inode *inode, struct file *file)
56269 {
56270 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
56271 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56272 + NULL);
56273 +#else
56274 xen_store_interface);
56275 +#endif
56276 +
56277 if (!file->private_data)
56278 return -ENOMEM;
56279 return 0;
56280 diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
56281 index c71e886..61d3d44b 100644
56282 --- a/fs/9p/vfs_addr.c
56283 +++ b/fs/9p/vfs_addr.c
56284 @@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
56285
56286 retval = v9fs_file_write_internal(inode,
56287 v9inode->writeback_fid,
56288 - (__force const char __user *)buffer,
56289 + (const char __force_user *)buffer,
56290 len, &offset, 0);
56291 if (retval > 0)
56292 retval = 0;
56293 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
56294 index 53161ec..e261d8a 100644
56295 --- a/fs/9p/vfs_inode.c
56296 +++ b/fs/9p/vfs_inode.c
56297 @@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
56298 void
56299 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
56300 {
56301 - char *s = nd_get_link(nd);
56302 + const char *s = nd_get_link(nd);
56303
56304 p9_debug(P9_DEBUG_VFS, " %s %s\n",
56305 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
56306 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
56307 index 370b24c..ff0be7b 100644
56308 --- a/fs/Kconfig.binfmt
56309 +++ b/fs/Kconfig.binfmt
56310 @@ -103,7 +103,7 @@ config HAVE_AOUT
56311
56312 config BINFMT_AOUT
56313 tristate "Kernel support for a.out and ECOFF binaries"
56314 - depends on HAVE_AOUT
56315 + depends on HAVE_AOUT && BROKEN
56316 ---help---
56317 A.out (Assembler.OUTput) is a set of formats for libraries and
56318 executables used in the earliest versions of UNIX. Linux used
56319 diff --git a/fs/afs/inode.c b/fs/afs/inode.c
56320 index 2946712..f737435 100644
56321 --- a/fs/afs/inode.c
56322 +++ b/fs/afs/inode.c
56323 @@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
56324 struct afs_vnode *vnode;
56325 struct super_block *sb;
56326 struct inode *inode;
56327 - static atomic_t afs_autocell_ino;
56328 + static atomic_unchecked_t afs_autocell_ino;
56329
56330 _enter("{%x:%u},%*.*s,",
56331 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
56332 @@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
56333 data.fid.unique = 0;
56334 data.fid.vnode = 0;
56335
56336 - inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
56337 + inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
56338 afs_iget5_autocell_test, afs_iget5_set,
56339 &data);
56340 if (!inode) {
56341 diff --git a/fs/aio.c b/fs/aio.c
56342 index 6d68e01..573d8dc 100644
56343 --- a/fs/aio.c
56344 +++ b/fs/aio.c
56345 @@ -380,7 +380,7 @@ static int aio_setup_ring(struct kioctx *ctx)
56346 size += sizeof(struct io_event) * nr_events;
56347
56348 nr_pages = PFN_UP(size);
56349 - if (nr_pages < 0)
56350 + if (nr_pages <= 0)
56351 return -EINVAL;
56352
56353 file = aio_private_file(ctx, nr_pages);
56354 diff --git a/fs/attr.c b/fs/attr.c
56355 index 6530ced..4a827e2 100644
56356 --- a/fs/attr.c
56357 +++ b/fs/attr.c
56358 @@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
56359 unsigned long limit;
56360
56361 limit = rlimit(RLIMIT_FSIZE);
56362 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
56363 if (limit != RLIM_INFINITY && offset > limit)
56364 goto out_sig;
56365 if (offset > inode->i_sb->s_maxbytes)
56366 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
56367 index 116fd38..c04182da 100644
56368 --- a/fs/autofs4/waitq.c
56369 +++ b/fs/autofs4/waitq.c
56370 @@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
56371 {
56372 unsigned long sigpipe, flags;
56373 mm_segment_t fs;
56374 - const char *data = (const char *)addr;
56375 + const char __user *data = (const char __force_user *)addr;
56376 ssize_t wr = 0;
56377
56378 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
56379 @@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
56380 return 1;
56381 }
56382
56383 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56384 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
56385 +#endif
56386 +
56387 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
56388 enum autofs_notify notify)
56389 {
56390 @@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
56391
56392 /* If this is a direct mount request create a dummy name */
56393 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
56394 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56395 + /* this name does get written to userland via autofs4_write() */
56396 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
56397 +#else
56398 qstr.len = sprintf(name, "%p", dentry);
56399 +#endif
56400 else {
56401 qstr.len = autofs4_getpath(sbi, dentry, &name);
56402 if (!qstr.len) {
56403 diff --git a/fs/befs/endian.h b/fs/befs/endian.h
56404 index 2722387..56059b5 100644
56405 --- a/fs/befs/endian.h
56406 +++ b/fs/befs/endian.h
56407 @@ -11,7 +11,7 @@
56408
56409 #include <asm/byteorder.h>
56410
56411 -static inline u64
56412 +static inline u64 __intentional_overflow(-1)
56413 fs64_to_cpu(const struct super_block *sb, fs64 n)
56414 {
56415 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56416 @@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
56417 return (__force fs64)cpu_to_be64(n);
56418 }
56419
56420 -static inline u32
56421 +static inline u32 __intentional_overflow(-1)
56422 fs32_to_cpu(const struct super_block *sb, fs32 n)
56423 {
56424 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56425 @@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
56426 return (__force fs32)cpu_to_be32(n);
56427 }
56428
56429 -static inline u16
56430 +static inline u16 __intentional_overflow(-1)
56431 fs16_to_cpu(const struct super_block *sb, fs16 n)
56432 {
56433 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56434 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
56435 index ca0ba15..0fa3257 100644
56436 --- a/fs/binfmt_aout.c
56437 +++ b/fs/binfmt_aout.c
56438 @@ -16,6 +16,7 @@
56439 #include <linux/string.h>
56440 #include <linux/fs.h>
56441 #include <linux/file.h>
56442 +#include <linux/security.h>
56443 #include <linux/stat.h>
56444 #include <linux/fcntl.h>
56445 #include <linux/ptrace.h>
56446 @@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
56447 #endif
56448 # define START_STACK(u) ((void __user *)u.start_stack)
56449
56450 + memset(&dump, 0, sizeof(dump));
56451 +
56452 fs = get_fs();
56453 set_fs(KERNEL_DS);
56454 has_dumped = 1;
56455 @@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
56456
56457 /* If the size of the dump file exceeds the rlimit, then see what would happen
56458 if we wrote the stack, but not the data area. */
56459 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
56460 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
56461 dump.u_dsize = 0;
56462
56463 /* Make sure we have enough room to write the stack and data areas. */
56464 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
56465 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
56466 dump.u_ssize = 0;
56467
56468 @@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
56469 rlim = rlimit(RLIMIT_DATA);
56470 if (rlim >= RLIM_INFINITY)
56471 rlim = ~0;
56472 +
56473 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
56474 if (ex.a_data + ex.a_bss > rlim)
56475 return -ENOMEM;
56476
56477 @@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
56478
56479 install_exec_creds(bprm);
56480
56481 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56482 + current->mm->pax_flags = 0UL;
56483 +#endif
56484 +
56485 +#ifdef CONFIG_PAX_PAGEEXEC
56486 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
56487 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
56488 +
56489 +#ifdef CONFIG_PAX_EMUTRAMP
56490 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
56491 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
56492 +#endif
56493 +
56494 +#ifdef CONFIG_PAX_MPROTECT
56495 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
56496 + current->mm->pax_flags |= MF_PAX_MPROTECT;
56497 +#endif
56498 +
56499 + }
56500 +#endif
56501 +
56502 if (N_MAGIC(ex) == OMAGIC) {
56503 unsigned long text_addr, map_size;
56504 loff_t pos;
56505 @@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
56506 }
56507
56508 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
56509 - PROT_READ | PROT_WRITE | PROT_EXEC,
56510 + PROT_READ | PROT_WRITE,
56511 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
56512 fd_offset + ex.a_text);
56513 if (error != N_DATADDR(ex)) {
56514 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
56515 index aa3cb62..bc53934 100644
56516 --- a/fs/binfmt_elf.c
56517 +++ b/fs/binfmt_elf.c
56518 @@ -34,6 +34,7 @@
56519 #include <linux/utsname.h>
56520 #include <linux/coredump.h>
56521 #include <linux/sched.h>
56522 +#include <linux/xattr.h>
56523 #include <asm/uaccess.h>
56524 #include <asm/param.h>
56525 #include <asm/page.h>
56526 @@ -47,7 +48,7 @@
56527
56528 static int load_elf_binary(struct linux_binprm *bprm);
56529 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
56530 - int, int, unsigned long);
56531 + int, int, unsigned long) __intentional_overflow(-1);
56532
56533 #ifdef CONFIG_USELIB
56534 static int load_elf_library(struct file *);
56535 @@ -65,6 +66,14 @@ static int elf_core_dump(struct coredump_params *cprm);
56536 #define elf_core_dump NULL
56537 #endif
56538
56539 +#ifdef CONFIG_PAX_MPROTECT
56540 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
56541 +#endif
56542 +
56543 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56544 +static void elf_handle_mmap(struct file *file);
56545 +#endif
56546 +
56547 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
56548 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
56549 #else
56550 @@ -84,6 +93,15 @@ static struct linux_binfmt elf_format = {
56551 .load_binary = load_elf_binary,
56552 .load_shlib = load_elf_library,
56553 .core_dump = elf_core_dump,
56554 +
56555 +#ifdef CONFIG_PAX_MPROTECT
56556 + .handle_mprotect= elf_handle_mprotect,
56557 +#endif
56558 +
56559 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56560 + .handle_mmap = elf_handle_mmap,
56561 +#endif
56562 +
56563 .min_coredump = ELF_EXEC_PAGESIZE,
56564 };
56565
56566 @@ -91,6 +109,8 @@ static struct linux_binfmt elf_format = {
56567
56568 static int set_brk(unsigned long start, unsigned long end)
56569 {
56570 + unsigned long e = end;
56571 +
56572 start = ELF_PAGEALIGN(start);
56573 end = ELF_PAGEALIGN(end);
56574 if (end > start) {
56575 @@ -99,7 +119,7 @@ static int set_brk(unsigned long start, unsigned long end)
56576 if (BAD_ADDR(addr))
56577 return addr;
56578 }
56579 - current->mm->start_brk = current->mm->brk = end;
56580 + current->mm->start_brk = current->mm->brk = e;
56581 return 0;
56582 }
56583
56584 @@ -160,12 +180,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56585 elf_addr_t __user *u_rand_bytes;
56586 const char *k_platform = ELF_PLATFORM;
56587 const char *k_base_platform = ELF_BASE_PLATFORM;
56588 - unsigned char k_rand_bytes[16];
56589 + u32 k_rand_bytes[4];
56590 int items;
56591 elf_addr_t *elf_info;
56592 int ei_index = 0;
56593 const struct cred *cred = current_cred();
56594 struct vm_area_struct *vma;
56595 + unsigned long saved_auxv[AT_VECTOR_SIZE];
56596
56597 /*
56598 * In some cases (e.g. Hyper-Threading), we want to avoid L1
56599 @@ -207,8 +228,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56600 * Generate 16 random bytes for userspace PRNG seeding.
56601 */
56602 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
56603 - u_rand_bytes = (elf_addr_t __user *)
56604 - STACK_ALLOC(p, sizeof(k_rand_bytes));
56605 + prandom_seed(k_rand_bytes[0] ^ prandom_u32());
56606 + prandom_seed(k_rand_bytes[1] ^ prandom_u32());
56607 + prandom_seed(k_rand_bytes[2] ^ prandom_u32());
56608 + prandom_seed(k_rand_bytes[3] ^ prandom_u32());
56609 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
56610 + u_rand_bytes = (elf_addr_t __user *) p;
56611 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
56612 return -EFAULT;
56613
56614 @@ -323,9 +348,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56615 return -EFAULT;
56616 current->mm->env_end = p;
56617
56618 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
56619 +
56620 /* Put the elf_info on the stack in the right place. */
56621 sp = (elf_addr_t __user *)envp + 1;
56622 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
56623 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
56624 return -EFAULT;
56625 return 0;
56626 }
56627 @@ -393,15 +420,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
56628 an ELF header */
56629
56630 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56631 - struct file *interpreter, unsigned long *interp_map_addr,
56632 - unsigned long no_base)
56633 + struct file *interpreter, unsigned long no_base)
56634 {
56635 struct elf_phdr *elf_phdata;
56636 struct elf_phdr *eppnt;
56637 - unsigned long load_addr = 0;
56638 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
56639 int load_addr_set = 0;
56640 unsigned long last_bss = 0, elf_bss = 0;
56641 - unsigned long error = ~0UL;
56642 + unsigned long error = -EINVAL;
56643 unsigned long total_size;
56644 int retval, i, size;
56645
56646 @@ -447,6 +473,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56647 goto out_close;
56648 }
56649
56650 +#ifdef CONFIG_PAX_SEGMEXEC
56651 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
56652 + pax_task_size = SEGMEXEC_TASK_SIZE;
56653 +#endif
56654 +
56655 eppnt = elf_phdata;
56656 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
56657 if (eppnt->p_type == PT_LOAD) {
56658 @@ -470,8 +501,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56659 map_addr = elf_map(interpreter, load_addr + vaddr,
56660 eppnt, elf_prot, elf_type, total_size);
56661 total_size = 0;
56662 - if (!*interp_map_addr)
56663 - *interp_map_addr = map_addr;
56664 error = map_addr;
56665 if (BAD_ADDR(map_addr))
56666 goto out_close;
56667 @@ -490,8 +519,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56668 k = load_addr + eppnt->p_vaddr;
56669 if (BAD_ADDR(k) ||
56670 eppnt->p_filesz > eppnt->p_memsz ||
56671 - eppnt->p_memsz > TASK_SIZE ||
56672 - TASK_SIZE - eppnt->p_memsz < k) {
56673 + eppnt->p_memsz > pax_task_size ||
56674 + pax_task_size - eppnt->p_memsz < k) {
56675 error = -ENOMEM;
56676 goto out_close;
56677 }
56678 @@ -530,9 +559,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56679 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
56680
56681 /* Map the last of the bss segment */
56682 - error = vm_brk(elf_bss, last_bss - elf_bss);
56683 - if (BAD_ADDR(error))
56684 - goto out_close;
56685 + if (last_bss > elf_bss) {
56686 + error = vm_brk(elf_bss, last_bss - elf_bss);
56687 + if (BAD_ADDR(error))
56688 + goto out_close;
56689 + }
56690 }
56691
56692 error = load_addr;
56693 @@ -543,6 +574,336 @@ out:
56694 return error;
56695 }
56696
56697 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
56698 +#ifdef CONFIG_PAX_SOFTMODE
56699 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
56700 +{
56701 + unsigned long pax_flags = 0UL;
56702 +
56703 +#ifdef CONFIG_PAX_PAGEEXEC
56704 + if (elf_phdata->p_flags & PF_PAGEEXEC)
56705 + pax_flags |= MF_PAX_PAGEEXEC;
56706 +#endif
56707 +
56708 +#ifdef CONFIG_PAX_SEGMEXEC
56709 + if (elf_phdata->p_flags & PF_SEGMEXEC)
56710 + pax_flags |= MF_PAX_SEGMEXEC;
56711 +#endif
56712 +
56713 +#ifdef CONFIG_PAX_EMUTRAMP
56714 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56715 + pax_flags |= MF_PAX_EMUTRAMP;
56716 +#endif
56717 +
56718 +#ifdef CONFIG_PAX_MPROTECT
56719 + if (elf_phdata->p_flags & PF_MPROTECT)
56720 + pax_flags |= MF_PAX_MPROTECT;
56721 +#endif
56722 +
56723 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56724 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
56725 + pax_flags |= MF_PAX_RANDMMAP;
56726 +#endif
56727 +
56728 + return pax_flags;
56729 +}
56730 +#endif
56731 +
56732 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
56733 +{
56734 + unsigned long pax_flags = 0UL;
56735 +
56736 +#ifdef CONFIG_PAX_PAGEEXEC
56737 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
56738 + pax_flags |= MF_PAX_PAGEEXEC;
56739 +#endif
56740 +
56741 +#ifdef CONFIG_PAX_SEGMEXEC
56742 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
56743 + pax_flags |= MF_PAX_SEGMEXEC;
56744 +#endif
56745 +
56746 +#ifdef CONFIG_PAX_EMUTRAMP
56747 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
56748 + pax_flags |= MF_PAX_EMUTRAMP;
56749 +#endif
56750 +
56751 +#ifdef CONFIG_PAX_MPROTECT
56752 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
56753 + pax_flags |= MF_PAX_MPROTECT;
56754 +#endif
56755 +
56756 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56757 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
56758 + pax_flags |= MF_PAX_RANDMMAP;
56759 +#endif
56760 +
56761 + return pax_flags;
56762 +}
56763 +#endif
56764 +
56765 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56766 +#ifdef CONFIG_PAX_SOFTMODE
56767 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
56768 +{
56769 + unsigned long pax_flags = 0UL;
56770 +
56771 +#ifdef CONFIG_PAX_PAGEEXEC
56772 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
56773 + pax_flags |= MF_PAX_PAGEEXEC;
56774 +#endif
56775 +
56776 +#ifdef CONFIG_PAX_SEGMEXEC
56777 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
56778 + pax_flags |= MF_PAX_SEGMEXEC;
56779 +#endif
56780 +
56781 +#ifdef CONFIG_PAX_EMUTRAMP
56782 + if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56783 + pax_flags |= MF_PAX_EMUTRAMP;
56784 +#endif
56785 +
56786 +#ifdef CONFIG_PAX_MPROTECT
56787 + if (pax_flags_softmode & MF_PAX_MPROTECT)
56788 + pax_flags |= MF_PAX_MPROTECT;
56789 +#endif
56790 +
56791 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56792 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
56793 + pax_flags |= MF_PAX_RANDMMAP;
56794 +#endif
56795 +
56796 + return pax_flags;
56797 +}
56798 +#endif
56799 +
56800 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
56801 +{
56802 + unsigned long pax_flags = 0UL;
56803 +
56804 +#ifdef CONFIG_PAX_PAGEEXEC
56805 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
56806 + pax_flags |= MF_PAX_PAGEEXEC;
56807 +#endif
56808 +
56809 +#ifdef CONFIG_PAX_SEGMEXEC
56810 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
56811 + pax_flags |= MF_PAX_SEGMEXEC;
56812 +#endif
56813 +
56814 +#ifdef CONFIG_PAX_EMUTRAMP
56815 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
56816 + pax_flags |= MF_PAX_EMUTRAMP;
56817 +#endif
56818 +
56819 +#ifdef CONFIG_PAX_MPROTECT
56820 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
56821 + pax_flags |= MF_PAX_MPROTECT;
56822 +#endif
56823 +
56824 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56825 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
56826 + pax_flags |= MF_PAX_RANDMMAP;
56827 +#endif
56828 +
56829 + return pax_flags;
56830 +}
56831 +#endif
56832 +
56833 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56834 +static unsigned long pax_parse_defaults(void)
56835 +{
56836 + unsigned long pax_flags = 0UL;
56837 +
56838 +#ifdef CONFIG_PAX_SOFTMODE
56839 + if (pax_softmode)
56840 + return pax_flags;
56841 +#endif
56842 +
56843 +#ifdef CONFIG_PAX_PAGEEXEC
56844 + pax_flags |= MF_PAX_PAGEEXEC;
56845 +#endif
56846 +
56847 +#ifdef CONFIG_PAX_SEGMEXEC
56848 + pax_flags |= MF_PAX_SEGMEXEC;
56849 +#endif
56850 +
56851 +#ifdef CONFIG_PAX_MPROTECT
56852 + pax_flags |= MF_PAX_MPROTECT;
56853 +#endif
56854 +
56855 +#ifdef CONFIG_PAX_RANDMMAP
56856 + if (randomize_va_space)
56857 + pax_flags |= MF_PAX_RANDMMAP;
56858 +#endif
56859 +
56860 + return pax_flags;
56861 +}
56862 +
56863 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
56864 +{
56865 + unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
56866 +
56867 +#ifdef CONFIG_PAX_EI_PAX
56868 +
56869 +#ifdef CONFIG_PAX_SOFTMODE
56870 + if (pax_softmode)
56871 + return pax_flags;
56872 +#endif
56873 +
56874 + pax_flags = 0UL;
56875 +
56876 +#ifdef CONFIG_PAX_PAGEEXEC
56877 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
56878 + pax_flags |= MF_PAX_PAGEEXEC;
56879 +#endif
56880 +
56881 +#ifdef CONFIG_PAX_SEGMEXEC
56882 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
56883 + pax_flags |= MF_PAX_SEGMEXEC;
56884 +#endif
56885 +
56886 +#ifdef CONFIG_PAX_EMUTRAMP
56887 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
56888 + pax_flags |= MF_PAX_EMUTRAMP;
56889 +#endif
56890 +
56891 +#ifdef CONFIG_PAX_MPROTECT
56892 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
56893 + pax_flags |= MF_PAX_MPROTECT;
56894 +#endif
56895 +
56896 +#ifdef CONFIG_PAX_ASLR
56897 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
56898 + pax_flags |= MF_PAX_RANDMMAP;
56899 +#endif
56900 +
56901 +#endif
56902 +
56903 + return pax_flags;
56904 +
56905 +}
56906 +
56907 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
56908 +{
56909 +
56910 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
56911 + unsigned long i;
56912 +
56913 + for (i = 0UL; i < elf_ex->e_phnum; i++)
56914 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
56915 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
56916 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
56917 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
56918 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
56919 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
56920 + return PAX_PARSE_FLAGS_FALLBACK;
56921 +
56922 +#ifdef CONFIG_PAX_SOFTMODE
56923 + if (pax_softmode)
56924 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
56925 + else
56926 +#endif
56927 +
56928 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
56929 + break;
56930 + }
56931 +#endif
56932 +
56933 + return PAX_PARSE_FLAGS_FALLBACK;
56934 +}
56935 +
56936 +static unsigned long pax_parse_xattr_pax(struct file * const file)
56937 +{
56938 +
56939 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56940 + ssize_t xattr_size, i;
56941 + unsigned char xattr_value[sizeof("pemrs") - 1];
56942 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
56943 +
56944 + xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
56945 + if (xattr_size < 0 || xattr_size > sizeof xattr_value)
56946 + return PAX_PARSE_FLAGS_FALLBACK;
56947 +
56948 + for (i = 0; i < xattr_size; i++)
56949 + switch (xattr_value[i]) {
56950 + default:
56951 + return PAX_PARSE_FLAGS_FALLBACK;
56952 +
56953 +#define parse_flag(option1, option2, flag) \
56954 + case option1: \
56955 + if (pax_flags_hardmode & MF_PAX_##flag) \
56956 + return PAX_PARSE_FLAGS_FALLBACK;\
56957 + pax_flags_hardmode |= MF_PAX_##flag; \
56958 + break; \
56959 + case option2: \
56960 + if (pax_flags_softmode & MF_PAX_##flag) \
56961 + return PAX_PARSE_FLAGS_FALLBACK;\
56962 + pax_flags_softmode |= MF_PAX_##flag; \
56963 + break;
56964 +
56965 + parse_flag('p', 'P', PAGEEXEC);
56966 + parse_flag('e', 'E', EMUTRAMP);
56967 + parse_flag('m', 'M', MPROTECT);
56968 + parse_flag('r', 'R', RANDMMAP);
56969 + parse_flag('s', 'S', SEGMEXEC);
56970 +
56971 +#undef parse_flag
56972 + }
56973 +
56974 + if (pax_flags_hardmode & pax_flags_softmode)
56975 + return PAX_PARSE_FLAGS_FALLBACK;
56976 +
56977 +#ifdef CONFIG_PAX_SOFTMODE
56978 + if (pax_softmode)
56979 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
56980 + else
56981 +#endif
56982 +
56983 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
56984 +#else
56985 + return PAX_PARSE_FLAGS_FALLBACK;
56986 +#endif
56987 +
56988 +}
56989 +
56990 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
56991 +{
56992 + unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
56993 +
56994 + pax_flags = pax_parse_defaults();
56995 + ei_pax_flags = pax_parse_ei_pax(elf_ex);
56996 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
56997 + xattr_pax_flags = pax_parse_xattr_pax(file);
56998 +
56999 + if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
57000 + xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
57001 + pt_pax_flags != xattr_pax_flags)
57002 + return -EINVAL;
57003 + if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
57004 + pax_flags = xattr_pax_flags;
57005 + else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
57006 + pax_flags = pt_pax_flags;
57007 + else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
57008 + pax_flags = ei_pax_flags;
57009 +
57010 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
57011 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57012 + if ((__supported_pte_mask & _PAGE_NX))
57013 + pax_flags &= ~MF_PAX_SEGMEXEC;
57014 + else
57015 + pax_flags &= ~MF_PAX_PAGEEXEC;
57016 + }
57017 +#endif
57018 +
57019 + if (0 > pax_check_flags(&pax_flags))
57020 + return -EINVAL;
57021 +
57022 + current->mm->pax_flags = pax_flags;
57023 + return 0;
57024 +}
57025 +#endif
57026 +
57027 /*
57028 * These are the functions used to load ELF style executables and shared
57029 * libraries. There is no binary dependent code anywhere else.
57030 @@ -556,6 +917,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
57031 {
57032 unsigned int random_variable = 0;
57033
57034 +#ifdef CONFIG_PAX_RANDUSTACK
57035 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
57036 + return stack_top - current->mm->delta_stack;
57037 +#endif
57038 +
57039 if ((current->flags & PF_RANDOMIZE) &&
57040 !(current->personality & ADDR_NO_RANDOMIZE)) {
57041 random_variable = get_random_int() & STACK_RND_MASK;
57042 @@ -574,7 +940,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
57043 unsigned long load_addr = 0, load_bias = 0;
57044 int load_addr_set = 0;
57045 char * elf_interpreter = NULL;
57046 - unsigned long error;
57047 + unsigned long error = 0;
57048 struct elf_phdr *elf_ppnt, *elf_phdata;
57049 unsigned long elf_bss, elf_brk;
57050 int retval, i;
57051 @@ -589,6 +955,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
57052 struct elfhdr elf_ex;
57053 struct elfhdr interp_elf_ex;
57054 } *loc;
57055 + unsigned long pax_task_size;
57056
57057 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
57058 if (!loc) {
57059 @@ -726,6 +1093,77 @@ static int load_elf_binary(struct linux_binprm *bprm)
57060 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
57061 may depend on the personality. */
57062 SET_PERSONALITY(loc->elf_ex);
57063 +
57064 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
57065 + current->mm->pax_flags = 0UL;
57066 +#endif
57067 +
57068 +#ifdef CONFIG_PAX_DLRESOLVE
57069 + current->mm->call_dl_resolve = 0UL;
57070 +#endif
57071 +
57072 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
57073 + current->mm->call_syscall = 0UL;
57074 +#endif
57075 +
57076 +#ifdef CONFIG_PAX_ASLR
57077 + current->mm->delta_mmap = 0UL;
57078 + current->mm->delta_stack = 0UL;
57079 +#endif
57080 +
57081 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
57082 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
57083 + send_sig(SIGKILL, current, 0);
57084 + goto out_free_dentry;
57085 + }
57086 +#endif
57087 +
57088 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57089 + pax_set_initial_flags(bprm);
57090 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
57091 + if (pax_set_initial_flags_func)
57092 + (pax_set_initial_flags_func)(bprm);
57093 +#endif
57094 +
57095 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
57096 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
57097 + current->mm->context.user_cs_limit = PAGE_SIZE;
57098 + current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
57099 + }
57100 +#endif
57101 +
57102 +#ifdef CONFIG_PAX_SEGMEXEC
57103 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
57104 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
57105 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
57106 + pax_task_size = SEGMEXEC_TASK_SIZE;
57107 + current->mm->def_flags |= VM_NOHUGEPAGE;
57108 + } else
57109 +#endif
57110 +
57111 + pax_task_size = TASK_SIZE;
57112 +
57113 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
57114 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57115 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
57116 + put_cpu();
57117 + }
57118 +#endif
57119 +
57120 +#ifdef CONFIG_PAX_ASLR
57121 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
57122 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
57123 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
57124 + }
57125 +#endif
57126 +
57127 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
57128 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57129 + executable_stack = EXSTACK_DISABLE_X;
57130 + current->personality &= ~READ_IMPLIES_EXEC;
57131 + } else
57132 +#endif
57133 +
57134 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
57135 current->personality |= READ_IMPLIES_EXEC;
57136
57137 @@ -815,6 +1253,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
57138 #else
57139 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
57140 #endif
57141 +
57142 +#ifdef CONFIG_PAX_RANDMMAP
57143 + /* PaX: randomize base address at the default exe base if requested */
57144 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
57145 +#ifdef CONFIG_SPARC64
57146 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
57147 +#else
57148 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
57149 +#endif
57150 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
57151 + elf_flags |= MAP_FIXED;
57152 + }
57153 +#endif
57154 +
57155 }
57156
57157 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
57158 @@ -847,9 +1299,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
57159 * allowed task size. Note that p_filesz must always be
57160 * <= p_memsz so it is only necessary to check p_memsz.
57161 */
57162 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
57163 - elf_ppnt->p_memsz > TASK_SIZE ||
57164 - TASK_SIZE - elf_ppnt->p_memsz < k) {
57165 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
57166 + elf_ppnt->p_memsz > pax_task_size ||
57167 + pax_task_size - elf_ppnt->p_memsz < k) {
57168 /* set_brk can never work. Avoid overflows. */
57169 send_sig(SIGKILL, current, 0);
57170 retval = -EINVAL;
57171 @@ -888,17 +1340,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
57172 goto out_free_dentry;
57173 }
57174 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
57175 - send_sig(SIGSEGV, current, 0);
57176 - retval = -EFAULT; /* Nobody gets to see this, but.. */
57177 - goto out_free_dentry;
57178 + /*
57179 + * This bss-zeroing can fail if the ELF
57180 + * file specifies odd protections. So
57181 + * we don't check the return value
57182 + */
57183 }
57184
57185 +#ifdef CONFIG_PAX_RANDMMAP
57186 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
57187 + unsigned long start, size, flags;
57188 + vm_flags_t vm_flags;
57189 +
57190 + start = ELF_PAGEALIGN(elf_brk);
57191 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
57192 + flags = MAP_FIXED | MAP_PRIVATE;
57193 + vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
57194 +
57195 + down_write(&current->mm->mmap_sem);
57196 + start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
57197 + retval = -ENOMEM;
57198 + if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
57199 +// if (current->personality & ADDR_NO_RANDOMIZE)
57200 +// vm_flags |= VM_READ | VM_MAYREAD;
57201 + start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
57202 + retval = IS_ERR_VALUE(start) ? start : 0;
57203 + }
57204 + up_write(&current->mm->mmap_sem);
57205 + if (retval == 0)
57206 + retval = set_brk(start + size, start + size + PAGE_SIZE);
57207 + if (retval < 0) {
57208 + send_sig(SIGKILL, current, 0);
57209 + goto out_free_dentry;
57210 + }
57211 + }
57212 +#endif
57213 +
57214 if (elf_interpreter) {
57215 - unsigned long interp_map_addr = 0;
57216 -
57217 elf_entry = load_elf_interp(&loc->interp_elf_ex,
57218 interpreter,
57219 - &interp_map_addr,
57220 load_bias);
57221 if (!IS_ERR((void *)elf_entry)) {
57222 /*
57223 @@ -1122,7 +1602,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
57224 * Decide what to dump of a segment, part, all or none.
57225 */
57226 static unsigned long vma_dump_size(struct vm_area_struct *vma,
57227 - unsigned long mm_flags)
57228 + unsigned long mm_flags, long signr)
57229 {
57230 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
57231
57232 @@ -1160,7 +1640,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
57233 if (vma->vm_file == NULL)
57234 return 0;
57235
57236 - if (FILTER(MAPPED_PRIVATE))
57237 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
57238 goto whole;
57239
57240 /*
57241 @@ -1367,9 +1847,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
57242 {
57243 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
57244 int i = 0;
57245 - do
57246 + do {
57247 i += 2;
57248 - while (auxv[i - 2] != AT_NULL);
57249 + } while (auxv[i - 2] != AT_NULL);
57250 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
57251 }
57252
57253 @@ -1378,7 +1858,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
57254 {
57255 mm_segment_t old_fs = get_fs();
57256 set_fs(KERNEL_DS);
57257 - copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
57258 + copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
57259 set_fs(old_fs);
57260 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
57261 }
57262 @@ -2002,14 +2482,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
57263 }
57264
57265 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
57266 - unsigned long mm_flags)
57267 + struct coredump_params *cprm)
57268 {
57269 struct vm_area_struct *vma;
57270 size_t size = 0;
57271
57272 for (vma = first_vma(current, gate_vma); vma != NULL;
57273 vma = next_vma(vma, gate_vma))
57274 - size += vma_dump_size(vma, mm_flags);
57275 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
57276 return size;
57277 }
57278
57279 @@ -2100,7 +2580,7 @@ static int elf_core_dump(struct coredump_params *cprm)
57280
57281 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
57282
57283 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
57284 + offset += elf_core_vma_data_size(gate_vma, cprm);
57285 offset += elf_core_extra_data_size();
57286 e_shoff = offset;
57287
57288 @@ -2128,7 +2608,7 @@ static int elf_core_dump(struct coredump_params *cprm)
57289 phdr.p_offset = offset;
57290 phdr.p_vaddr = vma->vm_start;
57291 phdr.p_paddr = 0;
57292 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
57293 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
57294 phdr.p_memsz = vma->vm_end - vma->vm_start;
57295 offset += phdr.p_filesz;
57296 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
57297 @@ -2161,7 +2641,7 @@ static int elf_core_dump(struct coredump_params *cprm)
57298 unsigned long addr;
57299 unsigned long end;
57300
57301 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
57302 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
57303
57304 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
57305 struct page *page;
57306 @@ -2202,6 +2682,167 @@ out:
57307
57308 #endif /* CONFIG_ELF_CORE */
57309
57310 +#ifdef CONFIG_PAX_MPROTECT
57311 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
57312 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
57313 + * we'll remove VM_MAYWRITE for good on RELRO segments.
57314 + *
57315 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
57316 + * basis because we want to allow the common case and not the special ones.
57317 + */
57318 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
57319 +{
57320 + struct elfhdr elf_h;
57321 + struct elf_phdr elf_p;
57322 + unsigned long i;
57323 + unsigned long oldflags;
57324 + bool is_textrel_rw, is_textrel_rx, is_relro;
57325 +
57326 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
57327 + return;
57328 +
57329 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
57330 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
57331 +
57332 +#ifdef CONFIG_PAX_ELFRELOCS
57333 + /* possible TEXTREL */
57334 + is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
57335 + is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
57336 +#else
57337 + is_textrel_rw = false;
57338 + is_textrel_rx = false;
57339 +#endif
57340 +
57341 + /* possible RELRO */
57342 + is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
57343 +
57344 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
57345 + return;
57346 +
57347 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
57348 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
57349 +
57350 +#ifdef CONFIG_PAX_ETEXECRELOCS
57351 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
57352 +#else
57353 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
57354 +#endif
57355 +
57356 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
57357 + !elf_check_arch(&elf_h) ||
57358 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
57359 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
57360 + return;
57361 +
57362 + for (i = 0UL; i < elf_h.e_phnum; i++) {
57363 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
57364 + return;
57365 + switch (elf_p.p_type) {
57366 + case PT_DYNAMIC:
57367 + if (!is_textrel_rw && !is_textrel_rx)
57368 + continue;
57369 + i = 0UL;
57370 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
57371 + elf_dyn dyn;
57372 +
57373 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
57374 + break;
57375 + if (dyn.d_tag == DT_NULL)
57376 + break;
57377 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
57378 + gr_log_textrel(vma);
57379 + if (is_textrel_rw)
57380 + vma->vm_flags |= VM_MAYWRITE;
57381 + else
57382 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
57383 + vma->vm_flags &= ~VM_MAYWRITE;
57384 + break;
57385 + }
57386 + i++;
57387 + }
57388 + is_textrel_rw = false;
57389 + is_textrel_rx = false;
57390 + continue;
57391 +
57392 + case PT_GNU_RELRO:
57393 + if (!is_relro)
57394 + continue;
57395 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
57396 + vma->vm_flags &= ~VM_MAYWRITE;
57397 + is_relro = false;
57398 + continue;
57399 +
57400 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
57401 + case PT_PAX_FLAGS: {
57402 + const char *msg_mprotect = "", *msg_emutramp = "";
57403 + char *buffer_lib, *buffer_exe;
57404 +
57405 + if (elf_p.p_flags & PF_NOMPROTECT)
57406 + msg_mprotect = "MPROTECT disabled";
57407 +
57408 +#ifdef CONFIG_PAX_EMUTRAMP
57409 + if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
57410 + msg_emutramp = "EMUTRAMP enabled";
57411 +#endif
57412 +
57413 + if (!msg_mprotect[0] && !msg_emutramp[0])
57414 + continue;
57415 +
57416 + if (!printk_ratelimit())
57417 + continue;
57418 +
57419 + buffer_lib = (char *)__get_free_page(GFP_KERNEL);
57420 + buffer_exe = (char *)__get_free_page(GFP_KERNEL);
57421 + if (buffer_lib && buffer_exe) {
57422 + char *path_lib, *path_exe;
57423 +
57424 + path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
57425 + path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
57426 +
57427 + pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
57428 + (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
57429 +
57430 + }
57431 + free_page((unsigned long)buffer_exe);
57432 + free_page((unsigned long)buffer_lib);
57433 + continue;
57434 + }
57435 +#endif
57436 +
57437 + }
57438 + }
57439 +}
57440 +#endif
57441 +
57442 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57443 +
57444 +extern int grsec_enable_log_rwxmaps;
57445 +
57446 +static void elf_handle_mmap(struct file *file)
57447 +{
57448 + struct elfhdr elf_h;
57449 + struct elf_phdr elf_p;
57450 + unsigned long i;
57451 +
57452 + if (!grsec_enable_log_rwxmaps)
57453 + return;
57454 +
57455 + if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
57456 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
57457 + (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
57458 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
57459 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
57460 + return;
57461 +
57462 + for (i = 0UL; i < elf_h.e_phnum; i++) {
57463 + if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
57464 + return;
57465 + if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
57466 + gr_log_ptgnustack(file);
57467 + }
57468 +}
57469 +#endif
57470 +
57471 static int __init init_elf_binfmt(void)
57472 {
57473 register_binfmt(&elf_format);
57474 diff --git a/fs/bio.c b/fs/bio.c
57475 index 6f0362b..26a7496 100644
57476 --- a/fs/bio.c
57477 +++ b/fs/bio.c
57478 @@ -1144,7 +1144,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
57479 /*
57480 * Overflow, abort
57481 */
57482 - if (end < start)
57483 + if (end < start || end - start > INT_MAX - nr_pages)
57484 return ERR_PTR(-EINVAL);
57485
57486 nr_pages += end - start;
57487 @@ -1278,7 +1278,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
57488 /*
57489 * Overflow, abort
57490 */
57491 - if (end < start)
57492 + if (end < start || end - start > INT_MAX - nr_pages)
57493 return ERR_PTR(-EINVAL);
57494
57495 nr_pages += end - start;
57496 @@ -1540,7 +1540,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
57497 const int read = bio_data_dir(bio) == READ;
57498 struct bio_map_data *bmd = bio->bi_private;
57499 int i;
57500 - char *p = bmd->sgvecs[0].iov_base;
57501 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
57502
57503 bio_for_each_segment_all(bvec, bio, i) {
57504 char *addr = page_address(bvec->bv_page);
57505 diff --git a/fs/block_dev.c b/fs/block_dev.c
57506 index 552a8d1..d51ccf3 100644
57507 --- a/fs/block_dev.c
57508 +++ b/fs/block_dev.c
57509 @@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
57510 else if (bdev->bd_contains == bdev)
57511 return true; /* is a whole device which isn't held */
57512
57513 - else if (whole->bd_holder == bd_may_claim)
57514 + else if (whole->bd_holder == (void *)bd_may_claim)
57515 return true; /* is a partition of a device that is being partitioned */
57516 else if (whole->bd_holder != NULL)
57517 return false; /* is a partition of a held device */
57518 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
57519 index 1bcfcdb..e942132 100644
57520 --- a/fs/btrfs/ctree.c
57521 +++ b/fs/btrfs/ctree.c
57522 @@ -1216,9 +1216,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
57523 free_extent_buffer(buf);
57524 add_root_to_dirty_list(root);
57525 } else {
57526 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
57527 - parent_start = parent->start;
57528 - else
57529 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
57530 + if (parent)
57531 + parent_start = parent->start;
57532 + else
57533 + parent_start = 0;
57534 + } else
57535 parent_start = 0;
57536
57537 WARN_ON(trans->transid != btrfs_header_generation(parent));
57538 diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
57539 index 33e561a..16df7ae 100644
57540 --- a/fs/btrfs/delayed-inode.c
57541 +++ b/fs/btrfs/delayed-inode.c
57542 @@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
57543
57544 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
57545 {
57546 - int seq = atomic_inc_return(&delayed_root->items_seq);
57547 + int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
57548 if ((atomic_dec_return(&delayed_root->items) <
57549 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
57550 waitqueue_active(&delayed_root->wait))
57551 @@ -1409,7 +1409,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
57552
57553 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
57554 {
57555 - int val = atomic_read(&delayed_root->items_seq);
57556 + int val = atomic_read_unchecked(&delayed_root->items_seq);
57557
57558 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
57559 return 1;
57560 @@ -1433,7 +1433,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
57561 int seq;
57562 int ret;
57563
57564 - seq = atomic_read(&delayed_root->items_seq);
57565 + seq = atomic_read_unchecked(&delayed_root->items_seq);
57566
57567 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
57568 if (ret)
57569 diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
57570 index f70119f..ab5894d 100644
57571 --- a/fs/btrfs/delayed-inode.h
57572 +++ b/fs/btrfs/delayed-inode.h
57573 @@ -43,7 +43,7 @@ struct btrfs_delayed_root {
57574 */
57575 struct list_head prepare_list;
57576 atomic_t items; /* for delayed items */
57577 - atomic_t items_seq; /* for delayed items */
57578 + atomic_unchecked_t items_seq; /* for delayed items */
57579 int nodes; /* for delayed nodes */
57580 wait_queue_head_t wait;
57581 };
57582 @@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
57583 struct btrfs_delayed_root *delayed_root)
57584 {
57585 atomic_set(&delayed_root->items, 0);
57586 - atomic_set(&delayed_root->items_seq, 0);
57587 + atomic_set_unchecked(&delayed_root->items_seq, 0);
57588 delayed_root->nodes = 0;
57589 spin_lock_init(&delayed_root->lock);
57590 init_waitqueue_head(&delayed_root->wait);
57591 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
57592 index 2f6d7b1..f186382 100644
57593 --- a/fs/btrfs/ioctl.c
57594 +++ b/fs/btrfs/ioctl.c
57595 @@ -3575,9 +3575,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57596 for (i = 0; i < num_types; i++) {
57597 struct btrfs_space_info *tmp;
57598
57599 + /* Don't copy in more than we allocated */
57600 if (!slot_count)
57601 break;
57602
57603 + slot_count--;
57604 +
57605 info = NULL;
57606 rcu_read_lock();
57607 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
57608 @@ -3599,10 +3602,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57609 memcpy(dest, &space, sizeof(space));
57610 dest++;
57611 space_args.total_spaces++;
57612 - slot_count--;
57613 }
57614 - if (!slot_count)
57615 - break;
57616 }
57617 up_read(&info->groups_sem);
57618 }
57619 diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
57620 index 9601d25..2896d6c 100644
57621 --- a/fs/btrfs/super.c
57622 +++ b/fs/btrfs/super.c
57623 @@ -270,7 +270,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
57624 function, line, errstr);
57625 return;
57626 }
57627 - ACCESS_ONCE(trans->transaction->aborted) = errno;
57628 + ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
57629 /* Wake up anybody who may be waiting on this transaction */
57630 wake_up(&root->fs_info->transaction_wait);
57631 wake_up(&root->fs_info->transaction_blocked_wait);
57632 diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
57633 index 4825cd2..b2fe768 100644
57634 --- a/fs/btrfs/sysfs.c
57635 +++ b/fs/btrfs/sysfs.c
57636 @@ -438,7 +438,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
57637 for (set = 0; set < FEAT_MAX; set++) {
57638 int i;
57639 struct attribute *attrs[2];
57640 - struct attribute_group agroup = {
57641 + attribute_group_no_const agroup = {
57642 .name = "features",
57643 .attrs = attrs,
57644 };
57645 diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
57646 index e2f45fc..b036909 100644
57647 --- a/fs/btrfs/tree-log.c
57648 +++ b/fs/btrfs/tree-log.c
57649 @@ -2533,7 +2533,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57650 blk_finish_plug(&plug);
57651 btrfs_abort_transaction(trans, root, ret);
57652 btrfs_free_logged_extents(log, log_transid);
57653 - ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57654 + ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57655 trans->transid;
57656 mutex_unlock(&root->log_mutex);
57657 goto out;
57658 @@ -2577,7 +2577,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57659 list_del_init(&root_log_ctx.list);
57660
57661 blk_finish_plug(&plug);
57662 - ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57663 + ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57664 trans->transid;
57665 if (ret != -ENOSPC) {
57666 btrfs_abort_transaction(trans, root, ret);
57667 @@ -2622,7 +2622,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57668 * now that we've moved on to the tree of log tree roots,
57669 * check the full commit flag again
57670 */
57671 - if (ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) ==
57672 + if (ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) ==
57673 trans->transid) {
57674 blk_finish_plug(&plug);
57675 btrfs_wait_marked_extents(log, &log->dirty_log_pages, mark);
57676 @@ -2637,7 +2637,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57677 EXTENT_DIRTY | EXTENT_NEW);
57678 blk_finish_plug(&plug);
57679 if (ret) {
57680 - ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57681 + ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57682 trans->transid;
57683 btrfs_abort_transaction(trans, root, ret);
57684 btrfs_free_logged_extents(log, log_transid);
57685 @@ -2667,7 +2667,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57686 */
57687 ret = write_ctree_super(trans, root->fs_info->tree_root, 1);
57688 if (ret) {
57689 - ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57690 + ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57691 trans->transid;
57692 btrfs_abort_transaction(trans, root, ret);
57693 goto out_wake_log_root;
57694 diff --git a/fs/buffer.c b/fs/buffer.c
57695 index 9ddb9fc..7aa2487 100644
57696 --- a/fs/buffer.c
57697 +++ b/fs/buffer.c
57698 @@ -3428,7 +3428,7 @@ void __init buffer_init(void)
57699 bh_cachep = kmem_cache_create("buffer_head",
57700 sizeof(struct buffer_head), 0,
57701 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
57702 - SLAB_MEM_SPREAD),
57703 + SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
57704 NULL);
57705
57706 /*
57707 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
57708 index 5b99baf..47fffb5 100644
57709 --- a/fs/cachefiles/bind.c
57710 +++ b/fs/cachefiles/bind.c
57711 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
57712 args);
57713
57714 /* start by checking things over */
57715 - ASSERT(cache->fstop_percent >= 0 &&
57716 - cache->fstop_percent < cache->fcull_percent &&
57717 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
57718 cache->fcull_percent < cache->frun_percent &&
57719 cache->frun_percent < 100);
57720
57721 - ASSERT(cache->bstop_percent >= 0 &&
57722 - cache->bstop_percent < cache->bcull_percent &&
57723 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
57724 cache->bcull_percent < cache->brun_percent &&
57725 cache->brun_percent < 100);
57726
57727 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
57728 index 0a1467b..6a53245 100644
57729 --- a/fs/cachefiles/daemon.c
57730 +++ b/fs/cachefiles/daemon.c
57731 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
57732 if (n > buflen)
57733 return -EMSGSIZE;
57734
57735 - if (copy_to_user(_buffer, buffer, n) != 0)
57736 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
57737 return -EFAULT;
57738
57739 return n;
57740 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
57741 if (test_bit(CACHEFILES_DEAD, &cache->flags))
57742 return -EIO;
57743
57744 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
57745 + if (datalen > PAGE_SIZE - 1)
57746 return -EOPNOTSUPP;
57747
57748 /* drag the command string into the kernel so we can parse it */
57749 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
57750 if (args[0] != '%' || args[1] != '\0')
57751 return -EINVAL;
57752
57753 - if (fstop < 0 || fstop >= cache->fcull_percent)
57754 + if (fstop >= cache->fcull_percent)
57755 return cachefiles_daemon_range_error(cache, args);
57756
57757 cache->fstop_percent = fstop;
57758 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
57759 if (args[0] != '%' || args[1] != '\0')
57760 return -EINVAL;
57761
57762 - if (bstop < 0 || bstop >= cache->bcull_percent)
57763 + if (bstop >= cache->bcull_percent)
57764 return cachefiles_daemon_range_error(cache, args);
57765
57766 cache->bstop_percent = bstop;
57767 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
57768 index 5349473..d6c0b93 100644
57769 --- a/fs/cachefiles/internal.h
57770 +++ b/fs/cachefiles/internal.h
57771 @@ -59,7 +59,7 @@ struct cachefiles_cache {
57772 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
57773 struct rb_root active_nodes; /* active nodes (can't be culled) */
57774 rwlock_t active_lock; /* lock for active_nodes */
57775 - atomic_t gravecounter; /* graveyard uniquifier */
57776 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
57777 unsigned frun_percent; /* when to stop culling (% files) */
57778 unsigned fcull_percent; /* when to start culling (% files) */
57779 unsigned fstop_percent; /* when to stop allocating (% files) */
57780 @@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
57781 * proc.c
57782 */
57783 #ifdef CONFIG_CACHEFILES_HISTOGRAM
57784 -extern atomic_t cachefiles_lookup_histogram[HZ];
57785 -extern atomic_t cachefiles_mkdir_histogram[HZ];
57786 -extern atomic_t cachefiles_create_histogram[HZ];
57787 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57788 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57789 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
57790
57791 extern int __init cachefiles_proc_init(void);
57792 extern void cachefiles_proc_cleanup(void);
57793 static inline
57794 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
57795 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
57796 {
57797 unsigned long jif = jiffies - start_jif;
57798 if (jif >= HZ)
57799 jif = HZ - 1;
57800 - atomic_inc(&histogram[jif]);
57801 + atomic_inc_unchecked(&histogram[jif]);
57802 }
57803
57804 #else
57805 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
57806 index c0a6817..ea811166 100644
57807 --- a/fs/cachefiles/namei.c
57808 +++ b/fs/cachefiles/namei.c
57809 @@ -317,7 +317,7 @@ try_again:
57810 /* first step is to make up a grave dentry in the graveyard */
57811 sprintf(nbuffer, "%08x%08x",
57812 (uint32_t) get_seconds(),
57813 - (uint32_t) atomic_inc_return(&cache->gravecounter));
57814 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
57815
57816 /* do the multiway lock magic */
57817 trap = lock_rename(cache->graveyard, dir);
57818 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
57819 index eccd339..4c1d995 100644
57820 --- a/fs/cachefiles/proc.c
57821 +++ b/fs/cachefiles/proc.c
57822 @@ -14,9 +14,9 @@
57823 #include <linux/seq_file.h>
57824 #include "internal.h"
57825
57826 -atomic_t cachefiles_lookup_histogram[HZ];
57827 -atomic_t cachefiles_mkdir_histogram[HZ];
57828 -atomic_t cachefiles_create_histogram[HZ];
57829 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57830 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57831 +atomic_unchecked_t cachefiles_create_histogram[HZ];
57832
57833 /*
57834 * display the latency histogram
57835 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
57836 return 0;
57837 default:
57838 index = (unsigned long) v - 3;
57839 - x = atomic_read(&cachefiles_lookup_histogram[index]);
57840 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
57841 - z = atomic_read(&cachefiles_create_histogram[index]);
57842 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
57843 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
57844 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
57845 if (x == 0 && y == 0 && z == 0)
57846 return 0;
57847
57848 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
57849 index 4b1fb5c..0d2a699 100644
57850 --- a/fs/cachefiles/rdwr.c
57851 +++ b/fs/cachefiles/rdwr.c
57852 @@ -943,7 +943,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
57853 old_fs = get_fs();
57854 set_fs(KERNEL_DS);
57855 ret = file->f_op->write(
57856 - file, (const void __user *) data, len, &pos);
57857 + file, (const void __force_user *) data, len, &pos);
57858 set_fs(old_fs);
57859 kunmap(page);
57860 file_end_write(file);
57861 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
57862 index c29d6ae..a56c4ae 100644
57863 --- a/fs/ceph/dir.c
57864 +++ b/fs/ceph/dir.c
57865 @@ -250,7 +250,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
57866 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
57867 struct ceph_mds_client *mdsc = fsc->mdsc;
57868 unsigned frag = fpos_frag(ctx->pos);
57869 - int off = fpos_off(ctx->pos);
57870 + unsigned int off = fpos_off(ctx->pos);
57871 int err;
57872 u32 ftype;
57873 struct ceph_mds_reply_info_parsed *rinfo;
57874 diff --git a/fs/ceph/super.c b/fs/ceph/super.c
57875 index 06150fd..192061b 100644
57876 --- a/fs/ceph/super.c
57877 +++ b/fs/ceph/super.c
57878 @@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
57879 /*
57880 * construct our own bdi so we can control readahead, etc.
57881 */
57882 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
57883 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
57884
57885 static int ceph_register_bdi(struct super_block *sb,
57886 struct ceph_fs_client *fsc)
57887 @@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
57888 default_backing_dev_info.ra_pages;
57889
57890 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
57891 - atomic_long_inc_return(&bdi_seq));
57892 + atomic_long_inc_return_unchecked(&bdi_seq));
57893 if (!err)
57894 sb->s_bdi = &fsc->backing_dev_info;
57895 return err;
57896 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
57897 index f3ac415..3d2420c 100644
57898 --- a/fs/cifs/cifs_debug.c
57899 +++ b/fs/cifs/cifs_debug.c
57900 @@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57901
57902 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
57903 #ifdef CONFIG_CIFS_STATS2
57904 - atomic_set(&totBufAllocCount, 0);
57905 - atomic_set(&totSmBufAllocCount, 0);
57906 + atomic_set_unchecked(&totBufAllocCount, 0);
57907 + atomic_set_unchecked(&totSmBufAllocCount, 0);
57908 #endif /* CONFIG_CIFS_STATS2 */
57909 spin_lock(&cifs_tcp_ses_lock);
57910 list_for_each(tmp1, &cifs_tcp_ses_list) {
57911 @@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57912 tcon = list_entry(tmp3,
57913 struct cifs_tcon,
57914 tcon_list);
57915 - atomic_set(&tcon->num_smbs_sent, 0);
57916 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
57917 if (server->ops->clear_stats)
57918 server->ops->clear_stats(tcon);
57919 }
57920 @@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57921 smBufAllocCount.counter, cifs_min_small);
57922 #ifdef CONFIG_CIFS_STATS2
57923 seq_printf(m, "Total Large %d Small %d Allocations\n",
57924 - atomic_read(&totBufAllocCount),
57925 - atomic_read(&totSmBufAllocCount));
57926 + atomic_read_unchecked(&totBufAllocCount),
57927 + atomic_read_unchecked(&totSmBufAllocCount));
57928 #endif /* CONFIG_CIFS_STATS2 */
57929
57930 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
57931 @@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57932 if (tcon->need_reconnect)
57933 seq_puts(m, "\tDISCONNECTED ");
57934 seq_printf(m, "\nSMBs: %d",
57935 - atomic_read(&tcon->num_smbs_sent));
57936 + atomic_read_unchecked(&tcon->num_smbs_sent));
57937 if (server->ops->print_stats)
57938 server->ops->print_stats(m, tcon);
57939 }
57940 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
57941 index 5be1f997..fa1015a1 100644
57942 --- a/fs/cifs/cifsfs.c
57943 +++ b/fs/cifs/cifsfs.c
57944 @@ -1068,7 +1068,7 @@ cifs_init_request_bufs(void)
57945 */
57946 cifs_req_cachep = kmem_cache_create("cifs_request",
57947 CIFSMaxBufSize + max_hdr_size, 0,
57948 - SLAB_HWCACHE_ALIGN, NULL);
57949 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
57950 if (cifs_req_cachep == NULL)
57951 return -ENOMEM;
57952
57953 @@ -1095,7 +1095,7 @@ cifs_init_request_bufs(void)
57954 efficient to alloc 1 per page off the slab compared to 17K (5page)
57955 alloc of large cifs buffers even when page debugging is on */
57956 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
57957 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
57958 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
57959 NULL);
57960 if (cifs_sm_req_cachep == NULL) {
57961 mempool_destroy(cifs_req_poolp);
57962 @@ -1180,8 +1180,8 @@ init_cifs(void)
57963 atomic_set(&bufAllocCount, 0);
57964 atomic_set(&smBufAllocCount, 0);
57965 #ifdef CONFIG_CIFS_STATS2
57966 - atomic_set(&totBufAllocCount, 0);
57967 - atomic_set(&totSmBufAllocCount, 0);
57968 + atomic_set_unchecked(&totBufAllocCount, 0);
57969 + atomic_set_unchecked(&totSmBufAllocCount, 0);
57970 #endif /* CONFIG_CIFS_STATS2 */
57971
57972 atomic_set(&midCount, 0);
57973 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
57974 index 30f6e92..e915ba5 100644
57975 --- a/fs/cifs/cifsglob.h
57976 +++ b/fs/cifs/cifsglob.h
57977 @@ -806,35 +806,35 @@ struct cifs_tcon {
57978 __u16 Flags; /* optional support bits */
57979 enum statusEnum tidStatus;
57980 #ifdef CONFIG_CIFS_STATS
57981 - atomic_t num_smbs_sent;
57982 + atomic_unchecked_t num_smbs_sent;
57983 union {
57984 struct {
57985 - atomic_t num_writes;
57986 - atomic_t num_reads;
57987 - atomic_t num_flushes;
57988 - atomic_t num_oplock_brks;
57989 - atomic_t num_opens;
57990 - atomic_t num_closes;
57991 - atomic_t num_deletes;
57992 - atomic_t num_mkdirs;
57993 - atomic_t num_posixopens;
57994 - atomic_t num_posixmkdirs;
57995 - atomic_t num_rmdirs;
57996 - atomic_t num_renames;
57997 - atomic_t num_t2renames;
57998 - atomic_t num_ffirst;
57999 - atomic_t num_fnext;
58000 - atomic_t num_fclose;
58001 - atomic_t num_hardlinks;
58002 - atomic_t num_symlinks;
58003 - atomic_t num_locks;
58004 - atomic_t num_acl_get;
58005 - atomic_t num_acl_set;
58006 + atomic_unchecked_t num_writes;
58007 + atomic_unchecked_t num_reads;
58008 + atomic_unchecked_t num_flushes;
58009 + atomic_unchecked_t num_oplock_brks;
58010 + atomic_unchecked_t num_opens;
58011 + atomic_unchecked_t num_closes;
58012 + atomic_unchecked_t num_deletes;
58013 + atomic_unchecked_t num_mkdirs;
58014 + atomic_unchecked_t num_posixopens;
58015 + atomic_unchecked_t num_posixmkdirs;
58016 + atomic_unchecked_t num_rmdirs;
58017 + atomic_unchecked_t num_renames;
58018 + atomic_unchecked_t num_t2renames;
58019 + atomic_unchecked_t num_ffirst;
58020 + atomic_unchecked_t num_fnext;
58021 + atomic_unchecked_t num_fclose;
58022 + atomic_unchecked_t num_hardlinks;
58023 + atomic_unchecked_t num_symlinks;
58024 + atomic_unchecked_t num_locks;
58025 + atomic_unchecked_t num_acl_get;
58026 + atomic_unchecked_t num_acl_set;
58027 } cifs_stats;
58028 #ifdef CONFIG_CIFS_SMB2
58029 struct {
58030 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
58031 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
58032 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
58033 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
58034 } smb2_stats;
58035 #endif /* CONFIG_CIFS_SMB2 */
58036 } stats;
58037 @@ -1170,7 +1170,7 @@ convert_delimiter(char *path, char delim)
58038 }
58039
58040 #ifdef CONFIG_CIFS_STATS
58041 -#define cifs_stats_inc atomic_inc
58042 +#define cifs_stats_inc atomic_inc_unchecked
58043
58044 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
58045 unsigned int bytes)
58046 @@ -1536,8 +1536,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
58047 /* Various Debug counters */
58048 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
58049 #ifdef CONFIG_CIFS_STATS2
58050 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
58051 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
58052 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
58053 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
58054 #endif
58055 GLOBAL_EXTERN atomic_t smBufAllocCount;
58056 GLOBAL_EXTERN atomic_t midCount;
58057 diff --git a/fs/cifs/file.c b/fs/cifs/file.c
58058 index 5ed03e0..e9a3a6c 100644
58059 --- a/fs/cifs/file.c
58060 +++ b/fs/cifs/file.c
58061 @@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
58062 index = mapping->writeback_index; /* Start from prev offset */
58063 end = -1;
58064 } else {
58065 - index = wbc->range_start >> PAGE_CACHE_SHIFT;
58066 - end = wbc->range_end >> PAGE_CACHE_SHIFT;
58067 - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
58068 + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
58069 range_whole = true;
58070 + index = 0;
58071 + end = ULONG_MAX;
58072 + } else {
58073 + index = wbc->range_start >> PAGE_CACHE_SHIFT;
58074 + end = wbc->range_end >> PAGE_CACHE_SHIFT;
58075 + }
58076 scanned = true;
58077 }
58078 retry:
58079 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
58080 index 3b0c62e..f7d090c 100644
58081 --- a/fs/cifs/misc.c
58082 +++ b/fs/cifs/misc.c
58083 @@ -170,7 +170,7 @@ cifs_buf_get(void)
58084 memset(ret_buf, 0, buf_size + 3);
58085 atomic_inc(&bufAllocCount);
58086 #ifdef CONFIG_CIFS_STATS2
58087 - atomic_inc(&totBufAllocCount);
58088 + atomic_inc_unchecked(&totBufAllocCount);
58089 #endif /* CONFIG_CIFS_STATS2 */
58090 }
58091
58092 @@ -205,7 +205,7 @@ cifs_small_buf_get(void)
58093 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
58094 atomic_inc(&smBufAllocCount);
58095 #ifdef CONFIG_CIFS_STATS2
58096 - atomic_inc(&totSmBufAllocCount);
58097 + atomic_inc_unchecked(&totSmBufAllocCount);
58098 #endif /* CONFIG_CIFS_STATS2 */
58099
58100 }
58101 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
58102 index d1fdfa8..94558f8 100644
58103 --- a/fs/cifs/smb1ops.c
58104 +++ b/fs/cifs/smb1ops.c
58105 @@ -626,27 +626,27 @@ static void
58106 cifs_clear_stats(struct cifs_tcon *tcon)
58107 {
58108 #ifdef CONFIG_CIFS_STATS
58109 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
58110 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
58111 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
58112 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
58113 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
58114 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
58115 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
58116 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
58117 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
58118 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
58119 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
58120 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
58121 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
58122 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
58123 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
58124 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
58125 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
58126 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
58127 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
58128 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
58129 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
58130 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
58131 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
58132 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
58133 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
58134 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
58135 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
58136 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
58137 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
58138 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
58139 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
58140 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
58141 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
58142 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
58143 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
58144 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
58145 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
58146 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
58147 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
58148 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
58149 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
58150 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
58151 #endif
58152 }
58153
58154 @@ -655,36 +655,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
58155 {
58156 #ifdef CONFIG_CIFS_STATS
58157 seq_printf(m, " Oplocks breaks: %d",
58158 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
58159 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
58160 seq_printf(m, "\nReads: %d Bytes: %llu",
58161 - atomic_read(&tcon->stats.cifs_stats.num_reads),
58162 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
58163 (long long)(tcon->bytes_read));
58164 seq_printf(m, "\nWrites: %d Bytes: %llu",
58165 - atomic_read(&tcon->stats.cifs_stats.num_writes),
58166 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
58167 (long long)(tcon->bytes_written));
58168 seq_printf(m, "\nFlushes: %d",
58169 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
58170 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
58171 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
58172 - atomic_read(&tcon->stats.cifs_stats.num_locks),
58173 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
58174 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
58175 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
58176 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
58177 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
58178 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
58179 - atomic_read(&tcon->stats.cifs_stats.num_opens),
58180 - atomic_read(&tcon->stats.cifs_stats.num_closes),
58181 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
58182 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
58183 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
58184 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
58185 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
58186 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
58187 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
58188 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
58189 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
58190 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
58191 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
58192 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
58193 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
58194 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
58195 seq_printf(m, "\nRenames: %d T2 Renames %d",
58196 - atomic_read(&tcon->stats.cifs_stats.num_renames),
58197 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
58198 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
58199 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
58200 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
58201 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
58202 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
58203 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
58204 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
58205 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
58206 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
58207 #endif
58208 }
58209
58210 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
58211 index 35ddc3e..563e809 100644
58212 --- a/fs/cifs/smb2ops.c
58213 +++ b/fs/cifs/smb2ops.c
58214 @@ -364,8 +364,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
58215 #ifdef CONFIG_CIFS_STATS
58216 int i;
58217 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
58218 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
58219 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
58220 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
58221 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
58222 }
58223 #endif
58224 }
58225 @@ -405,65 +405,65 @@ static void
58226 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
58227 {
58228 #ifdef CONFIG_CIFS_STATS
58229 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
58230 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
58231 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
58232 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
58233 seq_printf(m, "\nNegotiates: %d sent %d failed",
58234 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
58235 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
58236 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
58237 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
58238 seq_printf(m, "\nSessionSetups: %d sent %d failed",
58239 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
58240 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
58241 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
58242 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
58243 seq_printf(m, "\nLogoffs: %d sent %d failed",
58244 - atomic_read(&sent[SMB2_LOGOFF_HE]),
58245 - atomic_read(&failed[SMB2_LOGOFF_HE]));
58246 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
58247 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
58248 seq_printf(m, "\nTreeConnects: %d sent %d failed",
58249 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
58250 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
58251 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
58252 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
58253 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
58254 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
58255 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
58256 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
58257 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
58258 seq_printf(m, "\nCreates: %d sent %d failed",
58259 - atomic_read(&sent[SMB2_CREATE_HE]),
58260 - atomic_read(&failed[SMB2_CREATE_HE]));
58261 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
58262 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
58263 seq_printf(m, "\nCloses: %d sent %d failed",
58264 - atomic_read(&sent[SMB2_CLOSE_HE]),
58265 - atomic_read(&failed[SMB2_CLOSE_HE]));
58266 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
58267 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
58268 seq_printf(m, "\nFlushes: %d sent %d failed",
58269 - atomic_read(&sent[SMB2_FLUSH_HE]),
58270 - atomic_read(&failed[SMB2_FLUSH_HE]));
58271 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
58272 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
58273 seq_printf(m, "\nReads: %d sent %d failed",
58274 - atomic_read(&sent[SMB2_READ_HE]),
58275 - atomic_read(&failed[SMB2_READ_HE]));
58276 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
58277 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
58278 seq_printf(m, "\nWrites: %d sent %d failed",
58279 - atomic_read(&sent[SMB2_WRITE_HE]),
58280 - atomic_read(&failed[SMB2_WRITE_HE]));
58281 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
58282 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
58283 seq_printf(m, "\nLocks: %d sent %d failed",
58284 - atomic_read(&sent[SMB2_LOCK_HE]),
58285 - atomic_read(&failed[SMB2_LOCK_HE]));
58286 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
58287 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
58288 seq_printf(m, "\nIOCTLs: %d sent %d failed",
58289 - atomic_read(&sent[SMB2_IOCTL_HE]),
58290 - atomic_read(&failed[SMB2_IOCTL_HE]));
58291 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
58292 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
58293 seq_printf(m, "\nCancels: %d sent %d failed",
58294 - atomic_read(&sent[SMB2_CANCEL_HE]),
58295 - atomic_read(&failed[SMB2_CANCEL_HE]));
58296 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
58297 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
58298 seq_printf(m, "\nEchos: %d sent %d failed",
58299 - atomic_read(&sent[SMB2_ECHO_HE]),
58300 - atomic_read(&failed[SMB2_ECHO_HE]));
58301 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
58302 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
58303 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
58304 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
58305 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
58306 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
58307 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
58308 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
58309 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
58310 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
58311 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
58312 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
58313 seq_printf(m, "\nQueryInfos: %d sent %d failed",
58314 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
58315 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
58316 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
58317 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
58318 seq_printf(m, "\nSetInfos: %d sent %d failed",
58319 - atomic_read(&sent[SMB2_SET_INFO_HE]),
58320 - atomic_read(&failed[SMB2_SET_INFO_HE]));
58321 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
58322 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
58323 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
58324 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
58325 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
58326 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
58327 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
58328 #endif
58329 }
58330
58331 diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
58332 index 1fb6ad2..758e171 100644
58333 --- a/fs/cifs/smb2pdu.c
58334 +++ b/fs/cifs/smb2pdu.c
58335 @@ -2097,8 +2097,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
58336 default:
58337 cifs_dbg(VFS, "info level %u isn't supported\n",
58338 srch_inf->info_level);
58339 - rc = -EINVAL;
58340 - goto qdir_exit;
58341 + return -EINVAL;
58342 }
58343
58344 req->FileIndex = cpu_to_le32(index);
58345 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
58346 index 1da168c..8bc7ff6 100644
58347 --- a/fs/coda/cache.c
58348 +++ b/fs/coda/cache.c
58349 @@ -24,7 +24,7 @@
58350 #include "coda_linux.h"
58351 #include "coda_cache.h"
58352
58353 -static atomic_t permission_epoch = ATOMIC_INIT(0);
58354 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
58355
58356 /* replace or extend an acl cache hit */
58357 void coda_cache_enter(struct inode *inode, int mask)
58358 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
58359 struct coda_inode_info *cii = ITOC(inode);
58360
58361 spin_lock(&cii->c_lock);
58362 - cii->c_cached_epoch = atomic_read(&permission_epoch);
58363 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
58364 if (!uid_eq(cii->c_uid, current_fsuid())) {
58365 cii->c_uid = current_fsuid();
58366 cii->c_cached_perm = mask;
58367 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
58368 {
58369 struct coda_inode_info *cii = ITOC(inode);
58370 spin_lock(&cii->c_lock);
58371 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
58372 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
58373 spin_unlock(&cii->c_lock);
58374 }
58375
58376 /* remove all acl caches */
58377 void coda_cache_clear_all(struct super_block *sb)
58378 {
58379 - atomic_inc(&permission_epoch);
58380 + atomic_inc_unchecked(&permission_epoch);
58381 }
58382
58383
58384 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
58385 spin_lock(&cii->c_lock);
58386 hit = (mask & cii->c_cached_perm) == mask &&
58387 uid_eq(cii->c_uid, current_fsuid()) &&
58388 - cii->c_cached_epoch == atomic_read(&permission_epoch);
58389 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
58390 spin_unlock(&cii->c_lock);
58391
58392 return hit;
58393 diff --git a/fs/compat.c b/fs/compat.c
58394 index 66d3d3c..9c10175 100644
58395 --- a/fs/compat.c
58396 +++ b/fs/compat.c
58397 @@ -54,7 +54,7 @@
58398 #include <asm/ioctls.h>
58399 #include "internal.h"
58400
58401 -int compat_log = 1;
58402 +int compat_log = 0;
58403
58404 int compat_printk(const char *fmt, ...)
58405 {
58406 @@ -512,7 +512,7 @@ COMPAT_SYSCALL_DEFINE2(io_setup, unsigned, nr_reqs, u32 __user *, ctx32p)
58407
58408 set_fs(KERNEL_DS);
58409 /* The __user pointer cast is valid because of the set_fs() */
58410 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
58411 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
58412 set_fs(oldfs);
58413 /* truncating is ok because it's a user address */
58414 if (!ret)
58415 @@ -562,7 +562,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
58416 goto out;
58417
58418 ret = -EINVAL;
58419 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
58420 + if (nr_segs > UIO_MAXIOV)
58421 goto out;
58422 if (nr_segs > fast_segs) {
58423 ret = -ENOMEM;
58424 @@ -850,6 +850,7 @@ struct compat_old_linux_dirent {
58425 struct compat_readdir_callback {
58426 struct dir_context ctx;
58427 struct compat_old_linux_dirent __user *dirent;
58428 + struct file * file;
58429 int result;
58430 };
58431
58432 @@ -867,6 +868,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
58433 buf->result = -EOVERFLOW;
58434 return -EOVERFLOW;
58435 }
58436 +
58437 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58438 + return 0;
58439 +
58440 buf->result++;
58441 dirent = buf->dirent;
58442 if (!access_ok(VERIFY_WRITE, dirent,
58443 @@ -898,6 +903,7 @@ COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
58444 if (!f.file)
58445 return -EBADF;
58446
58447 + buf.file = f.file;
58448 error = iterate_dir(f.file, &buf.ctx);
58449 if (buf.result)
58450 error = buf.result;
58451 @@ -917,6 +923,7 @@ struct compat_getdents_callback {
58452 struct dir_context ctx;
58453 struct compat_linux_dirent __user *current_dir;
58454 struct compat_linux_dirent __user *previous;
58455 + struct file * file;
58456 int count;
58457 int error;
58458 };
58459 @@ -938,6 +945,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
58460 buf->error = -EOVERFLOW;
58461 return -EOVERFLOW;
58462 }
58463 +
58464 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58465 + return 0;
58466 +
58467 dirent = buf->previous;
58468 if (dirent) {
58469 if (__put_user(offset, &dirent->d_off))
58470 @@ -983,6 +994,7 @@ COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
58471 if (!f.file)
58472 return -EBADF;
58473
58474 + buf.file = f.file;
58475 error = iterate_dir(f.file, &buf.ctx);
58476 if (error >= 0)
58477 error = buf.error;
58478 @@ -1003,6 +1015,7 @@ struct compat_getdents_callback64 {
58479 struct dir_context ctx;
58480 struct linux_dirent64 __user *current_dir;
58481 struct linux_dirent64 __user *previous;
58482 + struct file * file;
58483 int count;
58484 int error;
58485 };
58486 @@ -1019,6 +1032,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
58487 buf->error = -EINVAL; /* only used if we fail.. */
58488 if (reclen > buf->count)
58489 return -EINVAL;
58490 +
58491 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58492 + return 0;
58493 +
58494 dirent = buf->previous;
58495
58496 if (dirent) {
58497 @@ -1068,6 +1085,7 @@ COMPAT_SYSCALL_DEFINE3(getdents64, unsigned int, fd,
58498 if (!f.file)
58499 return -EBADF;
58500
58501 + buf.file = f.file;
58502 error = iterate_dir(f.file, &buf.ctx);
58503 if (error >= 0)
58504 error = buf.error;
58505 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
58506 index 4d24d17..4f8c09e 100644
58507 --- a/fs/compat_binfmt_elf.c
58508 +++ b/fs/compat_binfmt_elf.c
58509 @@ -30,11 +30,13 @@
58510 #undef elf_phdr
58511 #undef elf_shdr
58512 #undef elf_note
58513 +#undef elf_dyn
58514 #undef elf_addr_t
58515 #define elfhdr elf32_hdr
58516 #define elf_phdr elf32_phdr
58517 #define elf_shdr elf32_shdr
58518 #define elf_note elf32_note
58519 +#define elf_dyn Elf32_Dyn
58520 #define elf_addr_t Elf32_Addr
58521
58522 /*
58523 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
58524 index e822890..fed89d9 100644
58525 --- a/fs/compat_ioctl.c
58526 +++ b/fs/compat_ioctl.c
58527 @@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
58528 return -EFAULT;
58529 if (__get_user(udata, &ss32->iomem_base))
58530 return -EFAULT;
58531 - ss.iomem_base = compat_ptr(udata);
58532 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
58533 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
58534 __get_user(ss.port_high, &ss32->port_high))
58535 return -EFAULT;
58536 @@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
58537 for (i = 0; i < nmsgs; i++) {
58538 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
58539 return -EFAULT;
58540 - if (get_user(datap, &umsgs[i].buf) ||
58541 - put_user(compat_ptr(datap), &tmsgs[i].buf))
58542 + if (get_user(datap, (compat_caddr_t __user *)&umsgs[i].buf) ||
58543 + put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
58544 return -EFAULT;
58545 }
58546 return sys_ioctl(fd, cmd, (unsigned long)tdata);
58547 @@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
58548 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
58549 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
58550 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
58551 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
58552 + copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
58553 return -EFAULT;
58554
58555 return ioctl_preallocate(file, p);
58556 @@ -1618,8 +1618,8 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
58557 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
58558 {
58559 unsigned int a, b;
58560 - a = *(unsigned int *)p;
58561 - b = *(unsigned int *)q;
58562 + a = *(const unsigned int *)p;
58563 + b = *(const unsigned int *)q;
58564 if (a > b)
58565 return 1;
58566 if (a < b)
58567 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
58568 index e081acb..911df21 100644
58569 --- a/fs/configfs/dir.c
58570 +++ b/fs/configfs/dir.c
58571 @@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58572 }
58573 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
58574 struct configfs_dirent *next;
58575 - const char *name;
58576 + const unsigned char * name;
58577 + char d_name[sizeof(next->s_dentry->d_iname)];
58578 int len;
58579 struct inode *inode = NULL;
58580
58581 @@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58582 continue;
58583
58584 name = configfs_get_name(next);
58585 - len = strlen(name);
58586 + if (next->s_dentry && name == next->s_dentry->d_iname) {
58587 + len = next->s_dentry->d_name.len;
58588 + memcpy(d_name, name, len);
58589 + name = d_name;
58590 + } else
58591 + len = strlen(name);
58592
58593 /*
58594 * We'll have a dentry and an inode for
58595 diff --git a/fs/coredump.c b/fs/coredump.c
58596 index a93f7e6..d58bcbe 100644
58597 --- a/fs/coredump.c
58598 +++ b/fs/coredump.c
58599 @@ -442,8 +442,8 @@ static void wait_for_dump_helpers(struct file *file)
58600 struct pipe_inode_info *pipe = file->private_data;
58601
58602 pipe_lock(pipe);
58603 - pipe->readers++;
58604 - pipe->writers--;
58605 + atomic_inc(&pipe->readers);
58606 + atomic_dec(&pipe->writers);
58607 wake_up_interruptible_sync(&pipe->wait);
58608 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58609 pipe_unlock(pipe);
58610 @@ -452,11 +452,11 @@ static void wait_for_dump_helpers(struct file *file)
58611 * We actually want wait_event_freezable() but then we need
58612 * to clear TIF_SIGPENDING and improve dump_interrupted().
58613 */
58614 - wait_event_interruptible(pipe->wait, pipe->readers == 1);
58615 + wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
58616
58617 pipe_lock(pipe);
58618 - pipe->readers--;
58619 - pipe->writers++;
58620 + atomic_dec(&pipe->readers);
58621 + atomic_inc(&pipe->writers);
58622 pipe_unlock(pipe);
58623 }
58624
58625 @@ -503,7 +503,9 @@ void do_coredump(const siginfo_t *siginfo)
58626 struct files_struct *displaced;
58627 bool need_nonrelative = false;
58628 bool core_dumped = false;
58629 - static atomic_t core_dump_count = ATOMIC_INIT(0);
58630 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
58631 + long signr = siginfo->si_signo;
58632 + int dumpable;
58633 struct coredump_params cprm = {
58634 .siginfo = siginfo,
58635 .regs = signal_pt_regs(),
58636 @@ -516,12 +518,17 @@ void do_coredump(const siginfo_t *siginfo)
58637 .mm_flags = mm->flags,
58638 };
58639
58640 - audit_core_dumps(siginfo->si_signo);
58641 + audit_core_dumps(signr);
58642 +
58643 + dumpable = __get_dumpable(cprm.mm_flags);
58644 +
58645 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
58646 + gr_handle_brute_attach(dumpable);
58647
58648 binfmt = mm->binfmt;
58649 if (!binfmt || !binfmt->core_dump)
58650 goto fail;
58651 - if (!__get_dumpable(cprm.mm_flags))
58652 + if (!dumpable)
58653 goto fail;
58654
58655 cred = prepare_creds();
58656 @@ -540,7 +547,7 @@ void do_coredump(const siginfo_t *siginfo)
58657 need_nonrelative = true;
58658 }
58659
58660 - retval = coredump_wait(siginfo->si_signo, &core_state);
58661 + retval = coredump_wait(signr, &core_state);
58662 if (retval < 0)
58663 goto fail_creds;
58664
58665 @@ -583,7 +590,7 @@ void do_coredump(const siginfo_t *siginfo)
58666 }
58667 cprm.limit = RLIM_INFINITY;
58668
58669 - dump_count = atomic_inc_return(&core_dump_count);
58670 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
58671 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
58672 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
58673 task_tgid_vnr(current), current->comm);
58674 @@ -615,6 +622,8 @@ void do_coredump(const siginfo_t *siginfo)
58675 } else {
58676 struct inode *inode;
58677
58678 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
58679 +
58680 if (cprm.limit < binfmt->min_coredump)
58681 goto fail_unlock;
58682
58683 @@ -673,7 +682,7 @@ close_fail:
58684 filp_close(cprm.file, NULL);
58685 fail_dropcount:
58686 if (ispipe)
58687 - atomic_dec(&core_dump_count);
58688 + atomic_dec_unchecked(&core_dump_count);
58689 fail_unlock:
58690 kfree(cn.corename);
58691 coredump_finish(mm, core_dumped);
58692 @@ -694,6 +703,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
58693 struct file *file = cprm->file;
58694 loff_t pos = file->f_pos;
58695 ssize_t n;
58696 +
58697 + gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
58698 if (cprm->written + nr > cprm->limit)
58699 return 0;
58700 while (nr) {
58701 diff --git a/fs/dcache.c b/fs/dcache.c
58702 index e99c6f5..2838bf58 100644
58703 --- a/fs/dcache.c
58704 +++ b/fs/dcache.c
58705 @@ -1445,7 +1445,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
58706 */
58707 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
58708 if (name->len > DNAME_INLINE_LEN-1) {
58709 - dname = kmalloc(name->len + 1, GFP_KERNEL);
58710 + dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
58711 if (!dname) {
58712 kmem_cache_free(dentry_cache, dentry);
58713 return NULL;
58714 @@ -3413,7 +3413,8 @@ void __init vfs_caches_init(unsigned long mempages)
58715 mempages -= reserve;
58716
58717 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
58718 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
58719 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
58720 + SLAB_NO_SANITIZE, NULL);
58721
58722 dcache_init();
58723 inode_init();
58724 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
58725 index 8c41b52..145b1b9 100644
58726 --- a/fs/debugfs/inode.c
58727 +++ b/fs/debugfs/inode.c
58728 @@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
58729 */
58730 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
58731 {
58732 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
58733 + return __create_file(name, S_IFDIR | S_IRWXU,
58734 +#else
58735 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
58736 +#endif
58737 parent, NULL, NULL);
58738 }
58739 EXPORT_SYMBOL_GPL(debugfs_create_dir);
58740 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
58741 index d4a9431..77f9b2e 100644
58742 --- a/fs/ecryptfs/inode.c
58743 +++ b/fs/ecryptfs/inode.c
58744 @@ -673,7 +673,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
58745 old_fs = get_fs();
58746 set_fs(get_ds());
58747 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
58748 - (char __user *)lower_buf,
58749 + (char __force_user *)lower_buf,
58750 PATH_MAX);
58751 set_fs(old_fs);
58752 if (rc < 0)
58753 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
58754 index e4141f2..d8263e8 100644
58755 --- a/fs/ecryptfs/miscdev.c
58756 +++ b/fs/ecryptfs/miscdev.c
58757 @@ -304,7 +304,7 @@ check_list:
58758 goto out_unlock_msg_ctx;
58759 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
58760 if (msg_ctx->msg) {
58761 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
58762 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
58763 goto out_unlock_msg_ctx;
58764 i += packet_length_size;
58765 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
58766 diff --git a/fs/exec.c b/fs/exec.c
58767 index 238b7aa..a421d91 100644
58768 --- a/fs/exec.c
58769 +++ b/fs/exec.c
58770 @@ -56,8 +56,20 @@
58771 #include <linux/pipe_fs_i.h>
58772 #include <linux/oom.h>
58773 #include <linux/compat.h>
58774 +#include <linux/random.h>
58775 +#include <linux/seq_file.h>
58776 +#include <linux/coredump.h>
58777 +#include <linux/mman.h>
58778 +
58779 +#ifdef CONFIG_PAX_REFCOUNT
58780 +#include <linux/kallsyms.h>
58781 +#include <linux/kdebug.h>
58782 +#endif
58783 +
58784 +#include <trace/events/fs.h>
58785
58786 #include <asm/uaccess.h>
58787 +#include <asm/sections.h>
58788 #include <asm/mmu_context.h>
58789 #include <asm/tlb.h>
58790
58791 @@ -66,19 +78,34 @@
58792
58793 #include <trace/events/sched.h>
58794
58795 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58796 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
58797 +{
58798 + 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");
58799 +}
58800 +#endif
58801 +
58802 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
58803 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
58804 +EXPORT_SYMBOL(pax_set_initial_flags_func);
58805 +#endif
58806 +
58807 int suid_dumpable = 0;
58808
58809 static LIST_HEAD(formats);
58810 static DEFINE_RWLOCK(binfmt_lock);
58811
58812 +extern int gr_process_kernel_exec_ban(void);
58813 +extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
58814 +
58815 void __register_binfmt(struct linux_binfmt * fmt, int insert)
58816 {
58817 BUG_ON(!fmt);
58818 if (WARN_ON(!fmt->load_binary))
58819 return;
58820 write_lock(&binfmt_lock);
58821 - insert ? list_add(&fmt->lh, &formats) :
58822 - list_add_tail(&fmt->lh, &formats);
58823 + insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
58824 + pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
58825 write_unlock(&binfmt_lock);
58826 }
58827
58828 @@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
58829 void unregister_binfmt(struct linux_binfmt * fmt)
58830 {
58831 write_lock(&binfmt_lock);
58832 - list_del(&fmt->lh);
58833 + pax_list_del((struct list_head *)&fmt->lh);
58834 write_unlock(&binfmt_lock);
58835 }
58836
58837 @@ -183,18 +210,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58838 int write)
58839 {
58840 struct page *page;
58841 - int ret;
58842
58843 -#ifdef CONFIG_STACK_GROWSUP
58844 - if (write) {
58845 - ret = expand_downwards(bprm->vma, pos);
58846 - if (ret < 0)
58847 - return NULL;
58848 - }
58849 -#endif
58850 - ret = get_user_pages(current, bprm->mm, pos,
58851 - 1, write, 1, &page, NULL);
58852 - if (ret <= 0)
58853 + if (0 > expand_downwards(bprm->vma, pos))
58854 + return NULL;
58855 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
58856 return NULL;
58857
58858 if (write) {
58859 @@ -210,6 +229,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58860 if (size <= ARG_MAX)
58861 return page;
58862
58863 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58864 + // only allow 512KB for argv+env on suid/sgid binaries
58865 + // to prevent easy ASLR exhaustion
58866 + if (((!uid_eq(bprm->cred->euid, current_euid())) ||
58867 + (!gid_eq(bprm->cred->egid, current_egid()))) &&
58868 + (size > (512 * 1024))) {
58869 + put_page(page);
58870 + return NULL;
58871 + }
58872 +#endif
58873 +
58874 /*
58875 * Limit to 1/4-th the stack size for the argv+env strings.
58876 * This ensures that:
58877 @@ -269,6 +299,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58878 vma->vm_end = STACK_TOP_MAX;
58879 vma->vm_start = vma->vm_end - PAGE_SIZE;
58880 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
58881 +
58882 +#ifdef CONFIG_PAX_SEGMEXEC
58883 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
58884 +#endif
58885 +
58886 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
58887 INIT_LIST_HEAD(&vma->anon_vma_chain);
58888
58889 @@ -279,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58890 mm->stack_vm = mm->total_vm = 1;
58891 up_write(&mm->mmap_sem);
58892 bprm->p = vma->vm_end - sizeof(void *);
58893 +
58894 +#ifdef CONFIG_PAX_RANDUSTACK
58895 + if (randomize_va_space)
58896 + bprm->p ^= prandom_u32() & ~PAGE_MASK;
58897 +#endif
58898 +
58899 return 0;
58900 err:
58901 up_write(&mm->mmap_sem);
58902 @@ -399,7 +440,7 @@ struct user_arg_ptr {
58903 } ptr;
58904 };
58905
58906 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58907 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58908 {
58909 const char __user *native;
58910
58911 @@ -408,14 +449,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58912 compat_uptr_t compat;
58913
58914 if (get_user(compat, argv.ptr.compat + nr))
58915 - return ERR_PTR(-EFAULT);
58916 + return (const char __force_user *)ERR_PTR(-EFAULT);
58917
58918 return compat_ptr(compat);
58919 }
58920 #endif
58921
58922 if (get_user(native, argv.ptr.native + nr))
58923 - return ERR_PTR(-EFAULT);
58924 + return (const char __force_user *)ERR_PTR(-EFAULT);
58925
58926 return native;
58927 }
58928 @@ -434,7 +475,7 @@ static int count(struct user_arg_ptr argv, int max)
58929 if (!p)
58930 break;
58931
58932 - if (IS_ERR(p))
58933 + if (IS_ERR((const char __force_kernel *)p))
58934 return -EFAULT;
58935
58936 if (i >= max)
58937 @@ -469,7 +510,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
58938
58939 ret = -EFAULT;
58940 str = get_user_arg_ptr(argv, argc);
58941 - if (IS_ERR(str))
58942 + if (IS_ERR((const char __force_kernel *)str))
58943 goto out;
58944
58945 len = strnlen_user(str, MAX_ARG_STRLEN);
58946 @@ -551,7 +592,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
58947 int r;
58948 mm_segment_t oldfs = get_fs();
58949 struct user_arg_ptr argv = {
58950 - .ptr.native = (const char __user *const __user *)__argv,
58951 + .ptr.native = (const char __user * const __force_user *)__argv,
58952 };
58953
58954 set_fs(KERNEL_DS);
58955 @@ -586,7 +627,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58956 unsigned long new_end = old_end - shift;
58957 struct mmu_gather tlb;
58958
58959 - BUG_ON(new_start > new_end);
58960 + if (new_start >= new_end || new_start < mmap_min_addr)
58961 + return -ENOMEM;
58962
58963 /*
58964 * ensure there are no vmas between where we want to go
58965 @@ -595,6 +637,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58966 if (vma != find_vma(mm, new_start))
58967 return -EFAULT;
58968
58969 +#ifdef CONFIG_PAX_SEGMEXEC
58970 + BUG_ON(pax_find_mirror_vma(vma));
58971 +#endif
58972 +
58973 /*
58974 * cover the whole range: [new_start, old_end)
58975 */
58976 @@ -675,10 +721,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58977 stack_top = arch_align_stack(stack_top);
58978 stack_top = PAGE_ALIGN(stack_top);
58979
58980 - if (unlikely(stack_top < mmap_min_addr) ||
58981 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
58982 - return -ENOMEM;
58983 -
58984 stack_shift = vma->vm_end - stack_top;
58985
58986 bprm->p -= stack_shift;
58987 @@ -690,8 +732,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
58988 bprm->exec -= stack_shift;
58989
58990 down_write(&mm->mmap_sem);
58991 +
58992 + /* Move stack pages down in memory. */
58993 + if (stack_shift) {
58994 + ret = shift_arg_pages(vma, stack_shift);
58995 + if (ret)
58996 + goto out_unlock;
58997 + }
58998 +
58999 vm_flags = VM_STACK_FLAGS;
59000
59001 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
59002 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59003 + vm_flags &= ~VM_EXEC;
59004 +
59005 +#ifdef CONFIG_PAX_MPROTECT
59006 + if (mm->pax_flags & MF_PAX_MPROTECT)
59007 + vm_flags &= ~VM_MAYEXEC;
59008 +#endif
59009 +
59010 + }
59011 +#endif
59012 +
59013 /*
59014 * Adjust stack execute permissions; explicitly enable for
59015 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
59016 @@ -710,13 +772,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
59017 goto out_unlock;
59018 BUG_ON(prev != vma);
59019
59020 - /* Move stack pages down in memory. */
59021 - if (stack_shift) {
59022 - ret = shift_arg_pages(vma, stack_shift);
59023 - if (ret)
59024 - goto out_unlock;
59025 - }
59026 -
59027 /* mprotect_fixup is overkill to remove the temporary stack flags */
59028 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
59029
59030 @@ -740,6 +795,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
59031 #endif
59032 current->mm->start_stack = bprm->p;
59033 ret = expand_stack(vma, stack_base);
59034 +
59035 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
59036 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
59037 + unsigned long size;
59038 + vm_flags_t vm_flags;
59039 +
59040 + size = STACK_TOP - vma->vm_end;
59041 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
59042 +
59043 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
59044 +
59045 +#ifdef CONFIG_X86
59046 + if (!ret) {
59047 + size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
59048 + ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
59049 + }
59050 +#endif
59051 +
59052 + }
59053 +#endif
59054 +
59055 if (ret)
59056 ret = -EFAULT;
59057
59058 @@ -775,6 +851,8 @@ static struct file *do_open_exec(struct filename *name)
59059
59060 fsnotify_open(file);
59061
59062 + trace_open_exec(name->name);
59063 +
59064 err = deny_write_access(file);
59065 if (err)
59066 goto exit;
59067 @@ -804,7 +882,7 @@ int kernel_read(struct file *file, loff_t offset,
59068 old_fs = get_fs();
59069 set_fs(get_ds());
59070 /* The cast to a user pointer is valid due to the set_fs() */
59071 - result = vfs_read(file, (void __user *)addr, count, &pos);
59072 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
59073 set_fs(old_fs);
59074 return result;
59075 }
59076 @@ -849,6 +927,7 @@ static int exec_mmap(struct mm_struct *mm)
59077 tsk->mm = mm;
59078 tsk->active_mm = mm;
59079 activate_mm(active_mm, mm);
59080 + populate_stack();
59081 tsk->mm->vmacache_seqnum = 0;
59082 vmacache_flush(tsk);
59083 task_unlock(tsk);
59084 @@ -1246,7 +1325,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
59085 }
59086 rcu_read_unlock();
59087
59088 - if (p->fs->users > n_fs)
59089 + if (atomic_read(&p->fs->users) > n_fs)
59090 bprm->unsafe |= LSM_UNSAFE_SHARE;
59091 else
59092 p->fs->in_exec = 1;
59093 @@ -1422,6 +1501,31 @@ static int exec_binprm(struct linux_binprm *bprm)
59094 return ret;
59095 }
59096
59097 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59098 +static DEFINE_PER_CPU(u64, exec_counter);
59099 +static int __init init_exec_counters(void)
59100 +{
59101 + unsigned int cpu;
59102 +
59103 + for_each_possible_cpu(cpu) {
59104 + per_cpu(exec_counter, cpu) = (u64)cpu;
59105 + }
59106 +
59107 + return 0;
59108 +}
59109 +early_initcall(init_exec_counters);
59110 +static inline void increment_exec_counter(void)
59111 +{
59112 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
59113 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
59114 +}
59115 +#else
59116 +static inline void increment_exec_counter(void) {}
59117 +#endif
59118 +
59119 +extern void gr_handle_exec_args(struct linux_binprm *bprm,
59120 + struct user_arg_ptr argv);
59121 +
59122 /*
59123 * sys_execve() executes a new program.
59124 */
59125 @@ -1429,6 +1533,11 @@ static int do_execve_common(struct filename *filename,
59126 struct user_arg_ptr argv,
59127 struct user_arg_ptr envp)
59128 {
59129 +#ifdef CONFIG_GRKERNSEC
59130 + struct file *old_exec_file;
59131 + struct acl_subject_label *old_acl;
59132 + struct rlimit old_rlim[RLIM_NLIMITS];
59133 +#endif
59134 struct linux_binprm *bprm;
59135 struct file *file;
59136 struct files_struct *displaced;
59137 @@ -1437,6 +1546,8 @@ static int do_execve_common(struct filename *filename,
59138 if (IS_ERR(filename))
59139 return PTR_ERR(filename);
59140
59141 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
59142 +
59143 /*
59144 * We move the actual failure in case of RLIMIT_NPROC excess from
59145 * set*uid() to execve() because too many poorly written programs
59146 @@ -1474,11 +1585,21 @@ static int do_execve_common(struct filename *filename,
59147 if (IS_ERR(file))
59148 goto out_unmark;
59149
59150 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
59151 + retval = -EPERM;
59152 + goto out_unmark;
59153 + }
59154 +
59155 sched_exec();
59156
59157 bprm->file = file;
59158 bprm->filename = bprm->interp = filename->name;
59159
59160 + if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
59161 + retval = -EACCES;
59162 + goto out_unmark;
59163 + }
59164 +
59165 retval = bprm_mm_init(bprm);
59166 if (retval)
59167 goto out_unmark;
59168 @@ -1495,24 +1616,70 @@ static int do_execve_common(struct filename *filename,
59169 if (retval < 0)
59170 goto out;
59171
59172 +#ifdef CONFIG_GRKERNSEC
59173 + old_acl = current->acl;
59174 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
59175 + old_exec_file = current->exec_file;
59176 + get_file(file);
59177 + current->exec_file = file;
59178 +#endif
59179 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59180 + /* limit suid stack to 8MB
59181 + * we saved the old limits above and will restore them if this exec fails
59182 + */
59183 + if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
59184 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
59185 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
59186 +#endif
59187 +
59188 + if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
59189 + retval = -EPERM;
59190 + goto out_fail;
59191 + }
59192 +
59193 + if (!gr_tpe_allow(file)) {
59194 + retval = -EACCES;
59195 + goto out_fail;
59196 + }
59197 +
59198 + if (gr_check_crash_exec(file)) {
59199 + retval = -EACCES;
59200 + goto out_fail;
59201 + }
59202 +
59203 + retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
59204 + bprm->unsafe);
59205 + if (retval < 0)
59206 + goto out_fail;
59207 +
59208 retval = copy_strings_kernel(1, &bprm->filename, bprm);
59209 if (retval < 0)
59210 - goto out;
59211 + goto out_fail;
59212
59213 bprm->exec = bprm->p;
59214 retval = copy_strings(bprm->envc, envp, bprm);
59215 if (retval < 0)
59216 - goto out;
59217 + goto out_fail;
59218
59219 retval = copy_strings(bprm->argc, argv, bprm);
59220 if (retval < 0)
59221 - goto out;
59222 + goto out_fail;
59223 +
59224 + gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
59225 +
59226 + gr_handle_exec_args(bprm, argv);
59227
59228 retval = exec_binprm(bprm);
59229 if (retval < 0)
59230 - goto out;
59231 + goto out_fail;
59232 +#ifdef CONFIG_GRKERNSEC
59233 + if (old_exec_file)
59234 + fput(old_exec_file);
59235 +#endif
59236
59237 /* execve succeeded */
59238 +
59239 + increment_exec_counter();
59240 current->fs->in_exec = 0;
59241 current->in_execve = 0;
59242 acct_update_integrals(current);
59243 @@ -1523,6 +1690,14 @@ static int do_execve_common(struct filename *filename,
59244 put_files_struct(displaced);
59245 return retval;
59246
59247 +out_fail:
59248 +#ifdef CONFIG_GRKERNSEC
59249 + current->acl = old_acl;
59250 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
59251 + fput(current->exec_file);
59252 + current->exec_file = old_exec_file;
59253 +#endif
59254 +
59255 out:
59256 if (bprm->mm) {
59257 acct_arg_size(bprm, 0);
59258 @@ -1614,3 +1789,312 @@ COMPAT_SYSCALL_DEFINE3(execve, const char __user *, filename,
59259 return compat_do_execve(getname(filename), argv, envp);
59260 }
59261 #endif
59262 +
59263 +int pax_check_flags(unsigned long *flags)
59264 +{
59265 + int retval = 0;
59266 +
59267 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
59268 + if (*flags & MF_PAX_SEGMEXEC)
59269 + {
59270 + *flags &= ~MF_PAX_SEGMEXEC;
59271 + retval = -EINVAL;
59272 + }
59273 +#endif
59274 +
59275 + if ((*flags & MF_PAX_PAGEEXEC)
59276 +
59277 +#ifdef CONFIG_PAX_PAGEEXEC
59278 + && (*flags & MF_PAX_SEGMEXEC)
59279 +#endif
59280 +
59281 + )
59282 + {
59283 + *flags &= ~MF_PAX_PAGEEXEC;
59284 + retval = -EINVAL;
59285 + }
59286 +
59287 + if ((*flags & MF_PAX_MPROTECT)
59288 +
59289 +#ifdef CONFIG_PAX_MPROTECT
59290 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
59291 +#endif
59292 +
59293 + )
59294 + {
59295 + *flags &= ~MF_PAX_MPROTECT;
59296 + retval = -EINVAL;
59297 + }
59298 +
59299 + if ((*flags & MF_PAX_EMUTRAMP)
59300 +
59301 +#ifdef CONFIG_PAX_EMUTRAMP
59302 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
59303 +#endif
59304 +
59305 + )
59306 + {
59307 + *flags &= ~MF_PAX_EMUTRAMP;
59308 + retval = -EINVAL;
59309 + }
59310 +
59311 + return retval;
59312 +}
59313 +
59314 +EXPORT_SYMBOL(pax_check_flags);
59315 +
59316 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
59317 +char *pax_get_path(const struct path *path, char *buf, int buflen)
59318 +{
59319 + char *pathname = d_path(path, buf, buflen);
59320 +
59321 + if (IS_ERR(pathname))
59322 + goto toolong;
59323 +
59324 + pathname = mangle_path(buf, pathname, "\t\n\\");
59325 + if (!pathname)
59326 + goto toolong;
59327 +
59328 + *pathname = 0;
59329 + return buf;
59330 +
59331 +toolong:
59332 + return "<path too long>";
59333 +}
59334 +EXPORT_SYMBOL(pax_get_path);
59335 +
59336 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
59337 +{
59338 + struct task_struct *tsk = current;
59339 + struct mm_struct *mm = current->mm;
59340 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
59341 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
59342 + char *path_exec = NULL;
59343 + char *path_fault = NULL;
59344 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
59345 + siginfo_t info = { };
59346 +
59347 + if (buffer_exec && buffer_fault) {
59348 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
59349 +
59350 + down_read(&mm->mmap_sem);
59351 + vma = mm->mmap;
59352 + while (vma && (!vma_exec || !vma_fault)) {
59353 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
59354 + vma_exec = vma;
59355 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
59356 + vma_fault = vma;
59357 + vma = vma->vm_next;
59358 + }
59359 + if (vma_exec)
59360 + path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
59361 + if (vma_fault) {
59362 + start = vma_fault->vm_start;
59363 + end = vma_fault->vm_end;
59364 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
59365 + if (vma_fault->vm_file)
59366 + path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
59367 + else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
59368 + path_fault = "<heap>";
59369 + else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
59370 + path_fault = "<stack>";
59371 + else
59372 + path_fault = "<anonymous mapping>";
59373 + }
59374 + up_read(&mm->mmap_sem);
59375 + }
59376 + if (tsk->signal->curr_ip)
59377 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
59378 + else
59379 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
59380 + 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),
59381 + from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
59382 + free_page((unsigned long)buffer_exec);
59383 + free_page((unsigned long)buffer_fault);
59384 + pax_report_insns(regs, pc, sp);
59385 + info.si_signo = SIGKILL;
59386 + info.si_errno = 0;
59387 + info.si_code = SI_KERNEL;
59388 + info.si_pid = 0;
59389 + info.si_uid = 0;
59390 + do_coredump(&info);
59391 +}
59392 +#endif
59393 +
59394 +#ifdef CONFIG_PAX_REFCOUNT
59395 +void pax_report_refcount_overflow(struct pt_regs *regs)
59396 +{
59397 + if (current->signal->curr_ip)
59398 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
59399 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
59400 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
59401 + else
59402 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
59403 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
59404 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
59405 + preempt_disable();
59406 + show_regs(regs);
59407 + preempt_enable();
59408 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
59409 +}
59410 +#endif
59411 +
59412 +#ifdef CONFIG_PAX_USERCOPY
59413 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
59414 +static noinline int check_stack_object(const void *obj, unsigned long len)
59415 +{
59416 + const void * const stack = task_stack_page(current);
59417 + const void * const stackend = stack + THREAD_SIZE;
59418 +
59419 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
59420 + const void *frame = NULL;
59421 + const void *oldframe;
59422 +#endif
59423 +
59424 + if (obj + len < obj)
59425 + return -1;
59426 +
59427 + if (obj + len <= stack || stackend <= obj)
59428 + return 0;
59429 +
59430 + if (obj < stack || stackend < obj + len)
59431 + return -1;
59432 +
59433 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
59434 + oldframe = __builtin_frame_address(1);
59435 + if (oldframe)
59436 + frame = __builtin_frame_address(2);
59437 + /*
59438 + low ----------------------------------------------> high
59439 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
59440 + ^----------------^
59441 + allow copies only within here
59442 + */
59443 + while (stack <= frame && frame < stackend) {
59444 + /* if obj + len extends past the last frame, this
59445 + check won't pass and the next frame will be 0,
59446 + causing us to bail out and correctly report
59447 + the copy as invalid
59448 + */
59449 + if (obj + len <= frame)
59450 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
59451 + oldframe = frame;
59452 + frame = *(const void * const *)frame;
59453 + }
59454 + return -1;
59455 +#else
59456 + return 1;
59457 +#endif
59458 +}
59459 +
59460 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
59461 +{
59462 + if (current->signal->curr_ip)
59463 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59464 + &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59465 + else
59466 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59467 + to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59468 + dump_stack();
59469 + gr_handle_kernel_exploit();
59470 + do_group_exit(SIGKILL);
59471 +}
59472 +#endif
59473 +
59474 +#ifdef CONFIG_PAX_USERCOPY
59475 +
59476 +static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
59477 +{
59478 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
59479 + unsigned long textlow = ktla_ktva((unsigned long)_stext);
59480 +#ifdef CONFIG_MODULES
59481 + unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
59482 +#else
59483 + unsigned long texthigh = ktla_ktva((unsigned long)_etext);
59484 +#endif
59485 +
59486 +#else
59487 + unsigned long textlow = (unsigned long)_stext;
59488 + unsigned long texthigh = (unsigned long)_etext;
59489 +
59490 +#ifdef CONFIG_X86_64
59491 + /* check against linear mapping as well */
59492 + if (high > (unsigned long)__va(__pa(textlow)) &&
59493 + low < (unsigned long)__va(__pa(texthigh)))
59494 + return true;
59495 +#endif
59496 +
59497 +#endif
59498 +
59499 + if (high <= textlow || low >= texthigh)
59500 + return false;
59501 + else
59502 + return true;
59503 +}
59504 +#endif
59505 +
59506 +void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size)
59507 +{
59508 +#ifdef CONFIG_PAX_USERCOPY
59509 + const char *type;
59510 +#endif
59511 +
59512 +#ifndef CONFIG_STACK_GROWSUP
59513 + unsigned long stackstart = (unsigned long)task_stack_page(current);
59514 + unsigned long currentsp = (unsigned long)&stackstart;
59515 + if (unlikely((currentsp < stackstart + 512 ||
59516 + currentsp >= stackstart + THREAD_SIZE) && !in_interrupt()))
59517 + BUG();
59518 +#endif
59519 +
59520 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
59521 + if (const_size)
59522 + return;
59523 +#endif
59524 +
59525 +#ifdef CONFIG_PAX_USERCOPY
59526 + if (!n)
59527 + return;
59528 +
59529 + type = check_heap_object(ptr, n);
59530 + if (!type) {
59531 + int ret = check_stack_object(ptr, n);
59532 + if (ret == 1 || ret == 2)
59533 + return;
59534 + if (ret == 0) {
59535 + if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
59536 + type = "<kernel text>";
59537 + else
59538 + return;
59539 + } else
59540 + type = "<process stack>";
59541 + }
59542 +
59543 + pax_report_usercopy(ptr, n, to_user, type);
59544 +#endif
59545 +
59546 +}
59547 +EXPORT_SYMBOL(__check_object_size);
59548 +
59549 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
59550 +void pax_track_stack(void)
59551 +{
59552 + unsigned long sp = (unsigned long)&sp;
59553 + if (sp < current_thread_info()->lowest_stack &&
59554 + sp > (unsigned long)task_stack_page(current))
59555 + current_thread_info()->lowest_stack = sp;
59556 + if (unlikely((sp & ~(THREAD_SIZE - 1)) < (THREAD_SIZE/16)))
59557 + BUG();
59558 +}
59559 +EXPORT_SYMBOL(pax_track_stack);
59560 +#endif
59561 +
59562 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
59563 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
59564 +{
59565 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
59566 + dump_stack();
59567 + do_group_exit(SIGKILL);
59568 +}
59569 +EXPORT_SYMBOL(report_size_overflow);
59570 +#endif
59571 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
59572 index 9f9992b..8b59411 100644
59573 --- a/fs/ext2/balloc.c
59574 +++ b/fs/ext2/balloc.c
59575 @@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
59576
59577 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59578 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59579 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59580 + if (free_blocks < root_blocks + 1 &&
59581 !uid_eq(sbi->s_resuid, current_fsuid()) &&
59582 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59583 - !in_group_p (sbi->s_resgid))) {
59584 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59585 return 0;
59586 }
59587 return 1;
59588 diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
59589 index 9142614..97484fa 100644
59590 --- a/fs/ext2/xattr.c
59591 +++ b/fs/ext2/xattr.c
59592 @@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
59593 struct buffer_head *bh = NULL;
59594 struct ext2_xattr_entry *entry;
59595 char *end;
59596 - size_t rest = buffer_size;
59597 + size_t rest = buffer_size, total_size = 0;
59598 int error;
59599
59600 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
59601 @@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
59602 buffer += size;
59603 }
59604 rest -= size;
59605 + total_size += size;
59606 }
59607 }
59608 - error = buffer_size - rest; /* total size */
59609 + error = total_size;
59610
59611 cleanup:
59612 brelse(bh);
59613 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
59614 index 158b5d4..2432610 100644
59615 --- a/fs/ext3/balloc.c
59616 +++ b/fs/ext3/balloc.c
59617 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
59618
59619 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59620 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59621 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59622 + if (free_blocks < root_blocks + 1 &&
59623 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
59624 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59625 - !in_group_p (sbi->s_resgid))) {
59626 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59627 return 0;
59628 }
59629 return 1;
59630 diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
59631 index c6874be..f8a6ae8 100644
59632 --- a/fs/ext3/xattr.c
59633 +++ b/fs/ext3/xattr.c
59634 @@ -330,7 +330,7 @@ static int
59635 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59636 char *buffer, size_t buffer_size)
59637 {
59638 - size_t rest = buffer_size;
59639 + size_t rest = buffer_size, total_size = 0;
59640
59641 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
59642 const struct xattr_handler *handler =
59643 @@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59644 buffer += size;
59645 }
59646 rest -= size;
59647 + total_size += size;
59648 }
59649 }
59650 - return buffer_size - rest;
59651 + return total_size;
59652 }
59653
59654 static int
59655 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
59656 index 5c56785..77698a2 100644
59657 --- a/fs/ext4/balloc.c
59658 +++ b/fs/ext4/balloc.c
59659 @@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
59660 /* Hm, nope. Are (enough) root reserved clusters available? */
59661 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
59662 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
59663 - capable(CAP_SYS_RESOURCE) ||
59664 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
59665 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
59666 + capable_nolog(CAP_SYS_RESOURCE)) {
59667
59668 if (free_clusters >= (nclusters + dirty_clusters +
59669 resv_clusters))
59670 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
59671 index f542e48..c0275f5 100644
59672 --- a/fs/ext4/ext4.h
59673 +++ b/fs/ext4/ext4.h
59674 @@ -1274,19 +1274,19 @@ struct ext4_sb_info {
59675 unsigned long s_mb_last_start;
59676
59677 /* stats for buddy allocator */
59678 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
59679 - atomic_t s_bal_success; /* we found long enough chunks */
59680 - atomic_t s_bal_allocated; /* in blocks */
59681 - atomic_t s_bal_ex_scanned; /* total extents scanned */
59682 - atomic_t s_bal_goals; /* goal hits */
59683 - atomic_t s_bal_breaks; /* too long searches */
59684 - atomic_t s_bal_2orders; /* 2^order hits */
59685 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
59686 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
59687 + atomic_unchecked_t s_bal_allocated; /* in blocks */
59688 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
59689 + atomic_unchecked_t s_bal_goals; /* goal hits */
59690 + atomic_unchecked_t s_bal_breaks; /* too long searches */
59691 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
59692 spinlock_t s_bal_lock;
59693 unsigned long s_mb_buddies_generated;
59694 unsigned long long s_mb_generation_time;
59695 - atomic_t s_mb_lost_chunks;
59696 - atomic_t s_mb_preallocated;
59697 - atomic_t s_mb_discarded;
59698 + atomic_unchecked_t s_mb_lost_chunks;
59699 + atomic_unchecked_t s_mb_preallocated;
59700 + atomic_unchecked_t s_mb_discarded;
59701 atomic_t s_lock_busy;
59702
59703 /* locality groups */
59704 diff --git a/fs/ext4/indirect.c b/fs/ext4/indirect.c
59705 index e6574d7..c30cbe2 100644
59706 --- a/fs/ext4/indirect.c
59707 +++ b/fs/ext4/indirect.c
59708 @@ -1345,8 +1345,8 @@ static int free_hole_blocks(handle_t *handle, struct inode *inode,
59709 if (level == 0 ||
59710 (bh && all_zeroes((__le32 *)bh->b_data,
59711 (__le32 *)bh->b_data + addr_per_block))) {
59712 - ext4_free_data(handle, inode, parent_bh, &blk, &blk+1);
59713 - *i_data = 0;
59714 + ext4_free_data(handle, inode, parent_bh,
59715 + i_data, i_data + 1);
59716 }
59717 brelse(bh);
59718 bh = NULL;
59719 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
59720 index 2735a72..d083044 100644
59721 --- a/fs/ext4/mballoc.c
59722 +++ b/fs/ext4/mballoc.c
59723 @@ -1889,7 +1889,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
59724 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
59725
59726 if (EXT4_SB(sb)->s_mb_stats)
59727 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
59728 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
59729
59730 break;
59731 }
59732 @@ -2199,7 +2199,7 @@ repeat:
59733 ac->ac_status = AC_STATUS_CONTINUE;
59734 ac->ac_flags |= EXT4_MB_HINT_FIRST;
59735 cr = 3;
59736 - atomic_inc(&sbi->s_mb_lost_chunks);
59737 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
59738 goto repeat;
59739 }
59740 }
59741 @@ -2707,25 +2707,25 @@ int ext4_mb_release(struct super_block *sb)
59742 if (sbi->s_mb_stats) {
59743 ext4_msg(sb, KERN_INFO,
59744 "mballoc: %u blocks %u reqs (%u success)",
59745 - atomic_read(&sbi->s_bal_allocated),
59746 - atomic_read(&sbi->s_bal_reqs),
59747 - atomic_read(&sbi->s_bal_success));
59748 + atomic_read_unchecked(&sbi->s_bal_allocated),
59749 + atomic_read_unchecked(&sbi->s_bal_reqs),
59750 + atomic_read_unchecked(&sbi->s_bal_success));
59751 ext4_msg(sb, KERN_INFO,
59752 "mballoc: %u extents scanned, %u goal hits, "
59753 "%u 2^N hits, %u breaks, %u lost",
59754 - atomic_read(&sbi->s_bal_ex_scanned),
59755 - atomic_read(&sbi->s_bal_goals),
59756 - atomic_read(&sbi->s_bal_2orders),
59757 - atomic_read(&sbi->s_bal_breaks),
59758 - atomic_read(&sbi->s_mb_lost_chunks));
59759 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
59760 + atomic_read_unchecked(&sbi->s_bal_goals),
59761 + atomic_read_unchecked(&sbi->s_bal_2orders),
59762 + atomic_read_unchecked(&sbi->s_bal_breaks),
59763 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
59764 ext4_msg(sb, KERN_INFO,
59765 "mballoc: %lu generated and it took %Lu",
59766 sbi->s_mb_buddies_generated,
59767 sbi->s_mb_generation_time);
59768 ext4_msg(sb, KERN_INFO,
59769 "mballoc: %u preallocated, %u discarded",
59770 - atomic_read(&sbi->s_mb_preallocated),
59771 - atomic_read(&sbi->s_mb_discarded));
59772 + atomic_read_unchecked(&sbi->s_mb_preallocated),
59773 + atomic_read_unchecked(&sbi->s_mb_discarded));
59774 }
59775
59776 free_percpu(sbi->s_locality_groups);
59777 @@ -3179,16 +3179,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
59778 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
59779
59780 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
59781 - atomic_inc(&sbi->s_bal_reqs);
59782 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59783 + atomic_inc_unchecked(&sbi->s_bal_reqs);
59784 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59785 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
59786 - atomic_inc(&sbi->s_bal_success);
59787 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
59788 + atomic_inc_unchecked(&sbi->s_bal_success);
59789 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
59790 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
59791 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
59792 - atomic_inc(&sbi->s_bal_goals);
59793 + atomic_inc_unchecked(&sbi->s_bal_goals);
59794 if (ac->ac_found > sbi->s_mb_max_to_scan)
59795 - atomic_inc(&sbi->s_bal_breaks);
59796 + atomic_inc_unchecked(&sbi->s_bal_breaks);
59797 }
59798
59799 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
59800 @@ -3593,7 +3593,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
59801 trace_ext4_mb_new_inode_pa(ac, pa);
59802
59803 ext4_mb_use_inode_pa(ac, pa);
59804 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
59805 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
59806
59807 ei = EXT4_I(ac->ac_inode);
59808 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59809 @@ -3653,7 +3653,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
59810 trace_ext4_mb_new_group_pa(ac, pa);
59811
59812 ext4_mb_use_group_pa(ac, pa);
59813 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59814 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59815
59816 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59817 lg = ac->ac_lg;
59818 @@ -3742,7 +3742,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
59819 * from the bitmap and continue.
59820 */
59821 }
59822 - atomic_add(free, &sbi->s_mb_discarded);
59823 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
59824
59825 return err;
59826 }
59827 @@ -3760,7 +3760,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
59828 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
59829 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
59830 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
59831 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59832 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59833 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
59834
59835 return 0;
59836 diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
59837 index 04434ad..6404663 100644
59838 --- a/fs/ext4/mmp.c
59839 +++ b/fs/ext4/mmp.c
59840 @@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
59841 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
59842 const char *function, unsigned int line, const char *msg)
59843 {
59844 - __ext4_warning(sb, function, line, msg);
59845 + __ext4_warning(sb, function, line, "%s", msg);
59846 __ext4_warning(sb, function, line,
59847 "MMP failure info: last update time: %llu, last update "
59848 "node: %s, last update device: %s\n",
59849 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
59850 index 29a403c..f58dbdb 100644
59851 --- a/fs/ext4/super.c
59852 +++ b/fs/ext4/super.c
59853 @@ -1275,7 +1275,7 @@ static ext4_fsblk_t get_sb_block(void **data)
59854 }
59855
59856 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
59857 -static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59858 +static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59859 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
59860
59861 #ifdef CONFIG_QUOTA
59862 @@ -2453,7 +2453,7 @@ struct ext4_attr {
59863 int offset;
59864 int deprecated_val;
59865 } u;
59866 -};
59867 +} __do_const;
59868
59869 static int parse_strtoull(const char *buf,
59870 unsigned long long max, unsigned long long *value)
59871 diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
59872 index 4eec399..1d9444c 100644
59873 --- a/fs/ext4/xattr.c
59874 +++ b/fs/ext4/xattr.c
59875 @@ -383,7 +383,7 @@ static int
59876 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59877 char *buffer, size_t buffer_size)
59878 {
59879 - size_t rest = buffer_size;
59880 + size_t rest = buffer_size, total_size = 0;
59881
59882 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
59883 const struct xattr_handler *handler =
59884 @@ -400,9 +400,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59885 buffer += size;
59886 }
59887 rest -= size;
59888 + total_size += size;
59889 }
59890 }
59891 - return buffer_size - rest;
59892 + return total_size;
59893 }
59894
59895 static int
59896 diff --git a/fs/fcntl.c b/fs/fcntl.c
59897 index 72c82f6..a18b263 100644
59898 --- a/fs/fcntl.c
59899 +++ b/fs/fcntl.c
59900 @@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
59901 if (err)
59902 return err;
59903
59904 + if (gr_handle_chroot_fowner(pid, type))
59905 + return -ENOENT;
59906 + if (gr_check_protected_task_fowner(pid, type))
59907 + return -EACCES;
59908 +
59909 f_modown(filp, pid, type, force);
59910 return 0;
59911 }
59912 diff --git a/fs/fhandle.c b/fs/fhandle.c
59913 index 999ff5c..ac037c9 100644
59914 --- a/fs/fhandle.c
59915 +++ b/fs/fhandle.c
59916 @@ -8,6 +8,7 @@
59917 #include <linux/fs_struct.h>
59918 #include <linux/fsnotify.h>
59919 #include <linux/personality.h>
59920 +#include <linux/grsecurity.h>
59921 #include <asm/uaccess.h>
59922 #include "internal.h"
59923 #include "mount.h"
59924 @@ -67,8 +68,7 @@ static long do_sys_name_to_handle(struct path *path,
59925 } else
59926 retval = 0;
59927 /* copy the mount id */
59928 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
59929 - sizeof(*mnt_id)) ||
59930 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
59931 copy_to_user(ufh, handle,
59932 sizeof(struct file_handle) + handle_bytes))
59933 retval = -EFAULT;
59934 @@ -175,7 +175,7 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
59935 * the directory. Ideally we would like CAP_DAC_SEARCH.
59936 * But we don't have that
59937 */
59938 - if (!capable(CAP_DAC_READ_SEARCH)) {
59939 + if (!capable(CAP_DAC_READ_SEARCH) || !gr_chroot_fhandle()) {
59940 retval = -EPERM;
59941 goto out_err;
59942 }
59943 diff --git a/fs/file.c b/fs/file.c
59944 index 8f294cf..d0f3872 100644
59945 --- a/fs/file.c
59946 +++ b/fs/file.c
59947 @@ -16,6 +16,7 @@
59948 #include <linux/slab.h>
59949 #include <linux/vmalloc.h>
59950 #include <linux/file.h>
59951 +#include <linux/security.h>
59952 #include <linux/fdtable.h>
59953 #include <linux/bitops.h>
59954 #include <linux/interrupt.h>
59955 @@ -144,7 +145,7 @@ out:
59956 * Return <0 error code on error; 1 on successful completion.
59957 * The files->file_lock should be held on entry, and will be held on exit.
59958 */
59959 -static int expand_fdtable(struct files_struct *files, int nr)
59960 +static int expand_fdtable(struct files_struct *files, unsigned int nr)
59961 __releases(files->file_lock)
59962 __acquires(files->file_lock)
59963 {
59964 @@ -189,7 +190,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
59965 * expanded and execution may have blocked.
59966 * The files->file_lock should be held on entry, and will be held on exit.
59967 */
59968 -static int expand_files(struct files_struct *files, int nr)
59969 +static int expand_files(struct files_struct *files, unsigned int nr)
59970 {
59971 struct fdtable *fdt;
59972
59973 @@ -804,6 +805,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
59974 if (!file)
59975 return __close_fd(files, fd);
59976
59977 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
59978 if (fd >= rlimit(RLIMIT_NOFILE))
59979 return -EBADF;
59980
59981 @@ -830,6 +832,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
59982 if (unlikely(oldfd == newfd))
59983 return -EINVAL;
59984
59985 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
59986 if (newfd >= rlimit(RLIMIT_NOFILE))
59987 return -EBADF;
59988
59989 @@ -885,6 +888,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
59990 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
59991 {
59992 int err;
59993 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
59994 if (from >= rlimit(RLIMIT_NOFILE))
59995 return -EINVAL;
59996 err = alloc_fd(from, flags);
59997 diff --git a/fs/filesystems.c b/fs/filesystems.c
59998 index 5797d45..7d7d79a 100644
59999 --- a/fs/filesystems.c
60000 +++ b/fs/filesystems.c
60001 @@ -275,7 +275,11 @@ struct file_system_type *get_fs_type(const char *name)
60002 int len = dot ? dot - name : strlen(name);
60003
60004 fs = __get_fs_type(name, len);
60005 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
60006 + if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
60007 +#else
60008 if (!fs && (request_module("fs-%.*s", len, name) == 0))
60009 +#endif
60010 fs = __get_fs_type(name, len);
60011
60012 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
60013 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
60014 index 7dca743..543d620 100644
60015 --- a/fs/fs_struct.c
60016 +++ b/fs/fs_struct.c
60017 @@ -4,6 +4,7 @@
60018 #include <linux/path.h>
60019 #include <linux/slab.h>
60020 #include <linux/fs_struct.h>
60021 +#include <linux/grsecurity.h>
60022 #include "internal.h"
60023
60024 /*
60025 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
60026 write_seqcount_begin(&fs->seq);
60027 old_root = fs->root;
60028 fs->root = *path;
60029 + gr_set_chroot_entries(current, path);
60030 write_seqcount_end(&fs->seq);
60031 spin_unlock(&fs->lock);
60032 if (old_root.dentry)
60033 @@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
60034 int hits = 0;
60035 spin_lock(&fs->lock);
60036 write_seqcount_begin(&fs->seq);
60037 + /* this root replacement is only done by pivot_root,
60038 + leave grsec's chroot tagging alone for this task
60039 + so that a pivoted root isn't treated as a chroot
60040 + */
60041 hits += replace_path(&fs->root, old_root, new_root);
60042 hits += replace_path(&fs->pwd, old_root, new_root);
60043 write_seqcount_end(&fs->seq);
60044 @@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
60045 task_lock(tsk);
60046 spin_lock(&fs->lock);
60047 tsk->fs = NULL;
60048 - kill = !--fs->users;
60049 + gr_clear_chroot_entries(tsk);
60050 + kill = !atomic_dec_return(&fs->users);
60051 spin_unlock(&fs->lock);
60052 task_unlock(tsk);
60053 if (kill)
60054 @@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
60055 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
60056 /* We don't need to lock fs - think why ;-) */
60057 if (fs) {
60058 - fs->users = 1;
60059 + atomic_set(&fs->users, 1);
60060 fs->in_exec = 0;
60061 spin_lock_init(&fs->lock);
60062 seqcount_init(&fs->seq);
60063 @@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
60064 spin_lock(&old->lock);
60065 fs->root = old->root;
60066 path_get(&fs->root);
60067 + /* instead of calling gr_set_chroot_entries here,
60068 + we call it from every caller of this function
60069 + */
60070 fs->pwd = old->pwd;
60071 path_get(&fs->pwd);
60072 spin_unlock(&old->lock);
60073 @@ -139,8 +149,9 @@ int unshare_fs_struct(void)
60074
60075 task_lock(current);
60076 spin_lock(&fs->lock);
60077 - kill = !--fs->users;
60078 + kill = !atomic_dec_return(&fs->users);
60079 current->fs = new_fs;
60080 + gr_set_chroot_entries(current, &new_fs->root);
60081 spin_unlock(&fs->lock);
60082 task_unlock(current);
60083
60084 @@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
60085
60086 int current_umask(void)
60087 {
60088 - return current->fs->umask;
60089 + return current->fs->umask | gr_acl_umask();
60090 }
60091 EXPORT_SYMBOL(current_umask);
60092
60093 /* to be mentioned only in INIT_TASK */
60094 struct fs_struct init_fs = {
60095 - .users = 1,
60096 + .users = ATOMIC_INIT(1),
60097 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
60098 .seq = SEQCNT_ZERO(init_fs.seq),
60099 .umask = 0022,
60100 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
60101 index 29d7feb..303644d 100644
60102 --- a/fs/fscache/cookie.c
60103 +++ b/fs/fscache/cookie.c
60104 @@ -19,7 +19,7 @@
60105
60106 struct kmem_cache *fscache_cookie_jar;
60107
60108 -static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
60109 +static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
60110
60111 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
60112 static int fscache_alloc_object(struct fscache_cache *cache,
60113 @@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
60114 parent ? (char *) parent->def->name : "<no-parent>",
60115 def->name, netfs_data, enable);
60116
60117 - fscache_stat(&fscache_n_acquires);
60118 + fscache_stat_unchecked(&fscache_n_acquires);
60119
60120 /* if there's no parent cookie, then we don't create one here either */
60121 if (!parent) {
60122 - fscache_stat(&fscache_n_acquires_null);
60123 + fscache_stat_unchecked(&fscache_n_acquires_null);
60124 _leave(" [no parent]");
60125 return NULL;
60126 }
60127 @@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
60128 /* allocate and initialise a cookie */
60129 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
60130 if (!cookie) {
60131 - fscache_stat(&fscache_n_acquires_oom);
60132 + fscache_stat_unchecked(&fscache_n_acquires_oom);
60133 _leave(" [ENOMEM]");
60134 return NULL;
60135 }
60136 @@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
60137
60138 switch (cookie->def->type) {
60139 case FSCACHE_COOKIE_TYPE_INDEX:
60140 - fscache_stat(&fscache_n_cookie_index);
60141 + fscache_stat_unchecked(&fscache_n_cookie_index);
60142 break;
60143 case FSCACHE_COOKIE_TYPE_DATAFILE:
60144 - fscache_stat(&fscache_n_cookie_data);
60145 + fscache_stat_unchecked(&fscache_n_cookie_data);
60146 break;
60147 default:
60148 - fscache_stat(&fscache_n_cookie_special);
60149 + fscache_stat_unchecked(&fscache_n_cookie_special);
60150 break;
60151 }
60152
60153 @@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
60154 } else {
60155 atomic_dec(&parent->n_children);
60156 __fscache_cookie_put(cookie);
60157 - fscache_stat(&fscache_n_acquires_nobufs);
60158 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
60159 _leave(" = NULL");
60160 return NULL;
60161 }
60162 @@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
60163 }
60164 }
60165
60166 - fscache_stat(&fscache_n_acquires_ok);
60167 + fscache_stat_unchecked(&fscache_n_acquires_ok);
60168 _leave(" = %p", cookie);
60169 return cookie;
60170 }
60171 @@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
60172 cache = fscache_select_cache_for_object(cookie->parent);
60173 if (!cache) {
60174 up_read(&fscache_addremove_sem);
60175 - fscache_stat(&fscache_n_acquires_no_cache);
60176 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
60177 _leave(" = -ENOMEDIUM [no cache]");
60178 return -ENOMEDIUM;
60179 }
60180 @@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
60181 object = cache->ops->alloc_object(cache, cookie);
60182 fscache_stat_d(&fscache_n_cop_alloc_object);
60183 if (IS_ERR(object)) {
60184 - fscache_stat(&fscache_n_object_no_alloc);
60185 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
60186 ret = PTR_ERR(object);
60187 goto error;
60188 }
60189
60190 - fscache_stat(&fscache_n_object_alloc);
60191 + fscache_stat_unchecked(&fscache_n_object_alloc);
60192
60193 - object->debug_id = atomic_inc_return(&fscache_object_debug_id);
60194 + object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
60195
60196 _debug("ALLOC OBJ%x: %s {%lx}",
60197 object->debug_id, cookie->def->name, object->events);
60198 @@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
60199
60200 _enter("{%s}", cookie->def->name);
60201
60202 - fscache_stat(&fscache_n_invalidates);
60203 + fscache_stat_unchecked(&fscache_n_invalidates);
60204
60205 /* Only permit invalidation of data files. Invalidating an index will
60206 * require the caller to release all its attachments to the tree rooted
60207 @@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
60208 {
60209 struct fscache_object *object;
60210
60211 - fscache_stat(&fscache_n_updates);
60212 + fscache_stat_unchecked(&fscache_n_updates);
60213
60214 if (!cookie) {
60215 - fscache_stat(&fscache_n_updates_null);
60216 + fscache_stat_unchecked(&fscache_n_updates_null);
60217 _leave(" [no cookie]");
60218 return;
60219 }
60220 @@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
60221 */
60222 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
60223 {
60224 - fscache_stat(&fscache_n_relinquishes);
60225 + fscache_stat_unchecked(&fscache_n_relinquishes);
60226 if (retire)
60227 - fscache_stat(&fscache_n_relinquishes_retire);
60228 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
60229
60230 if (!cookie) {
60231 - fscache_stat(&fscache_n_relinquishes_null);
60232 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
60233 _leave(" [no cookie]");
60234 return;
60235 }
60236 @@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
60237 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
60238 goto inconsistent;
60239
60240 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
60241 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60242
60243 __fscache_use_cookie(cookie);
60244 if (fscache_submit_op(object, op) < 0)
60245 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
60246 index 4226f66..0fb3f45 100644
60247 --- a/fs/fscache/internal.h
60248 +++ b/fs/fscache/internal.h
60249 @@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
60250 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
60251 extern int fscache_wait_for_operation_activation(struct fscache_object *,
60252 struct fscache_operation *,
60253 - atomic_t *,
60254 - atomic_t *,
60255 + atomic_unchecked_t *,
60256 + atomic_unchecked_t *,
60257 void (*)(struct fscache_operation *));
60258 extern void fscache_invalidate_writes(struct fscache_cookie *);
60259
60260 @@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
60261 * stats.c
60262 */
60263 #ifdef CONFIG_FSCACHE_STATS
60264 -extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
60265 -extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
60266 +extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
60267 +extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
60268
60269 -extern atomic_t fscache_n_op_pend;
60270 -extern atomic_t fscache_n_op_run;
60271 -extern atomic_t fscache_n_op_enqueue;
60272 -extern atomic_t fscache_n_op_deferred_release;
60273 -extern atomic_t fscache_n_op_release;
60274 -extern atomic_t fscache_n_op_gc;
60275 -extern atomic_t fscache_n_op_cancelled;
60276 -extern atomic_t fscache_n_op_rejected;
60277 +extern atomic_unchecked_t fscache_n_op_pend;
60278 +extern atomic_unchecked_t fscache_n_op_run;
60279 +extern atomic_unchecked_t fscache_n_op_enqueue;
60280 +extern atomic_unchecked_t fscache_n_op_deferred_release;
60281 +extern atomic_unchecked_t fscache_n_op_release;
60282 +extern atomic_unchecked_t fscache_n_op_gc;
60283 +extern atomic_unchecked_t fscache_n_op_cancelled;
60284 +extern atomic_unchecked_t fscache_n_op_rejected;
60285
60286 -extern atomic_t fscache_n_attr_changed;
60287 -extern atomic_t fscache_n_attr_changed_ok;
60288 -extern atomic_t fscache_n_attr_changed_nobufs;
60289 -extern atomic_t fscache_n_attr_changed_nomem;
60290 -extern atomic_t fscache_n_attr_changed_calls;
60291 +extern atomic_unchecked_t fscache_n_attr_changed;
60292 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
60293 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
60294 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
60295 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
60296
60297 -extern atomic_t fscache_n_allocs;
60298 -extern atomic_t fscache_n_allocs_ok;
60299 -extern atomic_t fscache_n_allocs_wait;
60300 -extern atomic_t fscache_n_allocs_nobufs;
60301 -extern atomic_t fscache_n_allocs_intr;
60302 -extern atomic_t fscache_n_allocs_object_dead;
60303 -extern atomic_t fscache_n_alloc_ops;
60304 -extern atomic_t fscache_n_alloc_op_waits;
60305 +extern atomic_unchecked_t fscache_n_allocs;
60306 +extern atomic_unchecked_t fscache_n_allocs_ok;
60307 +extern atomic_unchecked_t fscache_n_allocs_wait;
60308 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
60309 +extern atomic_unchecked_t fscache_n_allocs_intr;
60310 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
60311 +extern atomic_unchecked_t fscache_n_alloc_ops;
60312 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
60313
60314 -extern atomic_t fscache_n_retrievals;
60315 -extern atomic_t fscache_n_retrievals_ok;
60316 -extern atomic_t fscache_n_retrievals_wait;
60317 -extern atomic_t fscache_n_retrievals_nodata;
60318 -extern atomic_t fscache_n_retrievals_nobufs;
60319 -extern atomic_t fscache_n_retrievals_intr;
60320 -extern atomic_t fscache_n_retrievals_nomem;
60321 -extern atomic_t fscache_n_retrievals_object_dead;
60322 -extern atomic_t fscache_n_retrieval_ops;
60323 -extern atomic_t fscache_n_retrieval_op_waits;
60324 +extern atomic_unchecked_t fscache_n_retrievals;
60325 +extern atomic_unchecked_t fscache_n_retrievals_ok;
60326 +extern atomic_unchecked_t fscache_n_retrievals_wait;
60327 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
60328 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
60329 +extern atomic_unchecked_t fscache_n_retrievals_intr;
60330 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
60331 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
60332 +extern atomic_unchecked_t fscache_n_retrieval_ops;
60333 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
60334
60335 -extern atomic_t fscache_n_stores;
60336 -extern atomic_t fscache_n_stores_ok;
60337 -extern atomic_t fscache_n_stores_again;
60338 -extern atomic_t fscache_n_stores_nobufs;
60339 -extern atomic_t fscache_n_stores_oom;
60340 -extern atomic_t fscache_n_store_ops;
60341 -extern atomic_t fscache_n_store_calls;
60342 -extern atomic_t fscache_n_store_pages;
60343 -extern atomic_t fscache_n_store_radix_deletes;
60344 -extern atomic_t fscache_n_store_pages_over_limit;
60345 +extern atomic_unchecked_t fscache_n_stores;
60346 +extern atomic_unchecked_t fscache_n_stores_ok;
60347 +extern atomic_unchecked_t fscache_n_stores_again;
60348 +extern atomic_unchecked_t fscache_n_stores_nobufs;
60349 +extern atomic_unchecked_t fscache_n_stores_oom;
60350 +extern atomic_unchecked_t fscache_n_store_ops;
60351 +extern atomic_unchecked_t fscache_n_store_calls;
60352 +extern atomic_unchecked_t fscache_n_store_pages;
60353 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
60354 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
60355
60356 -extern atomic_t fscache_n_store_vmscan_not_storing;
60357 -extern atomic_t fscache_n_store_vmscan_gone;
60358 -extern atomic_t fscache_n_store_vmscan_busy;
60359 -extern atomic_t fscache_n_store_vmscan_cancelled;
60360 -extern atomic_t fscache_n_store_vmscan_wait;
60361 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
60362 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
60363 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
60364 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
60365 +extern atomic_unchecked_t fscache_n_store_vmscan_wait;
60366
60367 -extern atomic_t fscache_n_marks;
60368 -extern atomic_t fscache_n_uncaches;
60369 +extern atomic_unchecked_t fscache_n_marks;
60370 +extern atomic_unchecked_t fscache_n_uncaches;
60371
60372 -extern atomic_t fscache_n_acquires;
60373 -extern atomic_t fscache_n_acquires_null;
60374 -extern atomic_t fscache_n_acquires_no_cache;
60375 -extern atomic_t fscache_n_acquires_ok;
60376 -extern atomic_t fscache_n_acquires_nobufs;
60377 -extern atomic_t fscache_n_acquires_oom;
60378 +extern atomic_unchecked_t fscache_n_acquires;
60379 +extern atomic_unchecked_t fscache_n_acquires_null;
60380 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
60381 +extern atomic_unchecked_t fscache_n_acquires_ok;
60382 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
60383 +extern atomic_unchecked_t fscache_n_acquires_oom;
60384
60385 -extern atomic_t fscache_n_invalidates;
60386 -extern atomic_t fscache_n_invalidates_run;
60387 +extern atomic_unchecked_t fscache_n_invalidates;
60388 +extern atomic_unchecked_t fscache_n_invalidates_run;
60389
60390 -extern atomic_t fscache_n_updates;
60391 -extern atomic_t fscache_n_updates_null;
60392 -extern atomic_t fscache_n_updates_run;
60393 +extern atomic_unchecked_t fscache_n_updates;
60394 +extern atomic_unchecked_t fscache_n_updates_null;
60395 +extern atomic_unchecked_t fscache_n_updates_run;
60396
60397 -extern atomic_t fscache_n_relinquishes;
60398 -extern atomic_t fscache_n_relinquishes_null;
60399 -extern atomic_t fscache_n_relinquishes_waitcrt;
60400 -extern atomic_t fscache_n_relinquishes_retire;
60401 +extern atomic_unchecked_t fscache_n_relinquishes;
60402 +extern atomic_unchecked_t fscache_n_relinquishes_null;
60403 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
60404 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
60405
60406 -extern atomic_t fscache_n_cookie_index;
60407 -extern atomic_t fscache_n_cookie_data;
60408 -extern atomic_t fscache_n_cookie_special;
60409 +extern atomic_unchecked_t fscache_n_cookie_index;
60410 +extern atomic_unchecked_t fscache_n_cookie_data;
60411 +extern atomic_unchecked_t fscache_n_cookie_special;
60412
60413 -extern atomic_t fscache_n_object_alloc;
60414 -extern atomic_t fscache_n_object_no_alloc;
60415 -extern atomic_t fscache_n_object_lookups;
60416 -extern atomic_t fscache_n_object_lookups_negative;
60417 -extern atomic_t fscache_n_object_lookups_positive;
60418 -extern atomic_t fscache_n_object_lookups_timed_out;
60419 -extern atomic_t fscache_n_object_created;
60420 -extern atomic_t fscache_n_object_avail;
60421 -extern atomic_t fscache_n_object_dead;
60422 +extern atomic_unchecked_t fscache_n_object_alloc;
60423 +extern atomic_unchecked_t fscache_n_object_no_alloc;
60424 +extern atomic_unchecked_t fscache_n_object_lookups;
60425 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
60426 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
60427 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
60428 +extern atomic_unchecked_t fscache_n_object_created;
60429 +extern atomic_unchecked_t fscache_n_object_avail;
60430 +extern atomic_unchecked_t fscache_n_object_dead;
60431
60432 -extern atomic_t fscache_n_checkaux_none;
60433 -extern atomic_t fscache_n_checkaux_okay;
60434 -extern atomic_t fscache_n_checkaux_update;
60435 -extern atomic_t fscache_n_checkaux_obsolete;
60436 +extern atomic_unchecked_t fscache_n_checkaux_none;
60437 +extern atomic_unchecked_t fscache_n_checkaux_okay;
60438 +extern atomic_unchecked_t fscache_n_checkaux_update;
60439 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
60440
60441 extern atomic_t fscache_n_cop_alloc_object;
60442 extern atomic_t fscache_n_cop_lookup_object;
60443 @@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
60444 atomic_inc(stat);
60445 }
60446
60447 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
60448 +{
60449 + atomic_inc_unchecked(stat);
60450 +}
60451 +
60452 static inline void fscache_stat_d(atomic_t *stat)
60453 {
60454 atomic_dec(stat);
60455 @@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
60456
60457 #define __fscache_stat(stat) (NULL)
60458 #define fscache_stat(stat) do {} while (0)
60459 +#define fscache_stat_unchecked(stat) do {} while (0)
60460 #define fscache_stat_d(stat) do {} while (0)
60461 #endif
60462
60463 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
60464 index d3b4539..ed0c659 100644
60465 --- a/fs/fscache/object.c
60466 +++ b/fs/fscache/object.c
60467 @@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
60468 _debug("LOOKUP \"%s\" in \"%s\"",
60469 cookie->def->name, object->cache->tag->name);
60470
60471 - fscache_stat(&fscache_n_object_lookups);
60472 + fscache_stat_unchecked(&fscache_n_object_lookups);
60473 fscache_stat(&fscache_n_cop_lookup_object);
60474 ret = object->cache->ops->lookup_object(object);
60475 fscache_stat_d(&fscache_n_cop_lookup_object);
60476 @@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
60477 if (ret == -ETIMEDOUT) {
60478 /* probably stuck behind another object, so move this one to
60479 * the back of the queue */
60480 - fscache_stat(&fscache_n_object_lookups_timed_out);
60481 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
60482 _leave(" [timeout]");
60483 return NO_TRANSIT;
60484 }
60485 @@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
60486 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
60487
60488 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60489 - fscache_stat(&fscache_n_object_lookups_negative);
60490 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
60491
60492 /* Allow write requests to begin stacking up and read requests to begin
60493 * returning ENODATA.
60494 @@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
60495 /* if we were still looking up, then we must have a positive lookup
60496 * result, in which case there may be data available */
60497 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60498 - fscache_stat(&fscache_n_object_lookups_positive);
60499 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
60500
60501 /* We do (presumably) have data */
60502 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
60503 @@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
60504 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
60505 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
60506 } else {
60507 - fscache_stat(&fscache_n_object_created);
60508 + fscache_stat_unchecked(&fscache_n_object_created);
60509 }
60510
60511 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
60512 @@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
60513 fscache_stat_d(&fscache_n_cop_lookup_complete);
60514
60515 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
60516 - fscache_stat(&fscache_n_object_avail);
60517 + fscache_stat_unchecked(&fscache_n_object_avail);
60518
60519 _leave("");
60520 return transit_to(JUMPSTART_DEPS);
60521 @@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
60522
60523 /* this just shifts the object release to the work processor */
60524 fscache_put_object(object);
60525 - fscache_stat(&fscache_n_object_dead);
60526 + fscache_stat_unchecked(&fscache_n_object_dead);
60527
60528 _leave("");
60529 return transit_to(OBJECT_DEAD);
60530 @@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60531 enum fscache_checkaux result;
60532
60533 if (!object->cookie->def->check_aux) {
60534 - fscache_stat(&fscache_n_checkaux_none);
60535 + fscache_stat_unchecked(&fscache_n_checkaux_none);
60536 return FSCACHE_CHECKAUX_OKAY;
60537 }
60538
60539 @@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60540 switch (result) {
60541 /* entry okay as is */
60542 case FSCACHE_CHECKAUX_OKAY:
60543 - fscache_stat(&fscache_n_checkaux_okay);
60544 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
60545 break;
60546
60547 /* entry requires update */
60548 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
60549 - fscache_stat(&fscache_n_checkaux_update);
60550 + fscache_stat_unchecked(&fscache_n_checkaux_update);
60551 break;
60552
60553 /* entry requires deletion */
60554 case FSCACHE_CHECKAUX_OBSOLETE:
60555 - fscache_stat(&fscache_n_checkaux_obsolete);
60556 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
60557 break;
60558
60559 default:
60560 @@ -992,7 +992,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
60561 {
60562 const struct fscache_state *s;
60563
60564 - fscache_stat(&fscache_n_invalidates_run);
60565 + fscache_stat_unchecked(&fscache_n_invalidates_run);
60566 fscache_stat(&fscache_n_cop_invalidate_object);
60567 s = _fscache_invalidate_object(object, event);
60568 fscache_stat_d(&fscache_n_cop_invalidate_object);
60569 @@ -1007,7 +1007,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
60570 {
60571 _enter("{OBJ%x},%d", object->debug_id, event);
60572
60573 - fscache_stat(&fscache_n_updates_run);
60574 + fscache_stat_unchecked(&fscache_n_updates_run);
60575 fscache_stat(&fscache_n_cop_update_object);
60576 object->cache->ops->update_object(object);
60577 fscache_stat_d(&fscache_n_cop_update_object);
60578 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
60579 index 318071a..379938b 100644
60580 --- a/fs/fscache/operation.c
60581 +++ b/fs/fscache/operation.c
60582 @@ -17,7 +17,7 @@
60583 #include <linux/slab.h>
60584 #include "internal.h"
60585
60586 -atomic_t fscache_op_debug_id;
60587 +atomic_unchecked_t fscache_op_debug_id;
60588 EXPORT_SYMBOL(fscache_op_debug_id);
60589
60590 /**
60591 @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
60592 ASSERTCMP(atomic_read(&op->usage), >, 0);
60593 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
60594
60595 - fscache_stat(&fscache_n_op_enqueue);
60596 + fscache_stat_unchecked(&fscache_n_op_enqueue);
60597 switch (op->flags & FSCACHE_OP_TYPE) {
60598 case FSCACHE_OP_ASYNC:
60599 _debug("queue async");
60600 @@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
60601 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
60602 if (op->processor)
60603 fscache_enqueue_operation(op);
60604 - fscache_stat(&fscache_n_op_run);
60605 + fscache_stat_unchecked(&fscache_n_op_run);
60606 }
60607
60608 /*
60609 @@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60610 if (object->n_in_progress > 0) {
60611 atomic_inc(&op->usage);
60612 list_add_tail(&op->pend_link, &object->pending_ops);
60613 - fscache_stat(&fscache_n_op_pend);
60614 + fscache_stat_unchecked(&fscache_n_op_pend);
60615 } else if (!list_empty(&object->pending_ops)) {
60616 atomic_inc(&op->usage);
60617 list_add_tail(&op->pend_link, &object->pending_ops);
60618 - fscache_stat(&fscache_n_op_pend);
60619 + fscache_stat_unchecked(&fscache_n_op_pend);
60620 fscache_start_operations(object);
60621 } else {
60622 ASSERTCMP(object->n_in_progress, ==, 0);
60623 @@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60624 object->n_exclusive++; /* reads and writes must wait */
60625 atomic_inc(&op->usage);
60626 list_add_tail(&op->pend_link, &object->pending_ops);
60627 - fscache_stat(&fscache_n_op_pend);
60628 + fscache_stat_unchecked(&fscache_n_op_pend);
60629 ret = 0;
60630 } else {
60631 /* If we're in any other state, there must have been an I/O
60632 @@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
60633 if (object->n_exclusive > 0) {
60634 atomic_inc(&op->usage);
60635 list_add_tail(&op->pend_link, &object->pending_ops);
60636 - fscache_stat(&fscache_n_op_pend);
60637 + fscache_stat_unchecked(&fscache_n_op_pend);
60638 } else if (!list_empty(&object->pending_ops)) {
60639 atomic_inc(&op->usage);
60640 list_add_tail(&op->pend_link, &object->pending_ops);
60641 - fscache_stat(&fscache_n_op_pend);
60642 + fscache_stat_unchecked(&fscache_n_op_pend);
60643 fscache_start_operations(object);
60644 } else {
60645 ASSERTCMP(object->n_exclusive, ==, 0);
60646 @@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
60647 object->n_ops++;
60648 atomic_inc(&op->usage);
60649 list_add_tail(&op->pend_link, &object->pending_ops);
60650 - fscache_stat(&fscache_n_op_pend);
60651 + fscache_stat_unchecked(&fscache_n_op_pend);
60652 ret = 0;
60653 } else if (fscache_object_is_dying(object)) {
60654 - fscache_stat(&fscache_n_op_rejected);
60655 + fscache_stat_unchecked(&fscache_n_op_rejected);
60656 op->state = FSCACHE_OP_ST_CANCELLED;
60657 ret = -ENOBUFS;
60658 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
60659 @@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
60660 ret = -EBUSY;
60661 if (op->state == FSCACHE_OP_ST_PENDING) {
60662 ASSERT(!list_empty(&op->pend_link));
60663 - fscache_stat(&fscache_n_op_cancelled);
60664 + fscache_stat_unchecked(&fscache_n_op_cancelled);
60665 list_del_init(&op->pend_link);
60666 if (do_cancel)
60667 do_cancel(op);
60668 @@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
60669 while (!list_empty(&object->pending_ops)) {
60670 op = list_entry(object->pending_ops.next,
60671 struct fscache_operation, pend_link);
60672 - fscache_stat(&fscache_n_op_cancelled);
60673 + fscache_stat_unchecked(&fscache_n_op_cancelled);
60674 list_del_init(&op->pend_link);
60675
60676 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
60677 @@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
60678 op->state, ==, FSCACHE_OP_ST_CANCELLED);
60679 op->state = FSCACHE_OP_ST_DEAD;
60680
60681 - fscache_stat(&fscache_n_op_release);
60682 + fscache_stat_unchecked(&fscache_n_op_release);
60683
60684 if (op->release) {
60685 op->release(op);
60686 @@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
60687 * lock, and defer it otherwise */
60688 if (!spin_trylock(&object->lock)) {
60689 _debug("defer put");
60690 - fscache_stat(&fscache_n_op_deferred_release);
60691 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
60692
60693 cache = object->cache;
60694 spin_lock(&cache->op_gc_list_lock);
60695 @@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
60696
60697 _debug("GC DEFERRED REL OBJ%x OP%x",
60698 object->debug_id, op->debug_id);
60699 - fscache_stat(&fscache_n_op_gc);
60700 + fscache_stat_unchecked(&fscache_n_op_gc);
60701
60702 ASSERTCMP(atomic_read(&op->usage), ==, 0);
60703 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
60704 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
60705 index 7f5c658..6c1e164 100644
60706 --- a/fs/fscache/page.c
60707 +++ b/fs/fscache/page.c
60708 @@ -61,7 +61,7 @@ try_again:
60709 val = radix_tree_lookup(&cookie->stores, page->index);
60710 if (!val) {
60711 rcu_read_unlock();
60712 - fscache_stat(&fscache_n_store_vmscan_not_storing);
60713 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
60714 __fscache_uncache_page(cookie, page);
60715 return true;
60716 }
60717 @@ -91,11 +91,11 @@ try_again:
60718 spin_unlock(&cookie->stores_lock);
60719
60720 if (xpage) {
60721 - fscache_stat(&fscache_n_store_vmscan_cancelled);
60722 - fscache_stat(&fscache_n_store_radix_deletes);
60723 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
60724 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60725 ASSERTCMP(xpage, ==, page);
60726 } else {
60727 - fscache_stat(&fscache_n_store_vmscan_gone);
60728 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
60729 }
60730
60731 wake_up_bit(&cookie->flags, 0);
60732 @@ -110,11 +110,11 @@ page_busy:
60733 * sleeping on memory allocation, so we may need to impose a timeout
60734 * too. */
60735 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
60736 - fscache_stat(&fscache_n_store_vmscan_busy);
60737 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
60738 return false;
60739 }
60740
60741 - fscache_stat(&fscache_n_store_vmscan_wait);
60742 + fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
60743 __fscache_wait_on_page_write(cookie, page);
60744 gfp &= ~__GFP_WAIT;
60745 goto try_again;
60746 @@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
60747 FSCACHE_COOKIE_STORING_TAG);
60748 if (!radix_tree_tag_get(&cookie->stores, page->index,
60749 FSCACHE_COOKIE_PENDING_TAG)) {
60750 - fscache_stat(&fscache_n_store_radix_deletes);
60751 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60752 xpage = radix_tree_delete(&cookie->stores, page->index);
60753 }
60754 spin_unlock(&cookie->stores_lock);
60755 @@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
60756
60757 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
60758
60759 - fscache_stat(&fscache_n_attr_changed_calls);
60760 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
60761
60762 if (fscache_object_is_active(object)) {
60763 fscache_stat(&fscache_n_cop_attr_changed);
60764 @@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60765
60766 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60767
60768 - fscache_stat(&fscache_n_attr_changed);
60769 + fscache_stat_unchecked(&fscache_n_attr_changed);
60770
60771 op = kzalloc(sizeof(*op), GFP_KERNEL);
60772 if (!op) {
60773 - fscache_stat(&fscache_n_attr_changed_nomem);
60774 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
60775 _leave(" = -ENOMEM");
60776 return -ENOMEM;
60777 }
60778 @@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60779 if (fscache_submit_exclusive_op(object, op) < 0)
60780 goto nobufs;
60781 spin_unlock(&cookie->lock);
60782 - fscache_stat(&fscache_n_attr_changed_ok);
60783 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
60784 fscache_put_operation(op);
60785 _leave(" = 0");
60786 return 0;
60787 @@ -225,7 +225,7 @@ nobufs:
60788 kfree(op);
60789 if (wake_cookie)
60790 __fscache_wake_unused_cookie(cookie);
60791 - fscache_stat(&fscache_n_attr_changed_nobufs);
60792 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
60793 _leave(" = %d", -ENOBUFS);
60794 return -ENOBUFS;
60795 }
60796 @@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
60797 /* allocate a retrieval operation and attempt to submit it */
60798 op = kzalloc(sizeof(*op), GFP_NOIO);
60799 if (!op) {
60800 - fscache_stat(&fscache_n_retrievals_nomem);
60801 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60802 return NULL;
60803 }
60804
60805 @@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
60806 return 0;
60807 }
60808
60809 - fscache_stat(&fscache_n_retrievals_wait);
60810 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
60811
60812 jif = jiffies;
60813 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
60814 fscache_wait_bit_interruptible,
60815 TASK_INTERRUPTIBLE) != 0) {
60816 - fscache_stat(&fscache_n_retrievals_intr);
60817 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
60818 _leave(" = -ERESTARTSYS");
60819 return -ERESTARTSYS;
60820 }
60821 @@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
60822 */
60823 int fscache_wait_for_operation_activation(struct fscache_object *object,
60824 struct fscache_operation *op,
60825 - atomic_t *stat_op_waits,
60826 - atomic_t *stat_object_dead,
60827 + atomic_unchecked_t *stat_op_waits,
60828 + atomic_unchecked_t *stat_object_dead,
60829 void (*do_cancel)(struct fscache_operation *))
60830 {
60831 int ret;
60832 @@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60833
60834 _debug(">>> WT");
60835 if (stat_op_waits)
60836 - fscache_stat(stat_op_waits);
60837 + fscache_stat_unchecked(stat_op_waits);
60838 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
60839 fscache_wait_bit_interruptible,
60840 TASK_INTERRUPTIBLE) != 0) {
60841 @@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60842 check_if_dead:
60843 if (op->state == FSCACHE_OP_ST_CANCELLED) {
60844 if (stat_object_dead)
60845 - fscache_stat(stat_object_dead);
60846 + fscache_stat_unchecked(stat_object_dead);
60847 _leave(" = -ENOBUFS [cancelled]");
60848 return -ENOBUFS;
60849 }
60850 @@ -366,7 +366,7 @@ check_if_dead:
60851 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
60852 fscache_cancel_op(op, do_cancel);
60853 if (stat_object_dead)
60854 - fscache_stat(stat_object_dead);
60855 + fscache_stat_unchecked(stat_object_dead);
60856 return -ENOBUFS;
60857 }
60858 return 0;
60859 @@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60860
60861 _enter("%p,%p,,,", cookie, page);
60862
60863 - fscache_stat(&fscache_n_retrievals);
60864 + fscache_stat_unchecked(&fscache_n_retrievals);
60865
60866 if (hlist_empty(&cookie->backing_objects))
60867 goto nobufs;
60868 @@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60869 goto nobufs_unlock_dec;
60870 spin_unlock(&cookie->lock);
60871
60872 - fscache_stat(&fscache_n_retrieval_ops);
60873 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
60874
60875 /* pin the netfs read context in case we need to do the actual netfs
60876 * read because we've encountered a cache read failure */
60877 @@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60878
60879 error:
60880 if (ret == -ENOMEM)
60881 - fscache_stat(&fscache_n_retrievals_nomem);
60882 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60883 else if (ret == -ERESTARTSYS)
60884 - fscache_stat(&fscache_n_retrievals_intr);
60885 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
60886 else if (ret == -ENODATA)
60887 - fscache_stat(&fscache_n_retrievals_nodata);
60888 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60889 else if (ret < 0)
60890 - fscache_stat(&fscache_n_retrievals_nobufs);
60891 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60892 else
60893 - fscache_stat(&fscache_n_retrievals_ok);
60894 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
60895
60896 fscache_put_retrieval(op);
60897 _leave(" = %d", ret);
60898 @@ -490,7 +490,7 @@ nobufs_unlock:
60899 __fscache_wake_unused_cookie(cookie);
60900 kfree(op);
60901 nobufs:
60902 - fscache_stat(&fscache_n_retrievals_nobufs);
60903 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60904 _leave(" = -ENOBUFS");
60905 return -ENOBUFS;
60906 }
60907 @@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60908
60909 _enter("%p,,%d,,,", cookie, *nr_pages);
60910
60911 - fscache_stat(&fscache_n_retrievals);
60912 + fscache_stat_unchecked(&fscache_n_retrievals);
60913
60914 if (hlist_empty(&cookie->backing_objects))
60915 goto nobufs;
60916 @@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60917 goto nobufs_unlock_dec;
60918 spin_unlock(&cookie->lock);
60919
60920 - fscache_stat(&fscache_n_retrieval_ops);
60921 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
60922
60923 /* pin the netfs read context in case we need to do the actual netfs
60924 * read because we've encountered a cache read failure */
60925 @@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60926
60927 error:
60928 if (ret == -ENOMEM)
60929 - fscache_stat(&fscache_n_retrievals_nomem);
60930 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60931 else if (ret == -ERESTARTSYS)
60932 - fscache_stat(&fscache_n_retrievals_intr);
60933 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
60934 else if (ret == -ENODATA)
60935 - fscache_stat(&fscache_n_retrievals_nodata);
60936 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60937 else if (ret < 0)
60938 - fscache_stat(&fscache_n_retrievals_nobufs);
60939 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60940 else
60941 - fscache_stat(&fscache_n_retrievals_ok);
60942 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
60943
60944 fscache_put_retrieval(op);
60945 _leave(" = %d", ret);
60946 @@ -621,7 +621,7 @@ nobufs_unlock:
60947 if (wake_cookie)
60948 __fscache_wake_unused_cookie(cookie);
60949 nobufs:
60950 - fscache_stat(&fscache_n_retrievals_nobufs);
60951 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60952 _leave(" = -ENOBUFS");
60953 return -ENOBUFS;
60954 }
60955 @@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60956
60957 _enter("%p,%p,,,", cookie, page);
60958
60959 - fscache_stat(&fscache_n_allocs);
60960 + fscache_stat_unchecked(&fscache_n_allocs);
60961
60962 if (hlist_empty(&cookie->backing_objects))
60963 goto nobufs;
60964 @@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60965 goto nobufs_unlock_dec;
60966 spin_unlock(&cookie->lock);
60967
60968 - fscache_stat(&fscache_n_alloc_ops);
60969 + fscache_stat_unchecked(&fscache_n_alloc_ops);
60970
60971 ret = fscache_wait_for_operation_activation(
60972 object, &op->op,
60973 @@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60974
60975 error:
60976 if (ret == -ERESTARTSYS)
60977 - fscache_stat(&fscache_n_allocs_intr);
60978 + fscache_stat_unchecked(&fscache_n_allocs_intr);
60979 else if (ret < 0)
60980 - fscache_stat(&fscache_n_allocs_nobufs);
60981 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60982 else
60983 - fscache_stat(&fscache_n_allocs_ok);
60984 + fscache_stat_unchecked(&fscache_n_allocs_ok);
60985
60986 fscache_put_retrieval(op);
60987 _leave(" = %d", ret);
60988 @@ -715,7 +715,7 @@ nobufs_unlock:
60989 if (wake_cookie)
60990 __fscache_wake_unused_cookie(cookie);
60991 nobufs:
60992 - fscache_stat(&fscache_n_allocs_nobufs);
60993 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60994 _leave(" = -ENOBUFS");
60995 return -ENOBUFS;
60996 }
60997 @@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60998
60999 spin_lock(&cookie->stores_lock);
61000
61001 - fscache_stat(&fscache_n_store_calls);
61002 + fscache_stat_unchecked(&fscache_n_store_calls);
61003
61004 /* find a page to store */
61005 page = NULL;
61006 @@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
61007 page = results[0];
61008 _debug("gang %d [%lx]", n, page->index);
61009 if (page->index > op->store_limit) {
61010 - fscache_stat(&fscache_n_store_pages_over_limit);
61011 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
61012 goto superseded;
61013 }
61014
61015 @@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
61016 spin_unlock(&cookie->stores_lock);
61017 spin_unlock(&object->lock);
61018
61019 - fscache_stat(&fscache_n_store_pages);
61020 + fscache_stat_unchecked(&fscache_n_store_pages);
61021 fscache_stat(&fscache_n_cop_write_page);
61022 ret = object->cache->ops->write_page(op, page);
61023 fscache_stat_d(&fscache_n_cop_write_page);
61024 @@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
61025 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
61026 ASSERT(PageFsCache(page));
61027
61028 - fscache_stat(&fscache_n_stores);
61029 + fscache_stat_unchecked(&fscache_n_stores);
61030
61031 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
61032 _leave(" = -ENOBUFS [invalidating]");
61033 @@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
61034 spin_unlock(&cookie->stores_lock);
61035 spin_unlock(&object->lock);
61036
61037 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
61038 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
61039 op->store_limit = object->store_limit;
61040
61041 __fscache_use_cookie(cookie);
61042 @@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
61043
61044 spin_unlock(&cookie->lock);
61045 radix_tree_preload_end();
61046 - fscache_stat(&fscache_n_store_ops);
61047 - fscache_stat(&fscache_n_stores_ok);
61048 + fscache_stat_unchecked(&fscache_n_store_ops);
61049 + fscache_stat_unchecked(&fscache_n_stores_ok);
61050
61051 /* the work queue now carries its own ref on the object */
61052 fscache_put_operation(&op->op);
61053 @@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
61054 return 0;
61055
61056 already_queued:
61057 - fscache_stat(&fscache_n_stores_again);
61058 + fscache_stat_unchecked(&fscache_n_stores_again);
61059 already_pending:
61060 spin_unlock(&cookie->stores_lock);
61061 spin_unlock(&object->lock);
61062 spin_unlock(&cookie->lock);
61063 radix_tree_preload_end();
61064 kfree(op);
61065 - fscache_stat(&fscache_n_stores_ok);
61066 + fscache_stat_unchecked(&fscache_n_stores_ok);
61067 _leave(" = 0");
61068 return 0;
61069
61070 @@ -1024,14 +1024,14 @@ nobufs:
61071 kfree(op);
61072 if (wake_cookie)
61073 __fscache_wake_unused_cookie(cookie);
61074 - fscache_stat(&fscache_n_stores_nobufs);
61075 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
61076 _leave(" = -ENOBUFS");
61077 return -ENOBUFS;
61078
61079 nomem_free:
61080 kfree(op);
61081 nomem:
61082 - fscache_stat(&fscache_n_stores_oom);
61083 + fscache_stat_unchecked(&fscache_n_stores_oom);
61084 _leave(" = -ENOMEM");
61085 return -ENOMEM;
61086 }
61087 @@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
61088 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
61089 ASSERTCMP(page, !=, NULL);
61090
61091 - fscache_stat(&fscache_n_uncaches);
61092 + fscache_stat_unchecked(&fscache_n_uncaches);
61093
61094 /* cache withdrawal may beat us to it */
61095 if (!PageFsCache(page))
61096 @@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
61097 struct fscache_cookie *cookie = op->op.object->cookie;
61098
61099 #ifdef CONFIG_FSCACHE_STATS
61100 - atomic_inc(&fscache_n_marks);
61101 + atomic_inc_unchecked(&fscache_n_marks);
61102 #endif
61103
61104 _debug("- mark %p{%lx}", page, page->index);
61105 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
61106 index 40d13c7..ddf52b9 100644
61107 --- a/fs/fscache/stats.c
61108 +++ b/fs/fscache/stats.c
61109 @@ -18,99 +18,99 @@
61110 /*
61111 * operation counters
61112 */
61113 -atomic_t fscache_n_op_pend;
61114 -atomic_t fscache_n_op_run;
61115 -atomic_t fscache_n_op_enqueue;
61116 -atomic_t fscache_n_op_requeue;
61117 -atomic_t fscache_n_op_deferred_release;
61118 -atomic_t fscache_n_op_release;
61119 -atomic_t fscache_n_op_gc;
61120 -atomic_t fscache_n_op_cancelled;
61121 -atomic_t fscache_n_op_rejected;
61122 +atomic_unchecked_t fscache_n_op_pend;
61123 +atomic_unchecked_t fscache_n_op_run;
61124 +atomic_unchecked_t fscache_n_op_enqueue;
61125 +atomic_unchecked_t fscache_n_op_requeue;
61126 +atomic_unchecked_t fscache_n_op_deferred_release;
61127 +atomic_unchecked_t fscache_n_op_release;
61128 +atomic_unchecked_t fscache_n_op_gc;
61129 +atomic_unchecked_t fscache_n_op_cancelled;
61130 +atomic_unchecked_t fscache_n_op_rejected;
61131
61132 -atomic_t fscache_n_attr_changed;
61133 -atomic_t fscache_n_attr_changed_ok;
61134 -atomic_t fscache_n_attr_changed_nobufs;
61135 -atomic_t fscache_n_attr_changed_nomem;
61136 -atomic_t fscache_n_attr_changed_calls;
61137 +atomic_unchecked_t fscache_n_attr_changed;
61138 +atomic_unchecked_t fscache_n_attr_changed_ok;
61139 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
61140 +atomic_unchecked_t fscache_n_attr_changed_nomem;
61141 +atomic_unchecked_t fscache_n_attr_changed_calls;
61142
61143 -atomic_t fscache_n_allocs;
61144 -atomic_t fscache_n_allocs_ok;
61145 -atomic_t fscache_n_allocs_wait;
61146 -atomic_t fscache_n_allocs_nobufs;
61147 -atomic_t fscache_n_allocs_intr;
61148 -atomic_t fscache_n_allocs_object_dead;
61149 -atomic_t fscache_n_alloc_ops;
61150 -atomic_t fscache_n_alloc_op_waits;
61151 +atomic_unchecked_t fscache_n_allocs;
61152 +atomic_unchecked_t fscache_n_allocs_ok;
61153 +atomic_unchecked_t fscache_n_allocs_wait;
61154 +atomic_unchecked_t fscache_n_allocs_nobufs;
61155 +atomic_unchecked_t fscache_n_allocs_intr;
61156 +atomic_unchecked_t fscache_n_allocs_object_dead;
61157 +atomic_unchecked_t fscache_n_alloc_ops;
61158 +atomic_unchecked_t fscache_n_alloc_op_waits;
61159
61160 -atomic_t fscache_n_retrievals;
61161 -atomic_t fscache_n_retrievals_ok;
61162 -atomic_t fscache_n_retrievals_wait;
61163 -atomic_t fscache_n_retrievals_nodata;
61164 -atomic_t fscache_n_retrievals_nobufs;
61165 -atomic_t fscache_n_retrievals_intr;
61166 -atomic_t fscache_n_retrievals_nomem;
61167 -atomic_t fscache_n_retrievals_object_dead;
61168 -atomic_t fscache_n_retrieval_ops;
61169 -atomic_t fscache_n_retrieval_op_waits;
61170 +atomic_unchecked_t fscache_n_retrievals;
61171 +atomic_unchecked_t fscache_n_retrievals_ok;
61172 +atomic_unchecked_t fscache_n_retrievals_wait;
61173 +atomic_unchecked_t fscache_n_retrievals_nodata;
61174 +atomic_unchecked_t fscache_n_retrievals_nobufs;
61175 +atomic_unchecked_t fscache_n_retrievals_intr;
61176 +atomic_unchecked_t fscache_n_retrievals_nomem;
61177 +atomic_unchecked_t fscache_n_retrievals_object_dead;
61178 +atomic_unchecked_t fscache_n_retrieval_ops;
61179 +atomic_unchecked_t fscache_n_retrieval_op_waits;
61180
61181 -atomic_t fscache_n_stores;
61182 -atomic_t fscache_n_stores_ok;
61183 -atomic_t fscache_n_stores_again;
61184 -atomic_t fscache_n_stores_nobufs;
61185 -atomic_t fscache_n_stores_oom;
61186 -atomic_t fscache_n_store_ops;
61187 -atomic_t fscache_n_store_calls;
61188 -atomic_t fscache_n_store_pages;
61189 -atomic_t fscache_n_store_radix_deletes;
61190 -atomic_t fscache_n_store_pages_over_limit;
61191 +atomic_unchecked_t fscache_n_stores;
61192 +atomic_unchecked_t fscache_n_stores_ok;
61193 +atomic_unchecked_t fscache_n_stores_again;
61194 +atomic_unchecked_t fscache_n_stores_nobufs;
61195 +atomic_unchecked_t fscache_n_stores_oom;
61196 +atomic_unchecked_t fscache_n_store_ops;
61197 +atomic_unchecked_t fscache_n_store_calls;
61198 +atomic_unchecked_t fscache_n_store_pages;
61199 +atomic_unchecked_t fscache_n_store_radix_deletes;
61200 +atomic_unchecked_t fscache_n_store_pages_over_limit;
61201
61202 -atomic_t fscache_n_store_vmscan_not_storing;
61203 -atomic_t fscache_n_store_vmscan_gone;
61204 -atomic_t fscache_n_store_vmscan_busy;
61205 -atomic_t fscache_n_store_vmscan_cancelled;
61206 -atomic_t fscache_n_store_vmscan_wait;
61207 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
61208 +atomic_unchecked_t fscache_n_store_vmscan_gone;
61209 +atomic_unchecked_t fscache_n_store_vmscan_busy;
61210 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
61211 +atomic_unchecked_t fscache_n_store_vmscan_wait;
61212
61213 -atomic_t fscache_n_marks;
61214 -atomic_t fscache_n_uncaches;
61215 +atomic_unchecked_t fscache_n_marks;
61216 +atomic_unchecked_t fscache_n_uncaches;
61217
61218 -atomic_t fscache_n_acquires;
61219 -atomic_t fscache_n_acquires_null;
61220 -atomic_t fscache_n_acquires_no_cache;
61221 -atomic_t fscache_n_acquires_ok;
61222 -atomic_t fscache_n_acquires_nobufs;
61223 -atomic_t fscache_n_acquires_oom;
61224 +atomic_unchecked_t fscache_n_acquires;
61225 +atomic_unchecked_t fscache_n_acquires_null;
61226 +atomic_unchecked_t fscache_n_acquires_no_cache;
61227 +atomic_unchecked_t fscache_n_acquires_ok;
61228 +atomic_unchecked_t fscache_n_acquires_nobufs;
61229 +atomic_unchecked_t fscache_n_acquires_oom;
61230
61231 -atomic_t fscache_n_invalidates;
61232 -atomic_t fscache_n_invalidates_run;
61233 +atomic_unchecked_t fscache_n_invalidates;
61234 +atomic_unchecked_t fscache_n_invalidates_run;
61235
61236 -atomic_t fscache_n_updates;
61237 -atomic_t fscache_n_updates_null;
61238 -atomic_t fscache_n_updates_run;
61239 +atomic_unchecked_t fscache_n_updates;
61240 +atomic_unchecked_t fscache_n_updates_null;
61241 +atomic_unchecked_t fscache_n_updates_run;
61242
61243 -atomic_t fscache_n_relinquishes;
61244 -atomic_t fscache_n_relinquishes_null;
61245 -atomic_t fscache_n_relinquishes_waitcrt;
61246 -atomic_t fscache_n_relinquishes_retire;
61247 +atomic_unchecked_t fscache_n_relinquishes;
61248 +atomic_unchecked_t fscache_n_relinquishes_null;
61249 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
61250 +atomic_unchecked_t fscache_n_relinquishes_retire;
61251
61252 -atomic_t fscache_n_cookie_index;
61253 -atomic_t fscache_n_cookie_data;
61254 -atomic_t fscache_n_cookie_special;
61255 +atomic_unchecked_t fscache_n_cookie_index;
61256 +atomic_unchecked_t fscache_n_cookie_data;
61257 +atomic_unchecked_t fscache_n_cookie_special;
61258
61259 -atomic_t fscache_n_object_alloc;
61260 -atomic_t fscache_n_object_no_alloc;
61261 -atomic_t fscache_n_object_lookups;
61262 -atomic_t fscache_n_object_lookups_negative;
61263 -atomic_t fscache_n_object_lookups_positive;
61264 -atomic_t fscache_n_object_lookups_timed_out;
61265 -atomic_t fscache_n_object_created;
61266 -atomic_t fscache_n_object_avail;
61267 -atomic_t fscache_n_object_dead;
61268 +atomic_unchecked_t fscache_n_object_alloc;
61269 +atomic_unchecked_t fscache_n_object_no_alloc;
61270 +atomic_unchecked_t fscache_n_object_lookups;
61271 +atomic_unchecked_t fscache_n_object_lookups_negative;
61272 +atomic_unchecked_t fscache_n_object_lookups_positive;
61273 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
61274 +atomic_unchecked_t fscache_n_object_created;
61275 +atomic_unchecked_t fscache_n_object_avail;
61276 +atomic_unchecked_t fscache_n_object_dead;
61277
61278 -atomic_t fscache_n_checkaux_none;
61279 -atomic_t fscache_n_checkaux_okay;
61280 -atomic_t fscache_n_checkaux_update;
61281 -atomic_t fscache_n_checkaux_obsolete;
61282 +atomic_unchecked_t fscache_n_checkaux_none;
61283 +atomic_unchecked_t fscache_n_checkaux_okay;
61284 +atomic_unchecked_t fscache_n_checkaux_update;
61285 +atomic_unchecked_t fscache_n_checkaux_obsolete;
61286
61287 atomic_t fscache_n_cop_alloc_object;
61288 atomic_t fscache_n_cop_lookup_object;
61289 @@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
61290 seq_puts(m, "FS-Cache statistics\n");
61291
61292 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
61293 - atomic_read(&fscache_n_cookie_index),
61294 - atomic_read(&fscache_n_cookie_data),
61295 - atomic_read(&fscache_n_cookie_special));
61296 + atomic_read_unchecked(&fscache_n_cookie_index),
61297 + atomic_read_unchecked(&fscache_n_cookie_data),
61298 + atomic_read_unchecked(&fscache_n_cookie_special));
61299
61300 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
61301 - atomic_read(&fscache_n_object_alloc),
61302 - atomic_read(&fscache_n_object_no_alloc),
61303 - atomic_read(&fscache_n_object_avail),
61304 - atomic_read(&fscache_n_object_dead));
61305 + atomic_read_unchecked(&fscache_n_object_alloc),
61306 + atomic_read_unchecked(&fscache_n_object_no_alloc),
61307 + atomic_read_unchecked(&fscache_n_object_avail),
61308 + atomic_read_unchecked(&fscache_n_object_dead));
61309 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
61310 - atomic_read(&fscache_n_checkaux_none),
61311 - atomic_read(&fscache_n_checkaux_okay),
61312 - atomic_read(&fscache_n_checkaux_update),
61313 - atomic_read(&fscache_n_checkaux_obsolete));
61314 + atomic_read_unchecked(&fscache_n_checkaux_none),
61315 + atomic_read_unchecked(&fscache_n_checkaux_okay),
61316 + atomic_read_unchecked(&fscache_n_checkaux_update),
61317 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
61318
61319 seq_printf(m, "Pages : mrk=%u unc=%u\n",
61320 - atomic_read(&fscache_n_marks),
61321 - atomic_read(&fscache_n_uncaches));
61322 + atomic_read_unchecked(&fscache_n_marks),
61323 + atomic_read_unchecked(&fscache_n_uncaches));
61324
61325 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
61326 " oom=%u\n",
61327 - atomic_read(&fscache_n_acquires),
61328 - atomic_read(&fscache_n_acquires_null),
61329 - atomic_read(&fscache_n_acquires_no_cache),
61330 - atomic_read(&fscache_n_acquires_ok),
61331 - atomic_read(&fscache_n_acquires_nobufs),
61332 - atomic_read(&fscache_n_acquires_oom));
61333 + atomic_read_unchecked(&fscache_n_acquires),
61334 + atomic_read_unchecked(&fscache_n_acquires_null),
61335 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
61336 + atomic_read_unchecked(&fscache_n_acquires_ok),
61337 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
61338 + atomic_read_unchecked(&fscache_n_acquires_oom));
61339
61340 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
61341 - atomic_read(&fscache_n_object_lookups),
61342 - atomic_read(&fscache_n_object_lookups_negative),
61343 - atomic_read(&fscache_n_object_lookups_positive),
61344 - atomic_read(&fscache_n_object_created),
61345 - atomic_read(&fscache_n_object_lookups_timed_out));
61346 + atomic_read_unchecked(&fscache_n_object_lookups),
61347 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
61348 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
61349 + atomic_read_unchecked(&fscache_n_object_created),
61350 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
61351
61352 seq_printf(m, "Invals : n=%u run=%u\n",
61353 - atomic_read(&fscache_n_invalidates),
61354 - atomic_read(&fscache_n_invalidates_run));
61355 + atomic_read_unchecked(&fscache_n_invalidates),
61356 + atomic_read_unchecked(&fscache_n_invalidates_run));
61357
61358 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
61359 - atomic_read(&fscache_n_updates),
61360 - atomic_read(&fscache_n_updates_null),
61361 - atomic_read(&fscache_n_updates_run));
61362 + atomic_read_unchecked(&fscache_n_updates),
61363 + atomic_read_unchecked(&fscache_n_updates_null),
61364 + atomic_read_unchecked(&fscache_n_updates_run));
61365
61366 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
61367 - atomic_read(&fscache_n_relinquishes),
61368 - atomic_read(&fscache_n_relinquishes_null),
61369 - atomic_read(&fscache_n_relinquishes_waitcrt),
61370 - atomic_read(&fscache_n_relinquishes_retire));
61371 + atomic_read_unchecked(&fscache_n_relinquishes),
61372 + atomic_read_unchecked(&fscache_n_relinquishes_null),
61373 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
61374 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
61375
61376 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
61377 - atomic_read(&fscache_n_attr_changed),
61378 - atomic_read(&fscache_n_attr_changed_ok),
61379 - atomic_read(&fscache_n_attr_changed_nobufs),
61380 - atomic_read(&fscache_n_attr_changed_nomem),
61381 - atomic_read(&fscache_n_attr_changed_calls));
61382 + atomic_read_unchecked(&fscache_n_attr_changed),
61383 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
61384 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
61385 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
61386 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
61387
61388 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
61389 - atomic_read(&fscache_n_allocs),
61390 - atomic_read(&fscache_n_allocs_ok),
61391 - atomic_read(&fscache_n_allocs_wait),
61392 - atomic_read(&fscache_n_allocs_nobufs),
61393 - atomic_read(&fscache_n_allocs_intr));
61394 + atomic_read_unchecked(&fscache_n_allocs),
61395 + atomic_read_unchecked(&fscache_n_allocs_ok),
61396 + atomic_read_unchecked(&fscache_n_allocs_wait),
61397 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
61398 + atomic_read_unchecked(&fscache_n_allocs_intr));
61399 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
61400 - atomic_read(&fscache_n_alloc_ops),
61401 - atomic_read(&fscache_n_alloc_op_waits),
61402 - atomic_read(&fscache_n_allocs_object_dead));
61403 + atomic_read_unchecked(&fscache_n_alloc_ops),
61404 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
61405 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
61406
61407 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
61408 " int=%u oom=%u\n",
61409 - atomic_read(&fscache_n_retrievals),
61410 - atomic_read(&fscache_n_retrievals_ok),
61411 - atomic_read(&fscache_n_retrievals_wait),
61412 - atomic_read(&fscache_n_retrievals_nodata),
61413 - atomic_read(&fscache_n_retrievals_nobufs),
61414 - atomic_read(&fscache_n_retrievals_intr),
61415 - atomic_read(&fscache_n_retrievals_nomem));
61416 + atomic_read_unchecked(&fscache_n_retrievals),
61417 + atomic_read_unchecked(&fscache_n_retrievals_ok),
61418 + atomic_read_unchecked(&fscache_n_retrievals_wait),
61419 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
61420 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
61421 + atomic_read_unchecked(&fscache_n_retrievals_intr),
61422 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
61423 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
61424 - atomic_read(&fscache_n_retrieval_ops),
61425 - atomic_read(&fscache_n_retrieval_op_waits),
61426 - atomic_read(&fscache_n_retrievals_object_dead));
61427 + atomic_read_unchecked(&fscache_n_retrieval_ops),
61428 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
61429 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
61430
61431 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
61432 - atomic_read(&fscache_n_stores),
61433 - atomic_read(&fscache_n_stores_ok),
61434 - atomic_read(&fscache_n_stores_again),
61435 - atomic_read(&fscache_n_stores_nobufs),
61436 - atomic_read(&fscache_n_stores_oom));
61437 + atomic_read_unchecked(&fscache_n_stores),
61438 + atomic_read_unchecked(&fscache_n_stores_ok),
61439 + atomic_read_unchecked(&fscache_n_stores_again),
61440 + atomic_read_unchecked(&fscache_n_stores_nobufs),
61441 + atomic_read_unchecked(&fscache_n_stores_oom));
61442 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
61443 - atomic_read(&fscache_n_store_ops),
61444 - atomic_read(&fscache_n_store_calls),
61445 - atomic_read(&fscache_n_store_pages),
61446 - atomic_read(&fscache_n_store_radix_deletes),
61447 - atomic_read(&fscache_n_store_pages_over_limit));
61448 + atomic_read_unchecked(&fscache_n_store_ops),
61449 + atomic_read_unchecked(&fscache_n_store_calls),
61450 + atomic_read_unchecked(&fscache_n_store_pages),
61451 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
61452 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
61453
61454 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
61455 - atomic_read(&fscache_n_store_vmscan_not_storing),
61456 - atomic_read(&fscache_n_store_vmscan_gone),
61457 - atomic_read(&fscache_n_store_vmscan_busy),
61458 - atomic_read(&fscache_n_store_vmscan_cancelled),
61459 - atomic_read(&fscache_n_store_vmscan_wait));
61460 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
61461 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
61462 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
61463 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
61464 + atomic_read_unchecked(&fscache_n_store_vmscan_wait));
61465
61466 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
61467 - atomic_read(&fscache_n_op_pend),
61468 - atomic_read(&fscache_n_op_run),
61469 - atomic_read(&fscache_n_op_enqueue),
61470 - atomic_read(&fscache_n_op_cancelled),
61471 - atomic_read(&fscache_n_op_rejected));
61472 + atomic_read_unchecked(&fscache_n_op_pend),
61473 + atomic_read_unchecked(&fscache_n_op_run),
61474 + atomic_read_unchecked(&fscache_n_op_enqueue),
61475 + atomic_read_unchecked(&fscache_n_op_cancelled),
61476 + atomic_read_unchecked(&fscache_n_op_rejected));
61477 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
61478 - atomic_read(&fscache_n_op_deferred_release),
61479 - atomic_read(&fscache_n_op_release),
61480 - atomic_read(&fscache_n_op_gc));
61481 + atomic_read_unchecked(&fscache_n_op_deferred_release),
61482 + atomic_read_unchecked(&fscache_n_op_release),
61483 + atomic_read_unchecked(&fscache_n_op_gc));
61484
61485 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
61486 atomic_read(&fscache_n_cop_alloc_object),
61487 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
61488 index 13b691a..1ffca5ae 100644
61489 --- a/fs/fuse/cuse.c
61490 +++ b/fs/fuse/cuse.c
61491 @@ -607,10 +607,12 @@ static int __init cuse_init(void)
61492 INIT_LIST_HEAD(&cuse_conntbl[i]);
61493
61494 /* inherit and extend fuse_dev_operations */
61495 - cuse_channel_fops = fuse_dev_operations;
61496 - cuse_channel_fops.owner = THIS_MODULE;
61497 - cuse_channel_fops.open = cuse_channel_open;
61498 - cuse_channel_fops.release = cuse_channel_release;
61499 + pax_open_kernel();
61500 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
61501 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
61502 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
61503 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
61504 + pax_close_kernel();
61505
61506 cuse_class = class_create(THIS_MODULE, "cuse");
61507 if (IS_ERR(cuse_class))
61508 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
61509 index 75fa055..73b76d8 100644
61510 --- a/fs/fuse/dev.c
61511 +++ b/fs/fuse/dev.c
61512 @@ -1318,7 +1318,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61513 ret = 0;
61514 pipe_lock(pipe);
61515
61516 - if (!pipe->readers) {
61517 + if (!atomic_read(&pipe->readers)) {
61518 send_sig(SIGPIPE, current, 0);
61519 if (!ret)
61520 ret = -EPIPE;
61521 @@ -1347,7 +1347,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61522 page_nr++;
61523 ret += buf->len;
61524
61525 - if (pipe->files)
61526 + if (atomic_read(&pipe->files))
61527 do_wakeup = 1;
61528 }
61529
61530 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
61531 index 202a972..c4836eb 100644
61532 --- a/fs/fuse/dir.c
61533 +++ b/fs/fuse/dir.c
61534 @@ -1479,7 +1479,7 @@ static char *read_link(struct dentry *dentry)
61535 return link;
61536 }
61537
61538 -static void free_link(char *link)
61539 +static void free_link(const char *link)
61540 {
61541 if (!IS_ERR(link))
61542 free_page((unsigned long) link);
61543 diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
61544 index 9c470fd..aae410e 100644
61545 --- a/fs/hostfs/hostfs_kern.c
61546 +++ b/fs/hostfs/hostfs_kern.c
61547 @@ -898,7 +898,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
61548
61549 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
61550 {
61551 - char *s = nd_get_link(nd);
61552 + const char *s = nd_get_link(nd);
61553 if (!IS_ERR(s))
61554 __putname(s);
61555 }
61556 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
61557 index e19d4c0..8a357a9 100644
61558 --- a/fs/hugetlbfs/inode.c
61559 +++ b/fs/hugetlbfs/inode.c
61560 @@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61561 struct mm_struct *mm = current->mm;
61562 struct vm_area_struct *vma;
61563 struct hstate *h = hstate_file(file);
61564 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
61565 struct vm_unmapped_area_info info;
61566
61567 if (len & ~huge_page_mask(h))
61568 @@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61569 return addr;
61570 }
61571
61572 +#ifdef CONFIG_PAX_RANDMMAP
61573 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
61574 +#endif
61575 +
61576 if (addr) {
61577 addr = ALIGN(addr, huge_page_size(h));
61578 vma = find_vma(mm, addr);
61579 - if (TASK_SIZE - len >= addr &&
61580 - (!vma || addr + len <= vma->vm_start))
61581 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
61582 return addr;
61583 }
61584
61585 info.flags = 0;
61586 info.length = len;
61587 info.low_limit = TASK_UNMAPPED_BASE;
61588 +
61589 +#ifdef CONFIG_PAX_RANDMMAP
61590 + if (mm->pax_flags & MF_PAX_RANDMMAP)
61591 + info.low_limit += mm->delta_mmap;
61592 +#endif
61593 +
61594 info.high_limit = TASK_SIZE;
61595 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
61596 info.align_offset = 0;
61597 @@ -921,7 +931,7 @@ static struct file_system_type hugetlbfs_fs_type = {
61598 };
61599 MODULE_ALIAS_FS("hugetlbfs");
61600
61601 -static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61602 +struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61603
61604 static int can_do_hugetlb_shm(void)
61605 {
61606 diff --git a/fs/inode.c b/fs/inode.c
61607 index d2fb2f2..a6444b0 100644
61608 --- a/fs/inode.c
61609 +++ b/fs/inode.c
61610 @@ -839,16 +839,20 @@ unsigned int get_next_ino(void)
61611 unsigned int *p = &get_cpu_var(last_ino);
61612 unsigned int res = *p;
61613
61614 +start:
61615 +
61616 #ifdef CONFIG_SMP
61617 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
61618 - static atomic_t shared_last_ino;
61619 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
61620 + static atomic_unchecked_t shared_last_ino;
61621 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
61622
61623 res = next - LAST_INO_BATCH;
61624 }
61625 #endif
61626
61627 - *p = ++res;
61628 + if (unlikely(!++res))
61629 + goto start; /* never zero */
61630 + *p = res;
61631 put_cpu_var(last_ino);
61632 return res;
61633 }
61634 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
61635 index 4a6cf28..d3a29d3 100644
61636 --- a/fs/jffs2/erase.c
61637 +++ b/fs/jffs2/erase.c
61638 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
61639 struct jffs2_unknown_node marker = {
61640 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
61641 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61642 - .totlen = cpu_to_je32(c->cleanmarker_size)
61643 + .totlen = cpu_to_je32(c->cleanmarker_size),
61644 + .hdr_crc = cpu_to_je32(0)
61645 };
61646
61647 jffs2_prealloc_raw_node_refs(c, jeb, 1);
61648 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
61649 index a6597d6..41b30ec 100644
61650 --- a/fs/jffs2/wbuf.c
61651 +++ b/fs/jffs2/wbuf.c
61652 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
61653 {
61654 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
61655 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61656 - .totlen = constant_cpu_to_je32(8)
61657 + .totlen = constant_cpu_to_je32(8),
61658 + .hdr_crc = constant_cpu_to_je32(0)
61659 };
61660
61661 /*
61662 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
61663 index 97f7fda..09bd33d 100644
61664 --- a/fs/jfs/super.c
61665 +++ b/fs/jfs/super.c
61666 @@ -885,7 +885,7 @@ static int __init init_jfs_fs(void)
61667
61668 jfs_inode_cachep =
61669 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
61670 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
61671 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
61672 init_once);
61673 if (jfs_inode_cachep == NULL)
61674 return -ENOMEM;
61675 diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
61676 index a693f5b..82276a1 100644
61677 --- a/fs/kernfs/dir.c
61678 +++ b/fs/kernfs/dir.c
61679 @@ -182,7 +182,7 @@ struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn)
61680 *
61681 * Returns 31 bit hash of ns + name (so it fits in an off_t )
61682 */
61683 -static unsigned int kernfs_name_hash(const char *name, const void *ns)
61684 +static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
61685 {
61686 unsigned long hash = init_name_hash();
61687 unsigned int len = strlen(name);
61688 diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
61689 index 5e9a80c..3853a24 100644
61690 --- a/fs/kernfs/file.c
61691 +++ b/fs/kernfs/file.c
61692 @@ -33,7 +33,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
61693
61694 struct kernfs_open_node {
61695 atomic_t refcnt;
61696 - atomic_t event;
61697 + atomic_unchecked_t event;
61698 wait_queue_head_t poll;
61699 struct list_head files; /* goes through kernfs_open_file.list */
61700 };
61701 @@ -149,7 +149,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
61702 {
61703 struct kernfs_open_file *of = sf->private;
61704
61705 - of->event = atomic_read(&of->kn->attr.open->event);
61706 + of->event = atomic_read_unchecked(&of->kn->attr.open->event);
61707
61708 return of->kn->attr.ops->seq_show(sf, v);
61709 }
61710 @@ -361,12 +361,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
61711 return ret;
61712 }
61713
61714 -static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
61715 - void *buf, int len, int write)
61716 +static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
61717 + void *buf, size_t len, int write)
61718 {
61719 struct file *file = vma->vm_file;
61720 struct kernfs_open_file *of = kernfs_of(file);
61721 - int ret;
61722 + ssize_t ret;
61723
61724 if (!of->vm_ops)
61725 return -EINVAL;
61726 @@ -567,7 +567,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
61727 return -ENOMEM;
61728
61729 atomic_set(&new_on->refcnt, 0);
61730 - atomic_set(&new_on->event, 1);
61731 + atomic_set_unchecked(&new_on->event, 1);
61732 init_waitqueue_head(&new_on->poll);
61733 INIT_LIST_HEAD(&new_on->files);
61734 goto retry;
61735 @@ -773,7 +773,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
61736
61737 kernfs_put_active(kn);
61738
61739 - if (of->event != atomic_read(&on->event))
61740 + if (of->event != atomic_read_unchecked(&on->event))
61741 goto trigger;
61742
61743 return DEFAULT_POLLMASK;
61744 @@ -798,7 +798,7 @@ void kernfs_notify(struct kernfs_node *kn)
61745 if (!WARN_ON(kernfs_type(kn) != KERNFS_FILE)) {
61746 on = kn->attr.open;
61747 if (on) {
61748 - atomic_inc(&on->event);
61749 + atomic_inc_unchecked(&on->event);
61750 wake_up_interruptible(&on->poll);
61751 }
61752 }
61753 diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
61754 index 8a19889..4c3069a 100644
61755 --- a/fs/kernfs/symlink.c
61756 +++ b/fs/kernfs/symlink.c
61757 @@ -128,7 +128,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
61758 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
61759 void *cookie)
61760 {
61761 - char *page = nd_get_link(nd);
61762 + const char *page = nd_get_link(nd);
61763 if (!IS_ERR(page))
61764 free_page((unsigned long)page);
61765 }
61766 diff --git a/fs/libfs.c b/fs/libfs.c
61767 index a184424..944ddce 100644
61768 --- a/fs/libfs.c
61769 +++ b/fs/libfs.c
61770 @@ -159,6 +159,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61771
61772 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
61773 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
61774 + char d_name[sizeof(next->d_iname)];
61775 + const unsigned char *name;
61776 +
61777 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
61778 if (!simple_positive(next)) {
61779 spin_unlock(&next->d_lock);
61780 @@ -167,7 +170,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61781
61782 spin_unlock(&next->d_lock);
61783 spin_unlock(&dentry->d_lock);
61784 - if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
61785 + name = next->d_name.name;
61786 + if (name == next->d_iname) {
61787 + memcpy(d_name, name, next->d_name.len);
61788 + name = d_name;
61789 + }
61790 + if (!dir_emit(ctx, name, next->d_name.len,
61791 next->d_inode->i_ino, dt_type(next->d_inode)))
61792 return 0;
61793 spin_lock(&dentry->d_lock);
61794 @@ -999,7 +1007,7 @@ EXPORT_SYMBOL(noop_fsync);
61795 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
61796 void *cookie)
61797 {
61798 - char *s = nd_get_link(nd);
61799 + const char *s = nd_get_link(nd);
61800 if (!IS_ERR(s))
61801 kfree(s);
61802 }
61803 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
61804 index acd3947..1f896e2 100644
61805 --- a/fs/lockd/clntproc.c
61806 +++ b/fs/lockd/clntproc.c
61807 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
61808 /*
61809 * Cookie counter for NLM requests
61810 */
61811 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
61812 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
61813
61814 void nlmclnt_next_cookie(struct nlm_cookie *c)
61815 {
61816 - u32 cookie = atomic_inc_return(&nlm_cookie);
61817 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
61818
61819 memcpy(c->data, &cookie, 4);
61820 c->len=4;
61821 diff --git a/fs/locks.c b/fs/locks.c
61822 index e390bd9..c79870e 100644
61823 --- a/fs/locks.c
61824 +++ b/fs/locks.c
61825 @@ -2315,16 +2315,16 @@ void locks_remove_file(struct file *filp)
61826 locks_remove_posix(filp, (fl_owner_t)filp);
61827
61828 if (filp->f_op->flock) {
61829 - struct file_lock fl = {
61830 + struct file_lock flock = {
61831 .fl_pid = current->tgid,
61832 .fl_file = filp,
61833 .fl_flags = FL_FLOCK,
61834 .fl_type = F_UNLCK,
61835 .fl_end = OFFSET_MAX,
61836 };
61837 - filp->f_op->flock(filp, F_SETLKW, &fl);
61838 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
61839 - fl.fl_ops->fl_release_private(&fl);
61840 + filp->f_op->flock(filp, F_SETLKW, &flock);
61841 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
61842 + flock.fl_ops->fl_release_private(&flock);
61843 }
61844
61845 spin_lock(&inode->i_lock);
61846 diff --git a/fs/mount.h b/fs/mount.h
61847 index d55297f..f5b28c5 100644
61848 --- a/fs/mount.h
61849 +++ b/fs/mount.h
61850 @@ -11,7 +11,7 @@ struct mnt_namespace {
61851 u64 seq; /* Sequence number to prevent loops */
61852 wait_queue_head_t poll;
61853 u64 event;
61854 -};
61855 +} __randomize_layout;
61856
61857 struct mnt_pcp {
61858 int mnt_count;
61859 @@ -57,7 +57,7 @@ struct mount {
61860 int mnt_expiry_mark; /* true if marked for expiry */
61861 int mnt_pinned;
61862 struct path mnt_ex_mountpoint;
61863 -};
61864 +} __randomize_layout;
61865
61866 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
61867
61868 diff --git a/fs/namei.c b/fs/namei.c
61869 index 9eb787e..5f520b67 100644
61870 --- a/fs/namei.c
61871 +++ b/fs/namei.c
61872 @@ -330,17 +330,32 @@ int generic_permission(struct inode *inode, int mask)
61873 if (ret != -EACCES)
61874 return ret;
61875
61876 +#ifdef CONFIG_GRKERNSEC
61877 + /* we'll block if we have to log due to a denied capability use */
61878 + if (mask & MAY_NOT_BLOCK)
61879 + return -ECHILD;
61880 +#endif
61881 +
61882 if (S_ISDIR(inode->i_mode)) {
61883 /* DACs are overridable for directories */
61884 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
61885 - return 0;
61886 if (!(mask & MAY_WRITE))
61887 - if (capable_wrt_inode_uidgid(inode,
61888 - CAP_DAC_READ_SEARCH))
61889 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
61890 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
61891 return 0;
61892 + if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
61893 + return 0;
61894 return -EACCES;
61895 }
61896 /*
61897 + * Searching includes executable on directories, else just read.
61898 + */
61899 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61900 + if (mask == MAY_READ)
61901 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
61902 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
61903 + return 0;
61904 +
61905 + /*
61906 * Read/write DACs are always overridable.
61907 * Executable DACs are overridable when there is
61908 * at least one exec bit set.
61909 @@ -349,14 +364,6 @@ int generic_permission(struct inode *inode, int mask)
61910 if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
61911 return 0;
61912
61913 - /*
61914 - * Searching includes executable on directories, else just read.
61915 - */
61916 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61917 - if (mask == MAY_READ)
61918 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
61919 - return 0;
61920 -
61921 return -EACCES;
61922 }
61923 EXPORT_SYMBOL(generic_permission);
61924 @@ -824,7 +831,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61925 {
61926 struct dentry *dentry = link->dentry;
61927 int error;
61928 - char *s;
61929 + const char *s;
61930
61931 BUG_ON(nd->flags & LOOKUP_RCU);
61932
61933 @@ -845,6 +852,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61934 if (error)
61935 goto out_put_nd_path;
61936
61937 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
61938 + dentry->d_inode, dentry, nd->path.mnt)) {
61939 + error = -EACCES;
61940 + goto out_put_nd_path;
61941 + }
61942 +
61943 nd->last_type = LAST_BIND;
61944 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
61945 error = PTR_ERR(*p);
61946 @@ -1596,6 +1609,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
61947 if (res)
61948 break;
61949 res = walk_component(nd, path, LOOKUP_FOLLOW);
61950 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
61951 + res = -EACCES;
61952 put_link(nd, &link, cookie);
61953 } while (res > 0);
61954
61955 @@ -1669,7 +1684,7 @@ EXPORT_SYMBOL(full_name_hash);
61956 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
61957 {
61958 unsigned long a, b, adata, bdata, mask, hash, len;
61959 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61960 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61961
61962 hash = a = 0;
61963 len = -sizeof(unsigned long);
61964 @@ -1953,6 +1968,8 @@ static int path_lookupat(int dfd, const char *name,
61965 if (err)
61966 break;
61967 err = lookup_last(nd, &path);
61968 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
61969 + err = -EACCES;
61970 put_link(nd, &link, cookie);
61971 }
61972 }
61973 @@ -1960,6 +1977,13 @@ static int path_lookupat(int dfd, const char *name,
61974 if (!err)
61975 err = complete_walk(nd);
61976
61977 + if (!err && !(nd->flags & LOOKUP_PARENT)) {
61978 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61979 + path_put(&nd->path);
61980 + err = -ENOENT;
61981 + }
61982 + }
61983 +
61984 if (!err && nd->flags & LOOKUP_DIRECTORY) {
61985 if (!d_can_lookup(nd->path.dentry)) {
61986 path_put(&nd->path);
61987 @@ -1987,8 +2011,15 @@ static int filename_lookup(int dfd, struct filename *name,
61988 retval = path_lookupat(dfd, name->name,
61989 flags | LOOKUP_REVAL, nd);
61990
61991 - if (likely(!retval))
61992 + if (likely(!retval)) {
61993 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
61994 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
61995 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
61996 + path_put(&nd->path);
61997 + return -ENOENT;
61998 + }
61999 + }
62000 + }
62001 return retval;
62002 }
62003
62004 @@ -2570,6 +2601,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
62005 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
62006 return -EPERM;
62007
62008 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
62009 + return -EPERM;
62010 + if (gr_handle_rawio(inode))
62011 + return -EPERM;
62012 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
62013 + return -EACCES;
62014 +
62015 return 0;
62016 }
62017
62018 @@ -2801,7 +2839,7 @@ looked_up:
62019 * cleared otherwise prior to returning.
62020 */
62021 static int lookup_open(struct nameidata *nd, struct path *path,
62022 - struct file *file,
62023 + struct path *link, struct file *file,
62024 const struct open_flags *op,
62025 bool got_write, int *opened)
62026 {
62027 @@ -2836,6 +2874,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
62028 /* Negative dentry, just create the file */
62029 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
62030 umode_t mode = op->mode;
62031 +
62032 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
62033 + error = -EACCES;
62034 + goto out_dput;
62035 + }
62036 +
62037 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
62038 + error = -EACCES;
62039 + goto out_dput;
62040 + }
62041 +
62042 if (!IS_POSIXACL(dir->d_inode))
62043 mode &= ~current_umask();
62044 /*
62045 @@ -2857,6 +2906,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
62046 nd->flags & LOOKUP_EXCL);
62047 if (error)
62048 goto out_dput;
62049 + else
62050 + gr_handle_create(dentry, nd->path.mnt);
62051 }
62052 out_no_open:
62053 path->dentry = dentry;
62054 @@ -2871,7 +2922,7 @@ out_dput:
62055 /*
62056 * Handle the last step of open()
62057 */
62058 -static int do_last(struct nameidata *nd, struct path *path,
62059 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
62060 struct file *file, const struct open_flags *op,
62061 int *opened, struct filename *name)
62062 {
62063 @@ -2921,6 +2972,15 @@ static int do_last(struct nameidata *nd, struct path *path,
62064 if (error)
62065 return error;
62066
62067 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
62068 + error = -ENOENT;
62069 + goto out;
62070 + }
62071 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
62072 + error = -EACCES;
62073 + goto out;
62074 + }
62075 +
62076 audit_inode(name, dir, LOOKUP_PARENT);
62077 error = -EISDIR;
62078 /* trailing slashes? */
62079 @@ -2940,7 +3000,7 @@ retry_lookup:
62080 */
62081 }
62082 mutex_lock(&dir->d_inode->i_mutex);
62083 - error = lookup_open(nd, path, file, op, got_write, opened);
62084 + error = lookup_open(nd, path, link, file, op, got_write, opened);
62085 mutex_unlock(&dir->d_inode->i_mutex);
62086
62087 if (error <= 0) {
62088 @@ -2964,11 +3024,28 @@ retry_lookup:
62089 goto finish_open_created;
62090 }
62091
62092 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
62093 + error = -ENOENT;
62094 + goto exit_dput;
62095 + }
62096 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
62097 + error = -EACCES;
62098 + goto exit_dput;
62099 + }
62100 +
62101 /*
62102 * create/update audit record if it already exists.
62103 */
62104 - if (d_is_positive(path->dentry))
62105 + if (d_is_positive(path->dentry)) {
62106 + /* only check if O_CREAT is specified, all other checks need to go
62107 + into may_open */
62108 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
62109 + error = -EACCES;
62110 + goto exit_dput;
62111 + }
62112 +
62113 audit_inode(name, path->dentry, 0);
62114 + }
62115
62116 /*
62117 * If atomic_open() acquired write access it is dropped now due to
62118 @@ -3009,6 +3086,11 @@ finish_lookup:
62119 }
62120 }
62121 BUG_ON(inode != path->dentry->d_inode);
62122 + /* if we're resolving a symlink to another symlink */
62123 + if (link && gr_handle_symlink_owner(link, inode)) {
62124 + error = -EACCES;
62125 + goto out;
62126 + }
62127 return 1;
62128 }
62129
62130 @@ -3018,7 +3100,6 @@ finish_lookup:
62131 save_parent.dentry = nd->path.dentry;
62132 save_parent.mnt = mntget(path->mnt);
62133 nd->path.dentry = path->dentry;
62134 -
62135 }
62136 nd->inode = inode;
62137 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
62138 @@ -3028,7 +3109,18 @@ finish_open:
62139 path_put(&save_parent);
62140 return error;
62141 }
62142 +
62143 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
62144 + error = -ENOENT;
62145 + goto out;
62146 + }
62147 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
62148 + error = -EACCES;
62149 + goto out;
62150 + }
62151 +
62152 audit_inode(name, nd->path.dentry, 0);
62153 +
62154 error = -EISDIR;
62155 if ((open_flag & O_CREAT) && d_is_dir(nd->path.dentry))
62156 goto out;
62157 @@ -3191,7 +3283,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
62158 if (unlikely(error))
62159 goto out;
62160
62161 - error = do_last(nd, &path, file, op, &opened, pathname);
62162 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
62163 while (unlikely(error > 0)) { /* trailing symlink */
62164 struct path link = path;
62165 void *cookie;
62166 @@ -3209,7 +3301,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
62167 error = follow_link(&link, nd, &cookie);
62168 if (unlikely(error))
62169 break;
62170 - error = do_last(nd, &path, file, op, &opened, pathname);
62171 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
62172 put_link(nd, &link, cookie);
62173 }
62174 out:
62175 @@ -3309,9 +3401,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
62176 goto unlock;
62177
62178 error = -EEXIST;
62179 - if (d_is_positive(dentry))
62180 + if (d_is_positive(dentry)) {
62181 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
62182 + error = -ENOENT;
62183 goto fail;
62184 -
62185 + }
62186 /*
62187 * Special case - lookup gave negative, but... we had foo/bar/
62188 * From the vfs_mknod() POV we just have a negative dentry -
62189 @@ -3363,6 +3457,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
62190 }
62191 EXPORT_SYMBOL(user_path_create);
62192
62193 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
62194 +{
62195 + struct filename *tmp = getname(pathname);
62196 + struct dentry *res;
62197 + if (IS_ERR(tmp))
62198 + return ERR_CAST(tmp);
62199 + res = kern_path_create(dfd, tmp->name, path, lookup_flags);
62200 + if (IS_ERR(res))
62201 + putname(tmp);
62202 + else
62203 + *to = tmp;
62204 + return res;
62205 +}
62206 +
62207 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
62208 {
62209 int error = may_create(dir, dentry);
62210 @@ -3426,6 +3534,17 @@ retry:
62211
62212 if (!IS_POSIXACL(path.dentry->d_inode))
62213 mode &= ~current_umask();
62214 +
62215 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
62216 + error = -EPERM;
62217 + goto out;
62218 + }
62219 +
62220 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
62221 + error = -EACCES;
62222 + goto out;
62223 + }
62224 +
62225 error = security_path_mknod(&path, dentry, mode, dev);
62226 if (error)
62227 goto out;
62228 @@ -3442,6 +3561,8 @@ retry:
62229 break;
62230 }
62231 out:
62232 + if (!error)
62233 + gr_handle_create(dentry, path.mnt);
62234 done_path_create(&path, dentry);
62235 if (retry_estale(error, lookup_flags)) {
62236 lookup_flags |= LOOKUP_REVAL;
62237 @@ -3495,9 +3616,16 @@ retry:
62238
62239 if (!IS_POSIXACL(path.dentry->d_inode))
62240 mode &= ~current_umask();
62241 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
62242 + error = -EACCES;
62243 + goto out;
62244 + }
62245 error = security_path_mkdir(&path, dentry, mode);
62246 if (!error)
62247 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
62248 + if (!error)
62249 + gr_handle_create(dentry, path.mnt);
62250 +out:
62251 done_path_create(&path, dentry);
62252 if (retry_estale(error, lookup_flags)) {
62253 lookup_flags |= LOOKUP_REVAL;
62254 @@ -3580,6 +3708,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
62255 struct filename *name;
62256 struct dentry *dentry;
62257 struct nameidata nd;
62258 + ino_t saved_ino = 0;
62259 + dev_t saved_dev = 0;
62260 unsigned int lookup_flags = 0;
62261 retry:
62262 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
62263 @@ -3612,10 +3742,21 @@ retry:
62264 error = -ENOENT;
62265 goto exit3;
62266 }
62267 +
62268 + saved_ino = dentry->d_inode->i_ino;
62269 + saved_dev = gr_get_dev_from_dentry(dentry);
62270 +
62271 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
62272 + error = -EACCES;
62273 + goto exit3;
62274 + }
62275 +
62276 error = security_path_rmdir(&nd.path, dentry);
62277 if (error)
62278 goto exit3;
62279 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
62280 + if (!error && (saved_dev || saved_ino))
62281 + gr_handle_delete(saved_ino, saved_dev);
62282 exit3:
62283 dput(dentry);
62284 exit2:
62285 @@ -3706,6 +3847,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
62286 struct nameidata nd;
62287 struct inode *inode = NULL;
62288 struct inode *delegated_inode = NULL;
62289 + ino_t saved_ino = 0;
62290 + dev_t saved_dev = 0;
62291 unsigned int lookup_flags = 0;
62292 retry:
62293 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
62294 @@ -3732,10 +3875,22 @@ retry_deleg:
62295 if (d_is_negative(dentry))
62296 goto slashes;
62297 ihold(inode);
62298 +
62299 + if (inode->i_nlink <= 1) {
62300 + saved_ino = inode->i_ino;
62301 + saved_dev = gr_get_dev_from_dentry(dentry);
62302 + }
62303 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
62304 + error = -EACCES;
62305 + goto exit2;
62306 + }
62307 +
62308 error = security_path_unlink(&nd.path, dentry);
62309 if (error)
62310 goto exit2;
62311 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
62312 + if (!error && (saved_ino || saved_dev))
62313 + gr_handle_delete(saved_ino, saved_dev);
62314 exit2:
62315 dput(dentry);
62316 }
62317 @@ -3824,9 +3979,17 @@ retry:
62318 if (IS_ERR(dentry))
62319 goto out_putname;
62320
62321 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
62322 + error = -EACCES;
62323 + goto out;
62324 + }
62325 +
62326 error = security_path_symlink(&path, dentry, from->name);
62327 if (!error)
62328 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
62329 + if (!error)
62330 + gr_handle_create(dentry, path.mnt);
62331 +out:
62332 done_path_create(&path, dentry);
62333 if (retry_estale(error, lookup_flags)) {
62334 lookup_flags |= LOOKUP_REVAL;
62335 @@ -3930,6 +4093,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
62336 struct dentry *new_dentry;
62337 struct path old_path, new_path;
62338 struct inode *delegated_inode = NULL;
62339 + struct filename *to = NULL;
62340 int how = 0;
62341 int error;
62342
62343 @@ -3953,7 +4117,7 @@ retry:
62344 if (error)
62345 return error;
62346
62347 - new_dentry = user_path_create(newdfd, newname, &new_path,
62348 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
62349 (how & LOOKUP_REVAL));
62350 error = PTR_ERR(new_dentry);
62351 if (IS_ERR(new_dentry))
62352 @@ -3965,11 +4129,28 @@ retry:
62353 error = may_linkat(&old_path);
62354 if (unlikely(error))
62355 goto out_dput;
62356 +
62357 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
62358 + old_path.dentry->d_inode,
62359 + old_path.dentry->d_inode->i_mode, to)) {
62360 + error = -EACCES;
62361 + goto out_dput;
62362 + }
62363 +
62364 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
62365 + old_path.dentry, old_path.mnt, to)) {
62366 + error = -EACCES;
62367 + goto out_dput;
62368 + }
62369 +
62370 error = security_path_link(old_path.dentry, &new_path, new_dentry);
62371 if (error)
62372 goto out_dput;
62373 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
62374 + if (!error)
62375 + gr_handle_create(new_dentry, new_path.mnt);
62376 out_dput:
62377 + putname(to);
62378 done_path_create(&new_path, new_dentry);
62379 if (delegated_inode) {
62380 error = break_deleg_wait(&delegated_inode);
62381 @@ -4279,6 +4460,12 @@ retry_deleg:
62382 if (new_dentry == trap)
62383 goto exit5;
62384
62385 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
62386 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
62387 + to, flags);
62388 + if (error)
62389 + goto exit5;
62390 +
62391 error = security_path_rename(&oldnd.path, old_dentry,
62392 &newnd.path, new_dentry, flags);
62393 if (error)
62394 @@ -4286,6 +4473,9 @@ retry_deleg:
62395 error = vfs_rename(old_dir->d_inode, old_dentry,
62396 new_dir->d_inode, new_dentry,
62397 &delegated_inode, flags);
62398 + if (!error)
62399 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
62400 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0, flags);
62401 exit5:
62402 dput(new_dentry);
62403 exit4:
62404 @@ -4328,14 +4518,24 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
62405
62406 int readlink_copy(char __user *buffer, int buflen, const char *link)
62407 {
62408 + char tmpbuf[64];
62409 + const char *newlink;
62410 int len = PTR_ERR(link);
62411 +
62412 if (IS_ERR(link))
62413 goto out;
62414
62415 len = strlen(link);
62416 if (len > (unsigned) buflen)
62417 len = buflen;
62418 - if (copy_to_user(buffer, link, len))
62419 +
62420 + if (len < sizeof(tmpbuf)) {
62421 + memcpy(tmpbuf, link, len);
62422 + newlink = tmpbuf;
62423 + } else
62424 + newlink = link;
62425 +
62426 + if (copy_to_user(buffer, newlink, len))
62427 len = -EFAULT;
62428 out:
62429 return len;
62430 diff --git a/fs/namespace.c b/fs/namespace.c
62431 index 182bc41..72e3cf1 100644
62432 --- a/fs/namespace.c
62433 +++ b/fs/namespace.c
62434 @@ -1348,6 +1348,9 @@ static int do_umount(struct mount *mnt, int flags)
62435 if (!(sb->s_flags & MS_RDONLY))
62436 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
62437 up_write(&sb->s_umount);
62438 +
62439 + gr_log_remount(mnt->mnt_devname, retval);
62440 +
62441 return retval;
62442 }
62443
62444 @@ -1370,6 +1373,9 @@ static int do_umount(struct mount *mnt, int flags)
62445 }
62446 unlock_mount_hash();
62447 namespace_unlock();
62448 +
62449 + gr_log_unmount(mnt->mnt_devname, retval);
62450 +
62451 return retval;
62452 }
62453
62454 @@ -1389,7 +1395,7 @@ static inline bool may_mount(void)
62455 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
62456 */
62457
62458 -SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
62459 +SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
62460 {
62461 struct path path;
62462 struct mount *mnt;
62463 @@ -1431,7 +1437,7 @@ out:
62464 /*
62465 * The 2.0 compatible umount. No flags.
62466 */
62467 -SYSCALL_DEFINE1(oldumount, char __user *, name)
62468 +SYSCALL_DEFINE1(oldumount, const char __user *, name)
62469 {
62470 return sys_umount(name, 0);
62471 }
62472 @@ -2440,6 +2446,16 @@ long do_mount(const char *dev_name, const char *dir_name,
62473 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
62474 MS_STRICTATIME);
62475
62476 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
62477 + retval = -EPERM;
62478 + goto dput_out;
62479 + }
62480 +
62481 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
62482 + retval = -EPERM;
62483 + goto dput_out;
62484 + }
62485 +
62486 if (flags & MS_REMOUNT)
62487 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
62488 data_page);
62489 @@ -2454,6 +2470,9 @@ long do_mount(const char *dev_name, const char *dir_name,
62490 dev_name, data_page);
62491 dput_out:
62492 path_put(&path);
62493 +
62494 + gr_log_mount(dev_name, dir_name, retval);
62495 +
62496 return retval;
62497 }
62498
62499 @@ -2471,7 +2490,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
62500 * number incrementing at 10Ghz will take 12,427 years to wrap which
62501 * is effectively never, so we can ignore the possibility.
62502 */
62503 -static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
62504 +static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
62505
62506 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62507 {
62508 @@ -2486,7 +2505,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62509 kfree(new_ns);
62510 return ERR_PTR(ret);
62511 }
62512 - new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
62513 + new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
62514 atomic_set(&new_ns->count, 1);
62515 new_ns->root = NULL;
62516 INIT_LIST_HEAD(&new_ns->list);
62517 @@ -2496,7 +2515,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62518 return new_ns;
62519 }
62520
62521 -struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
62522 +__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
62523 struct user_namespace *user_ns, struct fs_struct *new_fs)
62524 {
62525 struct mnt_namespace *new_ns;
62526 @@ -2617,8 +2636,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
62527 }
62528 EXPORT_SYMBOL(mount_subtree);
62529
62530 -SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
62531 - char __user *, type, unsigned long, flags, void __user *, data)
62532 +SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
62533 + const char __user *, type, unsigned long, flags, void __user *, data)
62534 {
62535 int ret;
62536 char *kernel_type;
62537 @@ -2731,6 +2750,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
62538 if (error)
62539 goto out2;
62540
62541 + if (gr_handle_chroot_pivot()) {
62542 + error = -EPERM;
62543 + goto out2;
62544 + }
62545 +
62546 get_fs_root(current->fs, &root);
62547 old_mp = lock_mount(&old);
62548 error = PTR_ERR(old_mp);
62549 @@ -2999,7 +3023,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
62550 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
62551 return -EPERM;
62552
62553 - if (fs->users != 1)
62554 + if (atomic_read(&fs->users) != 1)
62555 return -EINVAL;
62556
62557 get_mnt_ns(mnt_ns);
62558 diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
62559 index f4ccfe6..a5cf064 100644
62560 --- a/fs/nfs/callback_xdr.c
62561 +++ b/fs/nfs/callback_xdr.c
62562 @@ -51,7 +51,7 @@ struct callback_op {
62563 callback_decode_arg_t decode_args;
62564 callback_encode_res_t encode_res;
62565 long res_maxsize;
62566 -};
62567 +} __do_const;
62568
62569 static struct callback_op callback_ops[];
62570
62571 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
62572 index c79f3e7..d61d671 100644
62573 --- a/fs/nfs/inode.c
62574 +++ b/fs/nfs/inode.c
62575 @@ -1209,16 +1209,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
62576 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
62577 }
62578
62579 -static atomic_long_t nfs_attr_generation_counter;
62580 +static atomic_long_unchecked_t nfs_attr_generation_counter;
62581
62582 static unsigned long nfs_read_attr_generation_counter(void)
62583 {
62584 - return atomic_long_read(&nfs_attr_generation_counter);
62585 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
62586 }
62587
62588 unsigned long nfs_inc_attr_generation_counter(void)
62589 {
62590 - return atomic_long_inc_return(&nfs_attr_generation_counter);
62591 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
62592 }
62593
62594 void nfs_fattr_init(struct nfs_fattr *fattr)
62595 diff --git a/fs/nfs/nfs3acl.c b/fs/nfs/nfs3acl.c
62596 index 8f854dd..d0fec26 100644
62597 --- a/fs/nfs/nfs3acl.c
62598 +++ b/fs/nfs/nfs3acl.c
62599 @@ -256,7 +256,7 @@ nfs3_list_one_acl(struct inode *inode, int type, const char *name, void *data,
62600 char *p = data + *result;
62601
62602 acl = get_acl(inode, type);
62603 - if (!acl)
62604 + if (IS_ERR_OR_NULL(acl))
62605 return 0;
62606
62607 posix_acl_release(acl);
62608 diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
62609 index 95e3720..46c23fa 100644
62610 --- a/fs/nfsd/nfs4proc.c
62611 +++ b/fs/nfsd/nfs4proc.c
62612 @@ -1169,7 +1169,7 @@ struct nfsd4_operation {
62613 nfsd4op_rsize op_rsize_bop;
62614 stateid_getter op_get_currentstateid;
62615 stateid_setter op_set_currentstateid;
62616 -};
62617 +} __do_const;
62618
62619 static struct nfsd4_operation nfsd4_ops[];
62620
62621 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
62622 index 3297158..7bb8436 100644
62623 --- a/fs/nfsd/nfs4xdr.c
62624 +++ b/fs/nfsd/nfs4xdr.c
62625 @@ -1541,7 +1541,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
62626
62627 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
62628
62629 -static nfsd4_dec nfsd4_dec_ops[] = {
62630 +static const nfsd4_dec nfsd4_dec_ops[] = {
62631 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
62632 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
62633 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
62634 diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
62635 index f8f060f..c4ba09a 100644
62636 --- a/fs/nfsd/nfscache.c
62637 +++ b/fs/nfsd/nfscache.c
62638 @@ -519,14 +519,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
62639 {
62640 struct svc_cacherep *rp = rqstp->rq_cacherep;
62641 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
62642 - int len;
62643 + long len;
62644 size_t bufsize = 0;
62645
62646 if (!rp)
62647 return;
62648
62649 - len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
62650 - len >>= 2;
62651 + if (statp) {
62652 + len = (char*)statp - (char*)resv->iov_base;
62653 + len = resv->iov_len - len;
62654 + len >>= 2;
62655 + }
62656
62657 /* Don't cache excessive amounts of data and XDR failures */
62658 if (!statp || len > (256 >> 2)) {
62659 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
62660 index 16f0673..1c2c30ab 100644
62661 --- a/fs/nfsd/vfs.c
62662 +++ b/fs/nfsd/vfs.c
62663 @@ -843,7 +843,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62664 } else {
62665 oldfs = get_fs();
62666 set_fs(KERNEL_DS);
62667 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
62668 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
62669 set_fs(oldfs);
62670 }
62671
62672 @@ -934,7 +934,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62673
62674 /* Write the data. */
62675 oldfs = get_fs(); set_fs(KERNEL_DS);
62676 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
62677 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
62678 set_fs(oldfs);
62679 if (host_err < 0)
62680 goto out_nfserr;
62681 @@ -1479,7 +1479,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
62682 */
62683
62684 oldfs = get_fs(); set_fs(KERNEL_DS);
62685 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
62686 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
62687 set_fs(oldfs);
62688
62689 if (host_err < 0)
62690 diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
62691 index 52ccd34..43a53b1 100644
62692 --- a/fs/nls/nls_base.c
62693 +++ b/fs/nls/nls_base.c
62694 @@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
62695
62696 int __register_nls(struct nls_table *nls, struct module *owner)
62697 {
62698 - struct nls_table ** tmp = &tables;
62699 + struct nls_table *tmp = tables;
62700
62701 if (nls->next)
62702 return -EBUSY;
62703
62704 - nls->owner = owner;
62705 + pax_open_kernel();
62706 + *(void **)&nls->owner = owner;
62707 + pax_close_kernel();
62708 spin_lock(&nls_lock);
62709 - while (*tmp) {
62710 - if (nls == *tmp) {
62711 + while (tmp) {
62712 + if (nls == tmp) {
62713 spin_unlock(&nls_lock);
62714 return -EBUSY;
62715 }
62716 - tmp = &(*tmp)->next;
62717 + tmp = tmp->next;
62718 }
62719 - nls->next = tables;
62720 + pax_open_kernel();
62721 + *(struct nls_table **)&nls->next = tables;
62722 + pax_close_kernel();
62723 tables = nls;
62724 spin_unlock(&nls_lock);
62725 return 0;
62726 @@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
62727
62728 int unregister_nls(struct nls_table * nls)
62729 {
62730 - struct nls_table ** tmp = &tables;
62731 + struct nls_table * const * tmp = &tables;
62732
62733 spin_lock(&nls_lock);
62734 while (*tmp) {
62735 if (nls == *tmp) {
62736 - *tmp = nls->next;
62737 + pax_open_kernel();
62738 + *(struct nls_table **)tmp = nls->next;
62739 + pax_close_kernel();
62740 spin_unlock(&nls_lock);
62741 return 0;
62742 }
62743 diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
62744 index 162b3f1..6076a7c 100644
62745 --- a/fs/nls/nls_euc-jp.c
62746 +++ b/fs/nls/nls_euc-jp.c
62747 @@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
62748 p_nls = load_nls("cp932");
62749
62750 if (p_nls) {
62751 - table.charset2upper = p_nls->charset2upper;
62752 - table.charset2lower = p_nls->charset2lower;
62753 + pax_open_kernel();
62754 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62755 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62756 + pax_close_kernel();
62757 return register_nls(&table);
62758 }
62759
62760 diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
62761 index a80a741..7b96e1b 100644
62762 --- a/fs/nls/nls_koi8-ru.c
62763 +++ b/fs/nls/nls_koi8-ru.c
62764 @@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
62765 p_nls = load_nls("koi8-u");
62766
62767 if (p_nls) {
62768 - table.charset2upper = p_nls->charset2upper;
62769 - table.charset2lower = p_nls->charset2lower;
62770 + pax_open_kernel();
62771 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62772 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62773 + pax_close_kernel();
62774 return register_nls(&table);
62775 }
62776
62777 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
62778 index 732648b..d3b017f 100644
62779 --- a/fs/notify/fanotify/fanotify_user.c
62780 +++ b/fs/notify/fanotify/fanotify_user.c
62781 @@ -203,8 +203,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
62782
62783 fd = fanotify_event_metadata.fd;
62784 ret = -EFAULT;
62785 - if (copy_to_user(buf, &fanotify_event_metadata,
62786 - fanotify_event_metadata.event_len))
62787 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
62788 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
62789 goto out_close_fd;
62790
62791 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
62792 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
62793 index 1e58402..bb2d6f4 100644
62794 --- a/fs/notify/notification.c
62795 +++ b/fs/notify/notification.c
62796 @@ -48,7 +48,7 @@
62797 #include <linux/fsnotify_backend.h>
62798 #include "fsnotify.h"
62799
62800 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62801 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62802
62803 /**
62804 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
62805 @@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62806 */
62807 u32 fsnotify_get_cookie(void)
62808 {
62809 - return atomic_inc_return(&fsnotify_sync_cookie);
62810 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
62811 }
62812 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
62813
62814 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
62815 index 9e38daf..5727cae 100644
62816 --- a/fs/ntfs/dir.c
62817 +++ b/fs/ntfs/dir.c
62818 @@ -1310,7 +1310,7 @@ find_next_index_buffer:
62819 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
62820 ~(s64)(ndir->itype.index.block_size - 1)));
62821 /* Bounds checks. */
62822 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62823 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62824 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
62825 "inode 0x%lx or driver bug.", vdir->i_ino);
62826 goto err_out;
62827 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
62828 index db9bd8a..8338fb6 100644
62829 --- a/fs/ntfs/file.c
62830 +++ b/fs/ntfs/file.c
62831 @@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
62832 char *addr;
62833 size_t total = 0;
62834 unsigned len;
62835 - int left;
62836 + unsigned left;
62837
62838 do {
62839 len = PAGE_CACHE_SIZE - ofs;
62840 diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
62841 index 9de2491..3306095 100644
62842 --- a/fs/ntfs/super.c
62843 +++ b/fs/ntfs/super.c
62844 @@ -688,7 +688,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62845 if (!silent)
62846 ntfs_error(sb, "Primary boot sector is invalid.");
62847 } else if (!silent)
62848 - ntfs_error(sb, read_err_str, "primary");
62849 + ntfs_error(sb, read_err_str, "%s", "primary");
62850 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
62851 if (bh_primary)
62852 brelse(bh_primary);
62853 @@ -704,7 +704,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62854 goto hotfix_primary_boot_sector;
62855 brelse(bh_backup);
62856 } else if (!silent)
62857 - ntfs_error(sb, read_err_str, "backup");
62858 + ntfs_error(sb, read_err_str, "%s", "backup");
62859 /* Try to read NT3.51- backup boot sector. */
62860 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
62861 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
62862 @@ -715,7 +715,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62863 "sector.");
62864 brelse(bh_backup);
62865 } else if (!silent)
62866 - ntfs_error(sb, read_err_str, "backup");
62867 + ntfs_error(sb, read_err_str, "%s", "backup");
62868 /* We failed. Cleanup and return. */
62869 if (bh_primary)
62870 brelse(bh_primary);
62871 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
62872 index 0440134..d52c93a 100644
62873 --- a/fs/ocfs2/localalloc.c
62874 +++ b/fs/ocfs2/localalloc.c
62875 @@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
62876 goto bail;
62877 }
62878
62879 - atomic_inc(&osb->alloc_stats.moves);
62880 + atomic_inc_unchecked(&osb->alloc_stats.moves);
62881
62882 bail:
62883 if (handle)
62884 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
62885 index 8d64a97..c37665d 100644
62886 --- a/fs/ocfs2/ocfs2.h
62887 +++ b/fs/ocfs2/ocfs2.h
62888 @@ -236,11 +236,11 @@ enum ocfs2_vol_state
62889
62890 struct ocfs2_alloc_stats
62891 {
62892 - atomic_t moves;
62893 - atomic_t local_data;
62894 - atomic_t bitmap_data;
62895 - atomic_t bg_allocs;
62896 - atomic_t bg_extends;
62897 + atomic_unchecked_t moves;
62898 + atomic_unchecked_t local_data;
62899 + atomic_unchecked_t bitmap_data;
62900 + atomic_unchecked_t bg_allocs;
62901 + atomic_unchecked_t bg_extends;
62902 };
62903
62904 enum ocfs2_local_alloc_state
62905 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
62906 index 0cb889a..6a26b24 100644
62907 --- a/fs/ocfs2/suballoc.c
62908 +++ b/fs/ocfs2/suballoc.c
62909 @@ -867,7 +867,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
62910 mlog_errno(status);
62911 goto bail;
62912 }
62913 - atomic_inc(&osb->alloc_stats.bg_extends);
62914 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
62915
62916 /* You should never ask for this much metadata */
62917 BUG_ON(bits_wanted >
62918 @@ -2014,7 +2014,7 @@ int ocfs2_claim_metadata(handle_t *handle,
62919 mlog_errno(status);
62920 goto bail;
62921 }
62922 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62923 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62924
62925 *suballoc_loc = res.sr_bg_blkno;
62926 *suballoc_bit_start = res.sr_bit_offset;
62927 @@ -2180,7 +2180,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
62928 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
62929 res->sr_bits);
62930
62931 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62932 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62933
62934 BUG_ON(res->sr_bits != 1);
62935
62936 @@ -2222,7 +2222,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
62937 mlog_errno(status);
62938 goto bail;
62939 }
62940 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62941 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62942
62943 BUG_ON(res.sr_bits != 1);
62944
62945 @@ -2326,7 +2326,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62946 cluster_start,
62947 num_clusters);
62948 if (!status)
62949 - atomic_inc(&osb->alloc_stats.local_data);
62950 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
62951 } else {
62952 if (min_clusters > (osb->bitmap_cpg - 1)) {
62953 /* The only paths asking for contiguousness
62954 @@ -2352,7 +2352,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62955 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
62956 res.sr_bg_blkno,
62957 res.sr_bit_offset);
62958 - atomic_inc(&osb->alloc_stats.bitmap_data);
62959 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
62960 *num_clusters = res.sr_bits;
62961 }
62962 }
62963 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
62964 index a7cdd56..c583144 100644
62965 --- a/fs/ocfs2/super.c
62966 +++ b/fs/ocfs2/super.c
62967 @@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
62968 "%10s => GlobalAllocs: %d LocalAllocs: %d "
62969 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
62970 "Stats",
62971 - atomic_read(&osb->alloc_stats.bitmap_data),
62972 - atomic_read(&osb->alloc_stats.local_data),
62973 - atomic_read(&osb->alloc_stats.bg_allocs),
62974 - atomic_read(&osb->alloc_stats.moves),
62975 - atomic_read(&osb->alloc_stats.bg_extends));
62976 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
62977 + atomic_read_unchecked(&osb->alloc_stats.local_data),
62978 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
62979 + atomic_read_unchecked(&osb->alloc_stats.moves),
62980 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
62981
62982 out += snprintf(buf + out, len - out,
62983 "%10s => State: %u Descriptor: %llu Size: %u bits "
62984 @@ -2104,11 +2104,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
62985
62986 mutex_init(&osb->system_file_mutex);
62987
62988 - atomic_set(&osb->alloc_stats.moves, 0);
62989 - atomic_set(&osb->alloc_stats.local_data, 0);
62990 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
62991 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
62992 - atomic_set(&osb->alloc_stats.bg_extends, 0);
62993 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
62994 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
62995 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
62996 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
62997 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
62998
62999 /* Copy the blockcheck stats from the superblock probe */
63000 osb->osb_ecc_stats = *stats;
63001 diff --git a/fs/open.c b/fs/open.c
63002 index dd24f21..c1f4b3a 100644
63003 --- a/fs/open.c
63004 +++ b/fs/open.c
63005 @@ -32,6 +32,8 @@
63006 #include <linux/dnotify.h>
63007 #include <linux/compat.h>
63008
63009 +#define CREATE_TRACE_POINTS
63010 +#include <trace/events/fs.h>
63011 #include "internal.h"
63012
63013 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
63014 @@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
63015 error = locks_verify_truncate(inode, NULL, length);
63016 if (!error)
63017 error = security_path_truncate(path);
63018 + if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
63019 + error = -EACCES;
63020 if (!error)
63021 error = do_truncate(path->dentry, length, 0, NULL);
63022
63023 @@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
63024 error = locks_verify_truncate(inode, f.file, length);
63025 if (!error)
63026 error = security_path_truncate(&f.file->f_path);
63027 + if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
63028 + error = -EACCES;
63029 if (!error)
63030 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
63031 sb_end_write(inode->i_sb);
63032 @@ -380,6 +386,9 @@ retry:
63033 if (__mnt_is_readonly(path.mnt))
63034 res = -EROFS;
63035
63036 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
63037 + res = -EACCES;
63038 +
63039 out_path_release:
63040 path_put(&path);
63041 if (retry_estale(res, lookup_flags)) {
63042 @@ -411,6 +420,8 @@ retry:
63043 if (error)
63044 goto dput_and_out;
63045
63046 + gr_log_chdir(path.dentry, path.mnt);
63047 +
63048 set_fs_pwd(current->fs, &path);
63049
63050 dput_and_out:
63051 @@ -440,6 +451,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
63052 goto out_putf;
63053
63054 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
63055 +
63056 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
63057 + error = -EPERM;
63058 +
63059 + if (!error)
63060 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
63061 +
63062 if (!error)
63063 set_fs_pwd(current->fs, &f.file->f_path);
63064 out_putf:
63065 @@ -469,7 +487,13 @@ retry:
63066 if (error)
63067 goto dput_and_out;
63068
63069 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
63070 + goto dput_and_out;
63071 +
63072 set_fs_root(current->fs, &path);
63073 +
63074 + gr_handle_chroot_chdir(&path);
63075 +
63076 error = 0;
63077 dput_and_out:
63078 path_put(&path);
63079 @@ -493,6 +517,16 @@ static int chmod_common(struct path *path, umode_t mode)
63080 return error;
63081 retry_deleg:
63082 mutex_lock(&inode->i_mutex);
63083 +
63084 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
63085 + error = -EACCES;
63086 + goto out_unlock;
63087 + }
63088 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
63089 + error = -EACCES;
63090 + goto out_unlock;
63091 + }
63092 +
63093 error = security_path_chmod(path, mode);
63094 if (error)
63095 goto out_unlock;
63096 @@ -558,6 +592,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
63097 uid = make_kuid(current_user_ns(), user);
63098 gid = make_kgid(current_user_ns(), group);
63099
63100 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
63101 + return -EACCES;
63102 +
63103 newattrs.ia_valid = ATTR_CTIME;
63104 if (user != (uid_t) -1) {
63105 if (!uid_valid(uid))
63106 @@ -977,6 +1014,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
63107 } else {
63108 fsnotify_open(f);
63109 fd_install(fd, f);
63110 + trace_do_sys_open(tmp->name, flags, mode);
63111 }
63112 }
63113 putname(tmp);
63114 diff --git a/fs/pipe.c b/fs/pipe.c
63115 index 034bffa..6c6b522 100644
63116 --- a/fs/pipe.c
63117 +++ b/fs/pipe.c
63118 @@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
63119
63120 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
63121 {
63122 - if (pipe->files)
63123 + if (atomic_read(&pipe->files))
63124 mutex_lock_nested(&pipe->mutex, subclass);
63125 }
63126
63127 @@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
63128
63129 void pipe_unlock(struct pipe_inode_info *pipe)
63130 {
63131 - if (pipe->files)
63132 + if (atomic_read(&pipe->files))
63133 mutex_unlock(&pipe->mutex);
63134 }
63135 EXPORT_SYMBOL(pipe_unlock);
63136 @@ -342,9 +342,9 @@ pipe_read(struct kiocb *iocb, const struct iovec *_iov,
63137 }
63138 if (bufs) /* More to do? */
63139 continue;
63140 - if (!pipe->writers)
63141 + if (!atomic_read(&pipe->writers))
63142 break;
63143 - if (!pipe->waiting_writers) {
63144 + if (!atomic_read(&pipe->waiting_writers)) {
63145 /* syscall merging: Usually we must not sleep
63146 * if O_NONBLOCK is set, or if we got some data.
63147 * But if a writer sleeps in kernel space, then
63148 @@ -406,7 +406,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
63149 ret = 0;
63150 __pipe_lock(pipe);
63151
63152 - if (!pipe->readers) {
63153 + if (!atomic_read(&pipe->readers)) {
63154 send_sig(SIGPIPE, current, 0);
63155 ret = -EPIPE;
63156 goto out;
63157 @@ -461,7 +461,7 @@ redo1:
63158 for (;;) {
63159 int bufs;
63160
63161 - if (!pipe->readers) {
63162 + if (!atomic_read(&pipe->readers)) {
63163 send_sig(SIGPIPE, current, 0);
63164 if (!ret)
63165 ret = -EPIPE;
63166 @@ -552,9 +552,9 @@ redo2:
63167 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
63168 do_wakeup = 0;
63169 }
63170 - pipe->waiting_writers++;
63171 + atomic_inc(&pipe->waiting_writers);
63172 pipe_wait(pipe);
63173 - pipe->waiting_writers--;
63174 + atomic_dec(&pipe->waiting_writers);
63175 }
63176 out:
63177 __pipe_unlock(pipe);
63178 @@ -609,7 +609,7 @@ pipe_poll(struct file *filp, poll_table *wait)
63179 mask = 0;
63180 if (filp->f_mode & FMODE_READ) {
63181 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
63182 - if (!pipe->writers && filp->f_version != pipe->w_counter)
63183 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
63184 mask |= POLLHUP;
63185 }
63186
63187 @@ -619,7 +619,7 @@ pipe_poll(struct file *filp, poll_table *wait)
63188 * Most Unices do not set POLLERR for FIFOs but on Linux they
63189 * behave exactly like pipes for poll().
63190 */
63191 - if (!pipe->readers)
63192 + if (!atomic_read(&pipe->readers))
63193 mask |= POLLERR;
63194 }
63195
63196 @@ -631,7 +631,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
63197 int kill = 0;
63198
63199 spin_lock(&inode->i_lock);
63200 - if (!--pipe->files) {
63201 + if (atomic_dec_and_test(&pipe->files)) {
63202 inode->i_pipe = NULL;
63203 kill = 1;
63204 }
63205 @@ -648,11 +648,11 @@ pipe_release(struct inode *inode, struct file *file)
63206
63207 __pipe_lock(pipe);
63208 if (file->f_mode & FMODE_READ)
63209 - pipe->readers--;
63210 + atomic_dec(&pipe->readers);
63211 if (file->f_mode & FMODE_WRITE)
63212 - pipe->writers--;
63213 + atomic_dec(&pipe->writers);
63214
63215 - if (pipe->readers || pipe->writers) {
63216 + if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
63217 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
63218 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
63219 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
63220 @@ -717,7 +717,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
63221 kfree(pipe);
63222 }
63223
63224 -static struct vfsmount *pipe_mnt __read_mostly;
63225 +struct vfsmount *pipe_mnt __read_mostly;
63226
63227 /*
63228 * pipefs_dname() is called from d_path().
63229 @@ -747,8 +747,9 @@ static struct inode * get_pipe_inode(void)
63230 goto fail_iput;
63231
63232 inode->i_pipe = pipe;
63233 - pipe->files = 2;
63234 - pipe->readers = pipe->writers = 1;
63235 + atomic_set(&pipe->files, 2);
63236 + atomic_set(&pipe->readers, 1);
63237 + atomic_set(&pipe->writers, 1);
63238 inode->i_fop = &pipefifo_fops;
63239
63240 /*
63241 @@ -927,17 +928,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
63242 spin_lock(&inode->i_lock);
63243 if (inode->i_pipe) {
63244 pipe = inode->i_pipe;
63245 - pipe->files++;
63246 + atomic_inc(&pipe->files);
63247 spin_unlock(&inode->i_lock);
63248 } else {
63249 spin_unlock(&inode->i_lock);
63250 pipe = alloc_pipe_info();
63251 if (!pipe)
63252 return -ENOMEM;
63253 - pipe->files = 1;
63254 + atomic_set(&pipe->files, 1);
63255 spin_lock(&inode->i_lock);
63256 if (unlikely(inode->i_pipe)) {
63257 - inode->i_pipe->files++;
63258 + atomic_inc(&inode->i_pipe->files);
63259 spin_unlock(&inode->i_lock);
63260 free_pipe_info(pipe);
63261 pipe = inode->i_pipe;
63262 @@ -962,10 +963,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
63263 * opened, even when there is no process writing the FIFO.
63264 */
63265 pipe->r_counter++;
63266 - if (pipe->readers++ == 0)
63267 + if (atomic_inc_return(&pipe->readers) == 1)
63268 wake_up_partner(pipe);
63269
63270 - if (!is_pipe && !pipe->writers) {
63271 + if (!is_pipe && !atomic_read(&pipe->writers)) {
63272 if ((filp->f_flags & O_NONBLOCK)) {
63273 /* suppress POLLHUP until we have
63274 * seen a writer */
63275 @@ -984,14 +985,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
63276 * errno=ENXIO when there is no process reading the FIFO.
63277 */
63278 ret = -ENXIO;
63279 - if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
63280 + if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
63281 goto err;
63282
63283 pipe->w_counter++;
63284 - if (!pipe->writers++)
63285 + if (atomic_inc_return(&pipe->writers) == 1)
63286 wake_up_partner(pipe);
63287
63288 - if (!is_pipe && !pipe->readers) {
63289 + if (!is_pipe && !atomic_read(&pipe->readers)) {
63290 if (wait_for_partner(pipe, &pipe->r_counter))
63291 goto err_wr;
63292 }
63293 @@ -1005,11 +1006,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
63294 * the process can at least talk to itself.
63295 */
63296
63297 - pipe->readers++;
63298 - pipe->writers++;
63299 + atomic_inc(&pipe->readers);
63300 + atomic_inc(&pipe->writers);
63301 pipe->r_counter++;
63302 pipe->w_counter++;
63303 - if (pipe->readers == 1 || pipe->writers == 1)
63304 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
63305 wake_up_partner(pipe);
63306 break;
63307
63308 @@ -1023,13 +1024,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
63309 return 0;
63310
63311 err_rd:
63312 - if (!--pipe->readers)
63313 + if (atomic_dec_and_test(&pipe->readers))
63314 wake_up_interruptible(&pipe->wait);
63315 ret = -ERESTARTSYS;
63316 goto err;
63317
63318 err_wr:
63319 - if (!--pipe->writers)
63320 + if (atomic_dec_and_test(&pipe->writers))
63321 wake_up_interruptible(&pipe->wait);
63322 ret = -ERESTARTSYS;
63323 goto err;
63324 diff --git a/fs/posix_acl.c b/fs/posix_acl.c
63325 index 0855f77..6787d50 100644
63326 --- a/fs/posix_acl.c
63327 +++ b/fs/posix_acl.c
63328 @@ -20,6 +20,7 @@
63329 #include <linux/xattr.h>
63330 #include <linux/export.h>
63331 #include <linux/user_namespace.h>
63332 +#include <linux/grsecurity.h>
63333
63334 struct posix_acl **acl_by_type(struct inode *inode, int type)
63335 {
63336 @@ -277,7 +278,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
63337 }
63338 }
63339 if (mode_p)
63340 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
63341 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
63342 return not_equiv;
63343 }
63344 EXPORT_SYMBOL(posix_acl_equiv_mode);
63345 @@ -427,7 +428,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
63346 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
63347 }
63348
63349 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
63350 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
63351 return not_equiv;
63352 }
63353
63354 @@ -485,6 +486,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
63355 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
63356 int err = -ENOMEM;
63357 if (clone) {
63358 + *mode_p &= ~gr_acl_umask();
63359 +
63360 err = posix_acl_create_masq(clone, mode_p);
63361 if (err < 0) {
63362 posix_acl_release(clone);
63363 @@ -659,11 +662,12 @@ struct posix_acl *
63364 posix_acl_from_xattr(struct user_namespace *user_ns,
63365 const void *value, size_t size)
63366 {
63367 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
63368 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
63369 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
63370 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
63371 int count;
63372 struct posix_acl *acl;
63373 struct posix_acl_entry *acl_e;
63374 + umode_t umask = gr_acl_umask();
63375
63376 if (!value)
63377 return NULL;
63378 @@ -689,12 +693,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
63379
63380 switch(acl_e->e_tag) {
63381 case ACL_USER_OBJ:
63382 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
63383 + break;
63384 case ACL_GROUP_OBJ:
63385 case ACL_MASK:
63386 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
63387 + break;
63388 case ACL_OTHER:
63389 + acl_e->e_perm &= ~(umask & S_IRWXO);
63390 break;
63391
63392 case ACL_USER:
63393 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
63394 acl_e->e_uid =
63395 make_kuid(user_ns,
63396 le32_to_cpu(entry->e_id));
63397 @@ -702,6 +712,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
63398 goto fail;
63399 break;
63400 case ACL_GROUP:
63401 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
63402 acl_e->e_gid =
63403 make_kgid(user_ns,
63404 le32_to_cpu(entry->e_id));
63405 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
63406 index 2183fcf..3c32a98 100644
63407 --- a/fs/proc/Kconfig
63408 +++ b/fs/proc/Kconfig
63409 @@ -30,7 +30,7 @@ config PROC_FS
63410
63411 config PROC_KCORE
63412 bool "/proc/kcore support" if !ARM
63413 - depends on PROC_FS && MMU
63414 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
63415 help
63416 Provides a virtual ELF core file of the live kernel. This can
63417 be read with gdb and other ELF tools. No modifications can be
63418 @@ -38,8 +38,8 @@ config PROC_KCORE
63419
63420 config PROC_VMCORE
63421 bool "/proc/vmcore support"
63422 - depends on PROC_FS && CRASH_DUMP
63423 - default y
63424 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
63425 + default n
63426 help
63427 Exports the dump image of crashed kernel in ELF format.
63428
63429 @@ -63,8 +63,8 @@ config PROC_SYSCTL
63430 limited in memory.
63431
63432 config PROC_PAGE_MONITOR
63433 - default y
63434 - depends on PROC_FS && MMU
63435 + default n
63436 + depends on PROC_FS && MMU && !GRKERNSEC
63437 bool "Enable /proc page monitoring" if EXPERT
63438 help
63439 Various /proc files exist to monitor process memory utilization:
63440 diff --git a/fs/proc/array.c b/fs/proc/array.c
63441 index 64db2bc..a8185d6 100644
63442 --- a/fs/proc/array.c
63443 +++ b/fs/proc/array.c
63444 @@ -60,6 +60,7 @@
63445 #include <linux/tty.h>
63446 #include <linux/string.h>
63447 #include <linux/mman.h>
63448 +#include <linux/grsecurity.h>
63449 #include <linux/proc_fs.h>
63450 #include <linux/ioport.h>
63451 #include <linux/uaccess.h>
63452 @@ -356,6 +357,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
63453 seq_putc(m, '\n');
63454 }
63455
63456 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63457 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
63458 +{
63459 + if (p->mm)
63460 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
63461 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
63462 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
63463 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
63464 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
63465 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
63466 + else
63467 + seq_printf(m, "PaX:\t-----\n");
63468 +}
63469 +#endif
63470 +
63471 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
63472 struct pid *pid, struct task_struct *task)
63473 {
63474 @@ -374,9 +390,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
63475 task_cpus_allowed(m, task);
63476 cpuset_task_status_allowed(m, task);
63477 task_context_switch_counts(m, task);
63478 +
63479 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63480 + task_pax(m, task);
63481 +#endif
63482 +
63483 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
63484 + task_grsec_rbac(m, task);
63485 +#endif
63486 +
63487 return 0;
63488 }
63489
63490 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63491 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63492 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
63493 + _mm->pax_flags & MF_PAX_SEGMEXEC))
63494 +#endif
63495 +
63496 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63497 struct pid *pid, struct task_struct *task, int whole)
63498 {
63499 @@ -398,6 +429,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63500 char tcomm[sizeof(task->comm)];
63501 unsigned long flags;
63502
63503 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63504 + if (current->exec_id != m->exec_id) {
63505 + gr_log_badprocpid("stat");
63506 + return 0;
63507 + }
63508 +#endif
63509 +
63510 state = *get_task_state(task);
63511 vsize = eip = esp = 0;
63512 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63513 @@ -468,6 +506,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63514 gtime = task_gtime(task);
63515 }
63516
63517 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63518 + if (PAX_RAND_FLAGS(mm)) {
63519 + eip = 0;
63520 + esp = 0;
63521 + wchan = 0;
63522 + }
63523 +#endif
63524 +#ifdef CONFIG_GRKERNSEC_HIDESYM
63525 + wchan = 0;
63526 + eip =0;
63527 + esp =0;
63528 +#endif
63529 +
63530 /* scale priority and nice values from timeslices to -20..20 */
63531 /* to make it look like a "normal" Unix priority/nice value */
63532 priority = task_prio(task);
63533 @@ -504,9 +555,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63534 seq_put_decimal_ull(m, ' ', vsize);
63535 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
63536 seq_put_decimal_ull(m, ' ', rsslim);
63537 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63538 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
63539 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
63540 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
63541 +#else
63542 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
63543 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
63544 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
63545 +#endif
63546 seq_put_decimal_ull(m, ' ', esp);
63547 seq_put_decimal_ull(m, ' ', eip);
63548 /* The signal information here is obsolete.
63549 @@ -528,7 +585,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63550 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
63551 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
63552
63553 - if (mm && permitted) {
63554 + if (mm && permitted
63555 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63556 + && !PAX_RAND_FLAGS(mm)
63557 +#endif
63558 + ) {
63559 seq_put_decimal_ull(m, ' ', mm->start_data);
63560 seq_put_decimal_ull(m, ' ', mm->end_data);
63561 seq_put_decimal_ull(m, ' ', mm->start_brk);
63562 @@ -566,8 +627,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63563 struct pid *pid, struct task_struct *task)
63564 {
63565 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
63566 - struct mm_struct *mm = get_task_mm(task);
63567 + struct mm_struct *mm;
63568
63569 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63570 + if (current->exec_id != m->exec_id) {
63571 + gr_log_badprocpid("statm");
63572 + return 0;
63573 + }
63574 +#endif
63575 + mm = get_task_mm(task);
63576 if (mm) {
63577 size = task_statm(mm, &shared, &text, &data, &resident);
63578 mmput(mm);
63579 @@ -590,6 +658,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63580 return 0;
63581 }
63582
63583 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63584 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
63585 +{
63586 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
63587 +}
63588 +#endif
63589 +
63590 #ifdef CONFIG_CHECKPOINT_RESTORE
63591 static struct pid *
63592 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
63593 diff --git a/fs/proc/base.c b/fs/proc/base.c
63594 index 2d696b0..b9da447 100644
63595 --- a/fs/proc/base.c
63596 +++ b/fs/proc/base.c
63597 @@ -113,6 +113,14 @@ struct pid_entry {
63598 union proc_op op;
63599 };
63600
63601 +struct getdents_callback {
63602 + struct linux_dirent __user * current_dir;
63603 + struct linux_dirent __user * previous;
63604 + struct file * file;
63605 + int count;
63606 + int error;
63607 +};
63608 +
63609 #define NOD(NAME, MODE, IOP, FOP, OP) { \
63610 .name = (NAME), \
63611 .len = sizeof(NAME) - 1, \
63612 @@ -205,12 +213,28 @@ static int proc_pid_cmdline(struct task_struct *task, char *buffer)
63613 return get_cmdline(task, buffer, PAGE_SIZE);
63614 }
63615
63616 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63617 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63618 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
63619 + _mm->pax_flags & MF_PAX_SEGMEXEC))
63620 +#endif
63621 +
63622 static int proc_pid_auxv(struct task_struct *task, char *buffer)
63623 {
63624 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
63625 int res = PTR_ERR(mm);
63626 if (mm && !IS_ERR(mm)) {
63627 unsigned int nwords = 0;
63628 +
63629 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63630 + /* allow if we're currently ptracing this task */
63631 + if (PAX_RAND_FLAGS(mm) &&
63632 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
63633 + mmput(mm);
63634 + return 0;
63635 + }
63636 +#endif
63637 +
63638 do {
63639 nwords += 2;
63640 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
63641 @@ -224,7 +248,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
63642 }
63643
63644
63645 -#ifdef CONFIG_KALLSYMS
63646 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63647 /*
63648 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
63649 * Returns the resolved symbol. If that fails, simply return the address.
63650 @@ -263,7 +287,7 @@ static void unlock_trace(struct task_struct *task)
63651 mutex_unlock(&task->signal->cred_guard_mutex);
63652 }
63653
63654 -#ifdef CONFIG_STACKTRACE
63655 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63656
63657 #define MAX_STACK_TRACE_DEPTH 64
63658
63659 @@ -486,7 +510,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
63660 return count;
63661 }
63662
63663 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63664 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63665 static int proc_pid_syscall(struct task_struct *task, char *buffer)
63666 {
63667 long nr;
63668 @@ -515,7 +539,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
63669 /************************************************************************/
63670
63671 /* permission checks */
63672 -static int proc_fd_access_allowed(struct inode *inode)
63673 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
63674 {
63675 struct task_struct *task;
63676 int allowed = 0;
63677 @@ -525,7 +549,10 @@ static int proc_fd_access_allowed(struct inode *inode)
63678 */
63679 task = get_proc_task(inode);
63680 if (task) {
63681 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63682 + if (log)
63683 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63684 + else
63685 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63686 put_task_struct(task);
63687 }
63688 return allowed;
63689 @@ -556,10 +583,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
63690 struct task_struct *task,
63691 int hide_pid_min)
63692 {
63693 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63694 + return false;
63695 +
63696 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63697 + rcu_read_lock();
63698 + {
63699 + const struct cred *tmpcred = current_cred();
63700 + const struct cred *cred = __task_cred(task);
63701 +
63702 + if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
63703 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63704 + || in_group_p(grsec_proc_gid)
63705 +#endif
63706 + ) {
63707 + rcu_read_unlock();
63708 + return true;
63709 + }
63710 + }
63711 + rcu_read_unlock();
63712 +
63713 + if (!pid->hide_pid)
63714 + return false;
63715 +#endif
63716 +
63717 if (pid->hide_pid < hide_pid_min)
63718 return true;
63719 if (in_group_p(pid->pid_gid))
63720 return true;
63721 +
63722 return ptrace_may_access(task, PTRACE_MODE_READ);
63723 }
63724
63725 @@ -577,7 +629,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
63726 put_task_struct(task);
63727
63728 if (!has_perms) {
63729 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63730 + {
63731 +#else
63732 if (pid->hide_pid == 2) {
63733 +#endif
63734 /*
63735 * Let's make getdents(), stat(), and open()
63736 * consistent with each other. If a process
63737 @@ -675,6 +731,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63738 if (!task)
63739 return -ESRCH;
63740
63741 + if (gr_acl_handle_procpidmem(task)) {
63742 + put_task_struct(task);
63743 + return -EPERM;
63744 + }
63745 +
63746 mm = mm_access(task, mode);
63747 put_task_struct(task);
63748
63749 @@ -690,6 +751,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63750
63751 file->private_data = mm;
63752
63753 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63754 + file->f_version = current->exec_id;
63755 +#endif
63756 +
63757 return 0;
63758 }
63759
63760 @@ -711,6 +776,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63761 ssize_t copied;
63762 char *page;
63763
63764 +#ifdef CONFIG_GRKERNSEC
63765 + if (write)
63766 + return -EPERM;
63767 +#endif
63768 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63769 + if (file->f_version != current->exec_id) {
63770 + gr_log_badprocpid("mem");
63771 + return 0;
63772 + }
63773 +#endif
63774 +
63775 if (!mm)
63776 return 0;
63777
63778 @@ -723,7 +799,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63779 goto free;
63780
63781 while (count > 0) {
63782 - int this_len = min_t(int, count, PAGE_SIZE);
63783 + ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
63784
63785 if (write && copy_from_user(page, buf, this_len)) {
63786 copied = -EFAULT;
63787 @@ -815,6 +891,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63788 if (!mm)
63789 return 0;
63790
63791 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63792 + if (file->f_version != current->exec_id) {
63793 + gr_log_badprocpid("environ");
63794 + return 0;
63795 + }
63796 +#endif
63797 +
63798 page = (char *)__get_free_page(GFP_TEMPORARY);
63799 if (!page)
63800 return -ENOMEM;
63801 @@ -824,7 +907,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63802 goto free;
63803 while (count > 0) {
63804 size_t this_len, max_len;
63805 - int retval;
63806 + ssize_t retval;
63807
63808 if (src >= (mm->env_end - mm->env_start))
63809 break;
63810 @@ -1438,7 +1521,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
63811 int error = -EACCES;
63812
63813 /* Are we allowed to snoop on the tasks file descriptors? */
63814 - if (!proc_fd_access_allowed(inode))
63815 + if (!proc_fd_access_allowed(inode, 0))
63816 goto out;
63817
63818 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63819 @@ -1482,8 +1565,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
63820 struct path path;
63821
63822 /* Are we allowed to snoop on the tasks file descriptors? */
63823 - if (!proc_fd_access_allowed(inode))
63824 - goto out;
63825 + /* logging this is needed for learning on chromium to work properly,
63826 + but we don't want to flood the logs from 'ps' which does a readlink
63827 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
63828 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
63829 + */
63830 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
63831 + if (!proc_fd_access_allowed(inode,0))
63832 + goto out;
63833 + } else {
63834 + if (!proc_fd_access_allowed(inode,1))
63835 + goto out;
63836 + }
63837
63838 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63839 if (error)
63840 @@ -1533,7 +1626,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
63841 rcu_read_lock();
63842 cred = __task_cred(task);
63843 inode->i_uid = cred->euid;
63844 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63845 + inode->i_gid = grsec_proc_gid;
63846 +#else
63847 inode->i_gid = cred->egid;
63848 +#endif
63849 rcu_read_unlock();
63850 }
63851 security_task_to_inode(task, inode);
63852 @@ -1569,10 +1666,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
63853 return -ENOENT;
63854 }
63855 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63856 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63857 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63858 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63859 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63860 +#endif
63861 task_dumpable(task)) {
63862 cred = __task_cred(task);
63863 stat->uid = cred->euid;
63864 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63865 + stat->gid = grsec_proc_gid;
63866 +#else
63867 stat->gid = cred->egid;
63868 +#endif
63869 }
63870 }
63871 rcu_read_unlock();
63872 @@ -1610,11 +1716,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
63873
63874 if (task) {
63875 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63876 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63877 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63878 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63879 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63880 +#endif
63881 task_dumpable(task)) {
63882 rcu_read_lock();
63883 cred = __task_cred(task);
63884 inode->i_uid = cred->euid;
63885 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63886 + inode->i_gid = grsec_proc_gid;
63887 +#else
63888 inode->i_gid = cred->egid;
63889 +#endif
63890 rcu_read_unlock();
63891 } else {
63892 inode->i_uid = GLOBAL_ROOT_UID;
63893 @@ -2149,6 +2264,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
63894 if (!task)
63895 goto out_no_task;
63896
63897 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63898 + goto out;
63899 +
63900 /*
63901 * Yes, it does not scale. And it should not. Don't add
63902 * new entries into /proc/<tgid>/ without very good reasons.
63903 @@ -2179,6 +2297,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
63904 if (!task)
63905 return -ENOENT;
63906
63907 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63908 + goto out;
63909 +
63910 if (!dir_emit_dots(file, ctx))
63911 goto out;
63912
63913 @@ -2568,7 +2689,7 @@ static const struct pid_entry tgid_base_stuff[] = {
63914 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
63915 #endif
63916 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63917 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63918 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63919 INF("syscall", S_IRUSR, proc_pid_syscall),
63920 #endif
63921 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63922 @@ -2593,10 +2714,10 @@ static const struct pid_entry tgid_base_stuff[] = {
63923 #ifdef CONFIG_SECURITY
63924 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63925 #endif
63926 -#ifdef CONFIG_KALLSYMS
63927 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63928 INF("wchan", S_IRUGO, proc_pid_wchan),
63929 #endif
63930 -#ifdef CONFIG_STACKTRACE
63931 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63932 ONE("stack", S_IRUSR, proc_pid_stack),
63933 #endif
63934 #ifdef CONFIG_SCHEDSTATS
63935 @@ -2630,6 +2751,9 @@ static const struct pid_entry tgid_base_stuff[] = {
63936 #ifdef CONFIG_HARDWALL
63937 INF("hardwall", S_IRUGO, proc_pid_hardwall),
63938 #endif
63939 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63940 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
63941 +#endif
63942 #ifdef CONFIG_USER_NS
63943 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
63944 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
63945 @@ -2760,7 +2884,14 @@ static int proc_pid_instantiate(struct inode *dir,
63946 if (!inode)
63947 goto out;
63948
63949 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63950 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
63951 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63952 + inode->i_gid = grsec_proc_gid;
63953 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
63954 +#else
63955 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
63956 +#endif
63957 inode->i_op = &proc_tgid_base_inode_operations;
63958 inode->i_fop = &proc_tgid_base_operations;
63959 inode->i_flags|=S_IMMUTABLE;
63960 @@ -2798,7 +2929,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
63961 if (!task)
63962 goto out;
63963
63964 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63965 + goto out_put_task;
63966 +
63967 result = proc_pid_instantiate(dir, dentry, task, NULL);
63968 +out_put_task:
63969 put_task_struct(task);
63970 out:
63971 return ERR_PTR(result);
63972 @@ -2904,7 +3039,7 @@ static const struct pid_entry tid_base_stuff[] = {
63973 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
63974 #endif
63975 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63976 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63977 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63978 INF("syscall", S_IRUSR, proc_pid_syscall),
63979 #endif
63980 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63981 @@ -2931,10 +3066,10 @@ static const struct pid_entry tid_base_stuff[] = {
63982 #ifdef CONFIG_SECURITY
63983 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63984 #endif
63985 -#ifdef CONFIG_KALLSYMS
63986 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63987 INF("wchan", S_IRUGO, proc_pid_wchan),
63988 #endif
63989 -#ifdef CONFIG_STACKTRACE
63990 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63991 ONE("stack", S_IRUSR, proc_pid_stack),
63992 #endif
63993 #ifdef CONFIG_SCHEDSTATS
63994 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
63995 index cbd82df..c0407d2 100644
63996 --- a/fs/proc/cmdline.c
63997 +++ b/fs/proc/cmdline.c
63998 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
63999
64000 static int __init proc_cmdline_init(void)
64001 {
64002 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
64003 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
64004 +#else
64005 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
64006 +#endif
64007 return 0;
64008 }
64009 fs_initcall(proc_cmdline_init);
64010 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
64011 index 50493ed..248166b 100644
64012 --- a/fs/proc/devices.c
64013 +++ b/fs/proc/devices.c
64014 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
64015
64016 static int __init proc_devices_init(void)
64017 {
64018 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
64019 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
64020 +#else
64021 proc_create("devices", 0, NULL, &proc_devinfo_operations);
64022 +#endif
64023 return 0;
64024 }
64025 fs_initcall(proc_devices_init);
64026 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
64027 index 0788d09..9cc1385 100644
64028 --- a/fs/proc/fd.c
64029 +++ b/fs/proc/fd.c
64030 @@ -26,7 +26,8 @@ static int seq_show(struct seq_file *m, void *v)
64031 if (!task)
64032 return -ENOENT;
64033
64034 - files = get_files_struct(task);
64035 + if (!gr_acl_handle_procpidmem(task))
64036 + files = get_files_struct(task);
64037 put_task_struct(task);
64038
64039 if (files) {
64040 @@ -285,11 +286,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
64041 */
64042 int proc_fd_permission(struct inode *inode, int mask)
64043 {
64044 + struct task_struct *task;
64045 int rv = generic_permission(inode, mask);
64046 - if (rv == 0)
64047 - return 0;
64048 +
64049 if (task_tgid(current) == proc_pid(inode))
64050 rv = 0;
64051 +
64052 + task = get_proc_task(inode);
64053 + if (task == NULL)
64054 + return rv;
64055 +
64056 + if (gr_acl_handle_procpidmem(task))
64057 + rv = -EACCES;
64058 +
64059 + put_task_struct(task);
64060 +
64061 return rv;
64062 }
64063
64064 diff --git a/fs/proc/generic.c b/fs/proc/generic.c
64065 index b7f268e..3bea6b7 100644
64066 --- a/fs/proc/generic.c
64067 +++ b/fs/proc/generic.c
64068 @@ -23,6 +23,7 @@
64069 #include <linux/bitops.h>
64070 #include <linux/spinlock.h>
64071 #include <linux/completion.h>
64072 +#include <linux/grsecurity.h>
64073 #include <asm/uaccess.h>
64074
64075 #include "internal.h"
64076 @@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
64077 return proc_lookup_de(PDE(dir), dir, dentry);
64078 }
64079
64080 +struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
64081 + unsigned int flags)
64082 +{
64083 + if (gr_proc_is_restricted())
64084 + return ERR_PTR(-EACCES);
64085 +
64086 + return proc_lookup_de(PDE(dir), dir, dentry);
64087 +}
64088 +
64089 /*
64090 * This returns non-zero if at EOF, so that the /proc
64091 * root directory can use this and check if it should
64092 @@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
64093 return proc_readdir_de(PDE(inode), file, ctx);
64094 }
64095
64096 +int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
64097 +{
64098 + struct inode *inode = file_inode(file);
64099 +
64100 + if (gr_proc_is_restricted())
64101 + return -EACCES;
64102 +
64103 + return proc_readdir_de(PDE(inode), file, ctx);
64104 +}
64105 +
64106 /*
64107 * These are the generic /proc directory operations. They
64108 * use the in-memory "struct proc_dir_entry" tree to parse
64109 @@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
64110 .iterate = proc_readdir,
64111 };
64112
64113 +static const struct file_operations proc_dir_restricted_operations = {
64114 + .llseek = generic_file_llseek,
64115 + .read = generic_read_dir,
64116 + .iterate = proc_readdir_restrict,
64117 +};
64118 +
64119 /*
64120 * proc directories can do almost nothing..
64121 */
64122 @@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
64123 .setattr = proc_notify_change,
64124 };
64125
64126 +static const struct inode_operations proc_dir_restricted_inode_operations = {
64127 + .lookup = proc_lookup_restrict,
64128 + .getattr = proc_getattr,
64129 + .setattr = proc_notify_change,
64130 +};
64131 +
64132 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
64133 {
64134 struct proc_dir_entry *tmp;
64135 @@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
64136 return ret;
64137
64138 if (S_ISDIR(dp->mode)) {
64139 - dp->proc_fops = &proc_dir_operations;
64140 - dp->proc_iops = &proc_dir_inode_operations;
64141 + if (dp->restricted) {
64142 + dp->proc_fops = &proc_dir_restricted_operations;
64143 + dp->proc_iops = &proc_dir_restricted_inode_operations;
64144 + } else {
64145 + dp->proc_fops = &proc_dir_operations;
64146 + dp->proc_iops = &proc_dir_inode_operations;
64147 + }
64148 dir->nlink++;
64149 } else if (S_ISLNK(dp->mode)) {
64150 dp->proc_iops = &proc_link_inode_operations;
64151 @@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
64152 }
64153 EXPORT_SYMBOL_GPL(proc_mkdir_data);
64154
64155 +struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
64156 + struct proc_dir_entry *parent, void *data)
64157 +{
64158 + struct proc_dir_entry *ent;
64159 +
64160 + if (mode == 0)
64161 + mode = S_IRUGO | S_IXUGO;
64162 +
64163 + ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
64164 + if (ent) {
64165 + ent->data = data;
64166 + ent->restricted = 1;
64167 + if (proc_register(parent, ent) < 0) {
64168 + kfree(ent);
64169 + ent = NULL;
64170 + }
64171 + }
64172 + return ent;
64173 +}
64174 +EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
64175 +
64176 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
64177 struct proc_dir_entry *parent)
64178 {
64179 @@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
64180 }
64181 EXPORT_SYMBOL(proc_mkdir);
64182
64183 +struct proc_dir_entry *proc_mkdir_restrict(const char *name,
64184 + struct proc_dir_entry *parent)
64185 +{
64186 + return proc_mkdir_data_restrict(name, 0, parent, NULL);
64187 +}
64188 +EXPORT_SYMBOL(proc_mkdir_restrict);
64189 +
64190 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
64191 struct proc_dir_entry *parent,
64192 const struct file_operations *proc_fops,
64193 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
64194 index 0adbc02..bee4d0b 100644
64195 --- a/fs/proc/inode.c
64196 +++ b/fs/proc/inode.c
64197 @@ -23,11 +23,17 @@
64198 #include <linux/slab.h>
64199 #include <linux/mount.h>
64200 #include <linux/magic.h>
64201 +#include <linux/grsecurity.h>
64202
64203 #include <asm/uaccess.h>
64204
64205 #include "internal.h"
64206
64207 +#ifdef CONFIG_PROC_SYSCTL
64208 +extern const struct inode_operations proc_sys_inode_operations;
64209 +extern const struct inode_operations proc_sys_dir_operations;
64210 +#endif
64211 +
64212 static void proc_evict_inode(struct inode *inode)
64213 {
64214 struct proc_dir_entry *de;
64215 @@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
64216 ns = PROC_I(inode)->ns.ns;
64217 if (ns_ops && ns)
64218 ns_ops->put(ns);
64219 +
64220 +#ifdef CONFIG_PROC_SYSCTL
64221 + if (inode->i_op == &proc_sys_inode_operations ||
64222 + inode->i_op == &proc_sys_dir_operations)
64223 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
64224 +#endif
64225 +
64226 }
64227
64228 static struct kmem_cache * proc_inode_cachep;
64229 @@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
64230 if (de->mode) {
64231 inode->i_mode = de->mode;
64232 inode->i_uid = de->uid;
64233 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64234 + inode->i_gid = grsec_proc_gid;
64235 +#else
64236 inode->i_gid = de->gid;
64237 +#endif
64238 }
64239 if (de->size)
64240 inode->i_size = de->size;
64241 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
64242 index 3ab6d14..b26174e 100644
64243 --- a/fs/proc/internal.h
64244 +++ b/fs/proc/internal.h
64245 @@ -46,9 +46,10 @@ struct proc_dir_entry {
64246 struct completion *pde_unload_completion;
64247 struct list_head pde_openers; /* who did ->open, but not ->release */
64248 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
64249 + u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
64250 u8 namelen;
64251 char name[];
64252 -};
64253 +} __randomize_layout;
64254
64255 union proc_op {
64256 int (*proc_get_link)(struct dentry *, struct path *);
64257 @@ -67,7 +68,7 @@ struct proc_inode {
64258 struct ctl_table *sysctl_entry;
64259 struct proc_ns ns;
64260 struct inode vfs_inode;
64261 -};
64262 +} __randomize_layout;
64263
64264 /*
64265 * General functions
64266 @@ -155,6 +156,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
64267 struct pid *, struct task_struct *);
64268 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
64269 struct pid *, struct task_struct *);
64270 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
64271 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
64272 +#endif
64273
64274 /*
64275 * base.c
64276 @@ -181,9 +185,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
64277 extern spinlock_t proc_subdir_lock;
64278
64279 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
64280 +extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
64281 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
64282 struct dentry *);
64283 extern int proc_readdir(struct file *, struct dir_context *);
64284 +extern int proc_readdir_restrict(struct file *, struct dir_context *);
64285 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
64286
64287 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
64288 diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
64289 index a352d57..cb94a5c 100644
64290 --- a/fs/proc/interrupts.c
64291 +++ b/fs/proc/interrupts.c
64292 @@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
64293
64294 static int __init proc_interrupts_init(void)
64295 {
64296 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
64297 + proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
64298 +#else
64299 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
64300 +#endif
64301 return 0;
64302 }
64303 fs_initcall(proc_interrupts_init);
64304 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
64305 index 39e6ef3..2f9cb5e 100644
64306 --- a/fs/proc/kcore.c
64307 +++ b/fs/proc/kcore.c
64308 @@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64309 * the addresses in the elf_phdr on our list.
64310 */
64311 start = kc_offset_to_vaddr(*fpos - elf_buflen);
64312 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
64313 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
64314 + if (tsz > buflen)
64315 tsz = buflen;
64316 -
64317 +
64318 while (buflen) {
64319 struct kcore_list *m;
64320
64321 @@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64322 kfree(elf_buf);
64323 } else {
64324 if (kern_addr_valid(start)) {
64325 - unsigned long n;
64326 + char *elf_buf;
64327 + mm_segment_t oldfs;
64328
64329 - n = copy_to_user(buffer, (char *)start, tsz);
64330 - /*
64331 - * We cannot distinguish between fault on source
64332 - * and fault on destination. When this happens
64333 - * we clear too and hope it will trigger the
64334 - * EFAULT again.
64335 - */
64336 - if (n) {
64337 - if (clear_user(buffer + tsz - n,
64338 - n))
64339 + elf_buf = kmalloc(tsz, GFP_KERNEL);
64340 + if (!elf_buf)
64341 + return -ENOMEM;
64342 + oldfs = get_fs();
64343 + set_fs(KERNEL_DS);
64344 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
64345 + set_fs(oldfs);
64346 + if (copy_to_user(buffer, elf_buf, tsz)) {
64347 + kfree(elf_buf);
64348 return -EFAULT;
64349 + }
64350 }
64351 + set_fs(oldfs);
64352 + kfree(elf_buf);
64353 } else {
64354 if (clear_user(buffer, tsz))
64355 return -EFAULT;
64356 @@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64357
64358 static int open_kcore(struct inode *inode, struct file *filp)
64359 {
64360 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
64361 + return -EPERM;
64362 +#endif
64363 if (!capable(CAP_SYS_RAWIO))
64364 return -EPERM;
64365 if (kcore_need_update)
64366 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
64367 index 7445af0..7c5113c 100644
64368 --- a/fs/proc/meminfo.c
64369 +++ b/fs/proc/meminfo.c
64370 @@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
64371 vmi.used >> 10,
64372 vmi.largest_chunk >> 10
64373 #ifdef CONFIG_MEMORY_FAILURE
64374 - ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
64375 + ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
64376 #endif
64377 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
64378 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
64379 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
64380 index d4a3574..b421ce9 100644
64381 --- a/fs/proc/nommu.c
64382 +++ b/fs/proc/nommu.c
64383 @@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
64384
64385 if (file) {
64386 seq_pad(m, ' ');
64387 - seq_path(m, &file->f_path, "");
64388 + seq_path(m, &file->f_path, "\n\\");
64389 }
64390
64391 seq_putc(m, '\n');
64392 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
64393 index 4677bb7..dad3045 100644
64394 --- a/fs/proc/proc_net.c
64395 +++ b/fs/proc/proc_net.c
64396 @@ -23,9 +23,27 @@
64397 #include <linux/nsproxy.h>
64398 #include <net/net_namespace.h>
64399 #include <linux/seq_file.h>
64400 +#include <linux/grsecurity.h>
64401
64402 #include "internal.h"
64403
64404 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
64405 +static struct seq_operations *ipv6_seq_ops_addr;
64406 +
64407 +void register_ipv6_seq_ops_addr(struct seq_operations *addr)
64408 +{
64409 + ipv6_seq_ops_addr = addr;
64410 +}
64411 +
64412 +void unregister_ipv6_seq_ops_addr(void)
64413 +{
64414 + ipv6_seq_ops_addr = NULL;
64415 +}
64416 +
64417 +EXPORT_SYMBOL_GPL(register_ipv6_seq_ops_addr);
64418 +EXPORT_SYMBOL_GPL(unregister_ipv6_seq_ops_addr);
64419 +#endif
64420 +
64421 static inline struct net *PDE_NET(struct proc_dir_entry *pde)
64422 {
64423 return pde->parent->data;
64424 @@ -36,6 +54,8 @@ static struct net *get_proc_net(const struct inode *inode)
64425 return maybe_get_net(PDE_NET(PDE(inode)));
64426 }
64427
64428 +extern const struct seq_operations dev_seq_ops;
64429 +
64430 int seq_open_net(struct inode *ino, struct file *f,
64431 const struct seq_operations *ops, int size)
64432 {
64433 @@ -44,6 +64,14 @@ int seq_open_net(struct inode *ino, struct file *f,
64434
64435 BUG_ON(size < sizeof(*p));
64436
64437 + /* only permit access to /proc/net/dev */
64438 + if (
64439 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
64440 + ops != ipv6_seq_ops_addr &&
64441 +#endif
64442 + ops != &dev_seq_ops && gr_proc_is_restricted())
64443 + return -EACCES;
64444 +
64445 net = get_proc_net(ino);
64446 if (net == NULL)
64447 return -ENXIO;
64448 @@ -66,6 +94,9 @@ int single_open_net(struct inode *inode, struct file *file,
64449 int err;
64450 struct net *net;
64451
64452 + if (gr_proc_is_restricted())
64453 + return -EACCES;
64454 +
64455 err = -ENXIO;
64456 net = get_proc_net(inode);
64457 if (net == NULL)
64458 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
64459 index 7129046..6914844 100644
64460 --- a/fs/proc/proc_sysctl.c
64461 +++ b/fs/proc/proc_sysctl.c
64462 @@ -11,13 +11,21 @@
64463 #include <linux/namei.h>
64464 #include <linux/mm.h>
64465 #include <linux/module.h>
64466 +#include <linux/nsproxy.h>
64467 +#ifdef CONFIG_GRKERNSEC
64468 +#include <net/net_namespace.h>
64469 +#endif
64470 #include "internal.h"
64471
64472 +extern int gr_handle_chroot_sysctl(const int op);
64473 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
64474 + const int op);
64475 +
64476 static const struct dentry_operations proc_sys_dentry_operations;
64477 static const struct file_operations proc_sys_file_operations;
64478 -static const struct inode_operations proc_sys_inode_operations;
64479 +const struct inode_operations proc_sys_inode_operations;
64480 static const struct file_operations proc_sys_dir_file_operations;
64481 -static const struct inode_operations proc_sys_dir_operations;
64482 +const struct inode_operations proc_sys_dir_operations;
64483
64484 void proc_sys_poll_notify(struct ctl_table_poll *poll)
64485 {
64486 @@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
64487
64488 err = NULL;
64489 d_set_d_op(dentry, &proc_sys_dentry_operations);
64490 +
64491 + gr_handle_proc_create(dentry, inode);
64492 +
64493 d_add(dentry, inode);
64494
64495 out:
64496 @@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64497 struct inode *inode = file_inode(filp);
64498 struct ctl_table_header *head = grab_header(inode);
64499 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
64500 + int op = write ? MAY_WRITE : MAY_READ;
64501 ssize_t error;
64502 size_t res;
64503
64504 @@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64505 * and won't be until we finish.
64506 */
64507 error = -EPERM;
64508 - if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
64509 + if (sysctl_perm(head, table, op))
64510 goto out;
64511
64512 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
64513 @@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64514 if (!table->proc_handler)
64515 goto out;
64516
64517 +#ifdef CONFIG_GRKERNSEC
64518 + error = -EPERM;
64519 + if (gr_handle_chroot_sysctl(op))
64520 + goto out;
64521 + dget(filp->f_path.dentry);
64522 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
64523 + dput(filp->f_path.dentry);
64524 + goto out;
64525 + }
64526 + dput(filp->f_path.dentry);
64527 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
64528 + goto out;
64529 + if (write) {
64530 + if (current->nsproxy->net_ns != table->extra2) {
64531 + if (!capable(CAP_SYS_ADMIN))
64532 + goto out;
64533 + } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
64534 + goto out;
64535 + }
64536 +#endif
64537 +
64538 /* careful: calling conventions are nasty here */
64539 res = count;
64540 error = table->proc_handler(table, write, buf, &res, ppos);
64541 @@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
64542 return false;
64543 } else {
64544 d_set_d_op(child, &proc_sys_dentry_operations);
64545 +
64546 + gr_handle_proc_create(child, inode);
64547 +
64548 d_add(child, inode);
64549 }
64550 } else {
64551 @@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
64552 if ((*pos)++ < ctx->pos)
64553 return true;
64554
64555 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
64556 + return 0;
64557 +
64558 if (unlikely(S_ISLNK(table->mode)))
64559 res = proc_sys_link_fill_cache(file, ctx, head, table);
64560 else
64561 @@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
64562 if (IS_ERR(head))
64563 return PTR_ERR(head);
64564
64565 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
64566 + return -ENOENT;
64567 +
64568 generic_fillattr(inode, stat);
64569 if (table)
64570 stat->mode = (stat->mode & S_IFMT) | table->mode;
64571 @@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
64572 .llseek = generic_file_llseek,
64573 };
64574
64575 -static const struct inode_operations proc_sys_inode_operations = {
64576 +const struct inode_operations proc_sys_inode_operations = {
64577 .permission = proc_sys_permission,
64578 .setattr = proc_sys_setattr,
64579 .getattr = proc_sys_getattr,
64580 };
64581
64582 -static const struct inode_operations proc_sys_dir_operations = {
64583 +const struct inode_operations proc_sys_dir_operations = {
64584 .lookup = proc_sys_lookup,
64585 .permission = proc_sys_permission,
64586 .setattr = proc_sys_setattr,
64587 @@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
64588 static struct ctl_dir *new_dir(struct ctl_table_set *set,
64589 const char *name, int namelen)
64590 {
64591 - struct ctl_table *table;
64592 + ctl_table_no_const *table;
64593 struct ctl_dir *new;
64594 struct ctl_node *node;
64595 char *new_name;
64596 @@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
64597 return NULL;
64598
64599 node = (struct ctl_node *)(new + 1);
64600 - table = (struct ctl_table *)(node + 1);
64601 + table = (ctl_table_no_const *)(node + 1);
64602 new_name = (char *)(table + 2);
64603 memcpy(new_name, name, namelen);
64604 new_name[namelen] = '\0';
64605 @@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
64606 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
64607 struct ctl_table_root *link_root)
64608 {
64609 - struct ctl_table *link_table, *entry, *link;
64610 + ctl_table_no_const *link_table, *link;
64611 + struct ctl_table *entry;
64612 struct ctl_table_header *links;
64613 struct ctl_node *node;
64614 char *link_name;
64615 @@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
64616 return NULL;
64617
64618 node = (struct ctl_node *)(links + 1);
64619 - link_table = (struct ctl_table *)(node + nr_entries);
64620 + link_table = (ctl_table_no_const *)(node + nr_entries);
64621 link_name = (char *)&link_table[nr_entries + 1];
64622
64623 for (link = link_table, entry = table; entry->procname; link++, entry++) {
64624 @@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64625 struct ctl_table_header ***subheader, struct ctl_table_set *set,
64626 struct ctl_table *table)
64627 {
64628 - struct ctl_table *ctl_table_arg = NULL;
64629 - struct ctl_table *entry, *files;
64630 + ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
64631 + struct ctl_table *entry;
64632 int nr_files = 0;
64633 int nr_dirs = 0;
64634 int err = -ENOMEM;
64635 @@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64636 nr_files++;
64637 }
64638
64639 - files = table;
64640 /* If there are mixed files and directories we need a new table */
64641 if (nr_dirs && nr_files) {
64642 - struct ctl_table *new;
64643 + ctl_table_no_const *new;
64644 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
64645 GFP_KERNEL);
64646 if (!files)
64647 @@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64648 /* Register everything except a directory full of subdirectories */
64649 if (nr_files || !nr_dirs) {
64650 struct ctl_table_header *header;
64651 - header = __register_sysctl_table(set, path, files);
64652 + header = __register_sysctl_table(set, path, files ? files : table);
64653 if (!header) {
64654 kfree(ctl_table_arg);
64655 goto out;
64656 diff --git a/fs/proc/root.c b/fs/proc/root.c
64657 index 5dbadec..473af2f 100644
64658 --- a/fs/proc/root.c
64659 +++ b/fs/proc/root.c
64660 @@ -185,7 +185,15 @@ void __init proc_root_init(void)
64661 proc_mkdir("openprom", NULL);
64662 #endif
64663 proc_tty_init();
64664 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
64665 +#ifdef CONFIG_GRKERNSEC_PROC_USER
64666 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
64667 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64668 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
64669 +#endif
64670 +#else
64671 proc_mkdir("bus", NULL);
64672 +#endif
64673 proc_sys_init();
64674 }
64675
64676 diff --git a/fs/proc/stat.c b/fs/proc/stat.c
64677 index 9d231e9..2e1b51a 100644
64678 --- a/fs/proc/stat.c
64679 +++ b/fs/proc/stat.c
64680 @@ -11,6 +11,7 @@
64681 #include <linux/irqnr.h>
64682 #include <linux/cputime.h>
64683 #include <linux/tick.h>
64684 +#include <linux/grsecurity.h>
64685
64686 #ifndef arch_irq_stat_cpu
64687 #define arch_irq_stat_cpu(cpu) 0
64688 @@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
64689 u64 sum_softirq = 0;
64690 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
64691 struct timespec boottime;
64692 + int unrestricted = 1;
64693 +
64694 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
64695 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64696 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
64697 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64698 + && !in_group_p(grsec_proc_gid)
64699 +#endif
64700 + )
64701 + unrestricted = 0;
64702 +#endif
64703 +#endif
64704
64705 user = nice = system = idle = iowait =
64706 irq = softirq = steal = 0;
64707 @@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
64708 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
64709 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
64710 idle += get_idle_time(i);
64711 - iowait += get_iowait_time(i);
64712 - irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64713 - softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64714 - steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64715 - guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64716 - guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64717 - sum += kstat_cpu_irqs_sum(i);
64718 - sum += arch_irq_stat_cpu(i);
64719 + if (unrestricted) {
64720 + iowait += get_iowait_time(i);
64721 + irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64722 + softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64723 + steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64724 + guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64725 + guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64726 + sum += kstat_cpu_irqs_sum(i);
64727 + sum += arch_irq_stat_cpu(i);
64728 + for (j = 0; j < NR_SOFTIRQS; j++) {
64729 + unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
64730
64731 - for (j = 0; j < NR_SOFTIRQS; j++) {
64732 - unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
64733 -
64734 - per_softirq_sums[j] += softirq_stat;
64735 - sum_softirq += softirq_stat;
64736 + per_softirq_sums[j] += softirq_stat;
64737 + sum_softirq += softirq_stat;
64738 + }
64739 }
64740 }
64741 - sum += arch_irq_stat();
64742 + if (unrestricted)
64743 + sum += arch_irq_stat();
64744
64745 seq_puts(p, "cpu ");
64746 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
64747 @@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
64748 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
64749 system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
64750 idle = get_idle_time(i);
64751 - iowait = get_iowait_time(i);
64752 - irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64753 - softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64754 - steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64755 - guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64756 - guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64757 + if (unrestricted) {
64758 + iowait = get_iowait_time(i);
64759 + irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64760 + softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64761 + steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64762 + guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64763 + guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64764 + }
64765 seq_printf(p, "cpu%d", i);
64766 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
64767 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
64768 @@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
64769
64770 /* sum again ? it could be updated? */
64771 for_each_irq_nr(j)
64772 - seq_put_decimal_ull(p, ' ', kstat_irqs(j));
64773 + seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
64774
64775 seq_printf(p,
64776 "\nctxt %llu\n"
64777 @@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
64778 "processes %lu\n"
64779 "procs_running %lu\n"
64780 "procs_blocked %lu\n",
64781 - nr_context_switches(),
64782 + unrestricted ? nr_context_switches() : 0ULL,
64783 (unsigned long)jif,
64784 - total_forks,
64785 - nr_running(),
64786 - nr_iowait());
64787 + unrestricted ? total_forks : 0UL,
64788 + unrestricted ? nr_running() : 0UL,
64789 + unrestricted ? nr_iowait() : 0UL);
64790
64791 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
64792
64793 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
64794 index c4b2646..84f0d7b 100644
64795 --- a/fs/proc/task_mmu.c
64796 +++ b/fs/proc/task_mmu.c
64797 @@ -13,12 +13,19 @@
64798 #include <linux/swap.h>
64799 #include <linux/swapops.h>
64800 #include <linux/mmu_notifier.h>
64801 +#include <linux/grsecurity.h>
64802
64803 #include <asm/elf.h>
64804 #include <asm/uaccess.h>
64805 #include <asm/tlbflush.h>
64806 #include "internal.h"
64807
64808 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64809 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
64810 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
64811 + _mm->pax_flags & MF_PAX_SEGMEXEC))
64812 +#endif
64813 +
64814 void task_mem(struct seq_file *m, struct mm_struct *mm)
64815 {
64816 unsigned long data, text, lib, swap;
64817 @@ -54,8 +61,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64818 "VmExe:\t%8lu kB\n"
64819 "VmLib:\t%8lu kB\n"
64820 "VmPTE:\t%8lu kB\n"
64821 - "VmSwap:\t%8lu kB\n",
64822 - hiwater_vm << (PAGE_SHIFT-10),
64823 + "VmSwap:\t%8lu kB\n"
64824 +
64825 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64826 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
64827 +#endif
64828 +
64829 + ,hiwater_vm << (PAGE_SHIFT-10),
64830 total_vm << (PAGE_SHIFT-10),
64831 mm->locked_vm << (PAGE_SHIFT-10),
64832 mm->pinned_vm << (PAGE_SHIFT-10),
64833 @@ -65,7 +77,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64834 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
64835 (PTRS_PER_PTE * sizeof(pte_t) *
64836 atomic_long_read(&mm->nr_ptes)) >> 10,
64837 - swap << (PAGE_SHIFT-10));
64838 + swap << (PAGE_SHIFT-10)
64839 +
64840 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64841 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64842 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
64843 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
64844 +#else
64845 + , mm->context.user_cs_base
64846 + , mm->context.user_cs_limit
64847 +#endif
64848 +#endif
64849 +
64850 + );
64851 }
64852
64853 unsigned long task_vsize(struct mm_struct *mm)
64854 @@ -271,13 +295,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64855 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
64856 }
64857
64858 - /* We don't show the stack guard page in /proc/maps */
64859 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64860 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
64861 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
64862 +#else
64863 start = vma->vm_start;
64864 - if (stack_guard_page_start(vma, start))
64865 - start += PAGE_SIZE;
64866 end = vma->vm_end;
64867 - if (stack_guard_page_end(vma, end))
64868 - end -= PAGE_SIZE;
64869 +#endif
64870
64871 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
64872 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
64873 @@ -287,7 +311,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64874 flags & VM_WRITE ? 'w' : '-',
64875 flags & VM_EXEC ? 'x' : '-',
64876 flags & VM_MAYSHARE ? 's' : 'p',
64877 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64878 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
64879 +#else
64880 pgoff,
64881 +#endif
64882 MAJOR(dev), MINOR(dev), ino);
64883
64884 /*
64885 @@ -296,7 +324,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64886 */
64887 if (file) {
64888 seq_pad(m, ' ');
64889 - seq_path(m, &file->f_path, "\n");
64890 + seq_path(m, &file->f_path, "\n\\");
64891 goto done;
64892 }
64893
64894 @@ -322,8 +350,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64895 * Thread stack in /proc/PID/task/TID/maps or
64896 * the main process stack.
64897 */
64898 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
64899 - vma->vm_end >= mm->start_stack)) {
64900 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
64901 + (vma->vm_start <= mm->start_stack &&
64902 + vma->vm_end >= mm->start_stack)) {
64903 name = "[stack]";
64904 } else {
64905 /* Thread stack in /proc/PID/maps */
64906 @@ -347,6 +376,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
64907 struct proc_maps_private *priv = m->private;
64908 struct task_struct *task = priv->task;
64909
64910 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64911 + if (current->exec_id != m->exec_id) {
64912 + gr_log_badprocpid("maps");
64913 + return 0;
64914 + }
64915 +#endif
64916 +
64917 show_map_vma(m, vma, is_pid);
64918
64919 if (m->count < m->size) /* vma is copied successfully */
64920 @@ -587,12 +623,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64921 .private = &mss,
64922 };
64923
64924 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64925 + if (current->exec_id != m->exec_id) {
64926 + gr_log_badprocpid("smaps");
64927 + return 0;
64928 + }
64929 +#endif
64930 memset(&mss, 0, sizeof mss);
64931 - mss.vma = vma;
64932 - /* mmap_sem is held in m_start */
64933 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64934 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64935 -
64936 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64937 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
64938 +#endif
64939 + mss.vma = vma;
64940 + /* mmap_sem is held in m_start */
64941 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64942 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64943 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64944 + }
64945 +#endif
64946 show_map_vma(m, vma, is_pid);
64947
64948 seq_printf(m,
64949 @@ -610,7 +657,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64950 "KernelPageSize: %8lu kB\n"
64951 "MMUPageSize: %8lu kB\n"
64952 "Locked: %8lu kB\n",
64953 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64954 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
64955 +#else
64956 (vma->vm_end - vma->vm_start) >> 10,
64957 +#endif
64958 mss.resident >> 10,
64959 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
64960 mss.shared_clean >> 10,
64961 @@ -1388,6 +1439,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64962 char buffer[64];
64963 int nid;
64964
64965 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64966 + if (current->exec_id != m->exec_id) {
64967 + gr_log_badprocpid("numa_maps");
64968 + return 0;
64969 + }
64970 +#endif
64971 +
64972 if (!mm)
64973 return 0;
64974
64975 @@ -1405,11 +1463,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64976 mpol_to_str(buffer, sizeof(buffer), pol);
64977 mpol_cond_put(pol);
64978
64979 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64980 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
64981 +#else
64982 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
64983 +#endif
64984
64985 if (file) {
64986 seq_printf(m, " file=");
64987 - seq_path(m, &file->f_path, "\n\t= ");
64988 + seq_path(m, &file->f_path, "\n\t\\= ");
64989 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
64990 seq_printf(m, " heap");
64991 } else {
64992 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
64993 index 678455d..ebd3245 100644
64994 --- a/fs/proc/task_nommu.c
64995 +++ b/fs/proc/task_nommu.c
64996 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64997 else
64998 bytes += kobjsize(mm);
64999
65000 - if (current->fs && current->fs->users > 1)
65001 + if (current->fs && atomic_read(&current->fs->users) > 1)
65002 sbytes += kobjsize(current->fs);
65003 else
65004 bytes += kobjsize(current->fs);
65005 @@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
65006
65007 if (file) {
65008 seq_pad(m, ' ');
65009 - seq_path(m, &file->f_path, "");
65010 + seq_path(m, &file->f_path, "\n\\");
65011 } else if (mm) {
65012 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
65013
65014 diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
65015 index 6a8e785..41f2a6c 100644
65016 --- a/fs/proc/vmcore.c
65017 +++ b/fs/proc/vmcore.c
65018 @@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
65019 nr_bytes = count;
65020
65021 /* If pfn is not ram, return zeros for sparse dump files */
65022 - if (pfn_is_ram(pfn) == 0)
65023 - memset(buf, 0, nr_bytes);
65024 - else {
65025 + if (pfn_is_ram(pfn) == 0) {
65026 + if (userbuf) {
65027 + if (clear_user((char __force_user *)buf, nr_bytes))
65028 + return -EFAULT;
65029 + } else
65030 + memset(buf, 0, nr_bytes);
65031 + } else {
65032 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
65033 offset, userbuf);
65034 if (tmp < 0)
65035 @@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
65036 static int copy_to(void *target, void *src, size_t size, int userbuf)
65037 {
65038 if (userbuf) {
65039 - if (copy_to_user((char __user *) target, src, size))
65040 + if (copy_to_user((char __force_user *) target, src, size))
65041 return -EFAULT;
65042 } else {
65043 memcpy(target, src, size);
65044 @@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
65045 if (*fpos < m->offset + m->size) {
65046 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
65047 start = m->paddr + *fpos - m->offset;
65048 - tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
65049 + tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
65050 if (tmp < 0)
65051 return tmp;
65052 buflen -= tsz;
65053 @@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
65054 static ssize_t read_vmcore(struct file *file, char __user *buffer,
65055 size_t buflen, loff_t *fpos)
65056 {
65057 - return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
65058 + return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
65059 }
65060
65061 /*
65062 diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
65063 index b00fcc9..e0c6381 100644
65064 --- a/fs/qnx6/qnx6.h
65065 +++ b/fs/qnx6/qnx6.h
65066 @@ -74,7 +74,7 @@ enum {
65067 BYTESEX_BE,
65068 };
65069
65070 -static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
65071 +static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
65072 {
65073 if (sbi->s_bytesex == BYTESEX_LE)
65074 return le64_to_cpu((__force __le64)n);
65075 @@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
65076 return (__force __fs64)cpu_to_be64(n);
65077 }
65078
65079 -static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
65080 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
65081 {
65082 if (sbi->s_bytesex == BYTESEX_LE)
65083 return le32_to_cpu((__force __le32)n);
65084 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
65085 index 72d2917..c917c12 100644
65086 --- a/fs/quota/netlink.c
65087 +++ b/fs/quota/netlink.c
65088 @@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
65089 void quota_send_warning(struct kqid qid, dev_t dev,
65090 const char warntype)
65091 {
65092 - static atomic_t seq;
65093 + static atomic_unchecked_t seq;
65094 struct sk_buff *skb;
65095 void *msg_head;
65096 int ret;
65097 @@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
65098 "VFS: Not enough memory to send quota warning.\n");
65099 return;
65100 }
65101 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
65102 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
65103 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
65104 if (!msg_head) {
65105 printk(KERN_ERR
65106 diff --git a/fs/read_write.c b/fs/read_write.c
65107 index 31c6efa..a068805 100644
65108 --- a/fs/read_write.c
65109 +++ b/fs/read_write.c
65110 @@ -450,7 +450,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
65111
65112 old_fs = get_fs();
65113 set_fs(get_ds());
65114 - p = (__force const char __user *)buf;
65115 + p = (const char __force_user *)buf;
65116 if (count > MAX_RW_COUNT)
65117 count = MAX_RW_COUNT;
65118 if (file->f_op->write)
65119 diff --git a/fs/readdir.c b/fs/readdir.c
65120 index 5b53d99..a6c3049 100644
65121 --- a/fs/readdir.c
65122 +++ b/fs/readdir.c
65123 @@ -17,6 +17,7 @@
65124 #include <linux/security.h>
65125 #include <linux/syscalls.h>
65126 #include <linux/unistd.h>
65127 +#include <linux/namei.h>
65128
65129 #include <asm/uaccess.h>
65130
65131 @@ -69,6 +70,7 @@ struct old_linux_dirent {
65132 struct readdir_callback {
65133 struct dir_context ctx;
65134 struct old_linux_dirent __user * dirent;
65135 + struct file * file;
65136 int result;
65137 };
65138
65139 @@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
65140 buf->result = -EOVERFLOW;
65141 return -EOVERFLOW;
65142 }
65143 +
65144 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
65145 + return 0;
65146 +
65147 buf->result++;
65148 dirent = buf->dirent;
65149 if (!access_ok(VERIFY_WRITE, dirent,
65150 @@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
65151 if (!f.file)
65152 return -EBADF;
65153
65154 + buf.file = f.file;
65155 error = iterate_dir(f.file, &buf.ctx);
65156 if (buf.result)
65157 error = buf.result;
65158 @@ -142,6 +149,7 @@ struct getdents_callback {
65159 struct dir_context ctx;
65160 struct linux_dirent __user * current_dir;
65161 struct linux_dirent __user * previous;
65162 + struct file * file;
65163 int count;
65164 int error;
65165 };
65166 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
65167 buf->error = -EOVERFLOW;
65168 return -EOVERFLOW;
65169 }
65170 +
65171 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
65172 + return 0;
65173 +
65174 dirent = buf->previous;
65175 if (dirent) {
65176 if (__put_user(offset, &dirent->d_off))
65177 @@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
65178 if (!f.file)
65179 return -EBADF;
65180
65181 + buf.file = f.file;
65182 error = iterate_dir(f.file, &buf.ctx);
65183 if (error >= 0)
65184 error = buf.error;
65185 @@ -226,6 +239,7 @@ struct getdents_callback64 {
65186 struct dir_context ctx;
65187 struct linux_dirent64 __user * current_dir;
65188 struct linux_dirent64 __user * previous;
65189 + struct file *file;
65190 int count;
65191 int error;
65192 };
65193 @@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
65194 buf->error = -EINVAL; /* only used if we fail.. */
65195 if (reclen > buf->count)
65196 return -EINVAL;
65197 +
65198 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
65199 + return 0;
65200 +
65201 dirent = buf->previous;
65202 if (dirent) {
65203 if (__put_user(offset, &dirent->d_off))
65204 @@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
65205 if (!f.file)
65206 return -EBADF;
65207
65208 + buf.file = f.file;
65209 error = iterate_dir(f.file, &buf.ctx);
65210 if (error >= 0)
65211 error = buf.error;
65212 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
65213 index 9a3c68c..767933e 100644
65214 --- a/fs/reiserfs/do_balan.c
65215 +++ b/fs/reiserfs/do_balan.c
65216 @@ -1546,7 +1546,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
65217 return;
65218 }
65219
65220 - atomic_inc(&(fs_generation(tb->tb_sb)));
65221 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
65222 do_balance_starts(tb);
65223
65224 /* balance leaf returns 0 except if combining L R and S into
65225 diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
65226 index ee382ef..f4eb6eb5 100644
65227 --- a/fs/reiserfs/item_ops.c
65228 +++ b/fs/reiserfs/item_ops.c
65229 @@ -725,18 +725,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
65230 }
65231
65232 static struct item_operations errcatch_ops = {
65233 - errcatch_bytes_number,
65234 - errcatch_decrement_key,
65235 - errcatch_is_left_mergeable,
65236 - errcatch_print_item,
65237 - errcatch_check_item,
65238 + .bytes_number = errcatch_bytes_number,
65239 + .decrement_key = errcatch_decrement_key,
65240 + .is_left_mergeable = errcatch_is_left_mergeable,
65241 + .print_item = errcatch_print_item,
65242 + .check_item = errcatch_check_item,
65243
65244 - errcatch_create_vi,
65245 - errcatch_check_left,
65246 - errcatch_check_right,
65247 - errcatch_part_size,
65248 - errcatch_unit_num,
65249 - errcatch_print_vi
65250 + .create_vi = errcatch_create_vi,
65251 + .check_left = errcatch_check_left,
65252 + .check_right = errcatch_check_right,
65253 + .part_size = errcatch_part_size,
65254 + .unit_num = errcatch_unit_num,
65255 + .print_vi = errcatch_print_vi
65256 };
65257
65258 //////////////////////////////////////////////////////////////////////////////
65259 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
65260 index 02b0b7d..c85018b 100644
65261 --- a/fs/reiserfs/procfs.c
65262 +++ b/fs/reiserfs/procfs.c
65263 @@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
65264 "SMALL_TAILS " : "NO_TAILS ",
65265 replay_only(sb) ? "REPLAY_ONLY " : "",
65266 convert_reiserfs(sb) ? "CONV " : "",
65267 - atomic_read(&r->s_generation_counter),
65268 + atomic_read_unchecked(&r->s_generation_counter),
65269 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
65270 SF(s_do_balance), SF(s_unneeded_left_neighbor),
65271 SF(s_good_search_by_key_reada), SF(s_bmaps),
65272 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
65273 index 83d4eac..04e39a7 100644
65274 --- a/fs/reiserfs/reiserfs.h
65275 +++ b/fs/reiserfs/reiserfs.h
65276 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
65277 /* Comment? -Hans */
65278 wait_queue_head_t s_wait;
65279 /* To be obsoleted soon by per buffer seals.. -Hans */
65280 - atomic_t s_generation_counter; // increased by one every time the
65281 + atomic_unchecked_t s_generation_counter; // increased by one every time the
65282 // tree gets re-balanced
65283 unsigned long s_properties; /* File system properties. Currently holds
65284 on-disk FS format */
65285 @@ -1972,7 +1972,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
65286 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
65287
65288 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
65289 -#define get_generation(s) atomic_read (&fs_generation(s))
65290 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
65291 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
65292 #define __fs_changed(gen,s) (gen != get_generation (s))
65293 #define fs_changed(gen,s) \
65294 diff --git a/fs/select.c b/fs/select.c
65295 index 467bb1c..cf9d65a 100644
65296 --- a/fs/select.c
65297 +++ b/fs/select.c
65298 @@ -20,6 +20,7 @@
65299 #include <linux/export.h>
65300 #include <linux/slab.h>
65301 #include <linux/poll.h>
65302 +#include <linux/security.h>
65303 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
65304 #include <linux/file.h>
65305 #include <linux/fdtable.h>
65306 @@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
65307 struct poll_list *walk = head;
65308 unsigned long todo = nfds;
65309
65310 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
65311 if (nfds > rlimit(RLIMIT_NOFILE))
65312 return -EINVAL;
65313
65314 diff --git a/fs/seq_file.c b/fs/seq_file.c
65315 index 1d641bb..c2f4743 100644
65316 --- a/fs/seq_file.c
65317 +++ b/fs/seq_file.c
65318 @@ -10,6 +10,8 @@
65319 #include <linux/seq_file.h>
65320 #include <linux/slab.h>
65321 #include <linux/cred.h>
65322 +#include <linux/sched.h>
65323 +#include <linux/grsecurity.h>
65324
65325 #include <asm/uaccess.h>
65326 #include <asm/page.h>
65327 @@ -60,6 +62,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
65328 #ifdef CONFIG_USER_NS
65329 p->user_ns = file->f_cred->user_ns;
65330 #endif
65331 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65332 + p->exec_id = current->exec_id;
65333 +#endif
65334
65335 /*
65336 * Wrappers around seq_open(e.g. swaps_open) need to be
65337 @@ -82,6 +87,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
65338 }
65339 EXPORT_SYMBOL(seq_open);
65340
65341 +
65342 +int seq_open_restrict(struct file *file, const struct seq_operations *op)
65343 +{
65344 + if (gr_proc_is_restricted())
65345 + return -EACCES;
65346 +
65347 + return seq_open(file, op);
65348 +}
65349 +EXPORT_SYMBOL(seq_open_restrict);
65350 +
65351 static int traverse(struct seq_file *m, loff_t offset)
65352 {
65353 loff_t pos = 0, index;
65354 @@ -96,7 +111,7 @@ static int traverse(struct seq_file *m, loff_t offset)
65355 return 0;
65356 }
65357 if (!m->buf) {
65358 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
65359 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
65360 if (!m->buf)
65361 return -ENOMEM;
65362 }
65363 @@ -137,7 +152,7 @@ Eoverflow:
65364 m->op->stop(m, p);
65365 kfree(m->buf);
65366 m->count = 0;
65367 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
65368 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
65369 return !m->buf ? -ENOMEM : -EAGAIN;
65370 }
65371
65372 @@ -153,7 +168,7 @@ Eoverflow:
65373 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65374 {
65375 struct seq_file *m = file->private_data;
65376 - size_t copied = 0;
65377 + ssize_t copied = 0;
65378 loff_t pos;
65379 size_t n;
65380 void *p;
65381 @@ -192,7 +207,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65382
65383 /* grab buffer if we didn't have one */
65384 if (!m->buf) {
65385 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
65386 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
65387 if (!m->buf)
65388 goto Enomem;
65389 }
65390 @@ -234,7 +249,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65391 m->op->stop(m, p);
65392 kfree(m->buf);
65393 m->count = 0;
65394 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
65395 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
65396 if (!m->buf)
65397 goto Enomem;
65398 m->version = 0;
65399 @@ -584,7 +599,7 @@ static void single_stop(struct seq_file *p, void *v)
65400 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
65401 void *data)
65402 {
65403 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
65404 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
65405 int res = -ENOMEM;
65406
65407 if (op) {
65408 @@ -620,6 +635,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
65409 }
65410 EXPORT_SYMBOL(single_open_size);
65411
65412 +int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
65413 + void *data)
65414 +{
65415 + if (gr_proc_is_restricted())
65416 + return -EACCES;
65417 +
65418 + return single_open(file, show, data);
65419 +}
65420 +EXPORT_SYMBOL(single_open_restrict);
65421 +
65422 +
65423 int single_release(struct inode *inode, struct file *file)
65424 {
65425 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
65426 diff --git a/fs/splice.c b/fs/splice.c
65427 index e246954..bd4f5b5 100644
65428 --- a/fs/splice.c
65429 +++ b/fs/splice.c
65430 @@ -192,7 +192,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65431 pipe_lock(pipe);
65432
65433 for (;;) {
65434 - if (!pipe->readers) {
65435 + if (!atomic_read(&pipe->readers)) {
65436 send_sig(SIGPIPE, current, 0);
65437 if (!ret)
65438 ret = -EPIPE;
65439 @@ -215,7 +215,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65440 page_nr++;
65441 ret += buf->len;
65442
65443 - if (pipe->files)
65444 + if (atomic_read(&pipe->files))
65445 do_wakeup = 1;
65446
65447 if (!--spd->nr_pages)
65448 @@ -246,9 +246,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65449 do_wakeup = 0;
65450 }
65451
65452 - pipe->waiting_writers++;
65453 + atomic_inc(&pipe->waiting_writers);
65454 pipe_wait(pipe);
65455 - pipe->waiting_writers--;
65456 + atomic_dec(&pipe->waiting_writers);
65457 }
65458
65459 pipe_unlock(pipe);
65460 @@ -575,7 +575,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
65461 old_fs = get_fs();
65462 set_fs(get_ds());
65463 /* The cast to a user pointer is valid due to the set_fs() */
65464 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
65465 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
65466 set_fs(old_fs);
65467
65468 return res;
65469 @@ -590,7 +590,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
65470 old_fs = get_fs();
65471 set_fs(get_ds());
65472 /* The cast to a user pointer is valid due to the set_fs() */
65473 - res = vfs_write(file, (__force const char __user *)buf, count, &pos);
65474 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
65475 set_fs(old_fs);
65476
65477 return res;
65478 @@ -643,7 +643,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
65479 goto err;
65480
65481 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
65482 - vec[i].iov_base = (void __user *) page_address(page);
65483 + vec[i].iov_base = (void __force_user *) page_address(page);
65484 vec[i].iov_len = this_len;
65485 spd.pages[i] = page;
65486 spd.nr_pages++;
65487 @@ -839,7 +839,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
65488 ops->release(pipe, buf);
65489 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
65490 pipe->nrbufs--;
65491 - if (pipe->files)
65492 + if (atomic_read(&pipe->files))
65493 sd->need_wakeup = true;
65494 }
65495
65496 @@ -864,10 +864,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
65497 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
65498 {
65499 while (!pipe->nrbufs) {
65500 - if (!pipe->writers)
65501 + if (!atomic_read(&pipe->writers))
65502 return 0;
65503
65504 - if (!pipe->waiting_writers && sd->num_spliced)
65505 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
65506 return 0;
65507
65508 if (sd->flags & SPLICE_F_NONBLOCK)
65509 @@ -1189,7 +1189,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
65510 * out of the pipe right after the splice_to_pipe(). So set
65511 * PIPE_READERS appropriately.
65512 */
65513 - pipe->readers = 1;
65514 + atomic_set(&pipe->readers, 1);
65515
65516 current->splice_pipe = pipe;
65517 }
65518 @@ -1485,6 +1485,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
65519
65520 partial[buffers].offset = off;
65521 partial[buffers].len = plen;
65522 + partial[buffers].private = 0;
65523
65524 off = 0;
65525 len -= plen;
65526 @@ -1721,9 +1722,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65527 ret = -ERESTARTSYS;
65528 break;
65529 }
65530 - if (!pipe->writers)
65531 + if (!atomic_read(&pipe->writers))
65532 break;
65533 - if (!pipe->waiting_writers) {
65534 + if (!atomic_read(&pipe->waiting_writers)) {
65535 if (flags & SPLICE_F_NONBLOCK) {
65536 ret = -EAGAIN;
65537 break;
65538 @@ -1755,7 +1756,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65539 pipe_lock(pipe);
65540
65541 while (pipe->nrbufs >= pipe->buffers) {
65542 - if (!pipe->readers) {
65543 + if (!atomic_read(&pipe->readers)) {
65544 send_sig(SIGPIPE, current, 0);
65545 ret = -EPIPE;
65546 break;
65547 @@ -1768,9 +1769,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65548 ret = -ERESTARTSYS;
65549 break;
65550 }
65551 - pipe->waiting_writers++;
65552 + atomic_inc(&pipe->waiting_writers);
65553 pipe_wait(pipe);
65554 - pipe->waiting_writers--;
65555 + atomic_dec(&pipe->waiting_writers);
65556 }
65557
65558 pipe_unlock(pipe);
65559 @@ -1806,14 +1807,14 @@ retry:
65560 pipe_double_lock(ipipe, opipe);
65561
65562 do {
65563 - if (!opipe->readers) {
65564 + if (!atomic_read(&opipe->readers)) {
65565 send_sig(SIGPIPE, current, 0);
65566 if (!ret)
65567 ret = -EPIPE;
65568 break;
65569 }
65570
65571 - if (!ipipe->nrbufs && !ipipe->writers)
65572 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
65573 break;
65574
65575 /*
65576 @@ -1910,7 +1911,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
65577 pipe_double_lock(ipipe, opipe);
65578
65579 do {
65580 - if (!opipe->readers) {
65581 + if (!atomic_read(&opipe->readers)) {
65582 send_sig(SIGPIPE, current, 0);
65583 if (!ret)
65584 ret = -EPIPE;
65585 @@ -1955,7 +1956,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
65586 * return EAGAIN if we have the potential of some data in the
65587 * future, otherwise just return 0
65588 */
65589 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
65590 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
65591 ret = -EAGAIN;
65592
65593 pipe_unlock(ipipe);
65594 diff --git a/fs/stat.c b/fs/stat.c
65595 index ae0c3ce..9ee641c 100644
65596 --- a/fs/stat.c
65597 +++ b/fs/stat.c
65598 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
65599 stat->gid = inode->i_gid;
65600 stat->rdev = inode->i_rdev;
65601 stat->size = i_size_read(inode);
65602 - stat->atime = inode->i_atime;
65603 - stat->mtime = inode->i_mtime;
65604 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65605 + stat->atime = inode->i_ctime;
65606 + stat->mtime = inode->i_ctime;
65607 + } else {
65608 + stat->atime = inode->i_atime;
65609 + stat->mtime = inode->i_mtime;
65610 + }
65611 stat->ctime = inode->i_ctime;
65612 stat->blksize = (1 << inode->i_blkbits);
65613 stat->blocks = inode->i_blocks;
65614 @@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
65615 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
65616 {
65617 struct inode *inode = path->dentry->d_inode;
65618 + int retval;
65619
65620 - if (inode->i_op->getattr)
65621 - return inode->i_op->getattr(path->mnt, path->dentry, stat);
65622 + if (inode->i_op->getattr) {
65623 + retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
65624 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65625 + stat->atime = stat->ctime;
65626 + stat->mtime = stat->ctime;
65627 + }
65628 + return retval;
65629 + }
65630
65631 generic_fillattr(inode, stat);
65632 return 0;
65633 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
65634 index 0b45ff4..847de5b 100644
65635 --- a/fs/sysfs/dir.c
65636 +++ b/fs/sysfs/dir.c
65637 @@ -41,9 +41,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
65638 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65639 {
65640 struct kernfs_node *parent, *kn;
65641 + const char *name;
65642 + umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
65643 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65644 + const char *parent_name;
65645 +#endif
65646
65647 BUG_ON(!kobj);
65648
65649 + name = kobject_name(kobj);
65650 +
65651 if (kobj->parent)
65652 parent = kobj->parent->sd;
65653 else
65654 @@ -52,11 +59,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65655 if (!parent)
65656 return -ENOENT;
65657
65658 - kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
65659 - S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
65660 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65661 + parent_name = parent->name;
65662 + mode = S_IRWXU;
65663 +
65664 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
65665 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
65666 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
65667 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
65668 + mode = S_IRWXU | S_IRUGO | S_IXUGO;
65669 +#endif
65670 +
65671 + kn = kernfs_create_dir_ns(parent, name,
65672 + mode, kobj, ns);
65673 if (IS_ERR(kn)) {
65674 if (PTR_ERR(kn) == -EEXIST)
65675 - sysfs_warn_dup(parent, kobject_name(kobj));
65676 + sysfs_warn_dup(parent, name);
65677 return PTR_ERR(kn);
65678 }
65679
65680 diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
65681 index 69d4889..a810bd4 100644
65682 --- a/fs/sysv/sysv.h
65683 +++ b/fs/sysv/sysv.h
65684 @@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
65685 #endif
65686 }
65687
65688 -static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65689 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65690 {
65691 if (sbi->s_bytesex == BYTESEX_PDP)
65692 return PDP_swab((__force __u32)n);
65693 diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
65694 index e18b988..f1d4ad0f 100644
65695 --- a/fs/ubifs/io.c
65696 +++ b/fs/ubifs/io.c
65697 @@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
65698 return err;
65699 }
65700
65701 -int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65702 +int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65703 {
65704 int err;
65705
65706 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
65707 index c175b4d..8f36a16 100644
65708 --- a/fs/udf/misc.c
65709 +++ b/fs/udf/misc.c
65710 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
65711
65712 u8 udf_tag_checksum(const struct tag *t)
65713 {
65714 - u8 *data = (u8 *)t;
65715 + const u8 *data = (const u8 *)t;
65716 u8 checksum = 0;
65717 int i;
65718 for (i = 0; i < sizeof(struct tag); ++i)
65719 diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
65720 index 8d974c4..b82f6ec 100644
65721 --- a/fs/ufs/swab.h
65722 +++ b/fs/ufs/swab.h
65723 @@ -22,7 +22,7 @@ enum {
65724 BYTESEX_BE
65725 };
65726
65727 -static inline u64
65728 +static inline u64 __intentional_overflow(-1)
65729 fs64_to_cpu(struct super_block *sbp, __fs64 n)
65730 {
65731 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
65732 @@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
65733 return (__force __fs64)cpu_to_be64(n);
65734 }
65735
65736 -static inline u32
65737 +static inline u32 __intentional_overflow(-1)
65738 fs32_to_cpu(struct super_block *sbp, __fs32 n)
65739 {
65740 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
65741 diff --git a/fs/utimes.c b/fs/utimes.c
65742 index aa138d6..5f3a811 100644
65743 --- a/fs/utimes.c
65744 +++ b/fs/utimes.c
65745 @@ -1,6 +1,7 @@
65746 #include <linux/compiler.h>
65747 #include <linux/file.h>
65748 #include <linux/fs.h>
65749 +#include <linux/security.h>
65750 #include <linux/linkage.h>
65751 #include <linux/mount.h>
65752 #include <linux/namei.h>
65753 @@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
65754 }
65755 }
65756 retry_deleg:
65757 +
65758 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
65759 + error = -EACCES;
65760 + goto mnt_drop_write_and_out;
65761 + }
65762 +
65763 mutex_lock(&inode->i_mutex);
65764 error = notify_change(path->dentry, &newattrs, &delegated_inode);
65765 mutex_unlock(&inode->i_mutex);
65766 diff --git a/fs/xattr.c b/fs/xattr.c
65767 index 3377dff..f394815 100644
65768 --- a/fs/xattr.c
65769 +++ b/fs/xattr.c
65770 @@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
65771 return rc;
65772 }
65773
65774 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
65775 +ssize_t
65776 +pax_getxattr(struct dentry *dentry, void *value, size_t size)
65777 +{
65778 + struct inode *inode = dentry->d_inode;
65779 + ssize_t error;
65780 +
65781 + error = inode_permission(inode, MAY_EXEC);
65782 + if (error)
65783 + return error;
65784 +
65785 + if (inode->i_op->getxattr)
65786 + error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
65787 + else
65788 + error = -EOPNOTSUPP;
65789 +
65790 + return error;
65791 +}
65792 +EXPORT_SYMBOL(pax_getxattr);
65793 +#endif
65794 +
65795 ssize_t
65796 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
65797 {
65798 @@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
65799 * Extended attribute SET operations
65800 */
65801 static long
65802 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
65803 +setxattr(struct path *path, const char __user *name, const void __user *value,
65804 size_t size, int flags)
65805 {
65806 int error;
65807 @@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
65808 posix_acl_fix_xattr_from_user(kvalue, size);
65809 }
65810
65811 - error = vfs_setxattr(d, kname, kvalue, size, flags);
65812 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
65813 + error = -EACCES;
65814 + goto out;
65815 + }
65816 +
65817 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
65818 out:
65819 if (vvalue)
65820 vfree(vvalue);
65821 @@ -377,7 +403,7 @@ retry:
65822 return error;
65823 error = mnt_want_write(path.mnt);
65824 if (!error) {
65825 - error = setxattr(path.dentry, name, value, size, flags);
65826 + error = setxattr(&path, name, value, size, flags);
65827 mnt_drop_write(path.mnt);
65828 }
65829 path_put(&path);
65830 @@ -401,7 +427,7 @@ retry:
65831 return error;
65832 error = mnt_want_write(path.mnt);
65833 if (!error) {
65834 - error = setxattr(path.dentry, name, value, size, flags);
65835 + error = setxattr(&path, name, value, size, flags);
65836 mnt_drop_write(path.mnt);
65837 }
65838 path_put(&path);
65839 @@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
65840 const void __user *,value, size_t, size, int, flags)
65841 {
65842 struct fd f = fdget(fd);
65843 - struct dentry *dentry;
65844 int error = -EBADF;
65845
65846 if (!f.file)
65847 return error;
65848 - dentry = f.file->f_path.dentry;
65849 - audit_inode(NULL, dentry, 0);
65850 + audit_inode(NULL, f.file->f_path.dentry, 0);
65851 error = mnt_want_write_file(f.file);
65852 if (!error) {
65853 - error = setxattr(dentry, name, value, size, flags);
65854 + error = setxattr(&f.file->f_path, name, value, size, flags);
65855 mnt_drop_write_file(f.file);
65856 }
65857 fdput(f);
65858 @@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
65859 * Extended attribute REMOVE operations
65860 */
65861 static long
65862 -removexattr(struct dentry *d, const char __user *name)
65863 +removexattr(struct path *path, const char __user *name)
65864 {
65865 int error;
65866 char kname[XATTR_NAME_MAX + 1];
65867 @@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
65868 if (error < 0)
65869 return error;
65870
65871 - return vfs_removexattr(d, kname);
65872 + if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
65873 + return -EACCES;
65874 +
65875 + return vfs_removexattr(path->dentry, kname);
65876 }
65877
65878 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
65879 @@ -652,7 +679,7 @@ retry:
65880 return error;
65881 error = mnt_want_write(path.mnt);
65882 if (!error) {
65883 - error = removexattr(path.dentry, name);
65884 + error = removexattr(&path, name);
65885 mnt_drop_write(path.mnt);
65886 }
65887 path_put(&path);
65888 @@ -675,7 +702,7 @@ retry:
65889 return error;
65890 error = mnt_want_write(path.mnt);
65891 if (!error) {
65892 - error = removexattr(path.dentry, name);
65893 + error = removexattr(&path, name);
65894 mnt_drop_write(path.mnt);
65895 }
65896 path_put(&path);
65897 @@ -689,16 +716,16 @@ retry:
65898 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
65899 {
65900 struct fd f = fdget(fd);
65901 - struct dentry *dentry;
65902 + struct path *path;
65903 int error = -EBADF;
65904
65905 if (!f.file)
65906 return error;
65907 - dentry = f.file->f_path.dentry;
65908 - audit_inode(NULL, dentry, 0);
65909 + path = &f.file->f_path;
65910 + audit_inode(NULL, path->dentry, 0);
65911 error = mnt_want_write_file(f.file);
65912 if (!error) {
65913 - error = removexattr(dentry, name);
65914 + error = removexattr(path, name);
65915 mnt_drop_write_file(f.file);
65916 }
65917 fdput(f);
65918 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
65919 index f0efc7e..ba72910 100644
65920 --- a/fs/xfs/xfs_bmap.c
65921 +++ b/fs/xfs/xfs_bmap.c
65922 @@ -584,7 +584,7 @@ xfs_bmap_validate_ret(
65923
65924 #else
65925 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
65926 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
65927 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
65928 #endif /* DEBUG */
65929
65930 /*
65931 diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
65932 index aead369..0dfecfd 100644
65933 --- a/fs/xfs/xfs_dir2_readdir.c
65934 +++ b/fs/xfs/xfs_dir2_readdir.c
65935 @@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
65936 ino = dp->d_ops->sf_get_ino(sfp, sfep);
65937 filetype = dp->d_ops->sf_get_ftype(sfep);
65938 ctx->pos = off & 0x7fffffff;
65939 - if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65940 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
65941 + char name[sfep->namelen];
65942 + memcpy(name, sfep->name, sfep->namelen);
65943 + if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
65944 + return 0;
65945 + } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65946 xfs_dir3_get_dtype(mp, filetype)))
65947 return 0;
65948 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
65949 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
65950 index 6152cbe..f0f9eaa 100644
65951 --- a/fs/xfs/xfs_ioctl.c
65952 +++ b/fs/xfs/xfs_ioctl.c
65953 @@ -122,7 +122,7 @@ xfs_find_handle(
65954 }
65955
65956 error = -EFAULT;
65957 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
65958 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
65959 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
65960 goto out_put;
65961
65962 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
65963 new file mode 100644
65964 index 0000000..bfd482c
65965 --- /dev/null
65966 +++ b/grsecurity/Kconfig
65967 @@ -0,0 +1,1176 @@
65968 +#
65969 +# grecurity configuration
65970 +#
65971 +menu "Memory Protections"
65972 +depends on GRKERNSEC
65973 +
65974 +config GRKERNSEC_KMEM
65975 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
65976 + default y if GRKERNSEC_CONFIG_AUTO
65977 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
65978 + help
65979 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
65980 + be written to or read from to modify or leak the contents of the running
65981 + kernel. /dev/port will also not be allowed to be opened, writing to
65982 + /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
65983 + If you have module support disabled, enabling this will close up several
65984 + ways that are currently used to insert malicious code into the running
65985 + kernel.
65986 +
65987 + Even with this feature enabled, we still highly recommend that
65988 + you use the RBAC system, as it is still possible for an attacker to
65989 + modify the running kernel through other more obscure methods.
65990 +
65991 + It is highly recommended that you say Y here if you meet all the
65992 + conditions above.
65993 +
65994 +config GRKERNSEC_VM86
65995 + bool "Restrict VM86 mode"
65996 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65997 + depends on X86_32
65998 +
65999 + help
66000 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
66001 + make use of a special execution mode on 32bit x86 processors called
66002 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
66003 + video cards and will still work with this option enabled. The purpose
66004 + of the option is to prevent exploitation of emulation errors in
66005 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
66006 + Nearly all users should be able to enable this option.
66007 +
66008 +config GRKERNSEC_IO
66009 + bool "Disable privileged I/O"
66010 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
66011 + depends on X86
66012 + select RTC_CLASS
66013 + select RTC_INTF_DEV
66014 + select RTC_DRV_CMOS
66015 +
66016 + help
66017 + If you say Y here, all ioperm and iopl calls will return an error.
66018 + Ioperm and iopl can be used to modify the running kernel.
66019 + Unfortunately, some programs need this access to operate properly,
66020 + the most notable of which are XFree86 and hwclock. hwclock can be
66021 + remedied by having RTC support in the kernel, so real-time
66022 + clock support is enabled if this option is enabled, to ensure
66023 + that hwclock operates correctly. If hwclock still does not work,
66024 + either update udev or symlink /dev/rtc to /dev/rtc0.
66025 +
66026 + If you're using XFree86 or a version of Xorg from 2012 or earlier,
66027 + you may not be able to boot into a graphical environment with this
66028 + option enabled. In this case, you should use the RBAC system instead.
66029 +
66030 +config GRKERNSEC_JIT_HARDEN
66031 + bool "Harden BPF JIT against spray attacks"
66032 + default y if GRKERNSEC_CONFIG_AUTO
66033 + depends on BPF_JIT && X86
66034 + help
66035 + If you say Y here, the native code generated by the kernel's Berkeley
66036 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
66037 + attacks that attempt to fit attacker-beneficial instructions in
66038 + 32bit immediate fields of JIT-generated native instructions. The
66039 + attacker will generally aim to cause an unintended instruction sequence
66040 + of JIT-generated native code to execute by jumping into the middle of
66041 + a generated instruction. This feature effectively randomizes the 32bit
66042 + immediate constants present in the generated code to thwart such attacks.
66043 +
66044 + If you're using KERNEXEC, it's recommended that you enable this option
66045 + to supplement the hardening of the kernel.
66046 +
66047 +config GRKERNSEC_PERF_HARDEN
66048 + bool "Disable unprivileged PERF_EVENTS usage by default"
66049 + default y if GRKERNSEC_CONFIG_AUTO
66050 + depends on PERF_EVENTS
66051 + help
66052 + If you say Y here, the range of acceptable values for the
66053 + /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
66054 + default to a new value: 3. When the sysctl is set to this value, no
66055 + unprivileged use of the PERF_EVENTS syscall interface will be permitted.
66056 +
66057 + Though PERF_EVENTS can be used legitimately for performance monitoring
66058 + and low-level application profiling, it is forced on regardless of
66059 + configuration, has been at fault for several vulnerabilities, and
66060 + creates new opportunities for side channels and other information leaks.
66061 +
66062 + This feature puts PERF_EVENTS into a secure default state and permits
66063 + the administrator to change out of it temporarily if unprivileged
66064 + application profiling is needed.
66065 +
66066 +config GRKERNSEC_RAND_THREADSTACK
66067 + bool "Insert random gaps between thread stacks"
66068 + default y if GRKERNSEC_CONFIG_AUTO
66069 + depends on PAX_RANDMMAP && !PPC
66070 + help
66071 + If you say Y here, a random-sized gap will be enforced between allocated
66072 + thread stacks. Glibc's NPTL and other threading libraries that
66073 + pass MAP_STACK to the kernel for thread stack allocation are supported.
66074 + The implementation currently provides 8 bits of entropy for the gap.
66075 +
66076 + Many distributions do not compile threaded remote services with the
66077 + -fstack-check argument to GCC, causing the variable-sized stack-based
66078 + allocator, alloca(), to not probe the stack on allocation. This
66079 + permits an unbounded alloca() to skip over any guard page and potentially
66080 + modify another thread's stack reliably. An enforced random gap
66081 + reduces the reliability of such an attack and increases the chance
66082 + that such a read/write to another thread's stack instead lands in
66083 + an unmapped area, causing a crash and triggering grsecurity's
66084 + anti-bruteforcing logic.
66085 +
66086 +config GRKERNSEC_PROC_MEMMAP
66087 + bool "Harden ASLR against information leaks and entropy reduction"
66088 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
66089 + depends on PAX_NOEXEC || PAX_ASLR
66090 + help
66091 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
66092 + give no information about the addresses of its mappings if
66093 + PaX features that rely on random addresses are enabled on the task.
66094 + In addition to sanitizing this information and disabling other
66095 + dangerous sources of information, this option causes reads of sensitive
66096 + /proc/<pid> entries where the file descriptor was opened in a different
66097 + task than the one performing the read. Such attempts are logged.
66098 + This option also limits argv/env strings for suid/sgid binaries
66099 + to 512KB to prevent a complete exhaustion of the stack entropy provided
66100 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
66101 + binaries to prevent alternative mmap layouts from being abused.
66102 +
66103 + If you use PaX it is essential that you say Y here as it closes up
66104 + several holes that make full ASLR useless locally.
66105 +
66106 +
66107 +config GRKERNSEC_KSTACKOVERFLOW
66108 + bool "Prevent kernel stack overflows"
66109 + default y if GRKERNSEC_CONFIG_AUTO
66110 + depends on !IA64 && 64BIT
66111 + help
66112 + If you say Y here, the kernel's process stacks will be allocated
66113 + with vmalloc instead of the kernel's default allocator. This
66114 + introduces guard pages that in combination with the alloca checking
66115 + of the STACKLEAK feature prevents all forms of kernel process stack
66116 + overflow abuse. Note that this is different from kernel stack
66117 + buffer overflows.
66118 +
66119 +config GRKERNSEC_BRUTE
66120 + bool "Deter exploit bruteforcing"
66121 + default y if GRKERNSEC_CONFIG_AUTO
66122 + help
66123 + If you say Y here, attempts to bruteforce exploits against forking
66124 + daemons such as apache or sshd, as well as against suid/sgid binaries
66125 + will be deterred. When a child of a forking daemon is killed by PaX
66126 + or crashes due to an illegal instruction or other suspicious signal,
66127 + the parent process will be delayed 30 seconds upon every subsequent
66128 + fork until the administrator is able to assess the situation and
66129 + restart the daemon.
66130 + In the suid/sgid case, the attempt is logged, the user has all their
66131 + existing instances of the suid/sgid binary terminated and will
66132 + be unable to execute any suid/sgid binaries for 15 minutes.
66133 +
66134 + It is recommended that you also enable signal logging in the auditing
66135 + section so that logs are generated when a process triggers a suspicious
66136 + signal.
66137 + If the sysctl option is enabled, a sysctl option with name
66138 + "deter_bruteforce" is created.
66139 +
66140 +config GRKERNSEC_MODHARDEN
66141 + bool "Harden module auto-loading"
66142 + default y if GRKERNSEC_CONFIG_AUTO
66143 + depends on MODULES
66144 + help
66145 + If you say Y here, module auto-loading in response to use of some
66146 + feature implemented by an unloaded module will be restricted to
66147 + root users. Enabling this option helps defend against attacks
66148 + by unprivileged users who abuse the auto-loading behavior to
66149 + cause a vulnerable module to load that is then exploited.
66150 +
66151 + If this option prevents a legitimate use of auto-loading for a
66152 + non-root user, the administrator can execute modprobe manually
66153 + with the exact name of the module mentioned in the alert log.
66154 + Alternatively, the administrator can add the module to the list
66155 + of modules loaded at boot by modifying init scripts.
66156 +
66157 + Modification of init scripts will most likely be needed on
66158 + Ubuntu servers with encrypted home directory support enabled,
66159 + as the first non-root user logging in will cause the ecb(aes),
66160 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
66161 +
66162 +config GRKERNSEC_HIDESYM
66163 + bool "Hide kernel symbols"
66164 + default y if GRKERNSEC_CONFIG_AUTO
66165 + select PAX_USERCOPY_SLABS
66166 + help
66167 + If you say Y here, getting information on loaded modules, and
66168 + displaying all kernel symbols through a syscall will be restricted
66169 + to users with CAP_SYS_MODULE. For software compatibility reasons,
66170 + /proc/kallsyms will be restricted to the root user. The RBAC
66171 + system can hide that entry even from root.
66172 +
66173 + This option also prevents leaking of kernel addresses through
66174 + several /proc entries.
66175 +
66176 + Note that this option is only effective provided the following
66177 + conditions are met:
66178 + 1) The kernel using grsecurity is not precompiled by some distribution
66179 + 2) You have also enabled GRKERNSEC_DMESG
66180 + 3) You are using the RBAC system and hiding other files such as your
66181 + kernel image and System.map. Alternatively, enabling this option
66182 + causes the permissions on /boot, /lib/modules, and the kernel
66183 + source directory to change at compile time to prevent
66184 + reading by non-root users.
66185 + If the above conditions are met, this option will aid in providing a
66186 + useful protection against local kernel exploitation of overflows
66187 + and arbitrary read/write vulnerabilities.
66188 +
66189 + It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
66190 + in addition to this feature.
66191 +
66192 +config GRKERNSEC_RANDSTRUCT
66193 + bool "Randomize layout of sensitive kernel structures"
66194 + default y if GRKERNSEC_CONFIG_AUTO
66195 + select GRKERNSEC_HIDESYM
66196 + select MODVERSIONS if MODULES
66197 + help
66198 + If you say Y here, the layouts of a number of sensitive kernel
66199 + structures (task, fs, cred, etc) and all structures composed entirely
66200 + of function pointers (aka "ops" structs) will be randomized at compile-time.
66201 + This can introduce the requirement of an additional infoleak
66202 + vulnerability for exploits targeting these structure types.
66203 +
66204 + Enabling this feature will introduce some performance impact, slightly
66205 + increase memory usage, and prevent the use of forensic tools like
66206 + Volatility against the system (unless the kernel source tree isn't
66207 + cleaned after kernel installation).
66208 +
66209 + The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
66210 + It remains after a make clean to allow for external modules to be compiled
66211 + with the existing seed and will be removed by a make mrproper or
66212 + make distclean.
66213 +
66214 + Note that the implementation requires gcc 4.6.4. or newer. You may need
66215 + to install the supporting headers explicitly in addition to the normal
66216 + gcc package.
66217 +
66218 +config GRKERNSEC_RANDSTRUCT_PERFORMANCE
66219 + bool "Use cacheline-aware structure randomization"
66220 + depends on GRKERNSEC_RANDSTRUCT
66221 + default y if GRKERNSEC_CONFIG_PRIORITY_PERF
66222 + help
66223 + If you say Y here, the RANDSTRUCT randomization will make a best effort
66224 + at restricting randomization to cacheline-sized groups of elements. It
66225 + will further not randomize bitfields in structures. This reduces the
66226 + performance hit of RANDSTRUCT at the cost of weakened randomization.
66227 +
66228 +config GRKERNSEC_KERN_LOCKOUT
66229 + bool "Active kernel exploit response"
66230 + default y if GRKERNSEC_CONFIG_AUTO
66231 + depends on X86 || ARM || PPC || SPARC
66232 + help
66233 + If you say Y here, when a PaX alert is triggered due to suspicious
66234 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
66235 + or an OOPS occurs due to bad memory accesses, instead of just
66236 + terminating the offending process (and potentially allowing
66237 + a subsequent exploit from the same user), we will take one of two
66238 + actions:
66239 + If the user was root, we will panic the system
66240 + If the user was non-root, we will log the attempt, terminate
66241 + all processes owned by the user, then prevent them from creating
66242 + any new processes until the system is restarted
66243 + This deters repeated kernel exploitation/bruteforcing attempts
66244 + and is useful for later forensics.
66245 +
66246 +config GRKERNSEC_OLD_ARM_USERLAND
66247 + bool "Old ARM userland compatibility"
66248 + depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
66249 + help
66250 + If you say Y here, stubs of executable code to perform such operations
66251 + as "compare-exchange" will be placed at fixed locations in the ARM vector
66252 + table. This is unfortunately needed for old ARM userland meant to run
66253 + across a wide range of processors. Without this option enabled,
66254 + the get_tls and data memory barrier stubs will be emulated by the kernel,
66255 + which is enough for Linaro userlands or other userlands designed for v6
66256 + and newer ARM CPUs. It's recommended that you try without this option enabled
66257 + first, and only enable it if your userland does not boot (it will likely fail
66258 + at init time).
66259 +
66260 +endmenu
66261 +menu "Role Based Access Control Options"
66262 +depends on GRKERNSEC
66263 +
66264 +config GRKERNSEC_RBAC_DEBUG
66265 + bool
66266 +
66267 +config GRKERNSEC_NO_RBAC
66268 + bool "Disable RBAC system"
66269 + help
66270 + If you say Y here, the /dev/grsec device will be removed from the kernel,
66271 + preventing the RBAC system from being enabled. You should only say Y
66272 + here if you have no intention of using the RBAC system, so as to prevent
66273 + an attacker with root access from misusing the RBAC system to hide files
66274 + and processes when loadable module support and /dev/[k]mem have been
66275 + locked down.
66276 +
66277 +config GRKERNSEC_ACL_HIDEKERN
66278 + bool "Hide kernel processes"
66279 + help
66280 + If you say Y here, all kernel threads will be hidden to all
66281 + processes but those whose subject has the "view hidden processes"
66282 + flag.
66283 +
66284 +config GRKERNSEC_ACL_MAXTRIES
66285 + int "Maximum tries before password lockout"
66286 + default 3
66287 + help
66288 + This option enforces the maximum number of times a user can attempt
66289 + to authorize themselves with the grsecurity RBAC system before being
66290 + denied the ability to attempt authorization again for a specified time.
66291 + The lower the number, the harder it will be to brute-force a password.
66292 +
66293 +config GRKERNSEC_ACL_TIMEOUT
66294 + int "Time to wait after max password tries, in seconds"
66295 + default 30
66296 + help
66297 + This option specifies the time the user must wait after attempting to
66298 + authorize to the RBAC system with the maximum number of invalid
66299 + passwords. The higher the number, the harder it will be to brute-force
66300 + a password.
66301 +
66302 +endmenu
66303 +menu "Filesystem Protections"
66304 +depends on GRKERNSEC
66305 +
66306 +config GRKERNSEC_PROC
66307 + bool "Proc restrictions"
66308 + default y if GRKERNSEC_CONFIG_AUTO
66309 + help
66310 + If you say Y here, the permissions of the /proc filesystem
66311 + will be altered to enhance system security and privacy. You MUST
66312 + choose either a user only restriction or a user and group restriction.
66313 + Depending upon the option you choose, you can either restrict users to
66314 + see only the processes they themselves run, or choose a group that can
66315 + view all processes and files normally restricted to root if you choose
66316 + the "restrict to user only" option. NOTE: If you're running identd or
66317 + ntpd as a non-root user, you will have to run it as the group you
66318 + specify here.
66319 +
66320 +config GRKERNSEC_PROC_USER
66321 + bool "Restrict /proc to user only"
66322 + depends on GRKERNSEC_PROC
66323 + help
66324 + If you say Y here, non-root users will only be able to view their own
66325 + processes, and restricts them from viewing network-related information,
66326 + and viewing kernel symbol and module information.
66327 +
66328 +config GRKERNSEC_PROC_USERGROUP
66329 + bool "Allow special group"
66330 + default y if GRKERNSEC_CONFIG_AUTO
66331 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
66332 + help
66333 + If you say Y here, you will be able to select a group that will be
66334 + able to view all processes and network-related information. If you've
66335 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
66336 + remain hidden. This option is useful if you want to run identd as
66337 + a non-root user. The group you select may also be chosen at boot time
66338 + via "grsec_proc_gid=" on the kernel commandline.
66339 +
66340 +config GRKERNSEC_PROC_GID
66341 + int "GID for special group"
66342 + depends on GRKERNSEC_PROC_USERGROUP
66343 + default 1001
66344 +
66345 +config GRKERNSEC_PROC_ADD
66346 + bool "Additional restrictions"
66347 + default y if GRKERNSEC_CONFIG_AUTO
66348 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
66349 + help
66350 + If you say Y here, additional restrictions will be placed on
66351 + /proc that keep normal users from viewing device information and
66352 + slabinfo information that could be useful for exploits.
66353 +
66354 +config GRKERNSEC_LINK
66355 + bool "Linking restrictions"
66356 + default y if GRKERNSEC_CONFIG_AUTO
66357 + help
66358 + If you say Y here, /tmp race exploits will be prevented, since users
66359 + will no longer be able to follow symlinks owned by other users in
66360 + world-writable +t directories (e.g. /tmp), unless the owner of the
66361 + symlink is the owner of the directory. users will also not be
66362 + able to hardlink to files they do not own. If the sysctl option is
66363 + enabled, a sysctl option with name "linking_restrictions" is created.
66364 +
66365 +config GRKERNSEC_SYMLINKOWN
66366 + bool "Kernel-enforced SymlinksIfOwnerMatch"
66367 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
66368 + help
66369 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
66370 + that prevents it from being used as a security feature. As Apache
66371 + verifies the symlink by performing a stat() against the target of
66372 + the symlink before it is followed, an attacker can setup a symlink
66373 + to point to a same-owned file, then replace the symlink with one
66374 + that targets another user's file just after Apache "validates" the
66375 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
66376 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
66377 + will be in place for the group you specify. If the sysctl option
66378 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
66379 + created.
66380 +
66381 +config GRKERNSEC_SYMLINKOWN_GID
66382 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
66383 + depends on GRKERNSEC_SYMLINKOWN
66384 + default 1006
66385 + help
66386 + Setting this GID determines what group kernel-enforced
66387 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
66388 + is enabled, a sysctl option with name "symlinkown_gid" is created.
66389 +
66390 +config GRKERNSEC_FIFO
66391 + bool "FIFO restrictions"
66392 + default y if GRKERNSEC_CONFIG_AUTO
66393 + help
66394 + If you say Y here, users will not be able to write to FIFOs they don't
66395 + own in world-writable +t directories (e.g. /tmp), unless the owner of
66396 + the FIFO is the same owner of the directory it's held in. If the sysctl
66397 + option is enabled, a sysctl option with name "fifo_restrictions" is
66398 + created.
66399 +
66400 +config GRKERNSEC_SYSFS_RESTRICT
66401 + bool "Sysfs/debugfs restriction"
66402 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
66403 + depends on SYSFS
66404 + help
66405 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
66406 + any filesystem normally mounted under it (e.g. debugfs) will be
66407 + mostly accessible only by root. These filesystems generally provide access
66408 + to hardware and debug information that isn't appropriate for unprivileged
66409 + users of the system. Sysfs and debugfs have also become a large source
66410 + of new vulnerabilities, ranging from infoleaks to local compromise.
66411 + There has been very little oversight with an eye toward security involved
66412 + in adding new exporters of information to these filesystems, so their
66413 + use is discouraged.
66414 + For reasons of compatibility, a few directories have been whitelisted
66415 + for access by non-root users:
66416 + /sys/fs/selinux
66417 + /sys/fs/fuse
66418 + /sys/devices/system/cpu
66419 +
66420 +config GRKERNSEC_ROFS
66421 + bool "Runtime read-only mount protection"
66422 + depends on SYSCTL
66423 + help
66424 + If you say Y here, a sysctl option with name "romount_protect" will
66425 + be created. By setting this option to 1 at runtime, filesystems
66426 + will be protected in the following ways:
66427 + * No new writable mounts will be allowed
66428 + * Existing read-only mounts won't be able to be remounted read/write
66429 + * Write operations will be denied on all block devices
66430 + This option acts independently of grsec_lock: once it is set to 1,
66431 + it cannot be turned off. Therefore, please be mindful of the resulting
66432 + behavior if this option is enabled in an init script on a read-only
66433 + filesystem.
66434 + Also be aware that as with other root-focused features, GRKERNSEC_KMEM
66435 + and GRKERNSEC_IO should be enabled and module loading disabled via
66436 + config or at runtime.
66437 + This feature is mainly intended for secure embedded systems.
66438 +
66439 +
66440 +config GRKERNSEC_DEVICE_SIDECHANNEL
66441 + bool "Eliminate stat/notify-based device sidechannels"
66442 + default y if GRKERNSEC_CONFIG_AUTO
66443 + help
66444 + If you say Y here, timing analyses on block or character
66445 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
66446 + will be thwarted for unprivileged users. If a process without
66447 + CAP_MKNOD stats such a device, the last access and last modify times
66448 + will match the device's create time. No access or modify events
66449 + will be triggered through inotify/dnotify/fanotify for such devices.
66450 + This feature will prevent attacks that may at a minimum
66451 + allow an attacker to determine the administrator's password length.
66452 +
66453 +config GRKERNSEC_CHROOT
66454 + bool "Chroot jail restrictions"
66455 + default y if GRKERNSEC_CONFIG_AUTO
66456 + help
66457 + If you say Y here, you will be able to choose several options that will
66458 + make breaking out of a chrooted jail much more difficult. If you
66459 + encounter no software incompatibilities with the following options, it
66460 + is recommended that you enable each one.
66461 +
66462 + Note that the chroot restrictions are not intended to apply to "chroots"
66463 + to directories that are simple bind mounts of the global root filesystem.
66464 + For several other reasons, a user shouldn't expect any significant
66465 + security by performing such a chroot.
66466 +
66467 +config GRKERNSEC_CHROOT_MOUNT
66468 + bool "Deny mounts"
66469 + default y if GRKERNSEC_CONFIG_AUTO
66470 + depends on GRKERNSEC_CHROOT
66471 + help
66472 + If you say Y here, processes inside a chroot will not be able to
66473 + mount or remount filesystems. If the sysctl option is enabled, a
66474 + sysctl option with name "chroot_deny_mount" is created.
66475 +
66476 +config GRKERNSEC_CHROOT_DOUBLE
66477 + bool "Deny double-chroots"
66478 + default y if GRKERNSEC_CONFIG_AUTO
66479 + depends on GRKERNSEC_CHROOT
66480 + help
66481 + If you say Y here, processes inside a chroot will not be able to chroot
66482 + again outside the chroot. This is a widely used method of breaking
66483 + out of a chroot jail and should not be allowed. If the sysctl
66484 + option is enabled, a sysctl option with name
66485 + "chroot_deny_chroot" is created.
66486 +
66487 +config GRKERNSEC_CHROOT_PIVOT
66488 + bool "Deny pivot_root in chroot"
66489 + default y if GRKERNSEC_CONFIG_AUTO
66490 + depends on GRKERNSEC_CHROOT
66491 + help
66492 + If you say Y here, processes inside a chroot will not be able to use
66493 + a function called pivot_root() that was introduced in Linux 2.3.41. It
66494 + works similar to chroot in that it changes the root filesystem. This
66495 + function could be misused in a chrooted process to attempt to break out
66496 + of the chroot, and therefore should not be allowed. If the sysctl
66497 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
66498 + created.
66499 +
66500 +config GRKERNSEC_CHROOT_CHDIR
66501 + bool "Enforce chdir(\"/\") on all chroots"
66502 + default y if GRKERNSEC_CONFIG_AUTO
66503 + depends on GRKERNSEC_CHROOT
66504 + help
66505 + If you say Y here, the current working directory of all newly-chrooted
66506 + applications will be set to the the root directory of the chroot.
66507 + The man page on chroot(2) states:
66508 + Note that this call does not change the current working
66509 + directory, so that `.' can be outside the tree rooted at
66510 + `/'. In particular, the super-user can escape from a
66511 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
66512 +
66513 + It is recommended that you say Y here, since it's not known to break
66514 + any software. If the sysctl option is enabled, a sysctl option with
66515 + name "chroot_enforce_chdir" is created.
66516 +
66517 +config GRKERNSEC_CHROOT_CHMOD
66518 + bool "Deny (f)chmod +s"
66519 + default y if GRKERNSEC_CONFIG_AUTO
66520 + depends on GRKERNSEC_CHROOT
66521 + help
66522 + If you say Y here, processes inside a chroot will not be able to chmod
66523 + or fchmod files to make them have suid or sgid bits. This protects
66524 + against another published method of breaking a chroot. If the sysctl
66525 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
66526 + created.
66527 +
66528 +config GRKERNSEC_CHROOT_FCHDIR
66529 + bool "Deny fchdir and fhandle out of chroot"
66530 + default y if GRKERNSEC_CONFIG_AUTO
66531 + depends on GRKERNSEC_CHROOT
66532 + help
66533 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
66534 + to a file descriptor of the chrooting process that points to a directory
66535 + outside the filesystem will be stopped. Additionally, this option prevents
66536 + use of the recently-created syscall for opening files by a guessable "file
66537 + handle" inside a chroot. If the sysctl option is enabled, a sysctl option
66538 + with name "chroot_deny_fchdir" is created.
66539 +
66540 +config GRKERNSEC_CHROOT_MKNOD
66541 + bool "Deny mknod"
66542 + default y if GRKERNSEC_CONFIG_AUTO
66543 + depends on GRKERNSEC_CHROOT
66544 + help
66545 + If you say Y here, processes inside a chroot will not be allowed to
66546 + mknod. The problem with using mknod inside a chroot is that it
66547 + would allow an attacker to create a device entry that is the same
66548 + as one on the physical root of your system, which could range from
66549 + anything from the console device to a device for your harddrive (which
66550 + they could then use to wipe the drive or steal data). It is recommended
66551 + that you say Y here, unless you run into software incompatibilities.
66552 + If the sysctl option is enabled, a sysctl option with name
66553 + "chroot_deny_mknod" is created.
66554 +
66555 +config GRKERNSEC_CHROOT_SHMAT
66556 + bool "Deny shmat() out of chroot"
66557 + default y if GRKERNSEC_CONFIG_AUTO
66558 + depends on GRKERNSEC_CHROOT
66559 + help
66560 + If you say Y here, processes inside a chroot will not be able to attach
66561 + to shared memory segments that were created outside of the chroot jail.
66562 + It is recommended that you say Y here. If the sysctl option is enabled,
66563 + a sysctl option with name "chroot_deny_shmat" is created.
66564 +
66565 +config GRKERNSEC_CHROOT_UNIX
66566 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
66567 + default y if GRKERNSEC_CONFIG_AUTO
66568 + depends on GRKERNSEC_CHROOT
66569 + help
66570 + If you say Y here, processes inside a chroot will not be able to
66571 + connect to abstract (meaning not belonging to a filesystem) Unix
66572 + domain sockets that were bound outside of a chroot. It is recommended
66573 + that you say Y here. If the sysctl option is enabled, a sysctl option
66574 + with name "chroot_deny_unix" is created.
66575 +
66576 +config GRKERNSEC_CHROOT_FINDTASK
66577 + bool "Protect outside processes"
66578 + default y if GRKERNSEC_CONFIG_AUTO
66579 + depends on GRKERNSEC_CHROOT
66580 + help
66581 + If you say Y here, processes inside a chroot will not be able to
66582 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
66583 + getsid, or view any process outside of the chroot. If the sysctl
66584 + option is enabled, a sysctl option with name "chroot_findtask" is
66585 + created.
66586 +
66587 +config GRKERNSEC_CHROOT_NICE
66588 + bool "Restrict priority changes"
66589 + default y if GRKERNSEC_CONFIG_AUTO
66590 + depends on GRKERNSEC_CHROOT
66591 + help
66592 + If you say Y here, processes inside a chroot will not be able to raise
66593 + the priority of processes in the chroot, or alter the priority of
66594 + processes outside the chroot. This provides more security than simply
66595 + removing CAP_SYS_NICE from the process' capability set. If the
66596 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
66597 + is created.
66598 +
66599 +config GRKERNSEC_CHROOT_SYSCTL
66600 + bool "Deny sysctl writes"
66601 + default y if GRKERNSEC_CONFIG_AUTO
66602 + depends on GRKERNSEC_CHROOT
66603 + help
66604 + If you say Y here, an attacker in a chroot will not be able to
66605 + write to sysctl entries, either by sysctl(2) or through a /proc
66606 + interface. It is strongly recommended that you say Y here. If the
66607 + sysctl option is enabled, a sysctl option with name
66608 + "chroot_deny_sysctl" is created.
66609 +
66610 +config GRKERNSEC_CHROOT_CAPS
66611 + bool "Capability restrictions"
66612 + default y if GRKERNSEC_CONFIG_AUTO
66613 + depends on GRKERNSEC_CHROOT
66614 + help
66615 + If you say Y here, the capabilities on all processes within a
66616 + chroot jail will be lowered to stop module insertion, raw i/o,
66617 + system and net admin tasks, rebooting the system, modifying immutable
66618 + files, modifying IPC owned by another, and changing the system time.
66619 + This is left an option because it can break some apps. Disable this
66620 + if your chrooted apps are having problems performing those kinds of
66621 + tasks. If the sysctl option is enabled, a sysctl option with
66622 + name "chroot_caps" is created.
66623 +
66624 +config GRKERNSEC_CHROOT_INITRD
66625 + bool "Exempt initrd tasks from restrictions"
66626 + default y if GRKERNSEC_CONFIG_AUTO
66627 + depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
66628 + help
66629 + If you say Y here, tasks started prior to init will be exempted from
66630 + grsecurity's chroot restrictions. This option is mainly meant to
66631 + resolve Plymouth's performing privileged operations unnecessarily
66632 + in a chroot.
66633 +
66634 +endmenu
66635 +menu "Kernel Auditing"
66636 +depends on GRKERNSEC
66637 +
66638 +config GRKERNSEC_AUDIT_GROUP
66639 + bool "Single group for auditing"
66640 + help
66641 + If you say Y here, the exec and chdir logging features will only operate
66642 + on a group you specify. This option is recommended if you only want to
66643 + watch certain users instead of having a large amount of logs from the
66644 + entire system. If the sysctl option is enabled, a sysctl option with
66645 + name "audit_group" is created.
66646 +
66647 +config GRKERNSEC_AUDIT_GID
66648 + int "GID for auditing"
66649 + depends on GRKERNSEC_AUDIT_GROUP
66650 + default 1007
66651 +
66652 +config GRKERNSEC_EXECLOG
66653 + bool "Exec logging"
66654 + help
66655 + If you say Y here, all execve() calls will be logged (since the
66656 + other exec*() calls are frontends to execve(), all execution
66657 + will be logged). Useful for shell-servers that like to keep track
66658 + of their users. If the sysctl option is enabled, a sysctl option with
66659 + name "exec_logging" is created.
66660 + WARNING: This option when enabled will produce a LOT of logs, especially
66661 + on an active system.
66662 +
66663 +config GRKERNSEC_RESLOG
66664 + bool "Resource logging"
66665 + default y if GRKERNSEC_CONFIG_AUTO
66666 + help
66667 + If you say Y here, all attempts to overstep resource limits will
66668 + be logged with the resource name, the requested size, and the current
66669 + limit. It is highly recommended that you say Y here. If the sysctl
66670 + option is enabled, a sysctl option with name "resource_logging" is
66671 + created. If the RBAC system is enabled, the sysctl value is ignored.
66672 +
66673 +config GRKERNSEC_CHROOT_EXECLOG
66674 + bool "Log execs within chroot"
66675 + help
66676 + If you say Y here, all executions inside a chroot jail will be logged
66677 + to syslog. This can cause a large amount of logs if certain
66678 + applications (eg. djb's daemontools) are installed on the system, and
66679 + is therefore left as an option. If the sysctl option is enabled, a
66680 + sysctl option with name "chroot_execlog" is created.
66681 +
66682 +config GRKERNSEC_AUDIT_PTRACE
66683 + bool "Ptrace logging"
66684 + help
66685 + If you say Y here, all attempts to attach to a process via ptrace
66686 + will be logged. If the sysctl option is enabled, a sysctl option
66687 + with name "audit_ptrace" is created.
66688 +
66689 +config GRKERNSEC_AUDIT_CHDIR
66690 + bool "Chdir logging"
66691 + help
66692 + If you say Y here, all chdir() calls will be logged. If the sysctl
66693 + option is enabled, a sysctl option with name "audit_chdir" is created.
66694 +
66695 +config GRKERNSEC_AUDIT_MOUNT
66696 + bool "(Un)Mount logging"
66697 + help
66698 + If you say Y here, all mounts and unmounts will be logged. If the
66699 + sysctl option is enabled, a sysctl option with name "audit_mount" is
66700 + created.
66701 +
66702 +config GRKERNSEC_SIGNAL
66703 + bool "Signal logging"
66704 + default y if GRKERNSEC_CONFIG_AUTO
66705 + help
66706 + If you say Y here, certain important signals will be logged, such as
66707 + SIGSEGV, which will as a result inform you of when a error in a program
66708 + occurred, which in some cases could mean a possible exploit attempt.
66709 + If the sysctl option is enabled, a sysctl option with name
66710 + "signal_logging" is created.
66711 +
66712 +config GRKERNSEC_FORKFAIL
66713 + bool "Fork failure logging"
66714 + help
66715 + If you say Y here, all failed fork() attempts will be logged.
66716 + This could suggest a fork bomb, or someone attempting to overstep
66717 + their process limit. If the sysctl option is enabled, a sysctl option
66718 + with name "forkfail_logging" is created.
66719 +
66720 +config GRKERNSEC_TIME
66721 + bool "Time change logging"
66722 + default y if GRKERNSEC_CONFIG_AUTO
66723 + help
66724 + If you say Y here, any changes of the system clock will be logged.
66725 + If the sysctl option is enabled, a sysctl option with name
66726 + "timechange_logging" is created.
66727 +
66728 +config GRKERNSEC_PROC_IPADDR
66729 + bool "/proc/<pid>/ipaddr support"
66730 + default y if GRKERNSEC_CONFIG_AUTO
66731 + help
66732 + If you say Y here, a new entry will be added to each /proc/<pid>
66733 + directory that contains the IP address of the person using the task.
66734 + The IP is carried across local TCP and AF_UNIX stream sockets.
66735 + This information can be useful for IDS/IPSes to perform remote response
66736 + to a local attack. The entry is readable by only the owner of the
66737 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
66738 + the RBAC system), and thus does not create privacy concerns.
66739 +
66740 +config GRKERNSEC_RWXMAP_LOG
66741 + bool 'Denied RWX mmap/mprotect logging'
66742 + default y if GRKERNSEC_CONFIG_AUTO
66743 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
66744 + help
66745 + If you say Y here, calls to mmap() and mprotect() with explicit
66746 + usage of PROT_WRITE and PROT_EXEC together will be logged when
66747 + denied by the PAX_MPROTECT feature. This feature will also
66748 + log other problematic scenarios that can occur when PAX_MPROTECT
66749 + is enabled on a binary, like textrels and PT_GNU_STACK. If the
66750 + sysctl option is enabled, a sysctl option with name "rwxmap_logging"
66751 + is created.
66752 +
66753 +endmenu
66754 +
66755 +menu "Executable Protections"
66756 +depends on GRKERNSEC
66757 +
66758 +config GRKERNSEC_DMESG
66759 + bool "Dmesg(8) restriction"
66760 + default y if GRKERNSEC_CONFIG_AUTO
66761 + help
66762 + If you say Y here, non-root users will not be able to use dmesg(8)
66763 + to view the contents of the kernel's circular log buffer.
66764 + The kernel's log buffer often contains kernel addresses and other
66765 + identifying information useful to an attacker in fingerprinting a
66766 + system for a targeted exploit.
66767 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
66768 + created.
66769 +
66770 +config GRKERNSEC_HARDEN_PTRACE
66771 + bool "Deter ptrace-based process snooping"
66772 + default y if GRKERNSEC_CONFIG_AUTO
66773 + help
66774 + If you say Y here, TTY sniffers and other malicious monitoring
66775 + programs implemented through ptrace will be defeated. If you
66776 + have been using the RBAC system, this option has already been
66777 + enabled for several years for all users, with the ability to make
66778 + fine-grained exceptions.
66779 +
66780 + This option only affects the ability of non-root users to ptrace
66781 + processes that are not a descendent of the ptracing process.
66782 + This means that strace ./binary and gdb ./binary will still work,
66783 + but attaching to arbitrary processes will not. If the sysctl
66784 + option is enabled, a sysctl option with name "harden_ptrace" is
66785 + created.
66786 +
66787 +config GRKERNSEC_PTRACE_READEXEC
66788 + bool "Require read access to ptrace sensitive binaries"
66789 + default y if GRKERNSEC_CONFIG_AUTO
66790 + help
66791 + If you say Y here, unprivileged users will not be able to ptrace unreadable
66792 + binaries. This option is useful in environments that
66793 + remove the read bits (e.g. file mode 4711) from suid binaries to
66794 + prevent infoleaking of their contents. This option adds
66795 + consistency to the use of that file mode, as the binary could normally
66796 + be read out when run without privileges while ptracing.
66797 +
66798 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
66799 + is created.
66800 +
66801 +config GRKERNSEC_SETXID
66802 + bool "Enforce consistent multithreaded privileges"
66803 + default y if GRKERNSEC_CONFIG_AUTO
66804 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
66805 + help
66806 + If you say Y here, a change from a root uid to a non-root uid
66807 + in a multithreaded application will cause the resulting uids,
66808 + gids, supplementary groups, and capabilities in that thread
66809 + to be propagated to the other threads of the process. In most
66810 + cases this is unnecessary, as glibc will emulate this behavior
66811 + on behalf of the application. Other libcs do not act in the
66812 + same way, allowing the other threads of the process to continue
66813 + running with root privileges. If the sysctl option is enabled,
66814 + a sysctl option with name "consistent_setxid" is created.
66815 +
66816 +config GRKERNSEC_HARDEN_IPC
66817 + bool "Disallow access to overly-permissive IPC objects"
66818 + default y if GRKERNSEC_CONFIG_AUTO
66819 + depends on SYSVIPC
66820 + help
66821 + If you say Y here, access to overly-permissive IPC objects (shared
66822 + memory, message queues, and semaphores) will be denied for processes
66823 + given the following criteria beyond normal permission checks:
66824 + 1) If the IPC object is world-accessible and the euid doesn't match
66825 + that of the creator or current uid for the IPC object
66826 + 2) If the IPC object is group-accessible and the egid doesn't
66827 + match that of the creator or current gid for the IPC object
66828 + It's a common error to grant too much permission to these objects,
66829 + with impact ranging from denial of service and information leaking to
66830 + privilege escalation. This feature was developed in response to
66831 + research by Tim Brown:
66832 + http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
66833 + who found hundreds of such insecure usages. Processes with
66834 + CAP_IPC_OWNER are still permitted to access these IPC objects.
66835 + If the sysctl option is enabled, a sysctl option with name
66836 + "harden_ipc" is created.
66837 +
66838 +config GRKERNSEC_TPE
66839 + bool "Trusted Path Execution (TPE)"
66840 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
66841 + help
66842 + If you say Y here, you will be able to choose a gid to add to the
66843 + supplementary groups of users you want to mark as "untrusted."
66844 + These users will not be able to execute any files that are not in
66845 + root-owned directories writable only by root. If the sysctl option
66846 + is enabled, a sysctl option with name "tpe" is created.
66847 +
66848 +config GRKERNSEC_TPE_ALL
66849 + bool "Partially restrict all non-root users"
66850 + depends on GRKERNSEC_TPE
66851 + help
66852 + If you say Y here, all non-root users will be covered under
66853 + a weaker TPE restriction. This is separate from, and in addition to,
66854 + the main TPE options that you have selected elsewhere. Thus, if a
66855 + "trusted" GID is chosen, this restriction applies to even that GID.
66856 + Under this restriction, all non-root users will only be allowed to
66857 + execute files in directories they own that are not group or
66858 + world-writable, or in directories owned by root and writable only by
66859 + root. If the sysctl option is enabled, a sysctl option with name
66860 + "tpe_restrict_all" is created.
66861 +
66862 +config GRKERNSEC_TPE_INVERT
66863 + bool "Invert GID option"
66864 + depends on GRKERNSEC_TPE
66865 + help
66866 + If you say Y here, the group you specify in the TPE configuration will
66867 + decide what group TPE restrictions will be *disabled* for. This
66868 + option is useful if you want TPE restrictions to be applied to most
66869 + users on the system. If the sysctl option is enabled, a sysctl option
66870 + with name "tpe_invert" is created. Unlike other sysctl options, this
66871 + entry will default to on for backward-compatibility.
66872 +
66873 +config GRKERNSEC_TPE_GID
66874 + int
66875 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
66876 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
66877 +
66878 +config GRKERNSEC_TPE_UNTRUSTED_GID
66879 + int "GID for TPE-untrusted users"
66880 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
66881 + default 1005
66882 + help
66883 + Setting this GID determines what group TPE restrictions will be
66884 + *enabled* for. If the sysctl option is enabled, a sysctl option
66885 + with name "tpe_gid" is created.
66886 +
66887 +config GRKERNSEC_TPE_TRUSTED_GID
66888 + int "GID for TPE-trusted users"
66889 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
66890 + default 1005
66891 + help
66892 + Setting this GID determines what group TPE restrictions will be
66893 + *disabled* for. If the sysctl option is enabled, a sysctl option
66894 + with name "tpe_gid" is created.
66895 +
66896 +endmenu
66897 +menu "Network Protections"
66898 +depends on GRKERNSEC
66899 +
66900 +config GRKERNSEC_RANDNET
66901 + bool "Larger entropy pools"
66902 + default y if GRKERNSEC_CONFIG_AUTO
66903 + help
66904 + If you say Y here, the entropy pools used for many features of Linux
66905 + and grsecurity will be doubled in size. Since several grsecurity
66906 + features use additional randomness, it is recommended that you say Y
66907 + here. Saying Y here has a similar effect as modifying
66908 + /proc/sys/kernel/random/poolsize.
66909 +
66910 +config GRKERNSEC_BLACKHOLE
66911 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
66912 + default y if GRKERNSEC_CONFIG_AUTO
66913 + depends on NET
66914 + help
66915 + If you say Y here, neither TCP resets nor ICMP
66916 + destination-unreachable packets will be sent in response to packets
66917 + sent to ports for which no associated listening process exists.
66918 + This feature supports both IPV4 and IPV6 and exempts the
66919 + loopback interface from blackholing. Enabling this feature
66920 + makes a host more resilient to DoS attacks and reduces network
66921 + visibility against scanners.
66922 +
66923 + The blackhole feature as-implemented is equivalent to the FreeBSD
66924 + blackhole feature, as it prevents RST responses to all packets, not
66925 + just SYNs. Under most application behavior this causes no
66926 + problems, but applications (like haproxy) may not close certain
66927 + connections in a way that cleanly terminates them on the remote
66928 + end, leaving the remote host in LAST_ACK state. Because of this
66929 + side-effect and to prevent intentional LAST_ACK DoSes, this
66930 + feature also adds automatic mitigation against such attacks.
66931 + The mitigation drastically reduces the amount of time a socket
66932 + can spend in LAST_ACK state. If you're using haproxy and not
66933 + all servers it connects to have this option enabled, consider
66934 + disabling this feature on the haproxy host.
66935 +
66936 + If the sysctl option is enabled, two sysctl options with names
66937 + "ip_blackhole" and "lastack_retries" will be created.
66938 + While "ip_blackhole" takes the standard zero/non-zero on/off
66939 + toggle, "lastack_retries" uses the same kinds of values as
66940 + "tcp_retries1" and "tcp_retries2". The default value of 4
66941 + prevents a socket from lasting more than 45 seconds in LAST_ACK
66942 + state.
66943 +
66944 +config GRKERNSEC_NO_SIMULT_CONNECT
66945 + bool "Disable TCP Simultaneous Connect"
66946 + default y if GRKERNSEC_CONFIG_AUTO
66947 + depends on NET
66948 + help
66949 + If you say Y here, a feature by Willy Tarreau will be enabled that
66950 + removes a weakness in Linux's strict implementation of TCP that
66951 + allows two clients to connect to each other without either entering
66952 + a listening state. The weakness allows an attacker to easily prevent
66953 + a client from connecting to a known server provided the source port
66954 + for the connection is guessed correctly.
66955 +
66956 + As the weakness could be used to prevent an antivirus or IPS from
66957 + fetching updates, or prevent an SSL gateway from fetching a CRL,
66958 + it should be eliminated by enabling this option. Though Linux is
66959 + one of few operating systems supporting simultaneous connect, it
66960 + has no legitimate use in practice and is rarely supported by firewalls.
66961 +
66962 +config GRKERNSEC_SOCKET
66963 + bool "Socket restrictions"
66964 + depends on NET
66965 + help
66966 + If you say Y here, you will be able to choose from several options.
66967 + If you assign a GID on your system and add it to the supplementary
66968 + groups of users you want to restrict socket access to, this patch
66969 + will perform up to three things, based on the option(s) you choose.
66970 +
66971 +config GRKERNSEC_SOCKET_ALL
66972 + bool "Deny any sockets to group"
66973 + depends on GRKERNSEC_SOCKET
66974 + help
66975 + If you say Y here, you will be able to choose a GID of whose users will
66976 + be unable to connect to other hosts from your machine or run server
66977 + applications from your machine. If the sysctl option is enabled, a
66978 + sysctl option with name "socket_all" is created.
66979 +
66980 +config GRKERNSEC_SOCKET_ALL_GID
66981 + int "GID to deny all sockets for"
66982 + depends on GRKERNSEC_SOCKET_ALL
66983 + default 1004
66984 + help
66985 + Here you can choose the GID to disable socket access for. Remember to
66986 + add the users you want socket access disabled for to the GID
66987 + specified here. If the sysctl option is enabled, a sysctl option
66988 + with name "socket_all_gid" is created.
66989 +
66990 +config GRKERNSEC_SOCKET_CLIENT
66991 + bool "Deny client sockets to group"
66992 + depends on GRKERNSEC_SOCKET
66993 + help
66994 + If you say Y here, you will be able to choose a GID of whose users will
66995 + be unable to connect to other hosts from your machine, but will be
66996 + able to run servers. If this option is enabled, all users in the group
66997 + you specify will have to use passive mode when initiating ftp transfers
66998 + from the shell on your machine. If the sysctl option is enabled, a
66999 + sysctl option with name "socket_client" is created.
67000 +
67001 +config GRKERNSEC_SOCKET_CLIENT_GID
67002 + int "GID to deny client sockets for"
67003 + depends on GRKERNSEC_SOCKET_CLIENT
67004 + default 1003
67005 + help
67006 + Here you can choose the GID to disable client socket access for.
67007 + Remember to add the users you want client socket access disabled for to
67008 + the GID specified here. If the sysctl option is enabled, a sysctl
67009 + option with name "socket_client_gid" is created.
67010 +
67011 +config GRKERNSEC_SOCKET_SERVER
67012 + bool "Deny server sockets to group"
67013 + depends on GRKERNSEC_SOCKET
67014 + help
67015 + If you say Y here, you will be able to choose a GID of whose users will
67016 + be unable to run server applications from your machine. If the sysctl
67017 + option is enabled, a sysctl option with name "socket_server" is created.
67018 +
67019 +config GRKERNSEC_SOCKET_SERVER_GID
67020 + int "GID to deny server sockets for"
67021 + depends on GRKERNSEC_SOCKET_SERVER
67022 + default 1002
67023 + help
67024 + Here you can choose the GID to disable server socket access for.
67025 + Remember to add the users you want server socket access disabled for to
67026 + the GID specified here. If the sysctl option is enabled, a sysctl
67027 + option with name "socket_server_gid" is created.
67028 +
67029 +endmenu
67030 +
67031 +menu "Physical Protections"
67032 +depends on GRKERNSEC
67033 +
67034 +config GRKERNSEC_DENYUSB
67035 + bool "Deny new USB connections after toggle"
67036 + default y if GRKERNSEC_CONFIG_AUTO
67037 + depends on SYSCTL && USB_SUPPORT
67038 + help
67039 + If you say Y here, a new sysctl option with name "deny_new_usb"
67040 + will be created. Setting its value to 1 will prevent any new
67041 + USB devices from being recognized by the OS. Any attempted USB
67042 + device insertion will be logged. This option is intended to be
67043 + used against custom USB devices designed to exploit vulnerabilities
67044 + in various USB device drivers.
67045 +
67046 + For greatest effectiveness, this sysctl should be set after any
67047 + relevant init scripts. This option is safe to enable in distros
67048 + as each user can choose whether or not to toggle the sysctl.
67049 +
67050 +config GRKERNSEC_DENYUSB_FORCE
67051 + bool "Reject all USB devices not connected at boot"
67052 + select USB
67053 + depends on GRKERNSEC_DENYUSB
67054 + help
67055 + If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
67056 + that doesn't involve a sysctl entry. This option should only be
67057 + enabled if you're sure you want to deny all new USB connections
67058 + at runtime and don't want to modify init scripts. This should not
67059 + be enabled by distros. It forces the core USB code to be built
67060 + into the kernel image so that all devices connected at boot time
67061 + can be recognized and new USB device connections can be prevented
67062 + prior to init running.
67063 +
67064 +endmenu
67065 +
67066 +menu "Sysctl Support"
67067 +depends on GRKERNSEC && SYSCTL
67068 +
67069 +config GRKERNSEC_SYSCTL
67070 + bool "Sysctl support"
67071 + default y if GRKERNSEC_CONFIG_AUTO
67072 + help
67073 + If you say Y here, you will be able to change the options that
67074 + grsecurity runs with at bootup, without having to recompile your
67075 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
67076 + to enable (1) or disable (0) various features. All the sysctl entries
67077 + are mutable until the "grsec_lock" entry is set to a non-zero value.
67078 + All features enabled in the kernel configuration are disabled at boot
67079 + if you do not say Y to the "Turn on features by default" option.
67080 + All options should be set at startup, and the grsec_lock entry should
67081 + be set to a non-zero value after all the options are set.
67082 + *THIS IS EXTREMELY IMPORTANT*
67083 +
67084 +config GRKERNSEC_SYSCTL_DISTRO
67085 + bool "Extra sysctl support for distro makers (READ HELP)"
67086 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
67087 + help
67088 + If you say Y here, additional sysctl options will be created
67089 + for features that affect processes running as root. Therefore,
67090 + it is critical when using this option that the grsec_lock entry be
67091 + enabled after boot. Only distros with prebuilt kernel packages
67092 + with this option enabled that can ensure grsec_lock is enabled
67093 + after boot should use this option.
67094 + *Failure to set grsec_lock after boot makes all grsec features
67095 + this option covers useless*
67096 +
67097 + Currently this option creates the following sysctl entries:
67098 + "Disable Privileged I/O": "disable_priv_io"
67099 +
67100 +config GRKERNSEC_SYSCTL_ON
67101 + bool "Turn on features by default"
67102 + default y if GRKERNSEC_CONFIG_AUTO
67103 + depends on GRKERNSEC_SYSCTL
67104 + help
67105 + If you say Y here, instead of having all features enabled in the
67106 + kernel configuration disabled at boot time, the features will be
67107 + enabled at boot time. It is recommended you say Y here unless
67108 + there is some reason you would want all sysctl-tunable features to
67109 + be disabled by default. As mentioned elsewhere, it is important
67110 + to enable the grsec_lock entry once you have finished modifying
67111 + the sysctl entries.
67112 +
67113 +endmenu
67114 +menu "Logging Options"
67115 +depends on GRKERNSEC
67116 +
67117 +config GRKERNSEC_FLOODTIME
67118 + int "Seconds in between log messages (minimum)"
67119 + default 10
67120 + help
67121 + This option allows you to enforce the number of seconds between
67122 + grsecurity log messages. The default should be suitable for most
67123 + people, however, if you choose to change it, choose a value small enough
67124 + to allow informative logs to be produced, but large enough to
67125 + prevent flooding.
67126 +
67127 + Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
67128 + any rate limiting on grsecurity log messages.
67129 +
67130 +config GRKERNSEC_FLOODBURST
67131 + int "Number of messages in a burst (maximum)"
67132 + default 6
67133 + help
67134 + This option allows you to choose the maximum number of messages allowed
67135 + within the flood time interval you chose in a separate option. The
67136 + default should be suitable for most people, however if you find that
67137 + many of your logs are being interpreted as flooding, you may want to
67138 + raise this value.
67139 +
67140 + Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
67141 + any rate limiting on grsecurity log messages.
67142 +
67143 +endmenu
67144 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
67145 new file mode 100644
67146 index 0000000..30ababb
67147 --- /dev/null
67148 +++ b/grsecurity/Makefile
67149 @@ -0,0 +1,54 @@
67150 +# grsecurity – access control and security hardening for Linux
67151 +# All code in this directory and various hooks located throughout the Linux kernel are
67152 +# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
67153 +# http://www.grsecurity.net spender@grsecurity.net
67154 +#
67155 +# This program is free software; you can redistribute it and/or
67156 +# modify it under the terms of the GNU General Public License version 2
67157 +# as published by the Free Software Foundation.
67158 +#
67159 +# This program is distributed in the hope that it will be useful,
67160 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
67161 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
67162 +# GNU General Public License for more details.
67163 +#
67164 +# You should have received a copy of the GNU General Public License
67165 +# along with this program; if not, write to the Free Software
67166 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
67167 +
67168 +KBUILD_CFLAGS += -Werror
67169 +
67170 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
67171 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
67172 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
67173 + grsec_usb.o grsec_ipc.o grsec_proc.o
67174 +
67175 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
67176 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
67177 + gracl_learn.o grsec_log.o gracl_policy.o
67178 +ifdef CONFIG_COMPAT
67179 +obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
67180 +endif
67181 +
67182 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
67183 +
67184 +ifdef CONFIG_NET
67185 +obj-y += grsec_sock.o
67186 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
67187 +endif
67188 +
67189 +ifndef CONFIG_GRKERNSEC
67190 +obj-y += grsec_disabled.o
67191 +endif
67192 +
67193 +ifdef CONFIG_GRKERNSEC_HIDESYM
67194 +extra-y := grsec_hidesym.o
67195 +$(obj)/grsec_hidesym.o:
67196 + @-chmod -f 500 /boot
67197 + @-chmod -f 500 /lib/modules
67198 + @-chmod -f 500 /lib64/modules
67199 + @-chmod -f 500 /lib32/modules
67200 + @-chmod -f 700 .
67201 + @-chmod -f 700 $(objtree)
67202 + @echo ' grsec: protected kernel image paths'
67203 +endif
67204 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
67205 new file mode 100644
67206 index 0000000..58223f6
67207 --- /dev/null
67208 +++ b/grsecurity/gracl.c
67209 @@ -0,0 +1,2702 @@
67210 +#include <linux/kernel.h>
67211 +#include <linux/module.h>
67212 +#include <linux/sched.h>
67213 +#include <linux/mm.h>
67214 +#include <linux/file.h>
67215 +#include <linux/fs.h>
67216 +#include <linux/namei.h>
67217 +#include <linux/mount.h>
67218 +#include <linux/tty.h>
67219 +#include <linux/proc_fs.h>
67220 +#include <linux/lglock.h>
67221 +#include <linux/slab.h>
67222 +#include <linux/vmalloc.h>
67223 +#include <linux/types.h>
67224 +#include <linux/sysctl.h>
67225 +#include <linux/netdevice.h>
67226 +#include <linux/ptrace.h>
67227 +#include <linux/gracl.h>
67228 +#include <linux/gralloc.h>
67229 +#include <linux/security.h>
67230 +#include <linux/grinternal.h>
67231 +#include <linux/pid_namespace.h>
67232 +#include <linux/stop_machine.h>
67233 +#include <linux/fdtable.h>
67234 +#include <linux/percpu.h>
67235 +#include <linux/lglock.h>
67236 +#include <linux/hugetlb.h>
67237 +#include <linux/posix-timers.h>
67238 +#include <linux/prefetch.h>
67239 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
67240 +#include <linux/magic.h>
67241 +#include <linux/pagemap.h>
67242 +#include "../fs/btrfs/async-thread.h"
67243 +#include "../fs/btrfs/ctree.h"
67244 +#include "../fs/btrfs/btrfs_inode.h"
67245 +#endif
67246 +#include "../fs/mount.h"
67247 +
67248 +#include <asm/uaccess.h>
67249 +#include <asm/errno.h>
67250 +#include <asm/mman.h>
67251 +
67252 +#define FOR_EACH_ROLE_START(role) \
67253 + role = running_polstate.role_list; \
67254 + while (role) {
67255 +
67256 +#define FOR_EACH_ROLE_END(role) \
67257 + role = role->prev; \
67258 + }
67259 +
67260 +extern struct path gr_real_root;
67261 +
67262 +static struct gr_policy_state running_polstate;
67263 +struct gr_policy_state *polstate = &running_polstate;
67264 +extern struct gr_alloc_state *current_alloc_state;
67265 +
67266 +extern char *gr_shared_page[4];
67267 +DEFINE_RWLOCK(gr_inode_lock);
67268 +
67269 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
67270 +
67271 +#ifdef CONFIG_NET
67272 +extern struct vfsmount *sock_mnt;
67273 +#endif
67274 +
67275 +extern struct vfsmount *pipe_mnt;
67276 +extern struct vfsmount *shm_mnt;
67277 +
67278 +#ifdef CONFIG_HUGETLBFS
67279 +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
67280 +#endif
67281 +
67282 +extern u16 acl_sp_role_value;
67283 +extern struct acl_object_label *fakefs_obj_rw;
67284 +extern struct acl_object_label *fakefs_obj_rwx;
67285 +
67286 +int gr_acl_is_enabled(void)
67287 +{
67288 + return (gr_status & GR_READY);
67289 +}
67290 +
67291 +void gr_enable_rbac_system(void)
67292 +{
67293 + pax_open_kernel();
67294 + gr_status |= GR_READY;
67295 + pax_close_kernel();
67296 +}
67297 +
67298 +int gr_rbac_disable(void *unused)
67299 +{
67300 + pax_open_kernel();
67301 + gr_status &= ~GR_READY;
67302 + pax_close_kernel();
67303 +
67304 + return 0;
67305 +}
67306 +
67307 +static inline dev_t __get_dev(const struct dentry *dentry)
67308 +{
67309 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
67310 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
67311 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
67312 + else
67313 +#endif
67314 + return dentry->d_sb->s_dev;
67315 +}
67316 +
67317 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
67318 +{
67319 + return __get_dev(dentry);
67320 +}
67321 +
67322 +static char gr_task_roletype_to_char(struct task_struct *task)
67323 +{
67324 + switch (task->role->roletype &
67325 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
67326 + GR_ROLE_SPECIAL)) {
67327 + case GR_ROLE_DEFAULT:
67328 + return 'D';
67329 + case GR_ROLE_USER:
67330 + return 'U';
67331 + case GR_ROLE_GROUP:
67332 + return 'G';
67333 + case GR_ROLE_SPECIAL:
67334 + return 'S';
67335 + }
67336 +
67337 + return 'X';
67338 +}
67339 +
67340 +char gr_roletype_to_char(void)
67341 +{
67342 + return gr_task_roletype_to_char(current);
67343 +}
67344 +
67345 +__inline__ int
67346 +gr_acl_tpe_check(void)
67347 +{
67348 + if (unlikely(!(gr_status & GR_READY)))
67349 + return 0;
67350 + if (current->role->roletype & GR_ROLE_TPE)
67351 + return 1;
67352 + else
67353 + return 0;
67354 +}
67355 +
67356 +int
67357 +gr_handle_rawio(const struct inode *inode)
67358 +{
67359 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
67360 + if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
67361 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
67362 + !capable(CAP_SYS_RAWIO))
67363 + return 1;
67364 +#endif
67365 + return 0;
67366 +}
67367 +
67368 +int
67369 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
67370 +{
67371 + if (likely(lena != lenb))
67372 + return 0;
67373 +
67374 + return !memcmp(a, b, lena);
67375 +}
67376 +
67377 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
67378 +{
67379 + *buflen -= namelen;
67380 + if (*buflen < 0)
67381 + return -ENAMETOOLONG;
67382 + *buffer -= namelen;
67383 + memcpy(*buffer, str, namelen);
67384 + return 0;
67385 +}
67386 +
67387 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
67388 +{
67389 + return prepend(buffer, buflen, name->name, name->len);
67390 +}
67391 +
67392 +static int prepend_path(const struct path *path, struct path *root,
67393 + char **buffer, int *buflen)
67394 +{
67395 + struct dentry *dentry = path->dentry;
67396 + struct vfsmount *vfsmnt = path->mnt;
67397 + struct mount *mnt = real_mount(vfsmnt);
67398 + bool slash = false;
67399 + int error = 0;
67400 +
67401 + while (dentry != root->dentry || vfsmnt != root->mnt) {
67402 + struct dentry * parent;
67403 +
67404 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
67405 + /* Global root? */
67406 + if (!mnt_has_parent(mnt)) {
67407 + goto out;
67408 + }
67409 + dentry = mnt->mnt_mountpoint;
67410 + mnt = mnt->mnt_parent;
67411 + vfsmnt = &mnt->mnt;
67412 + continue;
67413 + }
67414 + parent = dentry->d_parent;
67415 + prefetch(parent);
67416 + spin_lock(&dentry->d_lock);
67417 + error = prepend_name(buffer, buflen, &dentry->d_name);
67418 + spin_unlock(&dentry->d_lock);
67419 + if (!error)
67420 + error = prepend(buffer, buflen, "/", 1);
67421 + if (error)
67422 + break;
67423 +
67424 + slash = true;
67425 + dentry = parent;
67426 + }
67427 +
67428 +out:
67429 + if (!error && !slash)
67430 + error = prepend(buffer, buflen, "/", 1);
67431 +
67432 + return error;
67433 +}
67434 +
67435 +/* this must be called with mount_lock and rename_lock held */
67436 +
67437 +static char *__our_d_path(const struct path *path, struct path *root,
67438 + char *buf, int buflen)
67439 +{
67440 + char *res = buf + buflen;
67441 + int error;
67442 +
67443 + prepend(&res, &buflen, "\0", 1);
67444 + error = prepend_path(path, root, &res, &buflen);
67445 + if (error)
67446 + return ERR_PTR(error);
67447 +
67448 + return res;
67449 +}
67450 +
67451 +static char *
67452 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
67453 +{
67454 + char *retval;
67455 +
67456 + retval = __our_d_path(path, root, buf, buflen);
67457 + if (unlikely(IS_ERR(retval)))
67458 + retval = strcpy(buf, "<path too long>");
67459 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
67460 + retval[1] = '\0';
67461 +
67462 + return retval;
67463 +}
67464 +
67465 +static char *
67466 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
67467 + char *buf, int buflen)
67468 +{
67469 + struct path path;
67470 + char *res;
67471 +
67472 + path.dentry = (struct dentry *)dentry;
67473 + path.mnt = (struct vfsmount *)vfsmnt;
67474 +
67475 + /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
67476 + by the RBAC system */
67477 + res = gen_full_path(&path, &gr_real_root, buf, buflen);
67478 +
67479 + return res;
67480 +}
67481 +
67482 +static char *
67483 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
67484 + char *buf, int buflen)
67485 +{
67486 + char *res;
67487 + struct path path;
67488 + struct path root;
67489 + struct task_struct *reaper = init_pid_ns.child_reaper;
67490 +
67491 + path.dentry = (struct dentry *)dentry;
67492 + path.mnt = (struct vfsmount *)vfsmnt;
67493 +
67494 + /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
67495 + get_fs_root(reaper->fs, &root);
67496 +
67497 + read_seqlock_excl(&mount_lock);
67498 + write_seqlock(&rename_lock);
67499 + res = gen_full_path(&path, &root, buf, buflen);
67500 + write_sequnlock(&rename_lock);
67501 + read_sequnlock_excl(&mount_lock);
67502 +
67503 + path_put(&root);
67504 + return res;
67505 +}
67506 +
67507 +char *
67508 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
67509 +{
67510 + char *ret;
67511 + read_seqlock_excl(&mount_lock);
67512 + write_seqlock(&rename_lock);
67513 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
67514 + PAGE_SIZE);
67515 + write_sequnlock(&rename_lock);
67516 + read_sequnlock_excl(&mount_lock);
67517 + return ret;
67518 +}
67519 +
67520 +static char *
67521 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
67522 +{
67523 + char *ret;
67524 + char *buf;
67525 + int buflen;
67526 +
67527 + read_seqlock_excl(&mount_lock);
67528 + write_seqlock(&rename_lock);
67529 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
67530 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
67531 + buflen = (int)(ret - buf);
67532 + if (buflen >= 5)
67533 + prepend(&ret, &buflen, "/proc", 5);
67534 + else
67535 + ret = strcpy(buf, "<path too long>");
67536 + write_sequnlock(&rename_lock);
67537 + read_sequnlock_excl(&mount_lock);
67538 + return ret;
67539 +}
67540 +
67541 +char *
67542 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
67543 +{
67544 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
67545 + PAGE_SIZE);
67546 +}
67547 +
67548 +char *
67549 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
67550 +{
67551 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
67552 + PAGE_SIZE);
67553 +}
67554 +
67555 +char *
67556 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
67557 +{
67558 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
67559 + PAGE_SIZE);
67560 +}
67561 +
67562 +char *
67563 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
67564 +{
67565 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
67566 + PAGE_SIZE);
67567 +}
67568 +
67569 +char *
67570 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
67571 +{
67572 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
67573 + PAGE_SIZE);
67574 +}
67575 +
67576 +__inline__ __u32
67577 +to_gr_audit(const __u32 reqmode)
67578 +{
67579 + /* masks off auditable permission flags, then shifts them to create
67580 + auditing flags, and adds the special case of append auditing if
67581 + we're requesting write */
67582 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
67583 +}
67584 +
67585 +struct acl_role_label *
67586 +__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
67587 + const gid_t gid)
67588 +{
67589 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
67590 + struct acl_role_label *match;
67591 + struct role_allowed_ip *ipp;
67592 + unsigned int x;
67593 + u32 curr_ip = task->signal->saved_ip;
67594 +
67595 + match = state->acl_role_set.r_hash[index];
67596 +
67597 + while (match) {
67598 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
67599 + for (x = 0; x < match->domain_child_num; x++) {
67600 + if (match->domain_children[x] == uid)
67601 + goto found;
67602 + }
67603 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
67604 + break;
67605 + match = match->next;
67606 + }
67607 +found:
67608 + if (match == NULL) {
67609 + try_group:
67610 + index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
67611 + match = state->acl_role_set.r_hash[index];
67612 +
67613 + while (match) {
67614 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
67615 + for (x = 0; x < match->domain_child_num; x++) {
67616 + if (match->domain_children[x] == gid)
67617 + goto found2;
67618 + }
67619 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
67620 + break;
67621 + match = match->next;
67622 + }
67623 +found2:
67624 + if (match == NULL)
67625 + match = state->default_role;
67626 + if (match->allowed_ips == NULL)
67627 + return match;
67628 + else {
67629 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67630 + if (likely
67631 + ((ntohl(curr_ip) & ipp->netmask) ==
67632 + (ntohl(ipp->addr) & ipp->netmask)))
67633 + return match;
67634 + }
67635 + match = state->default_role;
67636 + }
67637 + } else if (match->allowed_ips == NULL) {
67638 + return match;
67639 + } else {
67640 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67641 + if (likely
67642 + ((ntohl(curr_ip) & ipp->netmask) ==
67643 + (ntohl(ipp->addr) & ipp->netmask)))
67644 + return match;
67645 + }
67646 + goto try_group;
67647 + }
67648 +
67649 + return match;
67650 +}
67651 +
67652 +static struct acl_role_label *
67653 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
67654 + const gid_t gid)
67655 +{
67656 + return __lookup_acl_role_label(&running_polstate, task, uid, gid);
67657 +}
67658 +
67659 +struct acl_subject_label *
67660 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
67661 + const struct acl_role_label *role)
67662 +{
67663 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67664 + struct acl_subject_label *match;
67665 +
67666 + match = role->subj_hash[index];
67667 +
67668 + while (match && (match->inode != ino || match->device != dev ||
67669 + (match->mode & GR_DELETED))) {
67670 + match = match->next;
67671 + }
67672 +
67673 + if (match && !(match->mode & GR_DELETED))
67674 + return match;
67675 + else
67676 + return NULL;
67677 +}
67678 +
67679 +struct acl_subject_label *
67680 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
67681 + const struct acl_role_label *role)
67682 +{
67683 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67684 + struct acl_subject_label *match;
67685 +
67686 + match = role->subj_hash[index];
67687 +
67688 + while (match && (match->inode != ino || match->device != dev ||
67689 + !(match->mode & GR_DELETED))) {
67690 + match = match->next;
67691 + }
67692 +
67693 + if (match && (match->mode & GR_DELETED))
67694 + return match;
67695 + else
67696 + return NULL;
67697 +}
67698 +
67699 +static struct acl_object_label *
67700 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
67701 + const struct acl_subject_label *subj)
67702 +{
67703 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67704 + struct acl_object_label *match;
67705 +
67706 + match = subj->obj_hash[index];
67707 +
67708 + while (match && (match->inode != ino || match->device != dev ||
67709 + (match->mode & GR_DELETED))) {
67710 + match = match->next;
67711 + }
67712 +
67713 + if (match && !(match->mode & GR_DELETED))
67714 + return match;
67715 + else
67716 + return NULL;
67717 +}
67718 +
67719 +static struct acl_object_label *
67720 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
67721 + const struct acl_subject_label *subj)
67722 +{
67723 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67724 + struct acl_object_label *match;
67725 +
67726 + match = subj->obj_hash[index];
67727 +
67728 + while (match && (match->inode != ino || match->device != dev ||
67729 + !(match->mode & GR_DELETED))) {
67730 + match = match->next;
67731 + }
67732 +
67733 + if (match && (match->mode & GR_DELETED))
67734 + return match;
67735 +
67736 + match = subj->obj_hash[index];
67737 +
67738 + while (match && (match->inode != ino || match->device != dev ||
67739 + (match->mode & GR_DELETED))) {
67740 + match = match->next;
67741 + }
67742 +
67743 + if (match && !(match->mode & GR_DELETED))
67744 + return match;
67745 + else
67746 + return NULL;
67747 +}
67748 +
67749 +struct name_entry *
67750 +__lookup_name_entry(const struct gr_policy_state *state, const char *name)
67751 +{
67752 + unsigned int len = strlen(name);
67753 + unsigned int key = full_name_hash(name, len);
67754 + unsigned int index = key % state->name_set.n_size;
67755 + struct name_entry *match;
67756 +
67757 + match = state->name_set.n_hash[index];
67758 +
67759 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
67760 + match = match->next;
67761 +
67762 + return match;
67763 +}
67764 +
67765 +static struct name_entry *
67766 +lookup_name_entry(const char *name)
67767 +{
67768 + return __lookup_name_entry(&running_polstate, name);
67769 +}
67770 +
67771 +static struct name_entry *
67772 +lookup_name_entry_create(const char *name)
67773 +{
67774 + unsigned int len = strlen(name);
67775 + unsigned int key = full_name_hash(name, len);
67776 + unsigned int index = key % running_polstate.name_set.n_size;
67777 + struct name_entry *match;
67778 +
67779 + match = running_polstate.name_set.n_hash[index];
67780 +
67781 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67782 + !match->deleted))
67783 + match = match->next;
67784 +
67785 + if (match && match->deleted)
67786 + return match;
67787 +
67788 + match = running_polstate.name_set.n_hash[index];
67789 +
67790 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67791 + match->deleted))
67792 + match = match->next;
67793 +
67794 + if (match && !match->deleted)
67795 + return match;
67796 + else
67797 + return NULL;
67798 +}
67799 +
67800 +static struct inodev_entry *
67801 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
67802 +{
67803 + unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
67804 + struct inodev_entry *match;
67805 +
67806 + match = running_polstate.inodev_set.i_hash[index];
67807 +
67808 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
67809 + match = match->next;
67810 +
67811 + return match;
67812 +}
67813 +
67814 +void
67815 +__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
67816 +{
67817 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
67818 + state->inodev_set.i_size);
67819 + struct inodev_entry **curr;
67820 +
67821 + entry->prev = NULL;
67822 +
67823 + curr = &state->inodev_set.i_hash[index];
67824 + if (*curr != NULL)
67825 + (*curr)->prev = entry;
67826 +
67827 + entry->next = *curr;
67828 + *curr = entry;
67829 +
67830 + return;
67831 +}
67832 +
67833 +static void
67834 +insert_inodev_entry(struct inodev_entry *entry)
67835 +{
67836 + __insert_inodev_entry(&running_polstate, entry);
67837 +}
67838 +
67839 +void
67840 +insert_acl_obj_label(struct acl_object_label *obj,
67841 + struct acl_subject_label *subj)
67842 +{
67843 + unsigned int index =
67844 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
67845 + struct acl_object_label **curr;
67846 +
67847 + obj->prev = NULL;
67848 +
67849 + curr = &subj->obj_hash[index];
67850 + if (*curr != NULL)
67851 + (*curr)->prev = obj;
67852 +
67853 + obj->next = *curr;
67854 + *curr = obj;
67855 +
67856 + return;
67857 +}
67858 +
67859 +void
67860 +insert_acl_subj_label(struct acl_subject_label *obj,
67861 + struct acl_role_label *role)
67862 +{
67863 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
67864 + struct acl_subject_label **curr;
67865 +
67866 + obj->prev = NULL;
67867 +
67868 + curr = &role->subj_hash[index];
67869 + if (*curr != NULL)
67870 + (*curr)->prev = obj;
67871 +
67872 + obj->next = *curr;
67873 + *curr = obj;
67874 +
67875 + return;
67876 +}
67877 +
67878 +/* derived from glibc fnmatch() 0: match, 1: no match*/
67879 +
67880 +static int
67881 +glob_match(const char *p, const char *n)
67882 +{
67883 + char c;
67884 +
67885 + while ((c = *p++) != '\0') {
67886 + switch (c) {
67887 + case '?':
67888 + if (*n == '\0')
67889 + return 1;
67890 + else if (*n == '/')
67891 + return 1;
67892 + break;
67893 + case '\\':
67894 + if (*n != c)
67895 + return 1;
67896 + break;
67897 + case '*':
67898 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
67899 + if (*n == '/')
67900 + return 1;
67901 + else if (c == '?') {
67902 + if (*n == '\0')
67903 + return 1;
67904 + else
67905 + ++n;
67906 + }
67907 + }
67908 + if (c == '\0') {
67909 + return 0;
67910 + } else {
67911 + const char *endp;
67912 +
67913 + if ((endp = strchr(n, '/')) == NULL)
67914 + endp = n + strlen(n);
67915 +
67916 + if (c == '[') {
67917 + for (--p; n < endp; ++n)
67918 + if (!glob_match(p, n))
67919 + return 0;
67920 + } else if (c == '/') {
67921 + while (*n != '\0' && *n != '/')
67922 + ++n;
67923 + if (*n == '/' && !glob_match(p, n + 1))
67924 + return 0;
67925 + } else {
67926 + for (--p; n < endp; ++n)
67927 + if (*n == c && !glob_match(p, n))
67928 + return 0;
67929 + }
67930 +
67931 + return 1;
67932 + }
67933 + case '[':
67934 + {
67935 + int not;
67936 + char cold;
67937 +
67938 + if (*n == '\0' || *n == '/')
67939 + return 1;
67940 +
67941 + not = (*p == '!' || *p == '^');
67942 + if (not)
67943 + ++p;
67944 +
67945 + c = *p++;
67946 + for (;;) {
67947 + unsigned char fn = (unsigned char)*n;
67948 +
67949 + if (c == '\0')
67950 + return 1;
67951 + else {
67952 + if (c == fn)
67953 + goto matched;
67954 + cold = c;
67955 + c = *p++;
67956 +
67957 + if (c == '-' && *p != ']') {
67958 + unsigned char cend = *p++;
67959 +
67960 + if (cend == '\0')
67961 + return 1;
67962 +
67963 + if (cold <= fn && fn <= cend)
67964 + goto matched;
67965 +
67966 + c = *p++;
67967 + }
67968 + }
67969 +
67970 + if (c == ']')
67971 + break;
67972 + }
67973 + if (!not)
67974 + return 1;
67975 + break;
67976 + matched:
67977 + while (c != ']') {
67978 + if (c == '\0')
67979 + return 1;
67980 +
67981 + c = *p++;
67982 + }
67983 + if (not)
67984 + return 1;
67985 + }
67986 + break;
67987 + default:
67988 + if (c != *n)
67989 + return 1;
67990 + }
67991 +
67992 + ++n;
67993 + }
67994 +
67995 + if (*n == '\0')
67996 + return 0;
67997 +
67998 + if (*n == '/')
67999 + return 0;
68000 +
68001 + return 1;
68002 +}
68003 +
68004 +static struct acl_object_label *
68005 +chk_glob_label(struct acl_object_label *globbed,
68006 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
68007 +{
68008 + struct acl_object_label *tmp;
68009 +
68010 + if (*path == NULL)
68011 + *path = gr_to_filename_nolock(dentry, mnt);
68012 +
68013 + tmp = globbed;
68014 +
68015 + while (tmp) {
68016 + if (!glob_match(tmp->filename, *path))
68017 + return tmp;
68018 + tmp = tmp->next;
68019 + }
68020 +
68021 + return NULL;
68022 +}
68023 +
68024 +static struct acl_object_label *
68025 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
68026 + const ino_t curr_ino, const dev_t curr_dev,
68027 + const struct acl_subject_label *subj, char **path, const int checkglob)
68028 +{
68029 + struct acl_subject_label *tmpsubj;
68030 + struct acl_object_label *retval;
68031 + struct acl_object_label *retval2;
68032 +
68033 + tmpsubj = (struct acl_subject_label *) subj;
68034 + read_lock(&gr_inode_lock);
68035 + do {
68036 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
68037 + if (retval) {
68038 + if (checkglob && retval->globbed) {
68039 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
68040 + if (retval2)
68041 + retval = retval2;
68042 + }
68043 + break;
68044 + }
68045 + } while ((tmpsubj = tmpsubj->parent_subject));
68046 + read_unlock(&gr_inode_lock);
68047 +
68048 + return retval;
68049 +}
68050 +
68051 +static __inline__ struct acl_object_label *
68052 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
68053 + struct dentry *curr_dentry,
68054 + const struct acl_subject_label *subj, char **path, const int checkglob)
68055 +{
68056 + int newglob = checkglob;
68057 + ino_t inode;
68058 + dev_t device;
68059 +
68060 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
68061 + as we don't want a / * rule to match instead of the / object
68062 + don't do this for create lookups that call this function though, since they're looking up
68063 + on the parent and thus need globbing checks on all paths
68064 + */
68065 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
68066 + newglob = GR_NO_GLOB;
68067 +
68068 + spin_lock(&curr_dentry->d_lock);
68069 + inode = curr_dentry->d_inode->i_ino;
68070 + device = __get_dev(curr_dentry);
68071 + spin_unlock(&curr_dentry->d_lock);
68072 +
68073 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
68074 +}
68075 +
68076 +#ifdef CONFIG_HUGETLBFS
68077 +static inline bool
68078 +is_hugetlbfs_mnt(const struct vfsmount *mnt)
68079 +{
68080 + int i;
68081 + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
68082 + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
68083 + return true;
68084 + }
68085 +
68086 + return false;
68087 +}
68088 +#endif
68089 +
68090 +static struct acl_object_label *
68091 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68092 + const struct acl_subject_label *subj, char *path, const int checkglob)
68093 +{
68094 + struct dentry *dentry = (struct dentry *) l_dentry;
68095 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
68096 + struct mount *real_mnt = real_mount(mnt);
68097 + struct acl_object_label *retval;
68098 + struct dentry *parent;
68099 +
68100 + read_seqlock_excl(&mount_lock);
68101 + write_seqlock(&rename_lock);
68102 +
68103 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
68104 +#ifdef CONFIG_NET
68105 + mnt == sock_mnt ||
68106 +#endif
68107 +#ifdef CONFIG_HUGETLBFS
68108 + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
68109 +#endif
68110 + /* ignore Eric Biederman */
68111 + IS_PRIVATE(l_dentry->d_inode))) {
68112 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
68113 + goto out;
68114 + }
68115 +
68116 + for (;;) {
68117 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
68118 + break;
68119 +
68120 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
68121 + if (!mnt_has_parent(real_mnt))
68122 + break;
68123 +
68124 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
68125 + if (retval != NULL)
68126 + goto out;
68127 +
68128 + dentry = real_mnt->mnt_mountpoint;
68129 + real_mnt = real_mnt->mnt_parent;
68130 + mnt = &real_mnt->mnt;
68131 + continue;
68132 + }
68133 +
68134 + parent = dentry->d_parent;
68135 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
68136 + if (retval != NULL)
68137 + goto out;
68138 +
68139 + dentry = parent;
68140 + }
68141 +
68142 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
68143 +
68144 + /* gr_real_root is pinned so we don't have to hold a reference */
68145 + if (retval == NULL)
68146 + retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
68147 +out:
68148 + write_sequnlock(&rename_lock);
68149 + read_sequnlock_excl(&mount_lock);
68150 +
68151 + BUG_ON(retval == NULL);
68152 +
68153 + return retval;
68154 +}
68155 +
68156 +static __inline__ struct acl_object_label *
68157 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68158 + const struct acl_subject_label *subj)
68159 +{
68160 + char *path = NULL;
68161 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
68162 +}
68163 +
68164 +static __inline__ struct acl_object_label *
68165 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68166 + const struct acl_subject_label *subj)
68167 +{
68168 + char *path = NULL;
68169 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
68170 +}
68171 +
68172 +static __inline__ struct acl_object_label *
68173 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68174 + const struct acl_subject_label *subj, char *path)
68175 +{
68176 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
68177 +}
68178 +
68179 +struct acl_subject_label *
68180 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68181 + const struct acl_role_label *role)
68182 +{
68183 + struct dentry *dentry = (struct dentry *) l_dentry;
68184 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
68185 + struct mount *real_mnt = real_mount(mnt);
68186 + struct acl_subject_label *retval;
68187 + struct dentry *parent;
68188 +
68189 + read_seqlock_excl(&mount_lock);
68190 + write_seqlock(&rename_lock);
68191 +
68192 + for (;;) {
68193 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
68194 + break;
68195 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
68196 + if (!mnt_has_parent(real_mnt))
68197 + break;
68198 +
68199 + spin_lock(&dentry->d_lock);
68200 + read_lock(&gr_inode_lock);
68201 + retval =
68202 + lookup_acl_subj_label(dentry->d_inode->i_ino,
68203 + __get_dev(dentry), role);
68204 + read_unlock(&gr_inode_lock);
68205 + spin_unlock(&dentry->d_lock);
68206 + if (retval != NULL)
68207 + goto out;
68208 +
68209 + dentry = real_mnt->mnt_mountpoint;
68210 + real_mnt = real_mnt->mnt_parent;
68211 + mnt = &real_mnt->mnt;
68212 + continue;
68213 + }
68214 +
68215 + spin_lock(&dentry->d_lock);
68216 + read_lock(&gr_inode_lock);
68217 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
68218 + __get_dev(dentry), role);
68219 + read_unlock(&gr_inode_lock);
68220 + parent = dentry->d_parent;
68221 + spin_unlock(&dentry->d_lock);
68222 +
68223 + if (retval != NULL)
68224 + goto out;
68225 +
68226 + dentry = parent;
68227 + }
68228 +
68229 + spin_lock(&dentry->d_lock);
68230 + read_lock(&gr_inode_lock);
68231 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
68232 + __get_dev(dentry), role);
68233 + read_unlock(&gr_inode_lock);
68234 + spin_unlock(&dentry->d_lock);
68235 +
68236 + if (unlikely(retval == NULL)) {
68237 + /* gr_real_root is pinned, we don't need to hold a reference */
68238 + read_lock(&gr_inode_lock);
68239 + retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
68240 + __get_dev(gr_real_root.dentry), role);
68241 + read_unlock(&gr_inode_lock);
68242 + }
68243 +out:
68244 + write_sequnlock(&rename_lock);
68245 + read_sequnlock_excl(&mount_lock);
68246 +
68247 + BUG_ON(retval == NULL);
68248 +
68249 + return retval;
68250 +}
68251 +
68252 +void
68253 +assign_special_role(const char *rolename)
68254 +{
68255 + struct acl_object_label *obj;
68256 + struct acl_role_label *r;
68257 + struct acl_role_label *assigned = NULL;
68258 + struct task_struct *tsk;
68259 + struct file *filp;
68260 +
68261 + FOR_EACH_ROLE_START(r)
68262 + if (!strcmp(rolename, r->rolename) &&
68263 + (r->roletype & GR_ROLE_SPECIAL)) {
68264 + assigned = r;
68265 + break;
68266 + }
68267 + FOR_EACH_ROLE_END(r)
68268 +
68269 + if (!assigned)
68270 + return;
68271 +
68272 + read_lock(&tasklist_lock);
68273 + read_lock(&grsec_exec_file_lock);
68274 +
68275 + tsk = current->real_parent;
68276 + if (tsk == NULL)
68277 + goto out_unlock;
68278 +
68279 + filp = tsk->exec_file;
68280 + if (filp == NULL)
68281 + goto out_unlock;
68282 +
68283 + tsk->is_writable = 0;
68284 + tsk->inherited = 0;
68285 +
68286 + tsk->acl_sp_role = 1;
68287 + tsk->acl_role_id = ++acl_sp_role_value;
68288 + tsk->role = assigned;
68289 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
68290 +
68291 + /* ignore additional mmap checks for processes that are writable
68292 + by the default ACL */
68293 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68294 + if (unlikely(obj->mode & GR_WRITE))
68295 + tsk->is_writable = 1;
68296 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
68297 + if (unlikely(obj->mode & GR_WRITE))
68298 + tsk->is_writable = 1;
68299 +
68300 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68301 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
68302 + tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
68303 +#endif
68304 +
68305 +out_unlock:
68306 + read_unlock(&grsec_exec_file_lock);
68307 + read_unlock(&tasklist_lock);
68308 + return;
68309 +}
68310 +
68311 +
68312 +static void
68313 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
68314 +{
68315 + struct task_struct *task = current;
68316 + const struct cred *cred = current_cred();
68317 +
68318 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
68319 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
68320 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
68321 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
68322 +
68323 + return;
68324 +}
68325 +
68326 +static void
68327 +gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
68328 +{
68329 + struct task_struct *task = current;
68330 + const struct cred *cred = current_cred();
68331 +
68332 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
68333 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
68334 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
68335 + 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
68336 +
68337 + return;
68338 +}
68339 +
68340 +static void
68341 +gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
68342 +{
68343 + struct task_struct *task = current;
68344 + const struct cred *cred = current_cred();
68345 +
68346 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
68347 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
68348 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
68349 + 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
68350 +
68351 + return;
68352 +}
68353 +
68354 +static void
68355 +gr_set_proc_res(struct task_struct *task)
68356 +{
68357 + struct acl_subject_label *proc;
68358 + unsigned short i;
68359 +
68360 + proc = task->acl;
68361 +
68362 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
68363 + return;
68364 +
68365 + for (i = 0; i < RLIM_NLIMITS; i++) {
68366 + if (!(proc->resmask & (1U << i)))
68367 + continue;
68368 +
68369 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
68370 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
68371 +
68372 + if (i == RLIMIT_CPU)
68373 + update_rlimit_cpu(task, proc->res[i].rlim_cur);
68374 + }
68375 +
68376 + return;
68377 +}
68378 +
68379 +/* both of the below must be called with
68380 + rcu_read_lock();
68381 + read_lock(&tasklist_lock);
68382 + read_lock(&grsec_exec_file_lock);
68383 +*/
68384 +
68385 +struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
68386 +{
68387 + char *tmpname;
68388 + struct acl_subject_label *tmpsubj;
68389 + struct file *filp;
68390 + struct name_entry *nmatch;
68391 +
68392 + filp = task->exec_file;
68393 + if (filp == NULL)
68394 + return NULL;
68395 +
68396 + /* the following is to apply the correct subject
68397 + on binaries running when the RBAC system
68398 + is enabled, when the binaries have been
68399 + replaced or deleted since their execution
68400 + -----
68401 + when the RBAC system starts, the inode/dev
68402 + from exec_file will be one the RBAC system
68403 + is unaware of. It only knows the inode/dev
68404 + of the present file on disk, or the absence
68405 + of it.
68406 + */
68407 +
68408 + if (filename)
68409 + nmatch = __lookup_name_entry(state, filename);
68410 + else {
68411 + preempt_disable();
68412 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
68413 +
68414 + nmatch = __lookup_name_entry(state, tmpname);
68415 + preempt_enable();
68416 + }
68417 + tmpsubj = NULL;
68418 + if (nmatch) {
68419 + if (nmatch->deleted)
68420 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
68421 + else
68422 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
68423 + }
68424 + /* this also works for the reload case -- if we don't match a potentially inherited subject
68425 + then we fall back to a normal lookup based on the binary's ino/dev
68426 + */
68427 + if (tmpsubj == NULL)
68428 + tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
68429 +
68430 + return tmpsubj;
68431 +}
68432 +
68433 +static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
68434 +{
68435 + return __gr_get_subject_for_task(&running_polstate, task, filename);
68436 +}
68437 +
68438 +void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
68439 +{
68440 + struct acl_object_label *obj;
68441 + struct file *filp;
68442 +
68443 + filp = task->exec_file;
68444 +
68445 + task->acl = subj;
68446 + task->is_writable = 0;
68447 + /* ignore additional mmap checks for processes that are writable
68448 + by the default ACL */
68449 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
68450 + if (unlikely(obj->mode & GR_WRITE))
68451 + task->is_writable = 1;
68452 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68453 + if (unlikely(obj->mode & GR_WRITE))
68454 + task->is_writable = 1;
68455 +
68456 + gr_set_proc_res(task);
68457 +
68458 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68459 + 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);
68460 +#endif
68461 +}
68462 +
68463 +static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
68464 +{
68465 + __gr_apply_subject_to_task(&running_polstate, task, subj);
68466 +}
68467 +
68468 +__u32
68469 +gr_search_file(const struct dentry * dentry, const __u32 mode,
68470 + const struct vfsmount * mnt)
68471 +{
68472 + __u32 retval = mode;
68473 + struct acl_subject_label *curracl;
68474 + struct acl_object_label *currobj;
68475 +
68476 + if (unlikely(!(gr_status & GR_READY)))
68477 + return (mode & ~GR_AUDITS);
68478 +
68479 + curracl = current->acl;
68480 +
68481 + currobj = chk_obj_label(dentry, mnt, curracl);
68482 + retval = currobj->mode & mode;
68483 +
68484 + /* if we're opening a specified transfer file for writing
68485 + (e.g. /dev/initctl), then transfer our role to init
68486 + */
68487 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
68488 + current->role->roletype & GR_ROLE_PERSIST)) {
68489 + struct task_struct *task = init_pid_ns.child_reaper;
68490 +
68491 + if (task->role != current->role) {
68492 + struct acl_subject_label *subj;
68493 +
68494 + task->acl_sp_role = 0;
68495 + task->acl_role_id = current->acl_role_id;
68496 + task->role = current->role;
68497 + rcu_read_lock();
68498 + read_lock(&grsec_exec_file_lock);
68499 + subj = gr_get_subject_for_task(task, NULL);
68500 + gr_apply_subject_to_task(task, subj);
68501 + read_unlock(&grsec_exec_file_lock);
68502 + rcu_read_unlock();
68503 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
68504 + }
68505 + }
68506 +
68507 + if (unlikely
68508 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
68509 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
68510 + __u32 new_mode = mode;
68511 +
68512 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
68513 +
68514 + retval = new_mode;
68515 +
68516 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
68517 + new_mode |= GR_INHERIT;
68518 +
68519 + if (!(mode & GR_NOLEARN))
68520 + gr_log_learn(dentry, mnt, new_mode);
68521 + }
68522 +
68523 + return retval;
68524 +}
68525 +
68526 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
68527 + const struct dentry *parent,
68528 + const struct vfsmount *mnt)
68529 +{
68530 + struct name_entry *match;
68531 + struct acl_object_label *matchpo;
68532 + struct acl_subject_label *curracl;
68533 + char *path;
68534 +
68535 + if (unlikely(!(gr_status & GR_READY)))
68536 + return NULL;
68537 +
68538 + preempt_disable();
68539 + path = gr_to_filename_rbac(new_dentry, mnt);
68540 + match = lookup_name_entry_create(path);
68541 +
68542 + curracl = current->acl;
68543 +
68544 + if (match) {
68545 + read_lock(&gr_inode_lock);
68546 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
68547 + read_unlock(&gr_inode_lock);
68548 +
68549 + if (matchpo) {
68550 + preempt_enable();
68551 + return matchpo;
68552 + }
68553 + }
68554 +
68555 + // lookup parent
68556 +
68557 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
68558 +
68559 + preempt_enable();
68560 + return matchpo;
68561 +}
68562 +
68563 +__u32
68564 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
68565 + const struct vfsmount * mnt, const __u32 mode)
68566 +{
68567 + struct acl_object_label *matchpo;
68568 + __u32 retval;
68569 +
68570 + if (unlikely(!(gr_status & GR_READY)))
68571 + return (mode & ~GR_AUDITS);
68572 +
68573 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
68574 +
68575 + retval = matchpo->mode & mode;
68576 +
68577 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
68578 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68579 + __u32 new_mode = mode;
68580 +
68581 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
68582 +
68583 + gr_log_learn(new_dentry, mnt, new_mode);
68584 + return new_mode;
68585 + }
68586 +
68587 + return retval;
68588 +}
68589 +
68590 +__u32
68591 +gr_check_link(const struct dentry * new_dentry,
68592 + const struct dentry * parent_dentry,
68593 + const struct vfsmount * parent_mnt,
68594 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
68595 +{
68596 + struct acl_object_label *obj;
68597 + __u32 oldmode, newmode;
68598 + __u32 needmode;
68599 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
68600 + GR_DELETE | GR_INHERIT;
68601 +
68602 + if (unlikely(!(gr_status & GR_READY)))
68603 + return (GR_CREATE | GR_LINK);
68604 +
68605 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
68606 + oldmode = obj->mode;
68607 +
68608 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
68609 + newmode = obj->mode;
68610 +
68611 + needmode = newmode & checkmodes;
68612 +
68613 + // old name for hardlink must have at least the permissions of the new name
68614 + if ((oldmode & needmode) != needmode)
68615 + goto bad;
68616 +
68617 + // if old name had restrictions/auditing, make sure the new name does as well
68618 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
68619 +
68620 + // don't allow hardlinking of suid/sgid/fcapped files without permission
68621 + if (is_privileged_binary(old_dentry))
68622 + needmode |= GR_SETID;
68623 +
68624 + if ((newmode & needmode) != needmode)
68625 + goto bad;
68626 +
68627 + // enforce minimum permissions
68628 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
68629 + return newmode;
68630 +bad:
68631 + needmode = oldmode;
68632 + if (is_privileged_binary(old_dentry))
68633 + needmode |= GR_SETID;
68634 +
68635 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
68636 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
68637 + return (GR_CREATE | GR_LINK);
68638 + } else if (newmode & GR_SUPPRESS)
68639 + return GR_SUPPRESS;
68640 + else
68641 + return 0;
68642 +}
68643 +
68644 +int
68645 +gr_check_hidden_task(const struct task_struct *task)
68646 +{
68647 + if (unlikely(!(gr_status & GR_READY)))
68648 + return 0;
68649 +
68650 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
68651 + return 1;
68652 +
68653 + return 0;
68654 +}
68655 +
68656 +int
68657 +gr_check_protected_task(const struct task_struct *task)
68658 +{
68659 + if (unlikely(!(gr_status & GR_READY) || !task))
68660 + return 0;
68661 +
68662 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68663 + task->acl != current->acl)
68664 + return 1;
68665 +
68666 + return 0;
68667 +}
68668 +
68669 +int
68670 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
68671 +{
68672 + struct task_struct *p;
68673 + int ret = 0;
68674 +
68675 + if (unlikely(!(gr_status & GR_READY) || !pid))
68676 + return ret;
68677 +
68678 + read_lock(&tasklist_lock);
68679 + do_each_pid_task(pid, type, p) {
68680 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68681 + p->acl != current->acl) {
68682 + ret = 1;
68683 + goto out;
68684 + }
68685 + } while_each_pid_task(pid, type, p);
68686 +out:
68687 + read_unlock(&tasklist_lock);
68688 +
68689 + return ret;
68690 +}
68691 +
68692 +void
68693 +gr_copy_label(struct task_struct *tsk)
68694 +{
68695 + struct task_struct *p = current;
68696 +
68697 + tsk->inherited = p->inherited;
68698 + tsk->acl_sp_role = 0;
68699 + tsk->acl_role_id = p->acl_role_id;
68700 + tsk->acl = p->acl;
68701 + tsk->role = p->role;
68702 + tsk->signal->used_accept = 0;
68703 + tsk->signal->curr_ip = p->signal->curr_ip;
68704 + tsk->signal->saved_ip = p->signal->saved_ip;
68705 + if (p->exec_file)
68706 + get_file(p->exec_file);
68707 + tsk->exec_file = p->exec_file;
68708 + tsk->is_writable = p->is_writable;
68709 + if (unlikely(p->signal->used_accept)) {
68710 + p->signal->curr_ip = 0;
68711 + p->signal->saved_ip = 0;
68712 + }
68713 +
68714 + return;
68715 +}
68716 +
68717 +extern int gr_process_kernel_setuid_ban(struct user_struct *user);
68718 +
68719 +int
68720 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
68721 +{
68722 + unsigned int i;
68723 + __u16 num;
68724 + uid_t *uidlist;
68725 + uid_t curuid;
68726 + int realok = 0;
68727 + int effectiveok = 0;
68728 + int fsok = 0;
68729 + uid_t globalreal, globaleffective, globalfs;
68730 +
68731 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
68732 + struct user_struct *user;
68733 +
68734 + if (!uid_valid(real))
68735 + goto skipit;
68736 +
68737 + /* find user based on global namespace */
68738 +
68739 + globalreal = GR_GLOBAL_UID(real);
68740 +
68741 + user = find_user(make_kuid(&init_user_ns, globalreal));
68742 + if (user == NULL)
68743 + goto skipit;
68744 +
68745 + if (gr_process_kernel_setuid_ban(user)) {
68746 + /* for find_user */
68747 + free_uid(user);
68748 + return 1;
68749 + }
68750 +
68751 + /* for find_user */
68752 + free_uid(user);
68753 +
68754 +skipit:
68755 +#endif
68756 +
68757 + if (unlikely(!(gr_status & GR_READY)))
68758 + return 0;
68759 +
68760 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68761 + gr_log_learn_uid_change(real, effective, fs);
68762 +
68763 + num = current->acl->user_trans_num;
68764 + uidlist = current->acl->user_transitions;
68765 +
68766 + if (uidlist == NULL)
68767 + return 0;
68768 +
68769 + if (!uid_valid(real)) {
68770 + realok = 1;
68771 + globalreal = (uid_t)-1;
68772 + } else {
68773 + globalreal = GR_GLOBAL_UID(real);
68774 + }
68775 + if (!uid_valid(effective)) {
68776 + effectiveok = 1;
68777 + globaleffective = (uid_t)-1;
68778 + } else {
68779 + globaleffective = GR_GLOBAL_UID(effective);
68780 + }
68781 + if (!uid_valid(fs)) {
68782 + fsok = 1;
68783 + globalfs = (uid_t)-1;
68784 + } else {
68785 + globalfs = GR_GLOBAL_UID(fs);
68786 + }
68787 +
68788 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
68789 + for (i = 0; i < num; i++) {
68790 + curuid = uidlist[i];
68791 + if (globalreal == curuid)
68792 + realok = 1;
68793 + if (globaleffective == curuid)
68794 + effectiveok = 1;
68795 + if (globalfs == curuid)
68796 + fsok = 1;
68797 + }
68798 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
68799 + for (i = 0; i < num; i++) {
68800 + curuid = uidlist[i];
68801 + if (globalreal == curuid)
68802 + break;
68803 + if (globaleffective == curuid)
68804 + break;
68805 + if (globalfs == curuid)
68806 + break;
68807 + }
68808 + /* not in deny list */
68809 + if (i == num) {
68810 + realok = 1;
68811 + effectiveok = 1;
68812 + fsok = 1;
68813 + }
68814 + }
68815 +
68816 + if (realok && effectiveok && fsok)
68817 + return 0;
68818 + else {
68819 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68820 + return 1;
68821 + }
68822 +}
68823 +
68824 +int
68825 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
68826 +{
68827 + unsigned int i;
68828 + __u16 num;
68829 + gid_t *gidlist;
68830 + gid_t curgid;
68831 + int realok = 0;
68832 + int effectiveok = 0;
68833 + int fsok = 0;
68834 + gid_t globalreal, globaleffective, globalfs;
68835 +
68836 + if (unlikely(!(gr_status & GR_READY)))
68837 + return 0;
68838 +
68839 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68840 + gr_log_learn_gid_change(real, effective, fs);
68841 +
68842 + num = current->acl->group_trans_num;
68843 + gidlist = current->acl->group_transitions;
68844 +
68845 + if (gidlist == NULL)
68846 + return 0;
68847 +
68848 + if (!gid_valid(real)) {
68849 + realok = 1;
68850 + globalreal = (gid_t)-1;
68851 + } else {
68852 + globalreal = GR_GLOBAL_GID(real);
68853 + }
68854 + if (!gid_valid(effective)) {
68855 + effectiveok = 1;
68856 + globaleffective = (gid_t)-1;
68857 + } else {
68858 + globaleffective = GR_GLOBAL_GID(effective);
68859 + }
68860 + if (!gid_valid(fs)) {
68861 + fsok = 1;
68862 + globalfs = (gid_t)-1;
68863 + } else {
68864 + globalfs = GR_GLOBAL_GID(fs);
68865 + }
68866 +
68867 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
68868 + for (i = 0; i < num; i++) {
68869 + curgid = gidlist[i];
68870 + if (globalreal == curgid)
68871 + realok = 1;
68872 + if (globaleffective == curgid)
68873 + effectiveok = 1;
68874 + if (globalfs == curgid)
68875 + fsok = 1;
68876 + }
68877 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
68878 + for (i = 0; i < num; i++) {
68879 + curgid = gidlist[i];
68880 + if (globalreal == curgid)
68881 + break;
68882 + if (globaleffective == curgid)
68883 + break;
68884 + if (globalfs == curgid)
68885 + break;
68886 + }
68887 + /* not in deny list */
68888 + if (i == num) {
68889 + realok = 1;
68890 + effectiveok = 1;
68891 + fsok = 1;
68892 + }
68893 + }
68894 +
68895 + if (realok && effectiveok && fsok)
68896 + return 0;
68897 + else {
68898 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68899 + return 1;
68900 + }
68901 +}
68902 +
68903 +extern int gr_acl_is_capable(const int cap);
68904 +
68905 +void
68906 +gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
68907 +{
68908 + struct acl_role_label *role = task->role;
68909 + struct acl_subject_label *subj = NULL;
68910 + struct acl_object_label *obj;
68911 + struct file *filp;
68912 + uid_t uid;
68913 + gid_t gid;
68914 +
68915 + if (unlikely(!(gr_status & GR_READY)))
68916 + return;
68917 +
68918 + uid = GR_GLOBAL_UID(kuid);
68919 + gid = GR_GLOBAL_GID(kgid);
68920 +
68921 + filp = task->exec_file;
68922 +
68923 + /* kernel process, we'll give them the kernel role */
68924 + if (unlikely(!filp)) {
68925 + task->role = running_polstate.kernel_role;
68926 + task->acl = running_polstate.kernel_role->root_label;
68927 + return;
68928 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
68929 + /* save the current ip at time of role lookup so that the proper
68930 + IP will be learned for role_allowed_ip */
68931 + task->signal->saved_ip = task->signal->curr_ip;
68932 + role = lookup_acl_role_label(task, uid, gid);
68933 + }
68934 +
68935 + /* don't change the role if we're not a privileged process */
68936 + if (role && task->role != role &&
68937 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
68938 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
68939 + return;
68940 +
68941 + /* perform subject lookup in possibly new role
68942 + we can use this result below in the case where role == task->role
68943 + */
68944 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
68945 +
68946 + /* if we changed uid/gid, but result in the same role
68947 + and are using inheritance, don't lose the inherited subject
68948 + if current subject is other than what normal lookup
68949 + would result in, we arrived via inheritance, don't
68950 + lose subject
68951 + */
68952 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
68953 + (subj == task->acl)))
68954 + task->acl = subj;
68955 +
68956 + /* leave task->inherited unaffected */
68957 +
68958 + task->role = role;
68959 +
68960 + task->is_writable = 0;
68961 +
68962 + /* ignore additional mmap checks for processes that are writable
68963 + by the default ACL */
68964 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68965 + if (unlikely(obj->mode & GR_WRITE))
68966 + task->is_writable = 1;
68967 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68968 + if (unlikely(obj->mode & GR_WRITE))
68969 + task->is_writable = 1;
68970 +
68971 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68972 + 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);
68973 +#endif
68974 +
68975 + gr_set_proc_res(task);
68976 +
68977 + return;
68978 +}
68979 +
68980 +int
68981 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
68982 + const int unsafe_flags)
68983 +{
68984 + struct task_struct *task = current;
68985 + struct acl_subject_label *newacl;
68986 + struct acl_object_label *obj;
68987 + __u32 retmode;
68988 +
68989 + if (unlikely(!(gr_status & GR_READY)))
68990 + return 0;
68991 +
68992 + newacl = chk_subj_label(dentry, mnt, task->role);
68993 +
68994 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
68995 + did an exec
68996 + */
68997 + rcu_read_lock();
68998 + read_lock(&tasklist_lock);
68999 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
69000 + (task->parent->acl->mode & GR_POVERRIDE))) {
69001 + read_unlock(&tasklist_lock);
69002 + rcu_read_unlock();
69003 + goto skip_check;
69004 + }
69005 + read_unlock(&tasklist_lock);
69006 + rcu_read_unlock();
69007 +
69008 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
69009 + !(task->role->roletype & GR_ROLE_GOD) &&
69010 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
69011 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
69012 + if (unsafe_flags & LSM_UNSAFE_SHARE)
69013 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
69014 + else
69015 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
69016 + return -EACCES;
69017 + }
69018 +
69019 +skip_check:
69020 +
69021 + obj = chk_obj_label(dentry, mnt, task->acl);
69022 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
69023 +
69024 + if (!(task->acl->mode & GR_INHERITLEARN) &&
69025 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
69026 + if (obj->nested)
69027 + task->acl = obj->nested;
69028 + else
69029 + task->acl = newacl;
69030 + task->inherited = 0;
69031 + } else {
69032 + task->inherited = 1;
69033 + if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
69034 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
69035 + }
69036 +
69037 + task->is_writable = 0;
69038 +
69039 + /* ignore additional mmap checks for processes that are writable
69040 + by the default ACL */
69041 + obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
69042 + if (unlikely(obj->mode & GR_WRITE))
69043 + task->is_writable = 1;
69044 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
69045 + if (unlikely(obj->mode & GR_WRITE))
69046 + task->is_writable = 1;
69047 +
69048 + gr_set_proc_res(task);
69049 +
69050 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
69051 + 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);
69052 +#endif
69053 + return 0;
69054 +}
69055 +
69056 +/* always called with valid inodev ptr */
69057 +static void
69058 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
69059 +{
69060 + struct acl_object_label *matchpo;
69061 + struct acl_subject_label *matchps;
69062 + struct acl_subject_label *subj;
69063 + struct acl_role_label *role;
69064 + unsigned int x;
69065 +
69066 + FOR_EACH_ROLE_START(role)
69067 + FOR_EACH_SUBJECT_START(role, subj, x)
69068 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
69069 + matchpo->mode |= GR_DELETED;
69070 + FOR_EACH_SUBJECT_END(subj,x)
69071 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
69072 + /* nested subjects aren't in the role's subj_hash table */
69073 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
69074 + matchpo->mode |= GR_DELETED;
69075 + FOR_EACH_NESTED_SUBJECT_END(subj)
69076 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
69077 + matchps->mode |= GR_DELETED;
69078 + FOR_EACH_ROLE_END(role)
69079 +
69080 + inodev->nentry->deleted = 1;
69081 +
69082 + return;
69083 +}
69084 +
69085 +void
69086 +gr_handle_delete(const ino_t ino, const dev_t dev)
69087 +{
69088 + struct inodev_entry *inodev;
69089 +
69090 + if (unlikely(!(gr_status & GR_READY)))
69091 + return;
69092 +
69093 + write_lock(&gr_inode_lock);
69094 + inodev = lookup_inodev_entry(ino, dev);
69095 + if (inodev != NULL)
69096 + do_handle_delete(inodev, ino, dev);
69097 + write_unlock(&gr_inode_lock);
69098 +
69099 + return;
69100 +}
69101 +
69102 +static void
69103 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
69104 + const ino_t newinode, const dev_t newdevice,
69105 + struct acl_subject_label *subj)
69106 +{
69107 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
69108 + struct acl_object_label *match;
69109 +
69110 + match = subj->obj_hash[index];
69111 +
69112 + while (match && (match->inode != oldinode ||
69113 + match->device != olddevice ||
69114 + !(match->mode & GR_DELETED)))
69115 + match = match->next;
69116 +
69117 + if (match && (match->inode == oldinode)
69118 + && (match->device == olddevice)
69119 + && (match->mode & GR_DELETED)) {
69120 + if (match->prev == NULL) {
69121 + subj->obj_hash[index] = match->next;
69122 + if (match->next != NULL)
69123 + match->next->prev = NULL;
69124 + } else {
69125 + match->prev->next = match->next;
69126 + if (match->next != NULL)
69127 + match->next->prev = match->prev;
69128 + }
69129 + match->prev = NULL;
69130 + match->next = NULL;
69131 + match->inode = newinode;
69132 + match->device = newdevice;
69133 + match->mode &= ~GR_DELETED;
69134 +
69135 + insert_acl_obj_label(match, subj);
69136 + }
69137 +
69138 + return;
69139 +}
69140 +
69141 +static void
69142 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
69143 + const ino_t newinode, const dev_t newdevice,
69144 + struct acl_role_label *role)
69145 +{
69146 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
69147 + struct acl_subject_label *match;
69148 +
69149 + match = role->subj_hash[index];
69150 +
69151 + while (match && (match->inode != oldinode ||
69152 + match->device != olddevice ||
69153 + !(match->mode & GR_DELETED)))
69154 + match = match->next;
69155 +
69156 + if (match && (match->inode == oldinode)
69157 + && (match->device == olddevice)
69158 + && (match->mode & GR_DELETED)) {
69159 + if (match->prev == NULL) {
69160 + role->subj_hash[index] = match->next;
69161 + if (match->next != NULL)
69162 + match->next->prev = NULL;
69163 + } else {
69164 + match->prev->next = match->next;
69165 + if (match->next != NULL)
69166 + match->next->prev = match->prev;
69167 + }
69168 + match->prev = NULL;
69169 + match->next = NULL;
69170 + match->inode = newinode;
69171 + match->device = newdevice;
69172 + match->mode &= ~GR_DELETED;
69173 +
69174 + insert_acl_subj_label(match, role);
69175 + }
69176 +
69177 + return;
69178 +}
69179 +
69180 +static void
69181 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
69182 + const ino_t newinode, const dev_t newdevice)
69183 +{
69184 + unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
69185 + struct inodev_entry *match;
69186 +
69187 + match = running_polstate.inodev_set.i_hash[index];
69188 +
69189 + while (match && (match->nentry->inode != oldinode ||
69190 + match->nentry->device != olddevice || !match->nentry->deleted))
69191 + match = match->next;
69192 +
69193 + if (match && (match->nentry->inode == oldinode)
69194 + && (match->nentry->device == olddevice) &&
69195 + match->nentry->deleted) {
69196 + if (match->prev == NULL) {
69197 + running_polstate.inodev_set.i_hash[index] = match->next;
69198 + if (match->next != NULL)
69199 + match->next->prev = NULL;
69200 + } else {
69201 + match->prev->next = match->next;
69202 + if (match->next != NULL)
69203 + match->next->prev = match->prev;
69204 + }
69205 + match->prev = NULL;
69206 + match->next = NULL;
69207 + match->nentry->inode = newinode;
69208 + match->nentry->device = newdevice;
69209 + match->nentry->deleted = 0;
69210 +
69211 + insert_inodev_entry(match);
69212 + }
69213 +
69214 + return;
69215 +}
69216 +
69217 +static void
69218 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
69219 +{
69220 + struct acl_subject_label *subj;
69221 + struct acl_role_label *role;
69222 + unsigned int x;
69223 +
69224 + FOR_EACH_ROLE_START(role)
69225 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
69226 +
69227 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
69228 + if ((subj->inode == ino) && (subj->device == dev)) {
69229 + subj->inode = ino;
69230 + subj->device = dev;
69231 + }
69232 + /* nested subjects aren't in the role's subj_hash table */
69233 + update_acl_obj_label(matchn->inode, matchn->device,
69234 + ino, dev, subj);
69235 + FOR_EACH_NESTED_SUBJECT_END(subj)
69236 + FOR_EACH_SUBJECT_START(role, subj, x)
69237 + update_acl_obj_label(matchn->inode, matchn->device,
69238 + ino, dev, subj);
69239 + FOR_EACH_SUBJECT_END(subj,x)
69240 + FOR_EACH_ROLE_END(role)
69241 +
69242 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
69243 +
69244 + return;
69245 +}
69246 +
69247 +static void
69248 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
69249 + const struct vfsmount *mnt)
69250 +{
69251 + ino_t ino = dentry->d_inode->i_ino;
69252 + dev_t dev = __get_dev(dentry);
69253 +
69254 + __do_handle_create(matchn, ino, dev);
69255 +
69256 + return;
69257 +}
69258 +
69259 +void
69260 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
69261 +{
69262 + struct name_entry *matchn;
69263 +
69264 + if (unlikely(!(gr_status & GR_READY)))
69265 + return;
69266 +
69267 + preempt_disable();
69268 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
69269 +
69270 + if (unlikely((unsigned long)matchn)) {
69271 + write_lock(&gr_inode_lock);
69272 + do_handle_create(matchn, dentry, mnt);
69273 + write_unlock(&gr_inode_lock);
69274 + }
69275 + preempt_enable();
69276 +
69277 + return;
69278 +}
69279 +
69280 +void
69281 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
69282 +{
69283 + struct name_entry *matchn;
69284 +
69285 + if (unlikely(!(gr_status & GR_READY)))
69286 + return;
69287 +
69288 + preempt_disable();
69289 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
69290 +
69291 + if (unlikely((unsigned long)matchn)) {
69292 + write_lock(&gr_inode_lock);
69293 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
69294 + write_unlock(&gr_inode_lock);
69295 + }
69296 + preempt_enable();
69297 +
69298 + return;
69299 +}
69300 +
69301 +void
69302 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
69303 + struct dentry *old_dentry,
69304 + struct dentry *new_dentry,
69305 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
69306 +{
69307 + struct name_entry *matchn;
69308 + struct name_entry *matchn2 = NULL;
69309 + struct inodev_entry *inodev;
69310 + struct inode *inode = new_dentry->d_inode;
69311 + ino_t old_ino = old_dentry->d_inode->i_ino;
69312 + dev_t old_dev = __get_dev(old_dentry);
69313 + unsigned int exchange = flags & RENAME_EXCHANGE;
69314 +
69315 + /* vfs_rename swaps the name and parent link for old_dentry and
69316 + new_dentry
69317 + at this point, old_dentry has the new name, parent link, and inode
69318 + for the renamed file
69319 + if a file is being replaced by a rename, new_dentry has the inode
69320 + and name for the replaced file
69321 + */
69322 +
69323 + if (unlikely(!(gr_status & GR_READY)))
69324 + return;
69325 +
69326 + preempt_disable();
69327 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
69328 +
69329 + /* exchange cases:
69330 + a filename exists for the source, but not dest
69331 + do a recreate on source
69332 + a filename exists for the dest, but not source
69333 + do a recreate on dest
69334 + a filename exists for both source and dest
69335 + delete source and dest, then create source and dest
69336 + a filename exists for neither source nor dest
69337 + no updates needed
69338 +
69339 + the name entry lookups get us the old inode/dev associated with
69340 + each name, so do the deletes first (if possible) so that when
69341 + we do the create, we pick up on the right entries
69342 + */
69343 +
69344 + if (exchange)
69345 + matchn2 = lookup_name_entry(gr_to_filename_rbac(new_dentry, mnt));
69346 +
69347 + /* we wouldn't have to check d_inode if it weren't for
69348 + NFS silly-renaming
69349 + */
69350 +
69351 + write_lock(&gr_inode_lock);
69352 + if (unlikely((replace || exchange) && inode)) {
69353 + ino_t new_ino = inode->i_ino;
69354 + dev_t new_dev = __get_dev(new_dentry);
69355 +
69356 + inodev = lookup_inodev_entry(new_ino, new_dev);
69357 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
69358 + do_handle_delete(inodev, new_ino, new_dev);
69359 + }
69360 +
69361 + inodev = lookup_inodev_entry(old_ino, old_dev);
69362 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
69363 + do_handle_delete(inodev, old_ino, old_dev);
69364 +
69365 + if (unlikely(matchn != NULL))
69366 + do_handle_create(matchn, old_dentry, mnt);
69367 +
69368 + if (unlikely(matchn2 != NULL))
69369 + do_handle_create(matchn2, new_dentry, mnt);
69370 +
69371 + write_unlock(&gr_inode_lock);
69372 + preempt_enable();
69373 +
69374 + return;
69375 +}
69376 +
69377 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
69378 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
69379 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
69380 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
69381 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
69382 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
69383 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
69384 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
69385 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
69386 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
69387 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
69388 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
69389 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
69390 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
69391 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
69392 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
69393 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
69394 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
69395 +};
69396 +
69397 +void
69398 +gr_learn_resource(const struct task_struct *task,
69399 + const int res, const unsigned long wanted, const int gt)
69400 +{
69401 + struct acl_subject_label *acl;
69402 + const struct cred *cred;
69403 +
69404 + if (unlikely((gr_status & GR_READY) &&
69405 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
69406 + goto skip_reslog;
69407 +
69408 + gr_log_resource(task, res, wanted, gt);
69409 +skip_reslog:
69410 +
69411 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
69412 + return;
69413 +
69414 + acl = task->acl;
69415 +
69416 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
69417 + !(acl->resmask & (1U << (unsigned short) res))))
69418 + return;
69419 +
69420 + if (wanted >= acl->res[res].rlim_cur) {
69421 + unsigned long res_add;
69422 +
69423 + res_add = wanted + res_learn_bumps[res];
69424 +
69425 + acl->res[res].rlim_cur = res_add;
69426 +
69427 + if (wanted > acl->res[res].rlim_max)
69428 + acl->res[res].rlim_max = res_add;
69429 +
69430 + /* only log the subject filename, since resource logging is supported for
69431 + single-subject learning only */
69432 + rcu_read_lock();
69433 + cred = __task_cred(task);
69434 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
69435 + task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
69436 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
69437 + "", (unsigned long) res, &task->signal->saved_ip);
69438 + rcu_read_unlock();
69439 + }
69440 +
69441 + return;
69442 +}
69443 +EXPORT_SYMBOL_GPL(gr_learn_resource);
69444 +#endif
69445 +
69446 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
69447 +void
69448 +pax_set_initial_flags(struct linux_binprm *bprm)
69449 +{
69450 + struct task_struct *task = current;
69451 + struct acl_subject_label *proc;
69452 + unsigned long flags;
69453 +
69454 + if (unlikely(!(gr_status & GR_READY)))
69455 + return;
69456 +
69457 + flags = pax_get_flags(task);
69458 +
69459 + proc = task->acl;
69460 +
69461 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
69462 + flags &= ~MF_PAX_PAGEEXEC;
69463 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
69464 + flags &= ~MF_PAX_SEGMEXEC;
69465 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
69466 + flags &= ~MF_PAX_RANDMMAP;
69467 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
69468 + flags &= ~MF_PAX_EMUTRAMP;
69469 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
69470 + flags &= ~MF_PAX_MPROTECT;
69471 +
69472 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
69473 + flags |= MF_PAX_PAGEEXEC;
69474 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
69475 + flags |= MF_PAX_SEGMEXEC;
69476 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
69477 + flags |= MF_PAX_RANDMMAP;
69478 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
69479 + flags |= MF_PAX_EMUTRAMP;
69480 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
69481 + flags |= MF_PAX_MPROTECT;
69482 +
69483 + pax_set_flags(task, flags);
69484 +
69485 + return;
69486 +}
69487 +#endif
69488 +
69489 +int
69490 +gr_handle_proc_ptrace(struct task_struct *task)
69491 +{
69492 + struct file *filp;
69493 + struct task_struct *tmp = task;
69494 + struct task_struct *curtemp = current;
69495 + __u32 retmode;
69496 +
69497 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
69498 + if (unlikely(!(gr_status & GR_READY)))
69499 + return 0;
69500 +#endif
69501 +
69502 + read_lock(&tasklist_lock);
69503 + read_lock(&grsec_exec_file_lock);
69504 + filp = task->exec_file;
69505 +
69506 + while (task_pid_nr(tmp) > 0) {
69507 + if (tmp == curtemp)
69508 + break;
69509 + tmp = tmp->real_parent;
69510 + }
69511 +
69512 + if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
69513 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
69514 + read_unlock(&grsec_exec_file_lock);
69515 + read_unlock(&tasklist_lock);
69516 + return 1;
69517 + }
69518 +
69519 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69520 + if (!(gr_status & GR_READY)) {
69521 + read_unlock(&grsec_exec_file_lock);
69522 + read_unlock(&tasklist_lock);
69523 + return 0;
69524 + }
69525 +#endif
69526 +
69527 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
69528 + read_unlock(&grsec_exec_file_lock);
69529 + read_unlock(&tasklist_lock);
69530 +
69531 + if (retmode & GR_NOPTRACE)
69532 + return 1;
69533 +
69534 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
69535 + && (current->acl != task->acl || (current->acl != current->role->root_label
69536 + && task_pid_nr(current) != task_pid_nr(task))))
69537 + return 1;
69538 +
69539 + return 0;
69540 +}
69541 +
69542 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
69543 +{
69544 + if (unlikely(!(gr_status & GR_READY)))
69545 + return;
69546 +
69547 + if (!(current->role->roletype & GR_ROLE_GOD))
69548 + return;
69549 +
69550 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
69551 + p->role->rolename, gr_task_roletype_to_char(p),
69552 + p->acl->filename);
69553 +}
69554 +
69555 +int
69556 +gr_handle_ptrace(struct task_struct *task, const long request)
69557 +{
69558 + struct task_struct *tmp = task;
69559 + struct task_struct *curtemp = current;
69560 + __u32 retmode;
69561 +
69562 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
69563 + if (unlikely(!(gr_status & GR_READY)))
69564 + return 0;
69565 +#endif
69566 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69567 + read_lock(&tasklist_lock);
69568 + while (task_pid_nr(tmp) > 0) {
69569 + if (tmp == curtemp)
69570 + break;
69571 + tmp = tmp->real_parent;
69572 + }
69573 +
69574 + if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
69575 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
69576 + read_unlock(&tasklist_lock);
69577 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69578 + return 1;
69579 + }
69580 + read_unlock(&tasklist_lock);
69581 + }
69582 +
69583 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69584 + if (!(gr_status & GR_READY))
69585 + return 0;
69586 +#endif
69587 +
69588 + read_lock(&grsec_exec_file_lock);
69589 + if (unlikely(!task->exec_file)) {
69590 + read_unlock(&grsec_exec_file_lock);
69591 + return 0;
69592 + }
69593 +
69594 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
69595 + read_unlock(&grsec_exec_file_lock);
69596 +
69597 + if (retmode & GR_NOPTRACE) {
69598 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69599 + return 1;
69600 + }
69601 +
69602 + if (retmode & GR_PTRACERD) {
69603 + switch (request) {
69604 + case PTRACE_SEIZE:
69605 + case PTRACE_POKETEXT:
69606 + case PTRACE_POKEDATA:
69607 + case PTRACE_POKEUSR:
69608 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
69609 + case PTRACE_SETREGS:
69610 + case PTRACE_SETFPREGS:
69611 +#endif
69612 +#ifdef CONFIG_X86
69613 + case PTRACE_SETFPXREGS:
69614 +#endif
69615 +#ifdef CONFIG_ALTIVEC
69616 + case PTRACE_SETVRREGS:
69617 +#endif
69618 + return 1;
69619 + default:
69620 + return 0;
69621 + }
69622 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
69623 + !(current->role->roletype & GR_ROLE_GOD) &&
69624 + (current->acl != task->acl)) {
69625 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69626 + return 1;
69627 + }
69628 +
69629 + return 0;
69630 +}
69631 +
69632 +static int is_writable_mmap(const struct file *filp)
69633 +{
69634 + struct task_struct *task = current;
69635 + struct acl_object_label *obj, *obj2;
69636 +
69637 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
69638 + !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))) {
69639 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
69640 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
69641 + task->role->root_label);
69642 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
69643 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
69644 + return 1;
69645 + }
69646 + }
69647 + return 0;
69648 +}
69649 +
69650 +int
69651 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
69652 +{
69653 + __u32 mode;
69654 +
69655 + if (unlikely(!file || !(prot & PROT_EXEC)))
69656 + return 1;
69657 +
69658 + if (is_writable_mmap(file))
69659 + return 0;
69660 +
69661 + mode =
69662 + gr_search_file(file->f_path.dentry,
69663 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69664 + file->f_path.mnt);
69665 +
69666 + if (!gr_tpe_allow(file))
69667 + return 0;
69668 +
69669 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69670 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69671 + return 0;
69672 + } else if (unlikely(!(mode & GR_EXEC))) {
69673 + return 0;
69674 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69675 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69676 + return 1;
69677 + }
69678 +
69679 + return 1;
69680 +}
69681 +
69682 +int
69683 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
69684 +{
69685 + __u32 mode;
69686 +
69687 + if (unlikely(!file || !(prot & PROT_EXEC)))
69688 + return 1;
69689 +
69690 + if (is_writable_mmap(file))
69691 + return 0;
69692 +
69693 + mode =
69694 + gr_search_file(file->f_path.dentry,
69695 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69696 + file->f_path.mnt);
69697 +
69698 + if (!gr_tpe_allow(file))
69699 + return 0;
69700 +
69701 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69702 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69703 + return 0;
69704 + } else if (unlikely(!(mode & GR_EXEC))) {
69705 + return 0;
69706 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69707 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69708 + return 1;
69709 + }
69710 +
69711 + return 1;
69712 +}
69713 +
69714 +void
69715 +gr_acl_handle_psacct(struct task_struct *task, const long code)
69716 +{
69717 + unsigned long runtime, cputime;
69718 + cputime_t utime, stime;
69719 + unsigned int wday, cday;
69720 + __u8 whr, chr;
69721 + __u8 wmin, cmin;
69722 + __u8 wsec, csec;
69723 + struct timespec timeval;
69724 +
69725 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
69726 + !(task->acl->mode & GR_PROCACCT)))
69727 + return;
69728 +
69729 + do_posix_clock_monotonic_gettime(&timeval);
69730 + runtime = timeval.tv_sec - task->start_time.tv_sec;
69731 + wday = runtime / (60 * 60 * 24);
69732 + runtime -= wday * (60 * 60 * 24);
69733 + whr = runtime / (60 * 60);
69734 + runtime -= whr * (60 * 60);
69735 + wmin = runtime / 60;
69736 + runtime -= wmin * 60;
69737 + wsec = runtime;
69738 +
69739 + task_cputime(task, &utime, &stime);
69740 + cputime = cputime_to_secs(utime + stime);
69741 + cday = cputime / (60 * 60 * 24);
69742 + cputime -= cday * (60 * 60 * 24);
69743 + chr = cputime / (60 * 60);
69744 + cputime -= chr * (60 * 60);
69745 + cmin = cputime / 60;
69746 + cputime -= cmin * 60;
69747 + csec = cputime;
69748 +
69749 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
69750 +
69751 + return;
69752 +}
69753 +
69754 +#ifdef CONFIG_TASKSTATS
69755 +int gr_is_taskstats_denied(int pid)
69756 +{
69757 + struct task_struct *task;
69758 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69759 + const struct cred *cred;
69760 +#endif
69761 + int ret = 0;
69762 +
69763 + /* restrict taskstats viewing to un-chrooted root users
69764 + who have the 'view' subject flag if the RBAC system is enabled
69765 + */
69766 +
69767 + rcu_read_lock();
69768 + read_lock(&tasklist_lock);
69769 + task = find_task_by_vpid(pid);
69770 + if (task) {
69771 +#ifdef CONFIG_GRKERNSEC_CHROOT
69772 + if (proc_is_chrooted(task))
69773 + ret = -EACCES;
69774 +#endif
69775 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69776 + cred = __task_cred(task);
69777 +#ifdef CONFIG_GRKERNSEC_PROC_USER
69778 + if (gr_is_global_nonroot(cred->uid))
69779 + ret = -EACCES;
69780 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69781 + if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
69782 + ret = -EACCES;
69783 +#endif
69784 +#endif
69785 + if (gr_status & GR_READY) {
69786 + if (!(task->acl->mode & GR_VIEW))
69787 + ret = -EACCES;
69788 + }
69789 + } else
69790 + ret = -ENOENT;
69791 +
69792 + read_unlock(&tasklist_lock);
69793 + rcu_read_unlock();
69794 +
69795 + return ret;
69796 +}
69797 +#endif
69798 +
69799 +/* AUXV entries are filled via a descendant of search_binary_handler
69800 + after we've already applied the subject for the target
69801 +*/
69802 +int gr_acl_enable_at_secure(void)
69803 +{
69804 + if (unlikely(!(gr_status & GR_READY)))
69805 + return 0;
69806 +
69807 + if (current->acl->mode & GR_ATSECURE)
69808 + return 1;
69809 +
69810 + return 0;
69811 +}
69812 +
69813 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
69814 +{
69815 + struct task_struct *task = current;
69816 + struct dentry *dentry = file->f_path.dentry;
69817 + struct vfsmount *mnt = file->f_path.mnt;
69818 + struct acl_object_label *obj, *tmp;
69819 + struct acl_subject_label *subj;
69820 + unsigned int bufsize;
69821 + int is_not_root;
69822 + char *path;
69823 + dev_t dev = __get_dev(dentry);
69824 +
69825 + if (unlikely(!(gr_status & GR_READY)))
69826 + return 1;
69827 +
69828 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
69829 + return 1;
69830 +
69831 + /* ignore Eric Biederman */
69832 + if (IS_PRIVATE(dentry->d_inode))
69833 + return 1;
69834 +
69835 + subj = task->acl;
69836 + read_lock(&gr_inode_lock);
69837 + do {
69838 + obj = lookup_acl_obj_label(ino, dev, subj);
69839 + if (obj != NULL) {
69840 + read_unlock(&gr_inode_lock);
69841 + return (obj->mode & GR_FIND) ? 1 : 0;
69842 + }
69843 + } while ((subj = subj->parent_subject));
69844 + read_unlock(&gr_inode_lock);
69845 +
69846 + /* this is purely an optimization since we're looking for an object
69847 + for the directory we're doing a readdir on
69848 + if it's possible for any globbed object to match the entry we're
69849 + filling into the directory, then the object we find here will be
69850 + an anchor point with attached globbed objects
69851 + */
69852 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
69853 + if (obj->globbed == NULL)
69854 + return (obj->mode & GR_FIND) ? 1 : 0;
69855 +
69856 + is_not_root = ((obj->filename[0] == '/') &&
69857 + (obj->filename[1] == '\0')) ? 0 : 1;
69858 + bufsize = PAGE_SIZE - namelen - is_not_root;
69859 +
69860 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
69861 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
69862 + return 1;
69863 +
69864 + preempt_disable();
69865 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
69866 + bufsize);
69867 +
69868 + bufsize = strlen(path);
69869 +
69870 + /* if base is "/", don't append an additional slash */
69871 + if (is_not_root)
69872 + *(path + bufsize) = '/';
69873 + memcpy(path + bufsize + is_not_root, name, namelen);
69874 + *(path + bufsize + namelen + is_not_root) = '\0';
69875 +
69876 + tmp = obj->globbed;
69877 + while (tmp) {
69878 + if (!glob_match(tmp->filename, path)) {
69879 + preempt_enable();
69880 + return (tmp->mode & GR_FIND) ? 1 : 0;
69881 + }
69882 + tmp = tmp->next;
69883 + }
69884 + preempt_enable();
69885 + return (obj->mode & GR_FIND) ? 1 : 0;
69886 +}
69887 +
69888 +void gr_put_exec_file(struct task_struct *task)
69889 +{
69890 + struct file *filp;
69891 +
69892 + write_lock(&grsec_exec_file_lock);
69893 + filp = task->exec_file;
69894 + task->exec_file = NULL;
69895 + write_unlock(&grsec_exec_file_lock);
69896 +
69897 + if (filp)
69898 + fput(filp);
69899 +
69900 + return;
69901 +}
69902 +
69903 +
69904 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
69905 +EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
69906 +#endif
69907 +#ifdef CONFIG_SECURITY
69908 +EXPORT_SYMBOL_GPL(gr_check_user_change);
69909 +EXPORT_SYMBOL_GPL(gr_check_group_change);
69910 +#endif
69911 +
69912 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
69913 new file mode 100644
69914 index 0000000..18ffbbd
69915 --- /dev/null
69916 +++ b/grsecurity/gracl_alloc.c
69917 @@ -0,0 +1,105 @@
69918 +#include <linux/kernel.h>
69919 +#include <linux/mm.h>
69920 +#include <linux/slab.h>
69921 +#include <linux/vmalloc.h>
69922 +#include <linux/gracl.h>
69923 +#include <linux/grsecurity.h>
69924 +
69925 +static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
69926 +struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
69927 +
69928 +static __inline__ int
69929 +alloc_pop(void)
69930 +{
69931 + if (current_alloc_state->alloc_stack_next == 1)
69932 + return 0;
69933 +
69934 + kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
69935 +
69936 + current_alloc_state->alloc_stack_next--;
69937 +
69938 + return 1;
69939 +}
69940 +
69941 +static __inline__ int
69942 +alloc_push(void *buf)
69943 +{
69944 + if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
69945 + return 1;
69946 +
69947 + current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
69948 +
69949 + current_alloc_state->alloc_stack_next++;
69950 +
69951 + return 0;
69952 +}
69953 +
69954 +void *
69955 +acl_alloc(unsigned long len)
69956 +{
69957 + void *ret = NULL;
69958 +
69959 + if (!len || len > PAGE_SIZE)
69960 + goto out;
69961 +
69962 + ret = kmalloc(len, GFP_KERNEL);
69963 +
69964 + if (ret) {
69965 + if (alloc_push(ret)) {
69966 + kfree(ret);
69967 + ret = NULL;
69968 + }
69969 + }
69970 +
69971 +out:
69972 + return ret;
69973 +}
69974 +
69975 +void *
69976 +acl_alloc_num(unsigned long num, unsigned long len)
69977 +{
69978 + if (!len || (num > (PAGE_SIZE / len)))
69979 + return NULL;
69980 +
69981 + return acl_alloc(num * len);
69982 +}
69983 +
69984 +void
69985 +acl_free_all(void)
69986 +{
69987 + if (!current_alloc_state->alloc_stack)
69988 + return;
69989 +
69990 + while (alloc_pop()) ;
69991 +
69992 + if (current_alloc_state->alloc_stack) {
69993 + if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
69994 + kfree(current_alloc_state->alloc_stack);
69995 + else
69996 + vfree(current_alloc_state->alloc_stack);
69997 + }
69998 +
69999 + current_alloc_state->alloc_stack = NULL;
70000 + current_alloc_state->alloc_stack_size = 1;
70001 + current_alloc_state->alloc_stack_next = 1;
70002 +
70003 + return;
70004 +}
70005 +
70006 +int
70007 +acl_alloc_stack_init(unsigned long size)
70008 +{
70009 + if ((size * sizeof (void *)) <= PAGE_SIZE)
70010 + current_alloc_state->alloc_stack =
70011 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
70012 + else
70013 + current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
70014 +
70015 + current_alloc_state->alloc_stack_size = size;
70016 + current_alloc_state->alloc_stack_next = 1;
70017 +
70018 + if (!current_alloc_state->alloc_stack)
70019 + return 0;
70020 + else
70021 + return 1;
70022 +}
70023 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
70024 new file mode 100644
70025 index 0000000..bdd51ea
70026 --- /dev/null
70027 +++ b/grsecurity/gracl_cap.c
70028 @@ -0,0 +1,110 @@
70029 +#include <linux/kernel.h>
70030 +#include <linux/module.h>
70031 +#include <linux/sched.h>
70032 +#include <linux/gracl.h>
70033 +#include <linux/grsecurity.h>
70034 +#include <linux/grinternal.h>
70035 +
70036 +extern const char *captab_log[];
70037 +extern int captab_log_entries;
70038 +
70039 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
70040 +{
70041 + struct acl_subject_label *curracl;
70042 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
70043 + kernel_cap_t cap_audit = __cap_empty_set;
70044 +
70045 + if (!gr_acl_is_enabled())
70046 + return 1;
70047 +
70048 + curracl = task->acl;
70049 +
70050 + cap_drop = curracl->cap_lower;
70051 + cap_mask = curracl->cap_mask;
70052 + cap_audit = curracl->cap_invert_audit;
70053 +
70054 + while ((curracl = curracl->parent_subject)) {
70055 + /* if the cap isn't specified in the current computed mask but is specified in the
70056 + current level subject, and is lowered in the current level subject, then add
70057 + it to the set of dropped capabilities
70058 + otherwise, add the current level subject's mask to the current computed mask
70059 + */
70060 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
70061 + cap_raise(cap_mask, cap);
70062 + if (cap_raised(curracl->cap_lower, cap))
70063 + cap_raise(cap_drop, cap);
70064 + if (cap_raised(curracl->cap_invert_audit, cap))
70065 + cap_raise(cap_audit, cap);
70066 + }
70067 + }
70068 +
70069 + if (!cap_raised(cap_drop, cap)) {
70070 + if (cap_raised(cap_audit, cap))
70071 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
70072 + return 1;
70073 + }
70074 +
70075 + curracl = task->acl;
70076 +
70077 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
70078 + && cap_raised(cred->cap_effective, cap)) {
70079 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
70080 + task->role->roletype, GR_GLOBAL_UID(cred->uid),
70081 + GR_GLOBAL_GID(cred->gid), task->exec_file ?
70082 + gr_to_filename(task->exec_file->f_path.dentry,
70083 + task->exec_file->f_path.mnt) : curracl->filename,
70084 + curracl->filename, 0UL,
70085 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
70086 + return 1;
70087 + }
70088 +
70089 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
70090 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
70091 +
70092 + return 0;
70093 +}
70094 +
70095 +int
70096 +gr_acl_is_capable(const int cap)
70097 +{
70098 + return gr_task_acl_is_capable(current, current_cred(), cap);
70099 +}
70100 +
70101 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
70102 +{
70103 + struct acl_subject_label *curracl;
70104 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
70105 +
70106 + if (!gr_acl_is_enabled())
70107 + return 1;
70108 +
70109 + curracl = task->acl;
70110 +
70111 + cap_drop = curracl->cap_lower;
70112 + cap_mask = curracl->cap_mask;
70113 +
70114 + while ((curracl = curracl->parent_subject)) {
70115 + /* if the cap isn't specified in the current computed mask but is specified in the
70116 + current level subject, and is lowered in the current level subject, then add
70117 + it to the set of dropped capabilities
70118 + otherwise, add the current level subject's mask to the current computed mask
70119 + */
70120 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
70121 + cap_raise(cap_mask, cap);
70122 + if (cap_raised(curracl->cap_lower, cap))
70123 + cap_raise(cap_drop, cap);
70124 + }
70125 + }
70126 +
70127 + if (!cap_raised(cap_drop, cap))
70128 + return 1;
70129 +
70130 + return 0;
70131 +}
70132 +
70133 +int
70134 +gr_acl_is_capable_nolog(const int cap)
70135 +{
70136 + return gr_task_acl_is_capable_nolog(current, cap);
70137 +}
70138 +
70139 diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
70140 new file mode 100644
70141 index 0000000..ca25605
70142 --- /dev/null
70143 +++ b/grsecurity/gracl_compat.c
70144 @@ -0,0 +1,270 @@
70145 +#include <linux/kernel.h>
70146 +#include <linux/gracl.h>
70147 +#include <linux/compat.h>
70148 +#include <linux/gracl_compat.h>
70149 +
70150 +#include <asm/uaccess.h>
70151 +
70152 +int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
70153 +{
70154 + struct gr_arg_wrapper_compat uwrapcompat;
70155 +
70156 + if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
70157 + return -EFAULT;
70158 +
70159 + if (((uwrapcompat.version != GRSECURITY_VERSION) &&
70160 + (uwrapcompat.version != 0x2901)) ||
70161 + (uwrapcompat.size != sizeof(struct gr_arg_compat)))
70162 + return -EINVAL;
70163 +
70164 + uwrap->arg = compat_ptr(uwrapcompat.arg);
70165 + uwrap->version = uwrapcompat.version;
70166 + uwrap->size = sizeof(struct gr_arg);
70167 +
70168 + return 0;
70169 +}
70170 +
70171 +int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
70172 +{
70173 + struct gr_arg_compat argcompat;
70174 +
70175 + if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
70176 + return -EFAULT;
70177 +
70178 + arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
70179 + arg->role_db.num_pointers = argcompat.role_db.num_pointers;
70180 + arg->role_db.num_roles = argcompat.role_db.num_roles;
70181 + arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
70182 + arg->role_db.num_subjects = argcompat.role_db.num_subjects;
70183 + arg->role_db.num_objects = argcompat.role_db.num_objects;
70184 +
70185 + memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
70186 + memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
70187 + memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
70188 + memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
70189 + arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
70190 + arg->segv_device = argcompat.segv_device;
70191 + arg->segv_inode = argcompat.segv_inode;
70192 + arg->segv_uid = argcompat.segv_uid;
70193 + arg->num_sprole_pws = argcompat.num_sprole_pws;
70194 + arg->mode = argcompat.mode;
70195 +
70196 + return 0;
70197 +}
70198 +
70199 +int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
70200 +{
70201 + struct acl_object_label_compat objcompat;
70202 +
70203 + if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
70204 + return -EFAULT;
70205 +
70206 + obj->filename = compat_ptr(objcompat.filename);
70207 + obj->inode = objcompat.inode;
70208 + obj->device = objcompat.device;
70209 + obj->mode = objcompat.mode;
70210 +
70211 + obj->nested = compat_ptr(objcompat.nested);
70212 + obj->globbed = compat_ptr(objcompat.globbed);
70213 +
70214 + obj->prev = compat_ptr(objcompat.prev);
70215 + obj->next = compat_ptr(objcompat.next);
70216 +
70217 + return 0;
70218 +}
70219 +
70220 +int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
70221 +{
70222 + unsigned int i;
70223 + struct acl_subject_label_compat subjcompat;
70224 +
70225 + if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
70226 + return -EFAULT;
70227 +
70228 + subj->filename = compat_ptr(subjcompat.filename);
70229 + subj->inode = subjcompat.inode;
70230 + subj->device = subjcompat.device;
70231 + subj->mode = subjcompat.mode;
70232 + subj->cap_mask = subjcompat.cap_mask;
70233 + subj->cap_lower = subjcompat.cap_lower;
70234 + subj->cap_invert_audit = subjcompat.cap_invert_audit;
70235 +
70236 + for (i = 0; i < GR_NLIMITS; i++) {
70237 + if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
70238 + subj->res[i].rlim_cur = RLIM_INFINITY;
70239 + else
70240 + subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
70241 + if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
70242 + subj->res[i].rlim_max = RLIM_INFINITY;
70243 + else
70244 + subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
70245 + }
70246 + subj->resmask = subjcompat.resmask;
70247 +
70248 + subj->user_trans_type = subjcompat.user_trans_type;
70249 + subj->group_trans_type = subjcompat.group_trans_type;
70250 + subj->user_transitions = compat_ptr(subjcompat.user_transitions);
70251 + subj->group_transitions = compat_ptr(subjcompat.group_transitions);
70252 + subj->user_trans_num = subjcompat.user_trans_num;
70253 + subj->group_trans_num = subjcompat.group_trans_num;
70254 +
70255 + memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
70256 + memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
70257 + subj->ip_type = subjcompat.ip_type;
70258 + subj->ips = compat_ptr(subjcompat.ips);
70259 + subj->ip_num = subjcompat.ip_num;
70260 + subj->inaddr_any_override = subjcompat.inaddr_any_override;
70261 +
70262 + subj->crashes = subjcompat.crashes;
70263 + subj->expires = subjcompat.expires;
70264 +
70265 + subj->parent_subject = compat_ptr(subjcompat.parent_subject);
70266 + subj->hash = compat_ptr(subjcompat.hash);
70267 + subj->prev = compat_ptr(subjcompat.prev);
70268 + subj->next = compat_ptr(subjcompat.next);
70269 +
70270 + subj->obj_hash = compat_ptr(subjcompat.obj_hash);
70271 + subj->obj_hash_size = subjcompat.obj_hash_size;
70272 + subj->pax_flags = subjcompat.pax_flags;
70273 +
70274 + return 0;
70275 +}
70276 +
70277 +int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
70278 +{
70279 + struct acl_role_label_compat rolecompat;
70280 +
70281 + if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
70282 + return -EFAULT;
70283 +
70284 + role->rolename = compat_ptr(rolecompat.rolename);
70285 + role->uidgid = rolecompat.uidgid;
70286 + role->roletype = rolecompat.roletype;
70287 +
70288 + role->auth_attempts = rolecompat.auth_attempts;
70289 + role->expires = rolecompat.expires;
70290 +
70291 + role->root_label = compat_ptr(rolecompat.root_label);
70292 + role->hash = compat_ptr(rolecompat.hash);
70293 +
70294 + role->prev = compat_ptr(rolecompat.prev);
70295 + role->next = compat_ptr(rolecompat.next);
70296 +
70297 + role->transitions = compat_ptr(rolecompat.transitions);
70298 + role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
70299 + role->domain_children = compat_ptr(rolecompat.domain_children);
70300 + role->domain_child_num = rolecompat.domain_child_num;
70301 +
70302 + role->umask = rolecompat.umask;
70303 +
70304 + role->subj_hash = compat_ptr(rolecompat.subj_hash);
70305 + role->subj_hash_size = rolecompat.subj_hash_size;
70306 +
70307 + return 0;
70308 +}
70309 +
70310 +int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
70311 +{
70312 + struct role_allowed_ip_compat roleip_compat;
70313 +
70314 + if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
70315 + return -EFAULT;
70316 +
70317 + roleip->addr = roleip_compat.addr;
70318 + roleip->netmask = roleip_compat.netmask;
70319 +
70320 + roleip->prev = compat_ptr(roleip_compat.prev);
70321 + roleip->next = compat_ptr(roleip_compat.next);
70322 +
70323 + return 0;
70324 +}
70325 +
70326 +int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
70327 +{
70328 + struct role_transition_compat trans_compat;
70329 +
70330 + if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
70331 + return -EFAULT;
70332 +
70333 + trans->rolename = compat_ptr(trans_compat.rolename);
70334 +
70335 + trans->prev = compat_ptr(trans_compat.prev);
70336 + trans->next = compat_ptr(trans_compat.next);
70337 +
70338 + return 0;
70339 +
70340 +}
70341 +
70342 +int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
70343 +{
70344 + struct gr_hash_struct_compat hash_compat;
70345 +
70346 + if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
70347 + return -EFAULT;
70348 +
70349 + hash->table = compat_ptr(hash_compat.table);
70350 + hash->nametable = compat_ptr(hash_compat.nametable);
70351 + hash->first = compat_ptr(hash_compat.first);
70352 +
70353 + hash->table_size = hash_compat.table_size;
70354 + hash->used_size = hash_compat.used_size;
70355 +
70356 + hash->type = hash_compat.type;
70357 +
70358 + return 0;
70359 +}
70360 +
70361 +int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
70362 +{
70363 + compat_uptr_t ptrcompat;
70364 +
70365 + if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
70366 + return -EFAULT;
70367 +
70368 + *(void **)ptr = compat_ptr(ptrcompat);
70369 +
70370 + return 0;
70371 +}
70372 +
70373 +int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
70374 +{
70375 + struct acl_ip_label_compat ip_compat;
70376 +
70377 + if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
70378 + return -EFAULT;
70379 +
70380 + ip->iface = compat_ptr(ip_compat.iface);
70381 + ip->addr = ip_compat.addr;
70382 + ip->netmask = ip_compat.netmask;
70383 + ip->low = ip_compat.low;
70384 + ip->high = ip_compat.high;
70385 + ip->mode = ip_compat.mode;
70386 + ip->type = ip_compat.type;
70387 +
70388 + memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
70389 +
70390 + ip->prev = compat_ptr(ip_compat.prev);
70391 + ip->next = compat_ptr(ip_compat.next);
70392 +
70393 + return 0;
70394 +}
70395 +
70396 +int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
70397 +{
70398 + struct sprole_pw_compat pw_compat;
70399 +
70400 + if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
70401 + return -EFAULT;
70402 +
70403 + pw->rolename = compat_ptr(pw_compat.rolename);
70404 + memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
70405 + memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
70406 +
70407 + return 0;
70408 +}
70409 +
70410 +size_t get_gr_arg_wrapper_size_compat(void)
70411 +{
70412 + return sizeof(struct gr_arg_wrapper_compat);
70413 +}
70414 +
70415 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
70416 new file mode 100644
70417 index 0000000..4008fdc
70418 --- /dev/null
70419 +++ b/grsecurity/gracl_fs.c
70420 @@ -0,0 +1,445 @@
70421 +#include <linux/kernel.h>
70422 +#include <linux/sched.h>
70423 +#include <linux/types.h>
70424 +#include <linux/fs.h>
70425 +#include <linux/file.h>
70426 +#include <linux/stat.h>
70427 +#include <linux/grsecurity.h>
70428 +#include <linux/grinternal.h>
70429 +#include <linux/gracl.h>
70430 +
70431 +umode_t
70432 +gr_acl_umask(void)
70433 +{
70434 + if (unlikely(!gr_acl_is_enabled()))
70435 + return 0;
70436 +
70437 + return current->role->umask;
70438 +}
70439 +
70440 +__u32
70441 +gr_acl_handle_hidden_file(const struct dentry * dentry,
70442 + const struct vfsmount * mnt)
70443 +{
70444 + __u32 mode;
70445 +
70446 + if (unlikely(d_is_negative(dentry)))
70447 + return GR_FIND;
70448 +
70449 + mode =
70450 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
70451 +
70452 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
70453 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
70454 + return mode;
70455 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
70456 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
70457 + return 0;
70458 + } else if (unlikely(!(mode & GR_FIND)))
70459 + return 0;
70460 +
70461 + return GR_FIND;
70462 +}
70463 +
70464 +__u32
70465 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
70466 + int acc_mode)
70467 +{
70468 + __u32 reqmode = GR_FIND;
70469 + __u32 mode;
70470 +
70471 + if (unlikely(d_is_negative(dentry)))
70472 + return reqmode;
70473 +
70474 + if (acc_mode & MAY_APPEND)
70475 + reqmode |= GR_APPEND;
70476 + else if (acc_mode & MAY_WRITE)
70477 + reqmode |= GR_WRITE;
70478 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
70479 + reqmode |= GR_READ;
70480 +
70481 + mode =
70482 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
70483 + mnt);
70484 +
70485 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70486 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
70487 + reqmode & GR_READ ? " reading" : "",
70488 + reqmode & GR_WRITE ? " writing" : reqmode &
70489 + GR_APPEND ? " appending" : "");
70490 + return reqmode;
70491 + } else
70492 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70493 + {
70494 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
70495 + reqmode & GR_READ ? " reading" : "",
70496 + reqmode & GR_WRITE ? " writing" : reqmode &
70497 + GR_APPEND ? " appending" : "");
70498 + return 0;
70499 + } else if (unlikely((mode & reqmode) != reqmode))
70500 + return 0;
70501 +
70502 + return reqmode;
70503 +}
70504 +
70505 +__u32
70506 +gr_acl_handle_creat(const struct dentry * dentry,
70507 + const struct dentry * p_dentry,
70508 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
70509 + const int imode)
70510 +{
70511 + __u32 reqmode = GR_WRITE | GR_CREATE;
70512 + __u32 mode;
70513 +
70514 + if (acc_mode & MAY_APPEND)
70515 + reqmode |= GR_APPEND;
70516 + // if a directory was required or the directory already exists, then
70517 + // don't count this open as a read
70518 + if ((acc_mode & MAY_READ) &&
70519 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
70520 + reqmode |= GR_READ;
70521 + if ((open_flags & O_CREAT) &&
70522 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
70523 + reqmode |= GR_SETID;
70524 +
70525 + mode =
70526 + gr_check_create(dentry, p_dentry, p_mnt,
70527 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
70528 +
70529 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70530 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
70531 + reqmode & GR_READ ? " reading" : "",
70532 + reqmode & GR_WRITE ? " writing" : reqmode &
70533 + GR_APPEND ? " appending" : "");
70534 + return reqmode;
70535 + } else
70536 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70537 + {
70538 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
70539 + reqmode & GR_READ ? " reading" : "",
70540 + reqmode & GR_WRITE ? " writing" : reqmode &
70541 + GR_APPEND ? " appending" : "");
70542 + return 0;
70543 + } else if (unlikely((mode & reqmode) != reqmode))
70544 + return 0;
70545 +
70546 + return reqmode;
70547 +}
70548 +
70549 +__u32
70550 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
70551 + const int fmode)
70552 +{
70553 + __u32 mode, reqmode = GR_FIND;
70554 +
70555 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
70556 + reqmode |= GR_EXEC;
70557 + if (fmode & S_IWOTH)
70558 + reqmode |= GR_WRITE;
70559 + if (fmode & S_IROTH)
70560 + reqmode |= GR_READ;
70561 +
70562 + mode =
70563 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
70564 + mnt);
70565 +
70566 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70567 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
70568 + reqmode & GR_READ ? " reading" : "",
70569 + reqmode & GR_WRITE ? " writing" : "",
70570 + reqmode & GR_EXEC ? " executing" : "");
70571 + return reqmode;
70572 + } else
70573 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70574 + {
70575 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
70576 + reqmode & GR_READ ? " reading" : "",
70577 + reqmode & GR_WRITE ? " writing" : "",
70578 + reqmode & GR_EXEC ? " executing" : "");
70579 + return 0;
70580 + } else if (unlikely((mode & reqmode) != reqmode))
70581 + return 0;
70582 +
70583 + return reqmode;
70584 +}
70585 +
70586 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
70587 +{
70588 + __u32 mode;
70589 +
70590 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
70591 +
70592 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
70593 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
70594 + return mode;
70595 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
70596 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
70597 + return 0;
70598 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
70599 + return 0;
70600 +
70601 + return (reqmode);
70602 +}
70603 +
70604 +__u32
70605 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
70606 +{
70607 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
70608 +}
70609 +
70610 +__u32
70611 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
70612 +{
70613 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
70614 +}
70615 +
70616 +__u32
70617 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
70618 +{
70619 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
70620 +}
70621 +
70622 +__u32
70623 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
70624 +{
70625 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
70626 +}
70627 +
70628 +__u32
70629 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
70630 + umode_t *modeptr)
70631 +{
70632 + umode_t mode;
70633 +
70634 + *modeptr &= ~gr_acl_umask();
70635 + mode = *modeptr;
70636 +
70637 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
70638 + return 1;
70639 +
70640 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
70641 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
70642 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
70643 + GR_CHMOD_ACL_MSG);
70644 + } else {
70645 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
70646 + }
70647 +}
70648 +
70649 +__u32
70650 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
70651 +{
70652 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
70653 +}
70654 +
70655 +__u32
70656 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
70657 +{
70658 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
70659 +}
70660 +
70661 +__u32
70662 +gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
70663 +{
70664 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
70665 +}
70666 +
70667 +__u32
70668 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
70669 +{
70670 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
70671 +}
70672 +
70673 +__u32
70674 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
70675 +{
70676 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
70677 + GR_UNIXCONNECT_ACL_MSG);
70678 +}
70679 +
70680 +/* hardlinks require at minimum create and link permission,
70681 + any additional privilege required is based on the
70682 + privilege of the file being linked to
70683 +*/
70684 +__u32
70685 +gr_acl_handle_link(const struct dentry * new_dentry,
70686 + const struct dentry * parent_dentry,
70687 + const struct vfsmount * parent_mnt,
70688 + const struct dentry * old_dentry,
70689 + const struct vfsmount * old_mnt, const struct filename *to)
70690 +{
70691 + __u32 mode;
70692 + __u32 needmode = GR_CREATE | GR_LINK;
70693 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
70694 +
70695 + mode =
70696 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
70697 + old_mnt);
70698 +
70699 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
70700 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70701 + return mode;
70702 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
70703 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70704 + return 0;
70705 + } else if (unlikely((mode & needmode) != needmode))
70706 + return 0;
70707 +
70708 + return 1;
70709 +}
70710 +
70711 +__u32
70712 +gr_acl_handle_symlink(const struct dentry * new_dentry,
70713 + const struct dentry * parent_dentry,
70714 + const struct vfsmount * parent_mnt, const struct filename *from)
70715 +{
70716 + __u32 needmode = GR_WRITE | GR_CREATE;
70717 + __u32 mode;
70718 +
70719 + mode =
70720 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
70721 + GR_CREATE | GR_AUDIT_CREATE |
70722 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
70723 +
70724 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
70725 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
70726 + return mode;
70727 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
70728 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
70729 + return 0;
70730 + } else if (unlikely((mode & needmode) != needmode))
70731 + return 0;
70732 +
70733 + return (GR_WRITE | GR_CREATE);
70734 +}
70735 +
70736 +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)
70737 +{
70738 + __u32 mode;
70739 +
70740 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
70741 +
70742 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
70743 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
70744 + return mode;
70745 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
70746 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
70747 + return 0;
70748 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
70749 + return 0;
70750 +
70751 + return (reqmode);
70752 +}
70753 +
70754 +__u32
70755 +gr_acl_handle_mknod(const struct dentry * new_dentry,
70756 + const struct dentry * parent_dentry,
70757 + const struct vfsmount * parent_mnt,
70758 + const int mode)
70759 +{
70760 + __u32 reqmode = GR_WRITE | GR_CREATE;
70761 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
70762 + reqmode |= GR_SETID;
70763 +
70764 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
70765 + reqmode, GR_MKNOD_ACL_MSG);
70766 +}
70767 +
70768 +__u32
70769 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
70770 + const struct dentry *parent_dentry,
70771 + const struct vfsmount *parent_mnt)
70772 +{
70773 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
70774 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
70775 +}
70776 +
70777 +#define RENAME_CHECK_SUCCESS(old, new) \
70778 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
70779 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
70780 +
70781 +int
70782 +gr_acl_handle_rename(struct dentry *new_dentry,
70783 + struct dentry *parent_dentry,
70784 + const struct vfsmount *parent_mnt,
70785 + struct dentry *old_dentry,
70786 + struct inode *old_parent_inode,
70787 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags)
70788 +{
70789 + __u32 comp1, comp2;
70790 + int error = 0;
70791 +
70792 + if (unlikely(!gr_acl_is_enabled()))
70793 + return 0;
70794 +
70795 + if (flags & RENAME_EXCHANGE) {
70796 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
70797 + GR_AUDIT_READ | GR_AUDIT_WRITE |
70798 + GR_SUPPRESS, parent_mnt);
70799 + comp2 =
70800 + gr_search_file(old_dentry,
70801 + GR_READ | GR_WRITE | GR_AUDIT_READ |
70802 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
70803 + } else if (d_is_negative(new_dentry)) {
70804 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
70805 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
70806 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
70807 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
70808 + GR_DELETE | GR_AUDIT_DELETE |
70809 + GR_AUDIT_READ | GR_AUDIT_WRITE |
70810 + GR_SUPPRESS, old_mnt);
70811 + } else {
70812 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
70813 + GR_CREATE | GR_DELETE |
70814 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
70815 + GR_AUDIT_READ | GR_AUDIT_WRITE |
70816 + GR_SUPPRESS, parent_mnt);
70817 + comp2 =
70818 + gr_search_file(old_dentry,
70819 + GR_READ | GR_WRITE | GR_AUDIT_READ |
70820 + GR_DELETE | GR_AUDIT_DELETE |
70821 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
70822 + }
70823 +
70824 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
70825 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
70826 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70827 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
70828 + && !(comp2 & GR_SUPPRESS)) {
70829 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70830 + error = -EACCES;
70831 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
70832 + error = -EACCES;
70833 +
70834 + return error;
70835 +}
70836 +
70837 +void
70838 +gr_acl_handle_exit(void)
70839 +{
70840 + u16 id;
70841 + char *rolename;
70842 +
70843 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
70844 + !(current->role->roletype & GR_ROLE_PERSIST))) {
70845 + id = current->acl_role_id;
70846 + rolename = current->role->rolename;
70847 + gr_set_acls(1);
70848 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
70849 + }
70850 +
70851 + gr_put_exec_file(current);
70852 + return;
70853 +}
70854 +
70855 +int
70856 +gr_acl_handle_procpidmem(const struct task_struct *task)
70857 +{
70858 + if (unlikely(!gr_acl_is_enabled()))
70859 + return 0;
70860 +
70861 + if (task != current && task->acl->mode & GR_PROTPROCFD)
70862 + return -EACCES;
70863 +
70864 + return 0;
70865 +}
70866 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
70867 new file mode 100644
70868 index 0000000..f056b81
70869 --- /dev/null
70870 +++ b/grsecurity/gracl_ip.c
70871 @@ -0,0 +1,386 @@
70872 +#include <linux/kernel.h>
70873 +#include <asm/uaccess.h>
70874 +#include <asm/errno.h>
70875 +#include <net/sock.h>
70876 +#include <linux/file.h>
70877 +#include <linux/fs.h>
70878 +#include <linux/net.h>
70879 +#include <linux/in.h>
70880 +#include <linux/skbuff.h>
70881 +#include <linux/ip.h>
70882 +#include <linux/udp.h>
70883 +#include <linux/types.h>
70884 +#include <linux/sched.h>
70885 +#include <linux/netdevice.h>
70886 +#include <linux/inetdevice.h>
70887 +#include <linux/gracl.h>
70888 +#include <linux/grsecurity.h>
70889 +#include <linux/grinternal.h>
70890 +
70891 +#define GR_BIND 0x01
70892 +#define GR_CONNECT 0x02
70893 +#define GR_INVERT 0x04
70894 +#define GR_BINDOVERRIDE 0x08
70895 +#define GR_CONNECTOVERRIDE 0x10
70896 +#define GR_SOCK_FAMILY 0x20
70897 +
70898 +static const char * gr_protocols[IPPROTO_MAX] = {
70899 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
70900 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
70901 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
70902 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
70903 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
70904 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
70905 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
70906 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
70907 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
70908 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
70909 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
70910 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
70911 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
70912 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
70913 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
70914 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
70915 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
70916 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
70917 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
70918 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
70919 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
70920 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
70921 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
70922 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
70923 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
70924 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
70925 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
70926 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
70927 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
70928 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
70929 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
70930 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
70931 + };
70932 +
70933 +static const char * gr_socktypes[SOCK_MAX] = {
70934 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
70935 + "unknown:7", "unknown:8", "unknown:9", "packet"
70936 + };
70937 +
70938 +static const char * gr_sockfamilies[AF_MAX+1] = {
70939 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
70940 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
70941 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
70942 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
70943 + };
70944 +
70945 +const char *
70946 +gr_proto_to_name(unsigned char proto)
70947 +{
70948 + return gr_protocols[proto];
70949 +}
70950 +
70951 +const char *
70952 +gr_socktype_to_name(unsigned char type)
70953 +{
70954 + return gr_socktypes[type];
70955 +}
70956 +
70957 +const char *
70958 +gr_sockfamily_to_name(unsigned char family)
70959 +{
70960 + return gr_sockfamilies[family];
70961 +}
70962 +
70963 +extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
70964 +
70965 +int
70966 +gr_search_socket(const int domain, const int type, const int protocol)
70967 +{
70968 + struct acl_subject_label *curr;
70969 + const struct cred *cred = current_cred();
70970 +
70971 + if (unlikely(!gr_acl_is_enabled()))
70972 + goto exit;
70973 +
70974 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
70975 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
70976 + goto exit; // let the kernel handle it
70977 +
70978 + curr = current->acl;
70979 +
70980 + if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
70981 + /* the family is allowed, if this is PF_INET allow it only if
70982 + the extra sock type/protocol checks pass */
70983 + if (domain == PF_INET)
70984 + goto inet_check;
70985 + goto exit;
70986 + } else {
70987 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70988 + __u32 fakeip = 0;
70989 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70990 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
70991 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
70992 + gr_to_filename(current->exec_file->f_path.dentry,
70993 + current->exec_file->f_path.mnt) :
70994 + curr->filename, curr->filename,
70995 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
70996 + &current->signal->saved_ip);
70997 + goto exit;
70998 + }
70999 + goto exit_fail;
71000 + }
71001 +
71002 +inet_check:
71003 + /* the rest of this checking is for IPv4 only */
71004 + if (!curr->ips)
71005 + goto exit;
71006 +
71007 + if ((curr->ip_type & (1U << type)) &&
71008 + (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
71009 + goto exit;
71010 +
71011 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
71012 + /* we don't place acls on raw sockets , and sometimes
71013 + dgram/ip sockets are opened for ioctl and not
71014 + bind/connect, so we'll fake a bind learn log */
71015 + if (type == SOCK_RAW || type == SOCK_PACKET) {
71016 + __u32 fakeip = 0;
71017 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
71018 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
71019 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
71020 + gr_to_filename(current->exec_file->f_path.dentry,
71021 + current->exec_file->f_path.mnt) :
71022 + curr->filename, curr->filename,
71023 + &fakeip, 0, type,
71024 + protocol, GR_CONNECT, &current->signal->saved_ip);
71025 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
71026 + __u32 fakeip = 0;
71027 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
71028 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
71029 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
71030 + gr_to_filename(current->exec_file->f_path.dentry,
71031 + current->exec_file->f_path.mnt) :
71032 + curr->filename, curr->filename,
71033 + &fakeip, 0, type,
71034 + protocol, GR_BIND, &current->signal->saved_ip);
71035 + }
71036 + /* we'll log when they use connect or bind */
71037 + goto exit;
71038 + }
71039 +
71040 +exit_fail:
71041 + if (domain == PF_INET)
71042 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
71043 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
71044 + else if (rcu_access_pointer(net_families[domain]) != NULL)
71045 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
71046 + gr_socktype_to_name(type), protocol);
71047 +
71048 + return 0;
71049 +exit:
71050 + return 1;
71051 +}
71052 +
71053 +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)
71054 +{
71055 + if ((ip->mode & mode) &&
71056 + (ip_port >= ip->low) &&
71057 + (ip_port <= ip->high) &&
71058 + ((ntohl(ip_addr) & our_netmask) ==
71059 + (ntohl(our_addr) & our_netmask))
71060 + && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
71061 + && (ip->type & (1U << type))) {
71062 + if (ip->mode & GR_INVERT)
71063 + return 2; // specifically denied
71064 + else
71065 + return 1; // allowed
71066 + }
71067 +
71068 + return 0; // not specifically allowed, may continue parsing
71069 +}
71070 +
71071 +static int
71072 +gr_search_connectbind(const int full_mode, struct sock *sk,
71073 + struct sockaddr_in *addr, const int type)
71074 +{
71075 + char iface[IFNAMSIZ] = {0};
71076 + struct acl_subject_label *curr;
71077 + struct acl_ip_label *ip;
71078 + struct inet_sock *isk;
71079 + struct net_device *dev;
71080 + struct in_device *idev;
71081 + unsigned long i;
71082 + int ret;
71083 + int mode = full_mode & (GR_BIND | GR_CONNECT);
71084 + __u32 ip_addr = 0;
71085 + __u32 our_addr;
71086 + __u32 our_netmask;
71087 + char *p;
71088 + __u16 ip_port = 0;
71089 + const struct cred *cred = current_cred();
71090 +
71091 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
71092 + return 0;
71093 +
71094 + curr = current->acl;
71095 + isk = inet_sk(sk);
71096 +
71097 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
71098 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
71099 + addr->sin_addr.s_addr = curr->inaddr_any_override;
71100 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
71101 + struct sockaddr_in saddr;
71102 + int err;
71103 +
71104 + saddr.sin_family = AF_INET;
71105 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
71106 + saddr.sin_port = isk->inet_sport;
71107 +
71108 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
71109 + if (err)
71110 + return err;
71111 +
71112 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
71113 + if (err)
71114 + return err;
71115 + }
71116 +
71117 + if (!curr->ips)
71118 + return 0;
71119 +
71120 + ip_addr = addr->sin_addr.s_addr;
71121 + ip_port = ntohs(addr->sin_port);
71122 +
71123 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
71124 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
71125 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
71126 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
71127 + gr_to_filename(current->exec_file->f_path.dentry,
71128 + current->exec_file->f_path.mnt) :
71129 + curr->filename, curr->filename,
71130 + &ip_addr, ip_port, type,
71131 + sk->sk_protocol, mode, &current->signal->saved_ip);
71132 + return 0;
71133 + }
71134 +
71135 + for (i = 0; i < curr->ip_num; i++) {
71136 + ip = *(curr->ips + i);
71137 + if (ip->iface != NULL) {
71138 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
71139 + p = strchr(iface, ':');
71140 + if (p != NULL)
71141 + *p = '\0';
71142 + dev = dev_get_by_name(sock_net(sk), iface);
71143 + if (dev == NULL)
71144 + continue;
71145 + idev = in_dev_get(dev);
71146 + if (idev == NULL) {
71147 + dev_put(dev);
71148 + continue;
71149 + }
71150 + rcu_read_lock();
71151 + for_ifa(idev) {
71152 + if (!strcmp(ip->iface, ifa->ifa_label)) {
71153 + our_addr = ifa->ifa_address;
71154 + our_netmask = 0xffffffff;
71155 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
71156 + if (ret == 1) {
71157 + rcu_read_unlock();
71158 + in_dev_put(idev);
71159 + dev_put(dev);
71160 + return 0;
71161 + } else if (ret == 2) {
71162 + rcu_read_unlock();
71163 + in_dev_put(idev);
71164 + dev_put(dev);
71165 + goto denied;
71166 + }
71167 + }
71168 + } endfor_ifa(idev);
71169 + rcu_read_unlock();
71170 + in_dev_put(idev);
71171 + dev_put(dev);
71172 + } else {
71173 + our_addr = ip->addr;
71174 + our_netmask = ip->netmask;
71175 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
71176 + if (ret == 1)
71177 + return 0;
71178 + else if (ret == 2)
71179 + goto denied;
71180 + }
71181 + }
71182 +
71183 +denied:
71184 + if (mode == GR_BIND)
71185 + 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));
71186 + else if (mode == GR_CONNECT)
71187 + 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));
71188 +
71189 + return -EACCES;
71190 +}
71191 +
71192 +int
71193 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
71194 +{
71195 + /* always allow disconnection of dgram sockets with connect */
71196 + if (addr->sin_family == AF_UNSPEC)
71197 + return 0;
71198 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
71199 +}
71200 +
71201 +int
71202 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
71203 +{
71204 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
71205 +}
71206 +
71207 +int gr_search_listen(struct socket *sock)
71208 +{
71209 + struct sock *sk = sock->sk;
71210 + struct sockaddr_in addr;
71211 +
71212 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
71213 + addr.sin_port = inet_sk(sk)->inet_sport;
71214 +
71215 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
71216 +}
71217 +
71218 +int gr_search_accept(struct socket *sock)
71219 +{
71220 + struct sock *sk = sock->sk;
71221 + struct sockaddr_in addr;
71222 +
71223 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
71224 + addr.sin_port = inet_sk(sk)->inet_sport;
71225 +
71226 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
71227 +}
71228 +
71229 +int
71230 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
71231 +{
71232 + if (addr)
71233 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
71234 + else {
71235 + struct sockaddr_in sin;
71236 + const struct inet_sock *inet = inet_sk(sk);
71237 +
71238 + sin.sin_addr.s_addr = inet->inet_daddr;
71239 + sin.sin_port = inet->inet_dport;
71240 +
71241 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
71242 + }
71243 +}
71244 +
71245 +int
71246 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
71247 +{
71248 + struct sockaddr_in sin;
71249 +
71250 + if (unlikely(skb->len < sizeof (struct udphdr)))
71251 + return 0; // skip this packet
71252 +
71253 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
71254 + sin.sin_port = udp_hdr(skb)->source;
71255 +
71256 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
71257 +}
71258 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
71259 new file mode 100644
71260 index 0000000..25f54ef
71261 --- /dev/null
71262 +++ b/grsecurity/gracl_learn.c
71263 @@ -0,0 +1,207 @@
71264 +#include <linux/kernel.h>
71265 +#include <linux/mm.h>
71266 +#include <linux/sched.h>
71267 +#include <linux/poll.h>
71268 +#include <linux/string.h>
71269 +#include <linux/file.h>
71270 +#include <linux/types.h>
71271 +#include <linux/vmalloc.h>
71272 +#include <linux/grinternal.h>
71273 +
71274 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
71275 + size_t count, loff_t *ppos);
71276 +extern int gr_acl_is_enabled(void);
71277 +
71278 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
71279 +static int gr_learn_attached;
71280 +
71281 +/* use a 512k buffer */
71282 +#define LEARN_BUFFER_SIZE (512 * 1024)
71283 +
71284 +static DEFINE_SPINLOCK(gr_learn_lock);
71285 +static DEFINE_MUTEX(gr_learn_user_mutex);
71286 +
71287 +/* we need to maintain two buffers, so that the kernel context of grlearn
71288 + uses a semaphore around the userspace copying, and the other kernel contexts
71289 + use a spinlock when copying into the buffer, since they cannot sleep
71290 +*/
71291 +static char *learn_buffer;
71292 +static char *learn_buffer_user;
71293 +static int learn_buffer_len;
71294 +static int learn_buffer_user_len;
71295 +
71296 +static ssize_t
71297 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
71298 +{
71299 + DECLARE_WAITQUEUE(wait, current);
71300 + ssize_t retval = 0;
71301 +
71302 + add_wait_queue(&learn_wait, &wait);
71303 + set_current_state(TASK_INTERRUPTIBLE);
71304 + do {
71305 + mutex_lock(&gr_learn_user_mutex);
71306 + spin_lock(&gr_learn_lock);
71307 + if (learn_buffer_len)
71308 + break;
71309 + spin_unlock(&gr_learn_lock);
71310 + mutex_unlock(&gr_learn_user_mutex);
71311 + if (file->f_flags & O_NONBLOCK) {
71312 + retval = -EAGAIN;
71313 + goto out;
71314 + }
71315 + if (signal_pending(current)) {
71316 + retval = -ERESTARTSYS;
71317 + goto out;
71318 + }
71319 +
71320 + schedule();
71321 + } while (1);
71322 +
71323 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
71324 + learn_buffer_user_len = learn_buffer_len;
71325 + retval = learn_buffer_len;
71326 + learn_buffer_len = 0;
71327 +
71328 + spin_unlock(&gr_learn_lock);
71329 +
71330 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
71331 + retval = -EFAULT;
71332 +
71333 + mutex_unlock(&gr_learn_user_mutex);
71334 +out:
71335 + set_current_state(TASK_RUNNING);
71336 + remove_wait_queue(&learn_wait, &wait);
71337 + return retval;
71338 +}
71339 +
71340 +static unsigned int
71341 +poll_learn(struct file * file, poll_table * wait)
71342 +{
71343 + poll_wait(file, &learn_wait, wait);
71344 +
71345 + if (learn_buffer_len)
71346 + return (POLLIN | POLLRDNORM);
71347 +
71348 + return 0;
71349 +}
71350 +
71351 +void
71352 +gr_clear_learn_entries(void)
71353 +{
71354 + char *tmp;
71355 +
71356 + mutex_lock(&gr_learn_user_mutex);
71357 + spin_lock(&gr_learn_lock);
71358 + tmp = learn_buffer;
71359 + learn_buffer = NULL;
71360 + spin_unlock(&gr_learn_lock);
71361 + if (tmp)
71362 + vfree(tmp);
71363 + if (learn_buffer_user != NULL) {
71364 + vfree(learn_buffer_user);
71365 + learn_buffer_user = NULL;
71366 + }
71367 + learn_buffer_len = 0;
71368 + mutex_unlock(&gr_learn_user_mutex);
71369 +
71370 + return;
71371 +}
71372 +
71373 +void
71374 +gr_add_learn_entry(const char *fmt, ...)
71375 +{
71376 + va_list args;
71377 + unsigned int len;
71378 +
71379 + if (!gr_learn_attached)
71380 + return;
71381 +
71382 + spin_lock(&gr_learn_lock);
71383 +
71384 + /* leave a gap at the end so we know when it's "full" but don't have to
71385 + compute the exact length of the string we're trying to append
71386 + */
71387 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
71388 + spin_unlock(&gr_learn_lock);
71389 + wake_up_interruptible(&learn_wait);
71390 + return;
71391 + }
71392 + if (learn_buffer == NULL) {
71393 + spin_unlock(&gr_learn_lock);
71394 + return;
71395 + }
71396 +
71397 + va_start(args, fmt);
71398 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
71399 + va_end(args);
71400 +
71401 + learn_buffer_len += len + 1;
71402 +
71403 + spin_unlock(&gr_learn_lock);
71404 + wake_up_interruptible(&learn_wait);
71405 +
71406 + return;
71407 +}
71408 +
71409 +static int
71410 +open_learn(struct inode *inode, struct file *file)
71411 +{
71412 + if (file->f_mode & FMODE_READ && gr_learn_attached)
71413 + return -EBUSY;
71414 + if (file->f_mode & FMODE_READ) {
71415 + int retval = 0;
71416 + mutex_lock(&gr_learn_user_mutex);
71417 + if (learn_buffer == NULL)
71418 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
71419 + if (learn_buffer_user == NULL)
71420 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
71421 + if (learn_buffer == NULL) {
71422 + retval = -ENOMEM;
71423 + goto out_error;
71424 + }
71425 + if (learn_buffer_user == NULL) {
71426 + retval = -ENOMEM;
71427 + goto out_error;
71428 + }
71429 + learn_buffer_len = 0;
71430 + learn_buffer_user_len = 0;
71431 + gr_learn_attached = 1;
71432 +out_error:
71433 + mutex_unlock(&gr_learn_user_mutex);
71434 + return retval;
71435 + }
71436 + return 0;
71437 +}
71438 +
71439 +static int
71440 +close_learn(struct inode *inode, struct file *file)
71441 +{
71442 + if (file->f_mode & FMODE_READ) {
71443 + char *tmp = NULL;
71444 + mutex_lock(&gr_learn_user_mutex);
71445 + spin_lock(&gr_learn_lock);
71446 + tmp = learn_buffer;
71447 + learn_buffer = NULL;
71448 + spin_unlock(&gr_learn_lock);
71449 + if (tmp)
71450 + vfree(tmp);
71451 + if (learn_buffer_user != NULL) {
71452 + vfree(learn_buffer_user);
71453 + learn_buffer_user = NULL;
71454 + }
71455 + learn_buffer_len = 0;
71456 + learn_buffer_user_len = 0;
71457 + gr_learn_attached = 0;
71458 + mutex_unlock(&gr_learn_user_mutex);
71459 + }
71460 +
71461 + return 0;
71462 +}
71463 +
71464 +const struct file_operations grsec_fops = {
71465 + .read = read_learn,
71466 + .write = write_grsec_handler,
71467 + .open = open_learn,
71468 + .release = close_learn,
71469 + .poll = poll_learn,
71470 +};
71471 diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
71472 new file mode 100644
71473 index 0000000..3f8ade0
71474 --- /dev/null
71475 +++ b/grsecurity/gracl_policy.c
71476 @@ -0,0 +1,1782 @@
71477 +#include <linux/kernel.h>
71478 +#include <linux/module.h>
71479 +#include <linux/sched.h>
71480 +#include <linux/mm.h>
71481 +#include <linux/file.h>
71482 +#include <linux/fs.h>
71483 +#include <linux/namei.h>
71484 +#include <linux/mount.h>
71485 +#include <linux/tty.h>
71486 +#include <linux/proc_fs.h>
71487 +#include <linux/lglock.h>
71488 +#include <linux/slab.h>
71489 +#include <linux/vmalloc.h>
71490 +#include <linux/types.h>
71491 +#include <linux/sysctl.h>
71492 +#include <linux/netdevice.h>
71493 +#include <linux/ptrace.h>
71494 +#include <linux/gracl.h>
71495 +#include <linux/gralloc.h>
71496 +#include <linux/security.h>
71497 +#include <linux/grinternal.h>
71498 +#include <linux/pid_namespace.h>
71499 +#include <linux/stop_machine.h>
71500 +#include <linux/fdtable.h>
71501 +#include <linux/percpu.h>
71502 +#include <linux/lglock.h>
71503 +#include <linux/hugetlb.h>
71504 +#include <linux/posix-timers.h>
71505 +#include "../fs/mount.h"
71506 +
71507 +#include <asm/uaccess.h>
71508 +#include <asm/errno.h>
71509 +#include <asm/mman.h>
71510 +
71511 +extern struct gr_policy_state *polstate;
71512 +
71513 +#define FOR_EACH_ROLE_START(role) \
71514 + role = polstate->role_list; \
71515 + while (role) {
71516 +
71517 +#define FOR_EACH_ROLE_END(role) \
71518 + role = role->prev; \
71519 + }
71520 +
71521 +struct path gr_real_root;
71522 +
71523 +extern struct gr_alloc_state *current_alloc_state;
71524 +
71525 +u16 acl_sp_role_value;
71526 +
71527 +static DEFINE_MUTEX(gr_dev_mutex);
71528 +
71529 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
71530 +extern void gr_clear_learn_entries(void);
71531 +
71532 +struct gr_arg *gr_usermode __read_only;
71533 +unsigned char *gr_system_salt __read_only;
71534 +unsigned char *gr_system_sum __read_only;
71535 +
71536 +static unsigned int gr_auth_attempts = 0;
71537 +static unsigned long gr_auth_expires = 0UL;
71538 +
71539 +struct acl_object_label *fakefs_obj_rw;
71540 +struct acl_object_label *fakefs_obj_rwx;
71541 +
71542 +extern int gr_init_uidset(void);
71543 +extern void gr_free_uidset(void);
71544 +extern void gr_remove_uid(uid_t uid);
71545 +extern int gr_find_uid(uid_t uid);
71546 +
71547 +extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
71548 +extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
71549 +extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
71550 +extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
71551 +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);
71552 +extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
71553 +extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
71554 +extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
71555 +extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
71556 +extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
71557 +extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
71558 +extern void assign_special_role(const char *rolename);
71559 +extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
71560 +extern int gr_rbac_disable(void *unused);
71561 +extern void gr_enable_rbac_system(void);
71562 +
71563 +static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
71564 +{
71565 + if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
71566 + return -EFAULT;
71567 +
71568 + return 0;
71569 +}
71570 +
71571 +static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
71572 +{
71573 + if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
71574 + return -EFAULT;
71575 +
71576 + return 0;
71577 +}
71578 +
71579 +static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
71580 +{
71581 + if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
71582 + return -EFAULT;
71583 +
71584 + return 0;
71585 +}
71586 +
71587 +static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
71588 +{
71589 + if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
71590 + return -EFAULT;
71591 +
71592 + return 0;
71593 +}
71594 +
71595 +static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
71596 +{
71597 + if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
71598 + return -EFAULT;
71599 +
71600 + return 0;
71601 +}
71602 +
71603 +static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
71604 +{
71605 + if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
71606 + return -EFAULT;
71607 +
71608 + return 0;
71609 +}
71610 +
71611 +static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
71612 +{
71613 + if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
71614 + return -EFAULT;
71615 +
71616 + return 0;
71617 +}
71618 +
71619 +static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
71620 +{
71621 + if (copy_from_user(trans, userp, sizeof(struct role_transition)))
71622 + return -EFAULT;
71623 +
71624 + return 0;
71625 +}
71626 +
71627 +int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
71628 +{
71629 + if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
71630 + return -EFAULT;
71631 +
71632 + return 0;
71633 +}
71634 +
71635 +static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
71636 +{
71637 + if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
71638 + return -EFAULT;
71639 +
71640 + if (((uwrap->version != GRSECURITY_VERSION) &&
71641 + (uwrap->version != 0x2901)) ||
71642 + (uwrap->size != sizeof(struct gr_arg)))
71643 + return -EINVAL;
71644 +
71645 + return 0;
71646 +}
71647 +
71648 +static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
71649 +{
71650 + if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
71651 + return -EFAULT;
71652 +
71653 + return 0;
71654 +}
71655 +
71656 +static size_t get_gr_arg_wrapper_size_normal(void)
71657 +{
71658 + return sizeof(struct gr_arg_wrapper);
71659 +}
71660 +
71661 +#ifdef CONFIG_COMPAT
71662 +extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
71663 +extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
71664 +extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
71665 +extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
71666 +extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
71667 +extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
71668 +extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
71669 +extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
71670 +extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
71671 +extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
71672 +extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
71673 +extern size_t get_gr_arg_wrapper_size_compat(void);
71674 +
71675 +int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
71676 +int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
71677 +int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
71678 +int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
71679 +int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
71680 +int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
71681 +int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
71682 +int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
71683 +int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
71684 +int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
71685 +int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
71686 +size_t (* get_gr_arg_wrapper_size)(void) __read_only;
71687 +
71688 +#else
71689 +#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
71690 +#define copy_gr_arg copy_gr_arg_normal
71691 +#define copy_gr_hash_struct copy_gr_hash_struct_normal
71692 +#define copy_acl_object_label copy_acl_object_label_normal
71693 +#define copy_acl_subject_label copy_acl_subject_label_normal
71694 +#define copy_acl_role_label copy_acl_role_label_normal
71695 +#define copy_acl_ip_label copy_acl_ip_label_normal
71696 +#define copy_pointer_from_array copy_pointer_from_array_normal
71697 +#define copy_sprole_pw copy_sprole_pw_normal
71698 +#define copy_role_transition copy_role_transition_normal
71699 +#define copy_role_allowed_ip copy_role_allowed_ip_normal
71700 +#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
71701 +#endif
71702 +
71703 +static struct acl_subject_label *
71704 +lookup_subject_map(const struct acl_subject_label *userp)
71705 +{
71706 + unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
71707 + struct subject_map *match;
71708 +
71709 + match = polstate->subj_map_set.s_hash[index];
71710 +
71711 + while (match && match->user != userp)
71712 + match = match->next;
71713 +
71714 + if (match != NULL)
71715 + return match->kernel;
71716 + else
71717 + return NULL;
71718 +}
71719 +
71720 +static void
71721 +insert_subj_map_entry(struct subject_map *subjmap)
71722 +{
71723 + unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
71724 + struct subject_map **curr;
71725 +
71726 + subjmap->prev = NULL;
71727 +
71728 + curr = &polstate->subj_map_set.s_hash[index];
71729 + if (*curr != NULL)
71730 + (*curr)->prev = subjmap;
71731 +
71732 + subjmap->next = *curr;
71733 + *curr = subjmap;
71734 +
71735 + return;
71736 +}
71737 +
71738 +static void
71739 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
71740 +{
71741 + unsigned int index =
71742 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
71743 + struct acl_role_label **curr;
71744 + struct acl_role_label *tmp, *tmp2;
71745 +
71746 + curr = &polstate->acl_role_set.r_hash[index];
71747 +
71748 + /* simple case, slot is empty, just set it to our role */
71749 + if (*curr == NULL) {
71750 + *curr = role;
71751 + } else {
71752 + /* example:
71753 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
71754 + 2 -> 3
71755 + */
71756 + /* first check to see if we can already be reached via this slot */
71757 + tmp = *curr;
71758 + while (tmp && tmp != role)
71759 + tmp = tmp->next;
71760 + if (tmp == role) {
71761 + /* we don't need to add ourselves to this slot's chain */
71762 + return;
71763 + }
71764 + /* we need to add ourselves to this chain, two cases */
71765 + if (role->next == NULL) {
71766 + /* simple case, append the current chain to our role */
71767 + role->next = *curr;
71768 + *curr = role;
71769 + } else {
71770 + /* 1 -> 2 -> 3 -> 4
71771 + 2 -> 3 -> 4
71772 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
71773 + */
71774 + /* trickier case: walk our role's chain until we find
71775 + the role for the start of the current slot's chain */
71776 + tmp = role;
71777 + tmp2 = *curr;
71778 + while (tmp->next && tmp->next != tmp2)
71779 + tmp = tmp->next;
71780 + if (tmp->next == tmp2) {
71781 + /* from example above, we found 3, so just
71782 + replace this slot's chain with ours */
71783 + *curr = role;
71784 + } else {
71785 + /* we didn't find a subset of our role's chain
71786 + in the current slot's chain, so append their
71787 + chain to ours, and set us as the first role in
71788 + the slot's chain
71789 +
71790 + we could fold this case with the case above,
71791 + but making it explicit for clarity
71792 + */
71793 + tmp->next = tmp2;
71794 + *curr = role;
71795 + }
71796 + }
71797 + }
71798 +
71799 + return;
71800 +}
71801 +
71802 +static void
71803 +insert_acl_role_label(struct acl_role_label *role)
71804 +{
71805 + int i;
71806 +
71807 + if (polstate->role_list == NULL) {
71808 + polstate->role_list = role;
71809 + role->prev = NULL;
71810 + } else {
71811 + role->prev = polstate->role_list;
71812 + polstate->role_list = role;
71813 + }
71814 +
71815 + /* used for hash chains */
71816 + role->next = NULL;
71817 +
71818 + if (role->roletype & GR_ROLE_DOMAIN) {
71819 + for (i = 0; i < role->domain_child_num; i++)
71820 + __insert_acl_role_label(role, role->domain_children[i]);
71821 + } else
71822 + __insert_acl_role_label(role, role->uidgid);
71823 +}
71824 +
71825 +static int
71826 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
71827 +{
71828 + struct name_entry **curr, *nentry;
71829 + struct inodev_entry *ientry;
71830 + unsigned int len = strlen(name);
71831 + unsigned int key = full_name_hash(name, len);
71832 + unsigned int index = key % polstate->name_set.n_size;
71833 +
71834 + curr = &polstate->name_set.n_hash[index];
71835 +
71836 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
71837 + curr = &((*curr)->next);
71838 +
71839 + if (*curr != NULL)
71840 + return 1;
71841 +
71842 + nentry = acl_alloc(sizeof (struct name_entry));
71843 + if (nentry == NULL)
71844 + return 0;
71845 + ientry = acl_alloc(sizeof (struct inodev_entry));
71846 + if (ientry == NULL)
71847 + return 0;
71848 + ientry->nentry = nentry;
71849 +
71850 + nentry->key = key;
71851 + nentry->name = name;
71852 + nentry->inode = inode;
71853 + nentry->device = device;
71854 + nentry->len = len;
71855 + nentry->deleted = deleted;
71856 +
71857 + nentry->prev = NULL;
71858 + curr = &polstate->name_set.n_hash[index];
71859 + if (*curr != NULL)
71860 + (*curr)->prev = nentry;
71861 + nentry->next = *curr;
71862 + *curr = nentry;
71863 +
71864 + /* insert us into the table searchable by inode/dev */
71865 + __insert_inodev_entry(polstate, ientry);
71866 +
71867 + return 1;
71868 +}
71869 +
71870 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
71871 +
71872 +static void *
71873 +create_table(__u32 * len, int elementsize)
71874 +{
71875 + unsigned int table_sizes[] = {
71876 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
71877 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
71878 + 4194301, 8388593, 16777213, 33554393, 67108859
71879 + };
71880 + void *newtable = NULL;
71881 + unsigned int pwr = 0;
71882 +
71883 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
71884 + table_sizes[pwr] <= *len)
71885 + pwr++;
71886 +
71887 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
71888 + return newtable;
71889 +
71890 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
71891 + newtable =
71892 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
71893 + else
71894 + newtable = vmalloc(table_sizes[pwr] * elementsize);
71895 +
71896 + *len = table_sizes[pwr];
71897 +
71898 + return newtable;
71899 +}
71900 +
71901 +static int
71902 +init_variables(const struct gr_arg *arg, bool reload)
71903 +{
71904 + struct task_struct *reaper = init_pid_ns.child_reaper;
71905 + unsigned int stacksize;
71906 +
71907 + polstate->subj_map_set.s_size = arg->role_db.num_subjects;
71908 + polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
71909 + polstate->name_set.n_size = arg->role_db.num_objects;
71910 + polstate->inodev_set.i_size = arg->role_db.num_objects;
71911 +
71912 + if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
71913 + !polstate->name_set.n_size || !polstate->inodev_set.i_size)
71914 + return 1;
71915 +
71916 + if (!reload) {
71917 + if (!gr_init_uidset())
71918 + return 1;
71919 + }
71920 +
71921 + /* set up the stack that holds allocation info */
71922 +
71923 + stacksize = arg->role_db.num_pointers + 5;
71924 +
71925 + if (!acl_alloc_stack_init(stacksize))
71926 + return 1;
71927 +
71928 + if (!reload) {
71929 + /* grab reference for the real root dentry and vfsmount */
71930 + get_fs_root(reaper->fs, &gr_real_root);
71931 +
71932 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71933 + 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);
71934 +#endif
71935 +
71936 + fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71937 + if (fakefs_obj_rw == NULL)
71938 + return 1;
71939 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
71940 +
71941 + fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71942 + if (fakefs_obj_rwx == NULL)
71943 + return 1;
71944 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
71945 + }
71946 +
71947 + polstate->subj_map_set.s_hash =
71948 + (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
71949 + polstate->acl_role_set.r_hash =
71950 + (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
71951 + polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
71952 + polstate->inodev_set.i_hash =
71953 + (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
71954 +
71955 + if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
71956 + !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
71957 + return 1;
71958 +
71959 + memset(polstate->subj_map_set.s_hash, 0,
71960 + sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
71961 + memset(polstate->acl_role_set.r_hash, 0,
71962 + sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
71963 + memset(polstate->name_set.n_hash, 0,
71964 + sizeof (struct name_entry *) * polstate->name_set.n_size);
71965 + memset(polstate->inodev_set.i_hash, 0,
71966 + sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
71967 +
71968 + return 0;
71969 +}
71970 +
71971 +/* free information not needed after startup
71972 + currently contains user->kernel pointer mappings for subjects
71973 +*/
71974 +
71975 +static void
71976 +free_init_variables(void)
71977 +{
71978 + __u32 i;
71979 +
71980 + if (polstate->subj_map_set.s_hash) {
71981 + for (i = 0; i < polstate->subj_map_set.s_size; i++) {
71982 + if (polstate->subj_map_set.s_hash[i]) {
71983 + kfree(polstate->subj_map_set.s_hash[i]);
71984 + polstate->subj_map_set.s_hash[i] = NULL;
71985 + }
71986 + }
71987 +
71988 + if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
71989 + PAGE_SIZE)
71990 + kfree(polstate->subj_map_set.s_hash);
71991 + else
71992 + vfree(polstate->subj_map_set.s_hash);
71993 + }
71994 +
71995 + return;
71996 +}
71997 +
71998 +static void
71999 +free_variables(bool reload)
72000 +{
72001 + struct acl_subject_label *s;
72002 + struct acl_role_label *r;
72003 + struct task_struct *task, *task2;
72004 + unsigned int x;
72005 +
72006 + if (!reload) {
72007 + gr_clear_learn_entries();
72008 +
72009 + read_lock(&tasklist_lock);
72010 + do_each_thread(task2, task) {
72011 + task->acl_sp_role = 0;
72012 + task->acl_role_id = 0;
72013 + task->inherited = 0;
72014 + task->acl = NULL;
72015 + task->role = NULL;
72016 + } while_each_thread(task2, task);
72017 + read_unlock(&tasklist_lock);
72018 +
72019 + kfree(fakefs_obj_rw);
72020 + fakefs_obj_rw = NULL;
72021 + kfree(fakefs_obj_rwx);
72022 + fakefs_obj_rwx = NULL;
72023 +
72024 + /* release the reference to the real root dentry and vfsmount */
72025 + path_put(&gr_real_root);
72026 + memset(&gr_real_root, 0, sizeof(gr_real_root));
72027 + }
72028 +
72029 + /* free all object hash tables */
72030 +
72031 + FOR_EACH_ROLE_START(r)
72032 + if (r->subj_hash == NULL)
72033 + goto next_role;
72034 + FOR_EACH_SUBJECT_START(r, s, x)
72035 + if (s->obj_hash == NULL)
72036 + break;
72037 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
72038 + kfree(s->obj_hash);
72039 + else
72040 + vfree(s->obj_hash);
72041 + FOR_EACH_SUBJECT_END(s, x)
72042 + FOR_EACH_NESTED_SUBJECT_START(r, s)
72043 + if (s->obj_hash == NULL)
72044 + break;
72045 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
72046 + kfree(s->obj_hash);
72047 + else
72048 + vfree(s->obj_hash);
72049 + FOR_EACH_NESTED_SUBJECT_END(s)
72050 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
72051 + kfree(r->subj_hash);
72052 + else
72053 + vfree(r->subj_hash);
72054 + r->subj_hash = NULL;
72055 +next_role:
72056 + FOR_EACH_ROLE_END(r)
72057 +
72058 + acl_free_all();
72059 +
72060 + if (polstate->acl_role_set.r_hash) {
72061 + if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
72062 + PAGE_SIZE)
72063 + kfree(polstate->acl_role_set.r_hash);
72064 + else
72065 + vfree(polstate->acl_role_set.r_hash);
72066 + }
72067 + if (polstate->name_set.n_hash) {
72068 + if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
72069 + PAGE_SIZE)
72070 + kfree(polstate->name_set.n_hash);
72071 + else
72072 + vfree(polstate->name_set.n_hash);
72073 + }
72074 +
72075 + if (polstate->inodev_set.i_hash) {
72076 + if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
72077 + PAGE_SIZE)
72078 + kfree(polstate->inodev_set.i_hash);
72079 + else
72080 + vfree(polstate->inodev_set.i_hash);
72081 + }
72082 +
72083 + if (!reload)
72084 + gr_free_uidset();
72085 +
72086 + memset(&polstate->name_set, 0, sizeof (struct name_db));
72087 + memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
72088 + memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
72089 + memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
72090 +
72091 + polstate->default_role = NULL;
72092 + polstate->kernel_role = NULL;
72093 + polstate->role_list = NULL;
72094 +
72095 + return;
72096 +}
72097 +
72098 +static struct acl_subject_label *
72099 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
72100 +
72101 +static int alloc_and_copy_string(char **name, unsigned int maxlen)
72102 +{
72103 + unsigned int len = strnlen_user(*name, maxlen);
72104 + char *tmp;
72105 +
72106 + if (!len || len >= maxlen)
72107 + return -EINVAL;
72108 +
72109 + if ((tmp = (char *) acl_alloc(len)) == NULL)
72110 + return -ENOMEM;
72111 +
72112 + if (copy_from_user(tmp, *name, len))
72113 + return -EFAULT;
72114 +
72115 + tmp[len-1] = '\0';
72116 + *name = tmp;
72117 +
72118 + return 0;
72119 +}
72120 +
72121 +static int
72122 +copy_user_glob(struct acl_object_label *obj)
72123 +{
72124 + struct acl_object_label *g_tmp, **guser;
72125 + int error;
72126 +
72127 + if (obj->globbed == NULL)
72128 + return 0;
72129 +
72130 + guser = &obj->globbed;
72131 + while (*guser) {
72132 + g_tmp = (struct acl_object_label *)
72133 + acl_alloc(sizeof (struct acl_object_label));
72134 + if (g_tmp == NULL)
72135 + return -ENOMEM;
72136 +
72137 + if (copy_acl_object_label(g_tmp, *guser))
72138 + return -EFAULT;
72139 +
72140 + error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
72141 + if (error)
72142 + return error;
72143 +
72144 + *guser = g_tmp;
72145 + guser = &(g_tmp->next);
72146 + }
72147 +
72148 + return 0;
72149 +}
72150 +
72151 +static int
72152 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
72153 + struct acl_role_label *role)
72154 +{
72155 + struct acl_object_label *o_tmp;
72156 + int ret;
72157 +
72158 + while (userp) {
72159 + if ((o_tmp = (struct acl_object_label *)
72160 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
72161 + return -ENOMEM;
72162 +
72163 + if (copy_acl_object_label(o_tmp, userp))
72164 + return -EFAULT;
72165 +
72166 + userp = o_tmp->prev;
72167 +
72168 + ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
72169 + if (ret)
72170 + return ret;
72171 +
72172 + insert_acl_obj_label(o_tmp, subj);
72173 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
72174 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
72175 + return -ENOMEM;
72176 +
72177 + ret = copy_user_glob(o_tmp);
72178 + if (ret)
72179 + return ret;
72180 +
72181 + if (o_tmp->nested) {
72182 + int already_copied;
72183 +
72184 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
72185 + if (IS_ERR(o_tmp->nested))
72186 + return PTR_ERR(o_tmp->nested);
72187 +
72188 + /* insert into nested subject list if we haven't copied this one yet
72189 + to prevent duplicate entries */
72190 + if (!already_copied) {
72191 + o_tmp->nested->next = role->hash->first;
72192 + role->hash->first = o_tmp->nested;
72193 + }
72194 + }
72195 + }
72196 +
72197 + return 0;
72198 +}
72199 +
72200 +static __u32
72201 +count_user_subjs(struct acl_subject_label *userp)
72202 +{
72203 + struct acl_subject_label s_tmp;
72204 + __u32 num = 0;
72205 +
72206 + while (userp) {
72207 + if (copy_acl_subject_label(&s_tmp, userp))
72208 + break;
72209 +
72210 + userp = s_tmp.prev;
72211 + }
72212 +
72213 + return num;
72214 +}
72215 +
72216 +static int
72217 +copy_user_allowedips(struct acl_role_label *rolep)
72218 +{
72219 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
72220 +
72221 + ruserip = rolep->allowed_ips;
72222 +
72223 + while (ruserip) {
72224 + rlast = rtmp;
72225 +
72226 + if ((rtmp = (struct role_allowed_ip *)
72227 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
72228 + return -ENOMEM;
72229 +
72230 + if (copy_role_allowed_ip(rtmp, ruserip))
72231 + return -EFAULT;
72232 +
72233 + ruserip = rtmp->prev;
72234 +
72235 + if (!rlast) {
72236 + rtmp->prev = NULL;
72237 + rolep->allowed_ips = rtmp;
72238 + } else {
72239 + rlast->next = rtmp;
72240 + rtmp->prev = rlast;
72241 + }
72242 +
72243 + if (!ruserip)
72244 + rtmp->next = NULL;
72245 + }
72246 +
72247 + return 0;
72248 +}
72249 +
72250 +static int
72251 +copy_user_transitions(struct acl_role_label *rolep)
72252 +{
72253 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
72254 + int error;
72255 +
72256 + rusertp = rolep->transitions;
72257 +
72258 + while (rusertp) {
72259 + rlast = rtmp;
72260 +
72261 + if ((rtmp = (struct role_transition *)
72262 + acl_alloc(sizeof (struct role_transition))) == NULL)
72263 + return -ENOMEM;
72264 +
72265 + if (copy_role_transition(rtmp, rusertp))
72266 + return -EFAULT;
72267 +
72268 + rusertp = rtmp->prev;
72269 +
72270 + error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
72271 + if (error)
72272 + return error;
72273 +
72274 + if (!rlast) {
72275 + rtmp->prev = NULL;
72276 + rolep->transitions = rtmp;
72277 + } else {
72278 + rlast->next = rtmp;
72279 + rtmp->prev = rlast;
72280 + }
72281 +
72282 + if (!rusertp)
72283 + rtmp->next = NULL;
72284 + }
72285 +
72286 + return 0;
72287 +}
72288 +
72289 +static __u32 count_user_objs(const struct acl_object_label __user *userp)
72290 +{
72291 + struct acl_object_label o_tmp;
72292 + __u32 num = 0;
72293 +
72294 + while (userp) {
72295 + if (copy_acl_object_label(&o_tmp, userp))
72296 + break;
72297 +
72298 + userp = o_tmp.prev;
72299 + num++;
72300 + }
72301 +
72302 + return num;
72303 +}
72304 +
72305 +static struct acl_subject_label *
72306 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
72307 +{
72308 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
72309 + __u32 num_objs;
72310 + struct acl_ip_label **i_tmp, *i_utmp2;
72311 + struct gr_hash_struct ghash;
72312 + struct subject_map *subjmap;
72313 + unsigned int i_num;
72314 + int err;
72315 +
72316 + if (already_copied != NULL)
72317 + *already_copied = 0;
72318 +
72319 + s_tmp = lookup_subject_map(userp);
72320 +
72321 + /* we've already copied this subject into the kernel, just return
72322 + the reference to it, and don't copy it over again
72323 + */
72324 + if (s_tmp) {
72325 + if (already_copied != NULL)
72326 + *already_copied = 1;
72327 + return(s_tmp);
72328 + }
72329 +
72330 + if ((s_tmp = (struct acl_subject_label *)
72331 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
72332 + return ERR_PTR(-ENOMEM);
72333 +
72334 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
72335 + if (subjmap == NULL)
72336 + return ERR_PTR(-ENOMEM);
72337 +
72338 + subjmap->user = userp;
72339 + subjmap->kernel = s_tmp;
72340 + insert_subj_map_entry(subjmap);
72341 +
72342 + if (copy_acl_subject_label(s_tmp, userp))
72343 + return ERR_PTR(-EFAULT);
72344 +
72345 + err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
72346 + if (err)
72347 + return ERR_PTR(err);
72348 +
72349 + if (!strcmp(s_tmp->filename, "/"))
72350 + role->root_label = s_tmp;
72351 +
72352 + if (copy_gr_hash_struct(&ghash, s_tmp->hash))
72353 + return ERR_PTR(-EFAULT);
72354 +
72355 + /* copy user and group transition tables */
72356 +
72357 + if (s_tmp->user_trans_num) {
72358 + uid_t *uidlist;
72359 +
72360 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
72361 + if (uidlist == NULL)
72362 + return ERR_PTR(-ENOMEM);
72363 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
72364 + return ERR_PTR(-EFAULT);
72365 +
72366 + s_tmp->user_transitions = uidlist;
72367 + }
72368 +
72369 + if (s_tmp->group_trans_num) {
72370 + gid_t *gidlist;
72371 +
72372 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
72373 + if (gidlist == NULL)
72374 + return ERR_PTR(-ENOMEM);
72375 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
72376 + return ERR_PTR(-EFAULT);
72377 +
72378 + s_tmp->group_transitions = gidlist;
72379 + }
72380 +
72381 + /* set up object hash table */
72382 + num_objs = count_user_objs(ghash.first);
72383 +
72384 + s_tmp->obj_hash_size = num_objs;
72385 + s_tmp->obj_hash =
72386 + (struct acl_object_label **)
72387 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
72388 +
72389 + if (!s_tmp->obj_hash)
72390 + return ERR_PTR(-ENOMEM);
72391 +
72392 + memset(s_tmp->obj_hash, 0,
72393 + s_tmp->obj_hash_size *
72394 + sizeof (struct acl_object_label *));
72395 +
72396 + /* add in objects */
72397 + err = copy_user_objs(ghash.first, s_tmp, role);
72398 +
72399 + if (err)
72400 + return ERR_PTR(err);
72401 +
72402 + /* set pointer for parent subject */
72403 + if (s_tmp->parent_subject) {
72404 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
72405 +
72406 + if (IS_ERR(s_tmp2))
72407 + return s_tmp2;
72408 +
72409 + s_tmp->parent_subject = s_tmp2;
72410 + }
72411 +
72412 + /* add in ip acls */
72413 +
72414 + if (!s_tmp->ip_num) {
72415 + s_tmp->ips = NULL;
72416 + goto insert;
72417 + }
72418 +
72419 + i_tmp =
72420 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
72421 + sizeof (struct acl_ip_label *));
72422 +
72423 + if (!i_tmp)
72424 + return ERR_PTR(-ENOMEM);
72425 +
72426 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
72427 + *(i_tmp + i_num) =
72428 + (struct acl_ip_label *)
72429 + acl_alloc(sizeof (struct acl_ip_label));
72430 + if (!*(i_tmp + i_num))
72431 + return ERR_PTR(-ENOMEM);
72432 +
72433 + if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
72434 + return ERR_PTR(-EFAULT);
72435 +
72436 + if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
72437 + return ERR_PTR(-EFAULT);
72438 +
72439 + if ((*(i_tmp + i_num))->iface == NULL)
72440 + continue;
72441 +
72442 + err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
72443 + if (err)
72444 + return ERR_PTR(err);
72445 + }
72446 +
72447 + s_tmp->ips = i_tmp;
72448 +
72449 +insert:
72450 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
72451 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
72452 + return ERR_PTR(-ENOMEM);
72453 +
72454 + return s_tmp;
72455 +}
72456 +
72457 +static int
72458 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
72459 +{
72460 + struct acl_subject_label s_pre;
72461 + struct acl_subject_label * ret;
72462 + int err;
72463 +
72464 + while (userp) {
72465 + if (copy_acl_subject_label(&s_pre, userp))
72466 + return -EFAULT;
72467 +
72468 + ret = do_copy_user_subj(userp, role, NULL);
72469 +
72470 + err = PTR_ERR(ret);
72471 + if (IS_ERR(ret))
72472 + return err;
72473 +
72474 + insert_acl_subj_label(ret, role);
72475 +
72476 + userp = s_pre.prev;
72477 + }
72478 +
72479 + return 0;
72480 +}
72481 +
72482 +static int
72483 +copy_user_acl(struct gr_arg *arg)
72484 +{
72485 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
72486 + struct acl_subject_label *subj_list;
72487 + struct sprole_pw *sptmp;
72488 + struct gr_hash_struct *ghash;
72489 + uid_t *domainlist;
72490 + unsigned int r_num;
72491 + int err = 0;
72492 + __u16 i;
72493 + __u32 num_subjs;
72494 +
72495 + /* we need a default and kernel role */
72496 + if (arg->role_db.num_roles < 2)
72497 + return -EINVAL;
72498 +
72499 + /* copy special role authentication info from userspace */
72500 +
72501 + polstate->num_sprole_pws = arg->num_sprole_pws;
72502 + polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
72503 +
72504 + if (!polstate->acl_special_roles && polstate->num_sprole_pws)
72505 + return -ENOMEM;
72506 +
72507 + for (i = 0; i < polstate->num_sprole_pws; i++) {
72508 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
72509 + if (!sptmp)
72510 + return -ENOMEM;
72511 + if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
72512 + return -EFAULT;
72513 +
72514 + err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
72515 + if (err)
72516 + return err;
72517 +
72518 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
72519 + printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
72520 +#endif
72521 +
72522 + polstate->acl_special_roles[i] = sptmp;
72523 + }
72524 +
72525 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
72526 +
72527 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
72528 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
72529 +
72530 + if (!r_tmp)
72531 + return -ENOMEM;
72532 +
72533 + if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
72534 + return -EFAULT;
72535 +
72536 + if (copy_acl_role_label(r_tmp, r_utmp2))
72537 + return -EFAULT;
72538 +
72539 + err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
72540 + if (err)
72541 + return err;
72542 +
72543 + if (!strcmp(r_tmp->rolename, "default")
72544 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
72545 + polstate->default_role = r_tmp;
72546 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
72547 + polstate->kernel_role = r_tmp;
72548 + }
72549 +
72550 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
72551 + return -ENOMEM;
72552 +
72553 + if (copy_gr_hash_struct(ghash, r_tmp->hash))
72554 + return -EFAULT;
72555 +
72556 + r_tmp->hash = ghash;
72557 +
72558 + num_subjs = count_user_subjs(r_tmp->hash->first);
72559 +
72560 + r_tmp->subj_hash_size = num_subjs;
72561 + r_tmp->subj_hash =
72562 + (struct acl_subject_label **)
72563 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
72564 +
72565 + if (!r_tmp->subj_hash)
72566 + return -ENOMEM;
72567 +
72568 + err = copy_user_allowedips(r_tmp);
72569 + if (err)
72570 + return err;
72571 +
72572 + /* copy domain info */
72573 + if (r_tmp->domain_children != NULL) {
72574 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
72575 + if (domainlist == NULL)
72576 + return -ENOMEM;
72577 +
72578 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
72579 + return -EFAULT;
72580 +
72581 + r_tmp->domain_children = domainlist;
72582 + }
72583 +
72584 + err = copy_user_transitions(r_tmp);
72585 + if (err)
72586 + return err;
72587 +
72588 + memset(r_tmp->subj_hash, 0,
72589 + r_tmp->subj_hash_size *
72590 + sizeof (struct acl_subject_label *));
72591 +
72592 + /* acquire the list of subjects, then NULL out
72593 + the list prior to parsing the subjects for this role,
72594 + as during this parsing the list is replaced with a list
72595 + of *nested* subjects for the role
72596 + */
72597 + subj_list = r_tmp->hash->first;
72598 +
72599 + /* set nested subject list to null */
72600 + r_tmp->hash->first = NULL;
72601 +
72602 + err = copy_user_subjs(subj_list, r_tmp);
72603 +
72604 + if (err)
72605 + return err;
72606 +
72607 + insert_acl_role_label(r_tmp);
72608 + }
72609 +
72610 + if (polstate->default_role == NULL || polstate->kernel_role == NULL)
72611 + return -EINVAL;
72612 +
72613 + return err;
72614 +}
72615 +
72616 +static int gracl_reload_apply_policies(void *reload)
72617 +{
72618 + struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
72619 + struct task_struct *task, *task2;
72620 + struct acl_role_label *role, *rtmp;
72621 + struct acl_subject_label *subj;
72622 + const struct cred *cred;
72623 + int role_applied;
72624 + int ret = 0;
72625 +
72626 + memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
72627 + memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
72628 +
72629 + /* first make sure we'll be able to apply the new policy cleanly */
72630 + do_each_thread(task2, task) {
72631 + if (task->exec_file == NULL)
72632 + continue;
72633 + role_applied = 0;
72634 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
72635 + /* preserve special roles */
72636 + FOR_EACH_ROLE_START(role)
72637 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72638 + rtmp = task->role;
72639 + task->role = role;
72640 + role_applied = 1;
72641 + break;
72642 + }
72643 + FOR_EACH_ROLE_END(role)
72644 + }
72645 + if (!role_applied) {
72646 + cred = __task_cred(task);
72647 + rtmp = task->role;
72648 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72649 + }
72650 + /* this handles non-nested inherited subjects, nested subjects will still
72651 + be dropped currently */
72652 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72653 + task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
72654 + /* change the role back so that we've made no modifications to the policy */
72655 + task->role = rtmp;
72656 +
72657 + if (subj == NULL || task->tmpacl == NULL) {
72658 + ret = -EINVAL;
72659 + goto out;
72660 + }
72661 + } while_each_thread(task2, task);
72662 +
72663 + /* now actually apply the policy */
72664 +
72665 + do_each_thread(task2, task) {
72666 + if (task->exec_file) {
72667 + role_applied = 0;
72668 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
72669 + /* preserve special roles */
72670 + FOR_EACH_ROLE_START(role)
72671 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72672 + task->role = role;
72673 + role_applied = 1;
72674 + break;
72675 + }
72676 + FOR_EACH_ROLE_END(role)
72677 + }
72678 + if (!role_applied) {
72679 + cred = __task_cred(task);
72680 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72681 + }
72682 + /* this handles non-nested inherited subjects, nested subjects will still
72683 + be dropped currently */
72684 + if (!reload_state->oldmode && task->inherited)
72685 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72686 + else {
72687 + /* looked up and tagged to the task previously */
72688 + subj = task->tmpacl;
72689 + }
72690 + /* subj will be non-null */
72691 + __gr_apply_subject_to_task(polstate, task, subj);
72692 + if (reload_state->oldmode) {
72693 + task->acl_role_id = 0;
72694 + task->acl_sp_role = 0;
72695 + task->inherited = 0;
72696 + }
72697 + } else {
72698 + // it's a kernel process
72699 + task->role = polstate->kernel_role;
72700 + task->acl = polstate->kernel_role->root_label;
72701 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
72702 + task->acl->mode &= ~GR_PROCFIND;
72703 +#endif
72704 + }
72705 + } while_each_thread(task2, task);
72706 +
72707 + memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
72708 + memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
72709 +
72710 +out:
72711 +
72712 + return ret;
72713 +}
72714 +
72715 +static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
72716 +{
72717 + struct gr_reload_state new_reload_state = { };
72718 + int err;
72719 +
72720 + new_reload_state.oldpolicy_ptr = polstate;
72721 + new_reload_state.oldalloc_ptr = current_alloc_state;
72722 + new_reload_state.oldmode = oldmode;
72723 +
72724 + current_alloc_state = &new_reload_state.newalloc;
72725 + polstate = &new_reload_state.newpolicy;
72726 +
72727 + /* everything relevant is now saved off, copy in the new policy */
72728 + if (init_variables(args, true)) {
72729 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
72730 + err = -ENOMEM;
72731 + goto error;
72732 + }
72733 +
72734 + err = copy_user_acl(args);
72735 + free_init_variables();
72736 + if (err)
72737 + goto error;
72738 + /* the new policy is copied in, with the old policy available via saved_state
72739 + first go through applying roles, making sure to preserve special roles
72740 + then apply new subjects, making sure to preserve inherited and nested subjects,
72741 + though currently only inherited subjects will be preserved
72742 + */
72743 + err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
72744 + if (err)
72745 + goto error;
72746 +
72747 + /* we've now applied the new policy, so restore the old policy state to free it */
72748 + polstate = &new_reload_state.oldpolicy;
72749 + current_alloc_state = &new_reload_state.oldalloc;
72750 + free_variables(true);
72751 +
72752 + /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
72753 + to running_polstate/current_alloc_state inside stop_machine
72754 + */
72755 + err = 0;
72756 + goto out;
72757 +error:
72758 + /* on error of loading the new policy, we'll just keep the previous
72759 + policy set around
72760 + */
72761 + free_variables(true);
72762 +
72763 + /* doesn't affect runtime, but maintains consistent state */
72764 +out:
72765 + polstate = new_reload_state.oldpolicy_ptr;
72766 + current_alloc_state = new_reload_state.oldalloc_ptr;
72767 +
72768 + return err;
72769 +}
72770 +
72771 +static int
72772 +gracl_init(struct gr_arg *args)
72773 +{
72774 + int error = 0;
72775 +
72776 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
72777 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
72778 +
72779 + if (init_variables(args, false)) {
72780 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
72781 + error = -ENOMEM;
72782 + goto out;
72783 + }
72784 +
72785 + error = copy_user_acl(args);
72786 + free_init_variables();
72787 + if (error)
72788 + goto out;
72789 +
72790 + error = gr_set_acls(0);
72791 + if (error)
72792 + goto out;
72793 +
72794 + gr_enable_rbac_system();
72795 +
72796 + return 0;
72797 +
72798 +out:
72799 + free_variables(false);
72800 + return error;
72801 +}
72802 +
72803 +static int
72804 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
72805 + unsigned char **sum)
72806 +{
72807 + struct acl_role_label *r;
72808 + struct role_allowed_ip *ipp;
72809 + struct role_transition *trans;
72810 + unsigned int i;
72811 + int found = 0;
72812 + u32 curr_ip = current->signal->curr_ip;
72813 +
72814 + current->signal->saved_ip = curr_ip;
72815 +
72816 + /* check transition table */
72817 +
72818 + for (trans = current->role->transitions; trans; trans = trans->next) {
72819 + if (!strcmp(rolename, trans->rolename)) {
72820 + found = 1;
72821 + break;
72822 + }
72823 + }
72824 +
72825 + if (!found)
72826 + return 0;
72827 +
72828 + /* handle special roles that do not require authentication
72829 + and check ip */
72830 +
72831 + FOR_EACH_ROLE_START(r)
72832 + if (!strcmp(rolename, r->rolename) &&
72833 + (r->roletype & GR_ROLE_SPECIAL)) {
72834 + found = 0;
72835 + if (r->allowed_ips != NULL) {
72836 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
72837 + if ((ntohl(curr_ip) & ipp->netmask) ==
72838 + (ntohl(ipp->addr) & ipp->netmask))
72839 + found = 1;
72840 + }
72841 + } else
72842 + found = 2;
72843 + if (!found)
72844 + return 0;
72845 +
72846 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
72847 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
72848 + *salt = NULL;
72849 + *sum = NULL;
72850 + return 1;
72851 + }
72852 + }
72853 + FOR_EACH_ROLE_END(r)
72854 +
72855 + for (i = 0; i < polstate->num_sprole_pws; i++) {
72856 + if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
72857 + *salt = polstate->acl_special_roles[i]->salt;
72858 + *sum = polstate->acl_special_roles[i]->sum;
72859 + return 1;
72860 + }
72861 + }
72862 +
72863 + return 0;
72864 +}
72865 +
72866 +int gr_check_secure_terminal(struct task_struct *task)
72867 +{
72868 + struct task_struct *p, *p2, *p3;
72869 + struct files_struct *files;
72870 + struct fdtable *fdt;
72871 + struct file *our_file = NULL, *file;
72872 + int i;
72873 +
72874 + if (task->signal->tty == NULL)
72875 + return 1;
72876 +
72877 + files = get_files_struct(task);
72878 + if (files != NULL) {
72879 + rcu_read_lock();
72880 + fdt = files_fdtable(files);
72881 + for (i=0; i < fdt->max_fds; i++) {
72882 + file = fcheck_files(files, i);
72883 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
72884 + get_file(file);
72885 + our_file = file;
72886 + }
72887 + }
72888 + rcu_read_unlock();
72889 + put_files_struct(files);
72890 + }
72891 +
72892 + if (our_file == NULL)
72893 + return 1;
72894 +
72895 + read_lock(&tasklist_lock);
72896 + do_each_thread(p2, p) {
72897 + files = get_files_struct(p);
72898 + if (files == NULL ||
72899 + (p->signal && p->signal->tty == task->signal->tty)) {
72900 + if (files != NULL)
72901 + put_files_struct(files);
72902 + continue;
72903 + }
72904 + rcu_read_lock();
72905 + fdt = files_fdtable(files);
72906 + for (i=0; i < fdt->max_fds; i++) {
72907 + file = fcheck_files(files, i);
72908 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
72909 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
72910 + p3 = task;
72911 + while (task_pid_nr(p3) > 0) {
72912 + if (p3 == p)
72913 + break;
72914 + p3 = p3->real_parent;
72915 + }
72916 + if (p3 == p)
72917 + break;
72918 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
72919 + gr_handle_alertkill(p);
72920 + rcu_read_unlock();
72921 + put_files_struct(files);
72922 + read_unlock(&tasklist_lock);
72923 + fput(our_file);
72924 + return 0;
72925 + }
72926 + }
72927 + rcu_read_unlock();
72928 + put_files_struct(files);
72929 + } while_each_thread(p2, p);
72930 + read_unlock(&tasklist_lock);
72931 +
72932 + fput(our_file);
72933 + return 1;
72934 +}
72935 +
72936 +ssize_t
72937 +write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
72938 +{
72939 + struct gr_arg_wrapper uwrap;
72940 + unsigned char *sprole_salt = NULL;
72941 + unsigned char *sprole_sum = NULL;
72942 + int error = 0;
72943 + int error2 = 0;
72944 + size_t req_count = 0;
72945 + unsigned char oldmode = 0;
72946 +
72947 + mutex_lock(&gr_dev_mutex);
72948 +
72949 + if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
72950 + error = -EPERM;
72951 + goto out;
72952 + }
72953 +
72954 +#ifdef CONFIG_COMPAT
72955 + pax_open_kernel();
72956 + if (is_compat_task()) {
72957 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
72958 + copy_gr_arg = &copy_gr_arg_compat;
72959 + copy_acl_object_label = &copy_acl_object_label_compat;
72960 + copy_acl_subject_label = &copy_acl_subject_label_compat;
72961 + copy_acl_role_label = &copy_acl_role_label_compat;
72962 + copy_acl_ip_label = &copy_acl_ip_label_compat;
72963 + copy_role_allowed_ip = &copy_role_allowed_ip_compat;
72964 + copy_role_transition = &copy_role_transition_compat;
72965 + copy_sprole_pw = &copy_sprole_pw_compat;
72966 + copy_gr_hash_struct = &copy_gr_hash_struct_compat;
72967 + copy_pointer_from_array = &copy_pointer_from_array_compat;
72968 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
72969 + } else {
72970 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
72971 + copy_gr_arg = &copy_gr_arg_normal;
72972 + copy_acl_object_label = &copy_acl_object_label_normal;
72973 + copy_acl_subject_label = &copy_acl_subject_label_normal;
72974 + copy_acl_role_label = &copy_acl_role_label_normal;
72975 + copy_acl_ip_label = &copy_acl_ip_label_normal;
72976 + copy_role_allowed_ip = &copy_role_allowed_ip_normal;
72977 + copy_role_transition = &copy_role_transition_normal;
72978 + copy_sprole_pw = &copy_sprole_pw_normal;
72979 + copy_gr_hash_struct = &copy_gr_hash_struct_normal;
72980 + copy_pointer_from_array = &copy_pointer_from_array_normal;
72981 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
72982 + }
72983 + pax_close_kernel();
72984 +#endif
72985 +
72986 + req_count = get_gr_arg_wrapper_size();
72987 +
72988 + if (count != req_count) {
72989 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
72990 + error = -EINVAL;
72991 + goto out;
72992 + }
72993 +
72994 +
72995 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
72996 + gr_auth_expires = 0;
72997 + gr_auth_attempts = 0;
72998 + }
72999 +
73000 + error = copy_gr_arg_wrapper(buf, &uwrap);
73001 + if (error)
73002 + goto out;
73003 +
73004 + error = copy_gr_arg(uwrap.arg, gr_usermode);
73005 + if (error)
73006 + goto out;
73007 +
73008 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
73009 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
73010 + time_after(gr_auth_expires, get_seconds())) {
73011 + error = -EBUSY;
73012 + goto out;
73013 + }
73014 +
73015 + /* if non-root trying to do anything other than use a special role,
73016 + do not attempt authentication, do not count towards authentication
73017 + locking
73018 + */
73019 +
73020 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
73021 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
73022 + gr_is_global_nonroot(current_uid())) {
73023 + error = -EPERM;
73024 + goto out;
73025 + }
73026 +
73027 + /* ensure pw and special role name are null terminated */
73028 +
73029 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
73030 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
73031 +
73032 + /* Okay.
73033 + * We have our enough of the argument structure..(we have yet
73034 + * to copy_from_user the tables themselves) . Copy the tables
73035 + * only if we need them, i.e. for loading operations. */
73036 +
73037 + switch (gr_usermode->mode) {
73038 + case GR_STATUS:
73039 + if (gr_acl_is_enabled()) {
73040 + error = 1;
73041 + if (!gr_check_secure_terminal(current))
73042 + error = 3;
73043 + } else
73044 + error = 2;
73045 + goto out;
73046 + case GR_SHUTDOWN:
73047 + if (gr_acl_is_enabled() && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
73048 + stop_machine(gr_rbac_disable, NULL, NULL);
73049 + free_variables(false);
73050 + memset(gr_usermode, 0, sizeof(struct gr_arg));
73051 + memset(gr_system_salt, 0, GR_SALT_LEN);
73052 + memset(gr_system_sum, 0, GR_SHA_LEN);
73053 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
73054 + } else if (gr_acl_is_enabled()) {
73055 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
73056 + error = -EPERM;
73057 + } else {
73058 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
73059 + error = -EAGAIN;
73060 + }
73061 + break;
73062 + case GR_ENABLE:
73063 + if (!gr_acl_is_enabled() && !(error2 = gracl_init(gr_usermode)))
73064 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
73065 + else {
73066 + if (gr_acl_is_enabled())
73067 + error = -EAGAIN;
73068 + else
73069 + error = error2;
73070 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
73071 + }
73072 + break;
73073 + case GR_OLDRELOAD:
73074 + oldmode = 1;
73075 + case GR_RELOAD:
73076 + if (!gr_acl_is_enabled()) {
73077 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
73078 + error = -EAGAIN;
73079 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
73080 + error2 = gracl_reload(gr_usermode, oldmode);
73081 + if (!error2)
73082 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
73083 + else {
73084 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
73085 + error = error2;
73086 + }
73087 + } else {
73088 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
73089 + error = -EPERM;
73090 + }
73091 + break;
73092 + case GR_SEGVMOD:
73093 + if (unlikely(!gr_acl_is_enabled())) {
73094 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
73095 + error = -EAGAIN;
73096 + break;
73097 + }
73098 +
73099 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
73100 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
73101 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
73102 + struct acl_subject_label *segvacl;
73103 + segvacl =
73104 + lookup_acl_subj_label(gr_usermode->segv_inode,
73105 + gr_usermode->segv_device,
73106 + current->role);
73107 + if (segvacl) {
73108 + segvacl->crashes = 0;
73109 + segvacl->expires = 0;
73110 + }
73111 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
73112 + gr_remove_uid(gr_usermode->segv_uid);
73113 + }
73114 + } else {
73115 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
73116 + error = -EPERM;
73117 + }
73118 + break;
73119 + case GR_SPROLE:
73120 + case GR_SPROLEPAM:
73121 + if (unlikely(!gr_acl_is_enabled())) {
73122 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
73123 + error = -EAGAIN;
73124 + break;
73125 + }
73126 +
73127 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
73128 + current->role->expires = 0;
73129 + current->role->auth_attempts = 0;
73130 + }
73131 +
73132 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
73133 + time_after(current->role->expires, get_seconds())) {
73134 + error = -EBUSY;
73135 + goto out;
73136 + }
73137 +
73138 + if (lookup_special_role_auth
73139 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
73140 + && ((!sprole_salt && !sprole_sum)
73141 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
73142 + char *p = "";
73143 + assign_special_role(gr_usermode->sp_role);
73144 + read_lock(&tasklist_lock);
73145 + if (current->real_parent)
73146 + p = current->real_parent->role->rolename;
73147 + read_unlock(&tasklist_lock);
73148 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
73149 + p, acl_sp_role_value);
73150 + } else {
73151 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
73152 + error = -EPERM;
73153 + if(!(current->role->auth_attempts++))
73154 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
73155 +
73156 + goto out;
73157 + }
73158 + break;
73159 + case GR_UNSPROLE:
73160 + if (unlikely(!gr_acl_is_enabled())) {
73161 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
73162 + error = -EAGAIN;
73163 + break;
73164 + }
73165 +
73166 + if (current->role->roletype & GR_ROLE_SPECIAL) {
73167 + char *p = "";
73168 + int i = 0;
73169 +
73170 + read_lock(&tasklist_lock);
73171 + if (current->real_parent) {
73172 + p = current->real_parent->role->rolename;
73173 + i = current->real_parent->acl_role_id;
73174 + }
73175 + read_unlock(&tasklist_lock);
73176 +
73177 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
73178 + gr_set_acls(1);
73179 + } else {
73180 + error = -EPERM;
73181 + goto out;
73182 + }
73183 + break;
73184 + default:
73185 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
73186 + error = -EINVAL;
73187 + break;
73188 + }
73189 +
73190 + if (error != -EPERM)
73191 + goto out;
73192 +
73193 + if(!(gr_auth_attempts++))
73194 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
73195 +
73196 + out:
73197 + mutex_unlock(&gr_dev_mutex);
73198 +
73199 + if (!error)
73200 + error = req_count;
73201 +
73202 + return error;
73203 +}
73204 +
73205 +int
73206 +gr_set_acls(const int type)
73207 +{
73208 + struct task_struct *task, *task2;
73209 + struct acl_role_label *role = current->role;
73210 + struct acl_subject_label *subj;
73211 + __u16 acl_role_id = current->acl_role_id;
73212 + const struct cred *cred;
73213 + int ret;
73214 +
73215 + rcu_read_lock();
73216 + read_lock(&tasklist_lock);
73217 + read_lock(&grsec_exec_file_lock);
73218 + do_each_thread(task2, task) {
73219 + /* check to see if we're called from the exit handler,
73220 + if so, only replace ACLs that have inherited the admin
73221 + ACL */
73222 +
73223 + if (type && (task->role != role ||
73224 + task->acl_role_id != acl_role_id))
73225 + continue;
73226 +
73227 + task->acl_role_id = 0;
73228 + task->acl_sp_role = 0;
73229 + task->inherited = 0;
73230 +
73231 + if (task->exec_file) {
73232 + cred = __task_cred(task);
73233 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
73234 + subj = __gr_get_subject_for_task(polstate, task, NULL);
73235 + if (subj == NULL) {
73236 + ret = -EINVAL;
73237 + read_unlock(&grsec_exec_file_lock);
73238 + read_unlock(&tasklist_lock);
73239 + rcu_read_unlock();
73240 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
73241 + return ret;
73242 + }
73243 + __gr_apply_subject_to_task(polstate, task, subj);
73244 + } else {
73245 + // it's a kernel process
73246 + task->role = polstate->kernel_role;
73247 + task->acl = polstate->kernel_role->root_label;
73248 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
73249 + task->acl->mode &= ~GR_PROCFIND;
73250 +#endif
73251 + }
73252 + } while_each_thread(task2, task);
73253 + read_unlock(&grsec_exec_file_lock);
73254 + read_unlock(&tasklist_lock);
73255 + rcu_read_unlock();
73256 +
73257 + return 0;
73258 +}
73259 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
73260 new file mode 100644
73261 index 0000000..39645c9
73262 --- /dev/null
73263 +++ b/grsecurity/gracl_res.c
73264 @@ -0,0 +1,68 @@
73265 +#include <linux/kernel.h>
73266 +#include <linux/sched.h>
73267 +#include <linux/gracl.h>
73268 +#include <linux/grinternal.h>
73269 +
73270 +static const char *restab_log[] = {
73271 + [RLIMIT_CPU] = "RLIMIT_CPU",
73272 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
73273 + [RLIMIT_DATA] = "RLIMIT_DATA",
73274 + [RLIMIT_STACK] = "RLIMIT_STACK",
73275 + [RLIMIT_CORE] = "RLIMIT_CORE",
73276 + [RLIMIT_RSS] = "RLIMIT_RSS",
73277 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
73278 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
73279 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
73280 + [RLIMIT_AS] = "RLIMIT_AS",
73281 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
73282 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
73283 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
73284 + [RLIMIT_NICE] = "RLIMIT_NICE",
73285 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
73286 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
73287 + [GR_CRASH_RES] = "RLIMIT_CRASH"
73288 +};
73289 +
73290 +void
73291 +gr_log_resource(const struct task_struct *task,
73292 + const int res, const unsigned long wanted, const int gt)
73293 +{
73294 + const struct cred *cred;
73295 + unsigned long rlim;
73296 +
73297 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
73298 + return;
73299 +
73300 + // not yet supported resource
73301 + if (unlikely(!restab_log[res]))
73302 + return;
73303 +
73304 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
73305 + rlim = task_rlimit_max(task, res);
73306 + else
73307 + rlim = task_rlimit(task, res);
73308 +
73309 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
73310 + return;
73311 +
73312 + rcu_read_lock();
73313 + cred = __task_cred(task);
73314 +
73315 + if (res == RLIMIT_NPROC &&
73316 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
73317 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
73318 + goto out_rcu_unlock;
73319 + else if (res == RLIMIT_MEMLOCK &&
73320 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
73321 + goto out_rcu_unlock;
73322 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
73323 + goto out_rcu_unlock;
73324 + rcu_read_unlock();
73325 +
73326 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
73327 +
73328 + return;
73329 +out_rcu_unlock:
73330 + rcu_read_unlock();
73331 + return;
73332 +}
73333 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
73334 new file mode 100644
73335 index 0000000..2040e61
73336 --- /dev/null
73337 +++ b/grsecurity/gracl_segv.c
73338 @@ -0,0 +1,313 @@
73339 +#include <linux/kernel.h>
73340 +#include <linux/mm.h>
73341 +#include <asm/uaccess.h>
73342 +#include <asm/errno.h>
73343 +#include <asm/mman.h>
73344 +#include <net/sock.h>
73345 +#include <linux/file.h>
73346 +#include <linux/fs.h>
73347 +#include <linux/net.h>
73348 +#include <linux/in.h>
73349 +#include <linux/slab.h>
73350 +#include <linux/types.h>
73351 +#include <linux/sched.h>
73352 +#include <linux/timer.h>
73353 +#include <linux/gracl.h>
73354 +#include <linux/grsecurity.h>
73355 +#include <linux/grinternal.h>
73356 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
73357 +#include <linux/magic.h>
73358 +#include <linux/pagemap.h>
73359 +#include "../fs/btrfs/async-thread.h"
73360 +#include "../fs/btrfs/ctree.h"
73361 +#include "../fs/btrfs/btrfs_inode.h"
73362 +#endif
73363 +
73364 +static struct crash_uid *uid_set;
73365 +static unsigned short uid_used;
73366 +static DEFINE_SPINLOCK(gr_uid_lock);
73367 +extern rwlock_t gr_inode_lock;
73368 +extern struct acl_subject_label *
73369 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
73370 + struct acl_role_label *role);
73371 +
73372 +static inline dev_t __get_dev(const struct dentry *dentry)
73373 +{
73374 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
73375 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
73376 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
73377 + else
73378 +#endif
73379 + return dentry->d_sb->s_dev;
73380 +}
73381 +
73382 +int
73383 +gr_init_uidset(void)
73384 +{
73385 + uid_set =
73386 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
73387 + uid_used = 0;
73388 +
73389 + return uid_set ? 1 : 0;
73390 +}
73391 +
73392 +void
73393 +gr_free_uidset(void)
73394 +{
73395 + if (uid_set) {
73396 + struct crash_uid *tmpset;
73397 + spin_lock(&gr_uid_lock);
73398 + tmpset = uid_set;
73399 + uid_set = NULL;
73400 + uid_used = 0;
73401 + spin_unlock(&gr_uid_lock);
73402 + if (tmpset)
73403 + kfree(tmpset);
73404 + }
73405 +
73406 + return;
73407 +}
73408 +
73409 +int
73410 +gr_find_uid(const uid_t uid)
73411 +{
73412 + struct crash_uid *tmp = uid_set;
73413 + uid_t buid;
73414 + int low = 0, high = uid_used - 1, mid;
73415 +
73416 + while (high >= low) {
73417 + mid = (low + high) >> 1;
73418 + buid = tmp[mid].uid;
73419 + if (buid == uid)
73420 + return mid;
73421 + if (buid > uid)
73422 + high = mid - 1;
73423 + if (buid < uid)
73424 + low = mid + 1;
73425 + }
73426 +
73427 + return -1;
73428 +}
73429 +
73430 +static __inline__ void
73431 +gr_insertsort(void)
73432 +{
73433 + unsigned short i, j;
73434 + struct crash_uid index;
73435 +
73436 + for (i = 1; i < uid_used; i++) {
73437 + index = uid_set[i];
73438 + j = i;
73439 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
73440 + uid_set[j] = uid_set[j - 1];
73441 + j--;
73442 + }
73443 + uid_set[j] = index;
73444 + }
73445 +
73446 + return;
73447 +}
73448 +
73449 +static __inline__ void
73450 +gr_insert_uid(const kuid_t kuid, const unsigned long expires)
73451 +{
73452 + int loc;
73453 + uid_t uid = GR_GLOBAL_UID(kuid);
73454 +
73455 + if (uid_used == GR_UIDTABLE_MAX)
73456 + return;
73457 +
73458 + loc = gr_find_uid(uid);
73459 +
73460 + if (loc >= 0) {
73461 + uid_set[loc].expires = expires;
73462 + return;
73463 + }
73464 +
73465 + uid_set[uid_used].uid = uid;
73466 + uid_set[uid_used].expires = expires;
73467 + uid_used++;
73468 +
73469 + gr_insertsort();
73470 +
73471 + return;
73472 +}
73473 +
73474 +void
73475 +gr_remove_uid(const unsigned short loc)
73476 +{
73477 + unsigned short i;
73478 +
73479 + for (i = loc + 1; i < uid_used; i++)
73480 + uid_set[i - 1] = uid_set[i];
73481 +
73482 + uid_used--;
73483 +
73484 + return;
73485 +}
73486 +
73487 +int
73488 +gr_check_crash_uid(const kuid_t kuid)
73489 +{
73490 + int loc;
73491 + int ret = 0;
73492 + uid_t uid;
73493 +
73494 + if (unlikely(!gr_acl_is_enabled()))
73495 + return 0;
73496 +
73497 + uid = GR_GLOBAL_UID(kuid);
73498 +
73499 + spin_lock(&gr_uid_lock);
73500 + loc = gr_find_uid(uid);
73501 +
73502 + if (loc < 0)
73503 + goto out_unlock;
73504 +
73505 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
73506 + gr_remove_uid(loc);
73507 + else
73508 + ret = 1;
73509 +
73510 +out_unlock:
73511 + spin_unlock(&gr_uid_lock);
73512 + return ret;
73513 +}
73514 +
73515 +static __inline__ int
73516 +proc_is_setxid(const struct cred *cred)
73517 +{
73518 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
73519 + !uid_eq(cred->uid, cred->fsuid))
73520 + return 1;
73521 + if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
73522 + !gid_eq(cred->gid, cred->fsgid))
73523 + return 1;
73524 +
73525 + return 0;
73526 +}
73527 +
73528 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
73529 +
73530 +void
73531 +gr_handle_crash(struct task_struct *task, const int sig)
73532 +{
73533 + struct acl_subject_label *curr;
73534 + struct task_struct *tsk, *tsk2;
73535 + const struct cred *cred;
73536 + const struct cred *cred2;
73537 +
73538 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
73539 + return;
73540 +
73541 + if (unlikely(!gr_acl_is_enabled()))
73542 + return;
73543 +
73544 + curr = task->acl;
73545 +
73546 + if (!(curr->resmask & (1U << GR_CRASH_RES)))
73547 + return;
73548 +
73549 + if (time_before_eq(curr->expires, get_seconds())) {
73550 + curr->expires = 0;
73551 + curr->crashes = 0;
73552 + }
73553 +
73554 + curr->crashes++;
73555 +
73556 + if (!curr->expires)
73557 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
73558 +
73559 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
73560 + time_after(curr->expires, get_seconds())) {
73561 + rcu_read_lock();
73562 + cred = __task_cred(task);
73563 + if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
73564 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
73565 + spin_lock(&gr_uid_lock);
73566 + gr_insert_uid(cred->uid, curr->expires);
73567 + spin_unlock(&gr_uid_lock);
73568 + curr->expires = 0;
73569 + curr->crashes = 0;
73570 + read_lock(&tasklist_lock);
73571 + do_each_thread(tsk2, tsk) {
73572 + cred2 = __task_cred(tsk);
73573 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
73574 + gr_fake_force_sig(SIGKILL, tsk);
73575 + } while_each_thread(tsk2, tsk);
73576 + read_unlock(&tasklist_lock);
73577 + } else {
73578 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
73579 + read_lock(&tasklist_lock);
73580 + read_lock(&grsec_exec_file_lock);
73581 + do_each_thread(tsk2, tsk) {
73582 + if (likely(tsk != task)) {
73583 + // if this thread has the same subject as the one that triggered
73584 + // RES_CRASH and it's the same binary, kill it
73585 + if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
73586 + gr_fake_force_sig(SIGKILL, tsk);
73587 + }
73588 + } while_each_thread(tsk2, tsk);
73589 + read_unlock(&grsec_exec_file_lock);
73590 + read_unlock(&tasklist_lock);
73591 + }
73592 + rcu_read_unlock();
73593 + }
73594 +
73595 + return;
73596 +}
73597 +
73598 +int
73599 +gr_check_crash_exec(const struct file *filp)
73600 +{
73601 + struct acl_subject_label *curr;
73602 +
73603 + if (unlikely(!gr_acl_is_enabled()))
73604 + return 0;
73605 +
73606 + read_lock(&gr_inode_lock);
73607 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
73608 + __get_dev(filp->f_path.dentry),
73609 + current->role);
73610 + read_unlock(&gr_inode_lock);
73611 +
73612 + if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
73613 + (!curr->crashes && !curr->expires))
73614 + return 0;
73615 +
73616 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
73617 + time_after(curr->expires, get_seconds()))
73618 + return 1;
73619 + else if (time_before_eq(curr->expires, get_seconds())) {
73620 + curr->crashes = 0;
73621 + curr->expires = 0;
73622 + }
73623 +
73624 + return 0;
73625 +}
73626 +
73627 +void
73628 +gr_handle_alertkill(struct task_struct *task)
73629 +{
73630 + struct acl_subject_label *curracl;
73631 + __u32 curr_ip;
73632 + struct task_struct *p, *p2;
73633 +
73634 + if (unlikely(!gr_acl_is_enabled()))
73635 + return;
73636 +
73637 + curracl = task->acl;
73638 + curr_ip = task->signal->curr_ip;
73639 +
73640 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
73641 + read_lock(&tasklist_lock);
73642 + do_each_thread(p2, p) {
73643 + if (p->signal->curr_ip == curr_ip)
73644 + gr_fake_force_sig(SIGKILL, p);
73645 + } while_each_thread(p2, p);
73646 + read_unlock(&tasklist_lock);
73647 + } else if (curracl->mode & GR_KILLPROC)
73648 + gr_fake_force_sig(SIGKILL, task);
73649 +
73650 + return;
73651 +}
73652 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
73653 new file mode 100644
73654 index 0000000..98011b0
73655 --- /dev/null
73656 +++ b/grsecurity/gracl_shm.c
73657 @@ -0,0 +1,40 @@
73658 +#include <linux/kernel.h>
73659 +#include <linux/mm.h>
73660 +#include <linux/sched.h>
73661 +#include <linux/file.h>
73662 +#include <linux/ipc.h>
73663 +#include <linux/gracl.h>
73664 +#include <linux/grsecurity.h>
73665 +#include <linux/grinternal.h>
73666 +
73667 +int
73668 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73669 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
73670 +{
73671 + struct task_struct *task;
73672 +
73673 + if (!gr_acl_is_enabled())
73674 + return 1;
73675 +
73676 + rcu_read_lock();
73677 + read_lock(&tasklist_lock);
73678 +
73679 + task = find_task_by_vpid(shm_cprid);
73680 +
73681 + if (unlikely(!task))
73682 + task = find_task_by_vpid(shm_lapid);
73683 +
73684 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
73685 + (task_pid_nr(task) == shm_lapid)) &&
73686 + (task->acl->mode & GR_PROTSHM) &&
73687 + (task->acl != current->acl))) {
73688 + read_unlock(&tasklist_lock);
73689 + rcu_read_unlock();
73690 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
73691 + return 0;
73692 + }
73693 + read_unlock(&tasklist_lock);
73694 + rcu_read_unlock();
73695 +
73696 + return 1;
73697 +}
73698 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
73699 new file mode 100644
73700 index 0000000..bc0be01
73701 --- /dev/null
73702 +++ b/grsecurity/grsec_chdir.c
73703 @@ -0,0 +1,19 @@
73704 +#include <linux/kernel.h>
73705 +#include <linux/sched.h>
73706 +#include <linux/fs.h>
73707 +#include <linux/file.h>
73708 +#include <linux/grsecurity.h>
73709 +#include <linux/grinternal.h>
73710 +
73711 +void
73712 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
73713 +{
73714 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
73715 + if ((grsec_enable_chdir && grsec_enable_group &&
73716 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
73717 + !grsec_enable_group)) {
73718 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
73719 + }
73720 +#endif
73721 + return;
73722 +}
73723 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
73724 new file mode 100644
73725 index 0000000..baa635c
73726 --- /dev/null
73727 +++ b/grsecurity/grsec_chroot.c
73728 @@ -0,0 +1,387 @@
73729 +#include <linux/kernel.h>
73730 +#include <linux/module.h>
73731 +#include <linux/sched.h>
73732 +#include <linux/file.h>
73733 +#include <linux/fs.h>
73734 +#include <linux/mount.h>
73735 +#include <linux/types.h>
73736 +#include "../fs/mount.h"
73737 +#include <linux/grsecurity.h>
73738 +#include <linux/grinternal.h>
73739 +
73740 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73741 +int gr_init_ran;
73742 +#endif
73743 +
73744 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
73745 +{
73746 +#ifdef CONFIG_GRKERNSEC
73747 + if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
73748 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
73749 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73750 + && gr_init_ran
73751 +#endif
73752 + )
73753 + task->gr_is_chrooted = 1;
73754 + else {
73755 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73756 + if (task_pid_nr(task) == 1 && !gr_init_ran)
73757 + gr_init_ran = 1;
73758 +#endif
73759 + task->gr_is_chrooted = 0;
73760 + }
73761 +
73762 + task->gr_chroot_dentry = path->dentry;
73763 +#endif
73764 + return;
73765 +}
73766 +
73767 +void gr_clear_chroot_entries(struct task_struct *task)
73768 +{
73769 +#ifdef CONFIG_GRKERNSEC
73770 + task->gr_is_chrooted = 0;
73771 + task->gr_chroot_dentry = NULL;
73772 +#endif
73773 + return;
73774 +}
73775 +
73776 +int
73777 +gr_handle_chroot_unix(const pid_t pid)
73778 +{
73779 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
73780 + struct task_struct *p;
73781 +
73782 + if (unlikely(!grsec_enable_chroot_unix))
73783 + return 1;
73784 +
73785 + if (likely(!proc_is_chrooted(current)))
73786 + return 1;
73787 +
73788 + rcu_read_lock();
73789 + read_lock(&tasklist_lock);
73790 + p = find_task_by_vpid_unrestricted(pid);
73791 + if (unlikely(p && !have_same_root(current, p))) {
73792 + read_unlock(&tasklist_lock);
73793 + rcu_read_unlock();
73794 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
73795 + return 0;
73796 + }
73797 + read_unlock(&tasklist_lock);
73798 + rcu_read_unlock();
73799 +#endif
73800 + return 1;
73801 +}
73802 +
73803 +int
73804 +gr_handle_chroot_nice(void)
73805 +{
73806 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73807 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
73808 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
73809 + return -EPERM;
73810 + }
73811 +#endif
73812 + return 0;
73813 +}
73814 +
73815 +int
73816 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
73817 +{
73818 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73819 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
73820 + && proc_is_chrooted(current)) {
73821 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
73822 + return -EACCES;
73823 + }
73824 +#endif
73825 + return 0;
73826 +}
73827 +
73828 +int
73829 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
73830 +{
73831 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73832 + struct task_struct *p;
73833 + int ret = 0;
73834 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
73835 + return ret;
73836 +
73837 + read_lock(&tasklist_lock);
73838 + do_each_pid_task(pid, type, p) {
73839 + if (!have_same_root(current, p)) {
73840 + ret = 1;
73841 + goto out;
73842 + }
73843 + } while_each_pid_task(pid, type, p);
73844 +out:
73845 + read_unlock(&tasklist_lock);
73846 + return ret;
73847 +#endif
73848 + return 0;
73849 +}
73850 +
73851 +int
73852 +gr_pid_is_chrooted(struct task_struct *p)
73853 +{
73854 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73855 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
73856 + return 0;
73857 +
73858 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
73859 + !have_same_root(current, p)) {
73860 + return 1;
73861 + }
73862 +#endif
73863 + return 0;
73864 +}
73865 +
73866 +EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
73867 +
73868 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
73869 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
73870 +{
73871 + struct path path, currentroot;
73872 + int ret = 0;
73873 +
73874 + path.dentry = (struct dentry *)u_dentry;
73875 + path.mnt = (struct vfsmount *)u_mnt;
73876 + get_fs_root(current->fs, &currentroot);
73877 + if (path_is_under(&path, &currentroot))
73878 + ret = 1;
73879 + path_put(&currentroot);
73880 +
73881 + return ret;
73882 +}
73883 +#endif
73884 +
73885 +int
73886 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
73887 +{
73888 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
73889 + if (!grsec_enable_chroot_fchdir)
73890 + return 1;
73891 +
73892 + if (!proc_is_chrooted(current))
73893 + return 1;
73894 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
73895 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
73896 + return 0;
73897 + }
73898 +#endif
73899 + return 1;
73900 +}
73901 +
73902 +int
73903 +gr_chroot_fhandle(void)
73904 +{
73905 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
73906 + if (!grsec_enable_chroot_fchdir)
73907 + return 1;
73908 +
73909 + if (!proc_is_chrooted(current))
73910 + return 1;
73911 + else {
73912 + gr_log_noargs(GR_DONT_AUDIT, GR_CHROOT_FHANDLE_MSG);
73913 + return 0;
73914 + }
73915 +#endif
73916 + return 1;
73917 +}
73918 +
73919 +int
73920 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73921 + const time_t shm_createtime)
73922 +{
73923 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
73924 + struct task_struct *p;
73925 + time_t starttime;
73926 +
73927 + if (unlikely(!grsec_enable_chroot_shmat))
73928 + return 1;
73929 +
73930 + if (likely(!proc_is_chrooted(current)))
73931 + return 1;
73932 +
73933 + rcu_read_lock();
73934 + read_lock(&tasklist_lock);
73935 +
73936 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
73937 + starttime = p->start_time.tv_sec;
73938 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
73939 + if (have_same_root(current, p)) {
73940 + goto allow;
73941 + } else {
73942 + read_unlock(&tasklist_lock);
73943 + rcu_read_unlock();
73944 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73945 + return 0;
73946 + }
73947 + }
73948 + /* creator exited, pid reuse, fall through to next check */
73949 + }
73950 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
73951 + if (unlikely(!have_same_root(current, p))) {
73952 + read_unlock(&tasklist_lock);
73953 + rcu_read_unlock();
73954 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73955 + return 0;
73956 + }
73957 + }
73958 +
73959 +allow:
73960 + read_unlock(&tasklist_lock);
73961 + rcu_read_unlock();
73962 +#endif
73963 + return 1;
73964 +}
73965 +
73966 +void
73967 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
73968 +{
73969 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
73970 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
73971 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
73972 +#endif
73973 + return;
73974 +}
73975 +
73976 +int
73977 +gr_handle_chroot_mknod(const struct dentry *dentry,
73978 + const struct vfsmount *mnt, const int mode)
73979 +{
73980 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
73981 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
73982 + proc_is_chrooted(current)) {
73983 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
73984 + return -EPERM;
73985 + }
73986 +#endif
73987 + return 0;
73988 +}
73989 +
73990 +int
73991 +gr_handle_chroot_mount(const struct dentry *dentry,
73992 + const struct vfsmount *mnt, const char *dev_name)
73993 +{
73994 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
73995 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
73996 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
73997 + return -EPERM;
73998 + }
73999 +#endif
74000 + return 0;
74001 +}
74002 +
74003 +int
74004 +gr_handle_chroot_pivot(void)
74005 +{
74006 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
74007 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
74008 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
74009 + return -EPERM;
74010 + }
74011 +#endif
74012 + return 0;
74013 +}
74014 +
74015 +int
74016 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
74017 +{
74018 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
74019 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
74020 + !gr_is_outside_chroot(dentry, mnt)) {
74021 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
74022 + return -EPERM;
74023 + }
74024 +#endif
74025 + return 0;
74026 +}
74027 +
74028 +extern const char *captab_log[];
74029 +extern int captab_log_entries;
74030 +
74031 +int
74032 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
74033 +{
74034 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74035 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
74036 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
74037 + if (cap_raised(chroot_caps, cap)) {
74038 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
74039 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
74040 + }
74041 + return 0;
74042 + }
74043 + }
74044 +#endif
74045 + return 1;
74046 +}
74047 +
74048 +int
74049 +gr_chroot_is_capable(const int cap)
74050 +{
74051 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74052 + return gr_task_chroot_is_capable(current, current_cred(), cap);
74053 +#endif
74054 + return 1;
74055 +}
74056 +
74057 +int
74058 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
74059 +{
74060 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74061 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
74062 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
74063 + if (cap_raised(chroot_caps, cap)) {
74064 + return 0;
74065 + }
74066 + }
74067 +#endif
74068 + return 1;
74069 +}
74070 +
74071 +int
74072 +gr_chroot_is_capable_nolog(const int cap)
74073 +{
74074 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74075 + return gr_task_chroot_is_capable_nolog(current, cap);
74076 +#endif
74077 + return 1;
74078 +}
74079 +
74080 +int
74081 +gr_handle_chroot_sysctl(const int op)
74082 +{
74083 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
74084 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
74085 + proc_is_chrooted(current))
74086 + return -EACCES;
74087 +#endif
74088 + return 0;
74089 +}
74090 +
74091 +void
74092 +gr_handle_chroot_chdir(const struct path *path)
74093 +{
74094 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
74095 + if (grsec_enable_chroot_chdir)
74096 + set_fs_pwd(current->fs, path);
74097 +#endif
74098 + return;
74099 +}
74100 +
74101 +int
74102 +gr_handle_chroot_chmod(const struct dentry *dentry,
74103 + const struct vfsmount *mnt, const int mode)
74104 +{
74105 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
74106 + /* allow chmod +s on directories, but not files */
74107 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
74108 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
74109 + proc_is_chrooted(current)) {
74110 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
74111 + return -EPERM;
74112 + }
74113 +#endif
74114 + return 0;
74115 +}
74116 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
74117 new file mode 100644
74118 index 0000000..de31e65
74119 --- /dev/null
74120 +++ b/grsecurity/grsec_disabled.c
74121 @@ -0,0 +1,434 @@
74122 +#include <linux/kernel.h>
74123 +#include <linux/module.h>
74124 +#include <linux/sched.h>
74125 +#include <linux/file.h>
74126 +#include <linux/fs.h>
74127 +#include <linux/kdev_t.h>
74128 +#include <linux/net.h>
74129 +#include <linux/in.h>
74130 +#include <linux/ip.h>
74131 +#include <linux/skbuff.h>
74132 +#include <linux/sysctl.h>
74133 +
74134 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
74135 +void
74136 +pax_set_initial_flags(struct linux_binprm *bprm)
74137 +{
74138 + return;
74139 +}
74140 +#endif
74141 +
74142 +#ifdef CONFIG_SYSCTL
74143 +__u32
74144 +gr_handle_sysctl(const struct ctl_table * table, const int op)
74145 +{
74146 + return 0;
74147 +}
74148 +#endif
74149 +
74150 +#ifdef CONFIG_TASKSTATS
74151 +int gr_is_taskstats_denied(int pid)
74152 +{
74153 + return 0;
74154 +}
74155 +#endif
74156 +
74157 +int
74158 +gr_acl_is_enabled(void)
74159 +{
74160 + return 0;
74161 +}
74162 +
74163 +void
74164 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
74165 +{
74166 + return;
74167 +}
74168 +
74169 +int
74170 +gr_handle_rawio(const struct inode *inode)
74171 +{
74172 + return 0;
74173 +}
74174 +
74175 +void
74176 +gr_acl_handle_psacct(struct task_struct *task, const long code)
74177 +{
74178 + return;
74179 +}
74180 +
74181 +int
74182 +gr_handle_ptrace(struct task_struct *task, const long request)
74183 +{
74184 + return 0;
74185 +}
74186 +
74187 +int
74188 +gr_handle_proc_ptrace(struct task_struct *task)
74189 +{
74190 + return 0;
74191 +}
74192 +
74193 +int
74194 +gr_set_acls(const int type)
74195 +{
74196 + return 0;
74197 +}
74198 +
74199 +int
74200 +gr_check_hidden_task(const struct task_struct *tsk)
74201 +{
74202 + return 0;
74203 +}
74204 +
74205 +int
74206 +gr_check_protected_task(const struct task_struct *task)
74207 +{
74208 + return 0;
74209 +}
74210 +
74211 +int
74212 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
74213 +{
74214 + return 0;
74215 +}
74216 +
74217 +void
74218 +gr_copy_label(struct task_struct *tsk)
74219 +{
74220 + return;
74221 +}
74222 +
74223 +void
74224 +gr_set_pax_flags(struct task_struct *task)
74225 +{
74226 + return;
74227 +}
74228 +
74229 +int
74230 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
74231 + const int unsafe_share)
74232 +{
74233 + return 0;
74234 +}
74235 +
74236 +void
74237 +gr_handle_delete(const ino_t ino, const dev_t dev)
74238 +{
74239 + return;
74240 +}
74241 +
74242 +void
74243 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
74244 +{
74245 + return;
74246 +}
74247 +
74248 +void
74249 +gr_handle_crash(struct task_struct *task, const int sig)
74250 +{
74251 + return;
74252 +}
74253 +
74254 +int
74255 +gr_check_crash_exec(const struct file *filp)
74256 +{
74257 + return 0;
74258 +}
74259 +
74260 +int
74261 +gr_check_crash_uid(const kuid_t uid)
74262 +{
74263 + return 0;
74264 +}
74265 +
74266 +void
74267 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
74268 + struct dentry *old_dentry,
74269 + struct dentry *new_dentry,
74270 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
74271 +{
74272 + return;
74273 +}
74274 +
74275 +int
74276 +gr_search_socket(const int family, const int type, const int protocol)
74277 +{
74278 + return 1;
74279 +}
74280 +
74281 +int
74282 +gr_search_connectbind(const int mode, const struct socket *sock,
74283 + const struct sockaddr_in *addr)
74284 +{
74285 + return 0;
74286 +}
74287 +
74288 +void
74289 +gr_handle_alertkill(struct task_struct *task)
74290 +{
74291 + return;
74292 +}
74293 +
74294 +__u32
74295 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
74296 +{
74297 + return 1;
74298 +}
74299 +
74300 +__u32
74301 +gr_acl_handle_hidden_file(const struct dentry * dentry,
74302 + const struct vfsmount * mnt)
74303 +{
74304 + return 1;
74305 +}
74306 +
74307 +__u32
74308 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
74309 + int acc_mode)
74310 +{
74311 + return 1;
74312 +}
74313 +
74314 +__u32
74315 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
74316 +{
74317 + return 1;
74318 +}
74319 +
74320 +__u32
74321 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
74322 +{
74323 + return 1;
74324 +}
74325 +
74326 +int
74327 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
74328 + unsigned int *vm_flags)
74329 +{
74330 + return 1;
74331 +}
74332 +
74333 +__u32
74334 +gr_acl_handle_truncate(const struct dentry * dentry,
74335 + const struct vfsmount * mnt)
74336 +{
74337 + return 1;
74338 +}
74339 +
74340 +__u32
74341 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
74342 +{
74343 + return 1;
74344 +}
74345 +
74346 +__u32
74347 +gr_acl_handle_access(const struct dentry * dentry,
74348 + const struct vfsmount * mnt, const int fmode)
74349 +{
74350 + return 1;
74351 +}
74352 +
74353 +__u32
74354 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
74355 + umode_t *mode)
74356 +{
74357 + return 1;
74358 +}
74359 +
74360 +__u32
74361 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
74362 +{
74363 + return 1;
74364 +}
74365 +
74366 +__u32
74367 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
74368 +{
74369 + return 1;
74370 +}
74371 +
74372 +__u32
74373 +gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
74374 +{
74375 + return 1;
74376 +}
74377 +
74378 +void
74379 +grsecurity_init(void)
74380 +{
74381 + return;
74382 +}
74383 +
74384 +umode_t gr_acl_umask(void)
74385 +{
74386 + return 0;
74387 +}
74388 +
74389 +__u32
74390 +gr_acl_handle_mknod(const struct dentry * new_dentry,
74391 + const struct dentry * parent_dentry,
74392 + const struct vfsmount * parent_mnt,
74393 + const int mode)
74394 +{
74395 + return 1;
74396 +}
74397 +
74398 +__u32
74399 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
74400 + const struct dentry * parent_dentry,
74401 + const struct vfsmount * parent_mnt)
74402 +{
74403 + return 1;
74404 +}
74405 +
74406 +__u32
74407 +gr_acl_handle_symlink(const struct dentry * new_dentry,
74408 + const struct dentry * parent_dentry,
74409 + const struct vfsmount * parent_mnt, const struct filename *from)
74410 +{
74411 + return 1;
74412 +}
74413 +
74414 +__u32
74415 +gr_acl_handle_link(const struct dentry * new_dentry,
74416 + const struct dentry * parent_dentry,
74417 + const struct vfsmount * parent_mnt,
74418 + const struct dentry * old_dentry,
74419 + const struct vfsmount * old_mnt, const struct filename *to)
74420 +{
74421 + return 1;
74422 +}
74423 +
74424 +int
74425 +gr_acl_handle_rename(const struct dentry *new_dentry,
74426 + const struct dentry *parent_dentry,
74427 + const struct vfsmount *parent_mnt,
74428 + const struct dentry *old_dentry,
74429 + const struct inode *old_parent_inode,
74430 + const struct vfsmount *old_mnt, const struct filename *newname,
74431 + unsigned int flags)
74432 +{
74433 + return 0;
74434 +}
74435 +
74436 +int
74437 +gr_acl_handle_filldir(const struct file *file, const char *name,
74438 + const int namelen, const ino_t ino)
74439 +{
74440 + return 1;
74441 +}
74442 +
74443 +int
74444 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74445 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
74446 +{
74447 + return 1;
74448 +}
74449 +
74450 +int
74451 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
74452 +{
74453 + return 0;
74454 +}
74455 +
74456 +int
74457 +gr_search_accept(const struct socket *sock)
74458 +{
74459 + return 0;
74460 +}
74461 +
74462 +int
74463 +gr_search_listen(const struct socket *sock)
74464 +{
74465 + return 0;
74466 +}
74467 +
74468 +int
74469 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
74470 +{
74471 + return 0;
74472 +}
74473 +
74474 +__u32
74475 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
74476 +{
74477 + return 1;
74478 +}
74479 +
74480 +__u32
74481 +gr_acl_handle_creat(const struct dentry * dentry,
74482 + const struct dentry * p_dentry,
74483 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
74484 + const int imode)
74485 +{
74486 + return 1;
74487 +}
74488 +
74489 +void
74490 +gr_acl_handle_exit(void)
74491 +{
74492 + return;
74493 +}
74494 +
74495 +int
74496 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
74497 +{
74498 + return 1;
74499 +}
74500 +
74501 +void
74502 +gr_set_role_label(const kuid_t uid, const kgid_t gid)
74503 +{
74504 + return;
74505 +}
74506 +
74507 +int
74508 +gr_acl_handle_procpidmem(const struct task_struct *task)
74509 +{
74510 + return 0;
74511 +}
74512 +
74513 +int
74514 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
74515 +{
74516 + return 0;
74517 +}
74518 +
74519 +int
74520 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
74521 +{
74522 + return 0;
74523 +}
74524 +
74525 +int
74526 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
74527 +{
74528 + return 0;
74529 +}
74530 +
74531 +int
74532 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
74533 +{
74534 + return 0;
74535 +}
74536 +
74537 +int gr_acl_enable_at_secure(void)
74538 +{
74539 + return 0;
74540 +}
74541 +
74542 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
74543 +{
74544 + return dentry->d_sb->s_dev;
74545 +}
74546 +
74547 +void gr_put_exec_file(struct task_struct *task)
74548 +{
74549 + return;
74550 +}
74551 +
74552 +#ifdef CONFIG_SECURITY
74553 +EXPORT_SYMBOL_GPL(gr_check_user_change);
74554 +EXPORT_SYMBOL_GPL(gr_check_group_change);
74555 +#endif
74556 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
74557 new file mode 100644
74558 index 0000000..f35f454
74559 --- /dev/null
74560 +++ b/grsecurity/grsec_exec.c
74561 @@ -0,0 +1,187 @@
74562 +#include <linux/kernel.h>
74563 +#include <linux/sched.h>
74564 +#include <linux/file.h>
74565 +#include <linux/binfmts.h>
74566 +#include <linux/fs.h>
74567 +#include <linux/types.h>
74568 +#include <linux/grdefs.h>
74569 +#include <linux/grsecurity.h>
74570 +#include <linux/grinternal.h>
74571 +#include <linux/capability.h>
74572 +#include <linux/module.h>
74573 +#include <linux/compat.h>
74574 +
74575 +#include <asm/uaccess.h>
74576 +
74577 +#ifdef CONFIG_GRKERNSEC_EXECLOG
74578 +static char gr_exec_arg_buf[132];
74579 +static DEFINE_MUTEX(gr_exec_arg_mutex);
74580 +#endif
74581 +
74582 +struct user_arg_ptr {
74583 +#ifdef CONFIG_COMPAT
74584 + bool is_compat;
74585 +#endif
74586 + union {
74587 + const char __user *const __user *native;
74588 +#ifdef CONFIG_COMPAT
74589 + const compat_uptr_t __user *compat;
74590 +#endif
74591 + } ptr;
74592 +};
74593 +
74594 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
74595 +
74596 +void
74597 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
74598 +{
74599 +#ifdef CONFIG_GRKERNSEC_EXECLOG
74600 + char *grarg = gr_exec_arg_buf;
74601 + unsigned int i, x, execlen = 0;
74602 + char c;
74603 +
74604 + if (!((grsec_enable_execlog && grsec_enable_group &&
74605 + in_group_p(grsec_audit_gid))
74606 + || (grsec_enable_execlog && !grsec_enable_group)))
74607 + return;
74608 +
74609 + mutex_lock(&gr_exec_arg_mutex);
74610 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
74611 +
74612 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
74613 + const char __user *p;
74614 + unsigned int len;
74615 +
74616 + p = get_user_arg_ptr(argv, i);
74617 + if (IS_ERR(p))
74618 + goto log;
74619 +
74620 + len = strnlen_user(p, 128 - execlen);
74621 + if (len > 128 - execlen)
74622 + len = 128 - execlen;
74623 + else if (len > 0)
74624 + len--;
74625 + if (copy_from_user(grarg + execlen, p, len))
74626 + goto log;
74627 +
74628 + /* rewrite unprintable characters */
74629 + for (x = 0; x < len; x++) {
74630 + c = *(grarg + execlen + x);
74631 + if (c < 32 || c > 126)
74632 + *(grarg + execlen + x) = ' ';
74633 + }
74634 +
74635 + execlen += len;
74636 + *(grarg + execlen) = ' ';
74637 + *(grarg + execlen + 1) = '\0';
74638 + execlen++;
74639 + }
74640 +
74641 + log:
74642 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
74643 + bprm->file->f_path.mnt, grarg);
74644 + mutex_unlock(&gr_exec_arg_mutex);
74645 +#endif
74646 + return;
74647 +}
74648 +
74649 +#ifdef CONFIG_GRKERNSEC
74650 +extern int gr_acl_is_capable(const int cap);
74651 +extern int gr_acl_is_capable_nolog(const int cap);
74652 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74653 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
74654 +extern int gr_chroot_is_capable(const int cap);
74655 +extern int gr_chroot_is_capable_nolog(const int cap);
74656 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74657 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
74658 +#endif
74659 +
74660 +const char *captab_log[] = {
74661 + "CAP_CHOWN",
74662 + "CAP_DAC_OVERRIDE",
74663 + "CAP_DAC_READ_SEARCH",
74664 + "CAP_FOWNER",
74665 + "CAP_FSETID",
74666 + "CAP_KILL",
74667 + "CAP_SETGID",
74668 + "CAP_SETUID",
74669 + "CAP_SETPCAP",
74670 + "CAP_LINUX_IMMUTABLE",
74671 + "CAP_NET_BIND_SERVICE",
74672 + "CAP_NET_BROADCAST",
74673 + "CAP_NET_ADMIN",
74674 + "CAP_NET_RAW",
74675 + "CAP_IPC_LOCK",
74676 + "CAP_IPC_OWNER",
74677 + "CAP_SYS_MODULE",
74678 + "CAP_SYS_RAWIO",
74679 + "CAP_SYS_CHROOT",
74680 + "CAP_SYS_PTRACE",
74681 + "CAP_SYS_PACCT",
74682 + "CAP_SYS_ADMIN",
74683 + "CAP_SYS_BOOT",
74684 + "CAP_SYS_NICE",
74685 + "CAP_SYS_RESOURCE",
74686 + "CAP_SYS_TIME",
74687 + "CAP_SYS_TTY_CONFIG",
74688 + "CAP_MKNOD",
74689 + "CAP_LEASE",
74690 + "CAP_AUDIT_WRITE",
74691 + "CAP_AUDIT_CONTROL",
74692 + "CAP_SETFCAP",
74693 + "CAP_MAC_OVERRIDE",
74694 + "CAP_MAC_ADMIN",
74695 + "CAP_SYSLOG",
74696 + "CAP_WAKE_ALARM"
74697 +};
74698 +
74699 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
74700 +
74701 +int gr_is_capable(const int cap)
74702 +{
74703 +#ifdef CONFIG_GRKERNSEC
74704 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
74705 + return 1;
74706 + return 0;
74707 +#else
74708 + return 1;
74709 +#endif
74710 +}
74711 +
74712 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
74713 +{
74714 +#ifdef CONFIG_GRKERNSEC
74715 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
74716 + return 1;
74717 + return 0;
74718 +#else
74719 + return 1;
74720 +#endif
74721 +}
74722 +
74723 +int gr_is_capable_nolog(const int cap)
74724 +{
74725 +#ifdef CONFIG_GRKERNSEC
74726 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
74727 + return 1;
74728 + return 0;
74729 +#else
74730 + return 1;
74731 +#endif
74732 +}
74733 +
74734 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
74735 +{
74736 +#ifdef CONFIG_GRKERNSEC
74737 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
74738 + return 1;
74739 + return 0;
74740 +#else
74741 + return 1;
74742 +#endif
74743 +}
74744 +
74745 +EXPORT_SYMBOL_GPL(gr_is_capable);
74746 +EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
74747 +EXPORT_SYMBOL_GPL(gr_task_is_capable);
74748 +EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
74749 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
74750 new file mode 100644
74751 index 0000000..06cc6ea
74752 --- /dev/null
74753 +++ b/grsecurity/grsec_fifo.c
74754 @@ -0,0 +1,24 @@
74755 +#include <linux/kernel.h>
74756 +#include <linux/sched.h>
74757 +#include <linux/fs.h>
74758 +#include <linux/file.h>
74759 +#include <linux/grinternal.h>
74760 +
74761 +int
74762 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
74763 + const struct dentry *dir, const int flag, const int acc_mode)
74764 +{
74765 +#ifdef CONFIG_GRKERNSEC_FIFO
74766 + const struct cred *cred = current_cred();
74767 +
74768 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
74769 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
74770 + !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
74771 + !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
74772 + if (!inode_permission(dentry->d_inode, acc_mode))
74773 + 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));
74774 + return -EACCES;
74775 + }
74776 +#endif
74777 + return 0;
74778 +}
74779 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
74780 new file mode 100644
74781 index 0000000..8ca18bf
74782 --- /dev/null
74783 +++ b/grsecurity/grsec_fork.c
74784 @@ -0,0 +1,23 @@
74785 +#include <linux/kernel.h>
74786 +#include <linux/sched.h>
74787 +#include <linux/grsecurity.h>
74788 +#include <linux/grinternal.h>
74789 +#include <linux/errno.h>
74790 +
74791 +void
74792 +gr_log_forkfail(const int retval)
74793 +{
74794 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
74795 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
74796 + switch (retval) {
74797 + case -EAGAIN:
74798 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
74799 + break;
74800 + case -ENOMEM:
74801 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
74802 + break;
74803 + }
74804 + }
74805 +#endif
74806 + return;
74807 +}
74808 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
74809 new file mode 100644
74810 index 0000000..b7cb191
74811 --- /dev/null
74812 +++ b/grsecurity/grsec_init.c
74813 @@ -0,0 +1,286 @@
74814 +#include <linux/kernel.h>
74815 +#include <linux/sched.h>
74816 +#include <linux/mm.h>
74817 +#include <linux/gracl.h>
74818 +#include <linux/slab.h>
74819 +#include <linux/vmalloc.h>
74820 +#include <linux/percpu.h>
74821 +#include <linux/module.h>
74822 +
74823 +int grsec_enable_ptrace_readexec;
74824 +int grsec_enable_setxid;
74825 +int grsec_enable_symlinkown;
74826 +kgid_t grsec_symlinkown_gid;
74827 +int grsec_enable_brute;
74828 +int grsec_enable_link;
74829 +int grsec_enable_dmesg;
74830 +int grsec_enable_harden_ptrace;
74831 +int grsec_enable_harden_ipc;
74832 +int grsec_enable_fifo;
74833 +int grsec_enable_execlog;
74834 +int grsec_enable_signal;
74835 +int grsec_enable_forkfail;
74836 +int grsec_enable_audit_ptrace;
74837 +int grsec_enable_time;
74838 +int grsec_enable_group;
74839 +kgid_t grsec_audit_gid;
74840 +int grsec_enable_chdir;
74841 +int grsec_enable_mount;
74842 +int grsec_enable_rofs;
74843 +int grsec_deny_new_usb;
74844 +int grsec_enable_chroot_findtask;
74845 +int grsec_enable_chroot_mount;
74846 +int grsec_enable_chroot_shmat;
74847 +int grsec_enable_chroot_fchdir;
74848 +int grsec_enable_chroot_double;
74849 +int grsec_enable_chroot_pivot;
74850 +int grsec_enable_chroot_chdir;
74851 +int grsec_enable_chroot_chmod;
74852 +int grsec_enable_chroot_mknod;
74853 +int grsec_enable_chroot_nice;
74854 +int grsec_enable_chroot_execlog;
74855 +int grsec_enable_chroot_caps;
74856 +int grsec_enable_chroot_sysctl;
74857 +int grsec_enable_chroot_unix;
74858 +int grsec_enable_tpe;
74859 +kgid_t grsec_tpe_gid;
74860 +int grsec_enable_blackhole;
74861 +#ifdef CONFIG_IPV6_MODULE
74862 +EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
74863 +#endif
74864 +int grsec_lastack_retries;
74865 +int grsec_enable_tpe_all;
74866 +int grsec_enable_tpe_invert;
74867 +int grsec_enable_socket_all;
74868 +kgid_t grsec_socket_all_gid;
74869 +int grsec_enable_socket_client;
74870 +kgid_t grsec_socket_client_gid;
74871 +int grsec_enable_socket_server;
74872 +kgid_t grsec_socket_server_gid;
74873 +int grsec_resource_logging;
74874 +int grsec_disable_privio;
74875 +int grsec_enable_log_rwxmaps;
74876 +int grsec_lock;
74877 +
74878 +DEFINE_SPINLOCK(grsec_alert_lock);
74879 +unsigned long grsec_alert_wtime = 0;
74880 +unsigned long grsec_alert_fyet = 0;
74881 +
74882 +DEFINE_SPINLOCK(grsec_audit_lock);
74883 +
74884 +DEFINE_RWLOCK(grsec_exec_file_lock);
74885 +
74886 +char *gr_shared_page[4];
74887 +
74888 +char *gr_alert_log_fmt;
74889 +char *gr_audit_log_fmt;
74890 +char *gr_alert_log_buf;
74891 +char *gr_audit_log_buf;
74892 +
74893 +extern struct gr_arg *gr_usermode;
74894 +extern unsigned char *gr_system_salt;
74895 +extern unsigned char *gr_system_sum;
74896 +
74897 +void __init
74898 +grsecurity_init(void)
74899 +{
74900 + int j;
74901 + /* create the per-cpu shared pages */
74902 +
74903 +#ifdef CONFIG_X86
74904 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
74905 +#endif
74906 +
74907 + for (j = 0; j < 4; j++) {
74908 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
74909 + if (gr_shared_page[j] == NULL) {
74910 + panic("Unable to allocate grsecurity shared page");
74911 + return;
74912 + }
74913 + }
74914 +
74915 + /* allocate log buffers */
74916 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
74917 + if (!gr_alert_log_fmt) {
74918 + panic("Unable to allocate grsecurity alert log format buffer");
74919 + return;
74920 + }
74921 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
74922 + if (!gr_audit_log_fmt) {
74923 + panic("Unable to allocate grsecurity audit log format buffer");
74924 + return;
74925 + }
74926 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74927 + if (!gr_alert_log_buf) {
74928 + panic("Unable to allocate grsecurity alert log buffer");
74929 + return;
74930 + }
74931 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74932 + if (!gr_audit_log_buf) {
74933 + panic("Unable to allocate grsecurity audit log buffer");
74934 + return;
74935 + }
74936 +
74937 + /* allocate memory for authentication structure */
74938 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
74939 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
74940 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
74941 +
74942 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
74943 + panic("Unable to allocate grsecurity authentication structure");
74944 + return;
74945 + }
74946 +
74947 +#ifdef CONFIG_GRKERNSEC_IO
74948 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
74949 + grsec_disable_privio = 1;
74950 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74951 + grsec_disable_privio = 1;
74952 +#else
74953 + grsec_disable_privio = 0;
74954 +#endif
74955 +#endif
74956 +
74957 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
74958 + /* for backward compatibility, tpe_invert always defaults to on if
74959 + enabled in the kernel
74960 + */
74961 + grsec_enable_tpe_invert = 1;
74962 +#endif
74963 +
74964 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74965 +#ifndef CONFIG_GRKERNSEC_SYSCTL
74966 + grsec_lock = 1;
74967 +#endif
74968 +
74969 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74970 + grsec_enable_log_rwxmaps = 1;
74971 +#endif
74972 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
74973 + grsec_enable_group = 1;
74974 + grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
74975 +#endif
74976 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
74977 + grsec_enable_ptrace_readexec = 1;
74978 +#endif
74979 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
74980 + grsec_enable_chdir = 1;
74981 +#endif
74982 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
74983 + grsec_enable_harden_ptrace = 1;
74984 +#endif
74985 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74986 + grsec_enable_harden_ipc = 1;
74987 +#endif
74988 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74989 + grsec_enable_mount = 1;
74990 +#endif
74991 +#ifdef CONFIG_GRKERNSEC_LINK
74992 + grsec_enable_link = 1;
74993 +#endif
74994 +#ifdef CONFIG_GRKERNSEC_BRUTE
74995 + grsec_enable_brute = 1;
74996 +#endif
74997 +#ifdef CONFIG_GRKERNSEC_DMESG
74998 + grsec_enable_dmesg = 1;
74999 +#endif
75000 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75001 + grsec_enable_blackhole = 1;
75002 + grsec_lastack_retries = 4;
75003 +#endif
75004 +#ifdef CONFIG_GRKERNSEC_FIFO
75005 + grsec_enable_fifo = 1;
75006 +#endif
75007 +#ifdef CONFIG_GRKERNSEC_EXECLOG
75008 + grsec_enable_execlog = 1;
75009 +#endif
75010 +#ifdef CONFIG_GRKERNSEC_SETXID
75011 + grsec_enable_setxid = 1;
75012 +#endif
75013 +#ifdef CONFIG_GRKERNSEC_SIGNAL
75014 + grsec_enable_signal = 1;
75015 +#endif
75016 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
75017 + grsec_enable_forkfail = 1;
75018 +#endif
75019 +#ifdef CONFIG_GRKERNSEC_TIME
75020 + grsec_enable_time = 1;
75021 +#endif
75022 +#ifdef CONFIG_GRKERNSEC_RESLOG
75023 + grsec_resource_logging = 1;
75024 +#endif
75025 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
75026 + grsec_enable_chroot_findtask = 1;
75027 +#endif
75028 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
75029 + grsec_enable_chroot_unix = 1;
75030 +#endif
75031 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
75032 + grsec_enable_chroot_mount = 1;
75033 +#endif
75034 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
75035 + grsec_enable_chroot_fchdir = 1;
75036 +#endif
75037 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
75038 + grsec_enable_chroot_shmat = 1;
75039 +#endif
75040 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
75041 + grsec_enable_audit_ptrace = 1;
75042 +#endif
75043 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
75044 + grsec_enable_chroot_double = 1;
75045 +#endif
75046 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
75047 + grsec_enable_chroot_pivot = 1;
75048 +#endif
75049 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
75050 + grsec_enable_chroot_chdir = 1;
75051 +#endif
75052 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
75053 + grsec_enable_chroot_chmod = 1;
75054 +#endif
75055 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
75056 + grsec_enable_chroot_mknod = 1;
75057 +#endif
75058 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
75059 + grsec_enable_chroot_nice = 1;
75060 +#endif
75061 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
75062 + grsec_enable_chroot_execlog = 1;
75063 +#endif
75064 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
75065 + grsec_enable_chroot_caps = 1;
75066 +#endif
75067 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
75068 + grsec_enable_chroot_sysctl = 1;
75069 +#endif
75070 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
75071 + grsec_enable_symlinkown = 1;
75072 + grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
75073 +#endif
75074 +#ifdef CONFIG_GRKERNSEC_TPE
75075 + grsec_enable_tpe = 1;
75076 + grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
75077 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
75078 + grsec_enable_tpe_all = 1;
75079 +#endif
75080 +#endif
75081 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
75082 + grsec_enable_socket_all = 1;
75083 + grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
75084 +#endif
75085 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
75086 + grsec_enable_socket_client = 1;
75087 + grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
75088 +#endif
75089 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75090 + grsec_enable_socket_server = 1;
75091 + grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
75092 +#endif
75093 +#endif
75094 +#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
75095 + grsec_deny_new_usb = 1;
75096 +#endif
75097 +
75098 + return;
75099 +}
75100 diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
75101 new file mode 100644
75102 index 0000000..1773300
75103 --- /dev/null
75104 +++ b/grsecurity/grsec_ipc.c
75105 @@ -0,0 +1,48 @@
75106 +#include <linux/kernel.h>
75107 +#include <linux/mm.h>
75108 +#include <linux/sched.h>
75109 +#include <linux/file.h>
75110 +#include <linux/ipc.h>
75111 +#include <linux/ipc_namespace.h>
75112 +#include <linux/grsecurity.h>
75113 +#include <linux/grinternal.h>
75114 +
75115 +int
75116 +gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
75117 +{
75118 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
75119 + int write;
75120 + int orig_granted_mode;
75121 + kuid_t euid;
75122 + kgid_t egid;
75123 +
75124 + if (!grsec_enable_harden_ipc)
75125 + return 1;
75126 +
75127 + euid = current_euid();
75128 + egid = current_egid();
75129 +
75130 + write = requested_mode & 00002;
75131 + orig_granted_mode = ipcp->mode;
75132 +
75133 + if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
75134 + orig_granted_mode >>= 6;
75135 + else {
75136 + /* if likely wrong permissions, lock to user */
75137 + if (orig_granted_mode & 0007)
75138 + orig_granted_mode = 0;
75139 + /* otherwise do a egid-only check */
75140 + else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
75141 + orig_granted_mode >>= 3;
75142 + /* otherwise, no access */
75143 + else
75144 + orig_granted_mode = 0;
75145 + }
75146 + if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
75147 + !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
75148 + gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
75149 + return 0;
75150 + }
75151 +#endif
75152 + return 1;
75153 +}
75154 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
75155 new file mode 100644
75156 index 0000000..5e05e20
75157 --- /dev/null
75158 +++ b/grsecurity/grsec_link.c
75159 @@ -0,0 +1,58 @@
75160 +#include <linux/kernel.h>
75161 +#include <linux/sched.h>
75162 +#include <linux/fs.h>
75163 +#include <linux/file.h>
75164 +#include <linux/grinternal.h>
75165 +
75166 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
75167 +{
75168 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
75169 + const struct inode *link_inode = link->dentry->d_inode;
75170 +
75171 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
75172 + /* ignore root-owned links, e.g. /proc/self */
75173 + gr_is_global_nonroot(link_inode->i_uid) && target &&
75174 + !uid_eq(link_inode->i_uid, target->i_uid)) {
75175 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
75176 + return 1;
75177 + }
75178 +#endif
75179 + return 0;
75180 +}
75181 +
75182 +int
75183 +gr_handle_follow_link(const struct inode *parent,
75184 + const struct inode *inode,
75185 + const struct dentry *dentry, const struct vfsmount *mnt)
75186 +{
75187 +#ifdef CONFIG_GRKERNSEC_LINK
75188 + const struct cred *cred = current_cred();
75189 +
75190 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
75191 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
75192 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
75193 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
75194 + return -EACCES;
75195 + }
75196 +#endif
75197 + return 0;
75198 +}
75199 +
75200 +int
75201 +gr_handle_hardlink(const struct dentry *dentry,
75202 + const struct vfsmount *mnt,
75203 + struct inode *inode, const int mode, const struct filename *to)
75204 +{
75205 +#ifdef CONFIG_GRKERNSEC_LINK
75206 + const struct cred *cred = current_cred();
75207 +
75208 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
75209 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
75210 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
75211 + !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
75212 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
75213 + return -EPERM;
75214 + }
75215 +#endif
75216 + return 0;
75217 +}
75218 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
75219 new file mode 100644
75220 index 0000000..dbe0a6b
75221 --- /dev/null
75222 +++ b/grsecurity/grsec_log.c
75223 @@ -0,0 +1,341 @@
75224 +#include <linux/kernel.h>
75225 +#include <linux/sched.h>
75226 +#include <linux/file.h>
75227 +#include <linux/tty.h>
75228 +#include <linux/fs.h>
75229 +#include <linux/mm.h>
75230 +#include <linux/grinternal.h>
75231 +
75232 +#ifdef CONFIG_TREE_PREEMPT_RCU
75233 +#define DISABLE_PREEMPT() preempt_disable()
75234 +#define ENABLE_PREEMPT() preempt_enable()
75235 +#else
75236 +#define DISABLE_PREEMPT()
75237 +#define ENABLE_PREEMPT()
75238 +#endif
75239 +
75240 +#define BEGIN_LOCKS(x) \
75241 + DISABLE_PREEMPT(); \
75242 + rcu_read_lock(); \
75243 + read_lock(&tasklist_lock); \
75244 + read_lock(&grsec_exec_file_lock); \
75245 + if (x != GR_DO_AUDIT) \
75246 + spin_lock(&grsec_alert_lock); \
75247 + else \
75248 + spin_lock(&grsec_audit_lock)
75249 +
75250 +#define END_LOCKS(x) \
75251 + if (x != GR_DO_AUDIT) \
75252 + spin_unlock(&grsec_alert_lock); \
75253 + else \
75254 + spin_unlock(&grsec_audit_lock); \
75255 + read_unlock(&grsec_exec_file_lock); \
75256 + read_unlock(&tasklist_lock); \
75257 + rcu_read_unlock(); \
75258 + ENABLE_PREEMPT(); \
75259 + if (x == GR_DONT_AUDIT) \
75260 + gr_handle_alertkill(current)
75261 +
75262 +enum {
75263 + FLOODING,
75264 + NO_FLOODING
75265 +};
75266 +
75267 +extern char *gr_alert_log_fmt;
75268 +extern char *gr_audit_log_fmt;
75269 +extern char *gr_alert_log_buf;
75270 +extern char *gr_audit_log_buf;
75271 +
75272 +static int gr_log_start(int audit)
75273 +{
75274 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
75275 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
75276 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75277 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
75278 + unsigned long curr_secs = get_seconds();
75279 +
75280 + if (audit == GR_DO_AUDIT)
75281 + goto set_fmt;
75282 +
75283 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
75284 + grsec_alert_wtime = curr_secs;
75285 + grsec_alert_fyet = 0;
75286 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
75287 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
75288 + grsec_alert_fyet++;
75289 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
75290 + grsec_alert_wtime = curr_secs;
75291 + grsec_alert_fyet++;
75292 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
75293 + return FLOODING;
75294 + }
75295 + else return FLOODING;
75296 +
75297 +set_fmt:
75298 +#endif
75299 + memset(buf, 0, PAGE_SIZE);
75300 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
75301 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
75302 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
75303 + } else if (current->signal->curr_ip) {
75304 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
75305 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
75306 + } else if (gr_acl_is_enabled()) {
75307 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
75308 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
75309 + } else {
75310 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
75311 + strcpy(buf, fmt);
75312 + }
75313 +
75314 + return NO_FLOODING;
75315 +}
75316 +
75317 +static void gr_log_middle(int audit, const char *msg, va_list ap)
75318 + __attribute__ ((format (printf, 2, 0)));
75319 +
75320 +static void gr_log_middle(int audit, const char *msg, va_list ap)
75321 +{
75322 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75323 + unsigned int len = strlen(buf);
75324 +
75325 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
75326 +
75327 + return;
75328 +}
75329 +
75330 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
75331 + __attribute__ ((format (printf, 2, 3)));
75332 +
75333 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
75334 +{
75335 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75336 + unsigned int len = strlen(buf);
75337 + va_list ap;
75338 +
75339 + va_start(ap, msg);
75340 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
75341 + va_end(ap);
75342 +
75343 + return;
75344 +}
75345 +
75346 +static void gr_log_end(int audit, int append_default)
75347 +{
75348 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75349 + if (append_default) {
75350 + struct task_struct *task = current;
75351 + struct task_struct *parent = task->real_parent;
75352 + const struct cred *cred = __task_cred(task);
75353 + const struct cred *pcred = __task_cred(parent);
75354 + unsigned int len = strlen(buf);
75355 +
75356 + 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));
75357 + }
75358 +
75359 + printk("%s\n", buf);
75360 +
75361 + return;
75362 +}
75363 +
75364 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
75365 +{
75366 + int logtype;
75367 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
75368 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
75369 + void *voidptr = NULL;
75370 + int num1 = 0, num2 = 0;
75371 + unsigned long ulong1 = 0, ulong2 = 0;
75372 + struct dentry *dentry = NULL;
75373 + struct vfsmount *mnt = NULL;
75374 + struct file *file = NULL;
75375 + struct task_struct *task = NULL;
75376 + struct vm_area_struct *vma = NULL;
75377 + const struct cred *cred, *pcred;
75378 + va_list ap;
75379 +
75380 + BEGIN_LOCKS(audit);
75381 + logtype = gr_log_start(audit);
75382 + if (logtype == FLOODING) {
75383 + END_LOCKS(audit);
75384 + return;
75385 + }
75386 + va_start(ap, argtypes);
75387 + switch (argtypes) {
75388 + case GR_TTYSNIFF:
75389 + task = va_arg(ap, struct task_struct *);
75390 + 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));
75391 + break;
75392 + case GR_SYSCTL_HIDDEN:
75393 + str1 = va_arg(ap, char *);
75394 + gr_log_middle_varargs(audit, msg, result, str1);
75395 + break;
75396 + case GR_RBAC:
75397 + dentry = va_arg(ap, struct dentry *);
75398 + mnt = va_arg(ap, struct vfsmount *);
75399 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
75400 + break;
75401 + case GR_RBAC_STR:
75402 + dentry = va_arg(ap, struct dentry *);
75403 + mnt = va_arg(ap, struct vfsmount *);
75404 + str1 = va_arg(ap, char *);
75405 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
75406 + break;
75407 + case GR_STR_RBAC:
75408 + str1 = va_arg(ap, char *);
75409 + dentry = va_arg(ap, struct dentry *);
75410 + mnt = va_arg(ap, struct vfsmount *);
75411 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
75412 + break;
75413 + case GR_RBAC_MODE2:
75414 + dentry = va_arg(ap, struct dentry *);
75415 + mnt = va_arg(ap, struct vfsmount *);
75416 + str1 = va_arg(ap, char *);
75417 + str2 = va_arg(ap, char *);
75418 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
75419 + break;
75420 + case GR_RBAC_MODE3:
75421 + dentry = va_arg(ap, struct dentry *);
75422 + mnt = va_arg(ap, struct vfsmount *);
75423 + str1 = va_arg(ap, char *);
75424 + str2 = va_arg(ap, char *);
75425 + str3 = va_arg(ap, char *);
75426 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
75427 + break;
75428 + case GR_FILENAME:
75429 + dentry = va_arg(ap, struct dentry *);
75430 + mnt = va_arg(ap, struct vfsmount *);
75431 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
75432 + break;
75433 + case GR_STR_FILENAME:
75434 + str1 = va_arg(ap, char *);
75435 + dentry = va_arg(ap, struct dentry *);
75436 + mnt = va_arg(ap, struct vfsmount *);
75437 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
75438 + break;
75439 + case GR_FILENAME_STR:
75440 + dentry = va_arg(ap, struct dentry *);
75441 + mnt = va_arg(ap, struct vfsmount *);
75442 + str1 = va_arg(ap, char *);
75443 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
75444 + break;
75445 + case GR_FILENAME_TWO_INT:
75446 + dentry = va_arg(ap, struct dentry *);
75447 + mnt = va_arg(ap, struct vfsmount *);
75448 + num1 = va_arg(ap, int);
75449 + num2 = va_arg(ap, int);
75450 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
75451 + break;
75452 + case GR_FILENAME_TWO_INT_STR:
75453 + dentry = va_arg(ap, struct dentry *);
75454 + mnt = va_arg(ap, struct vfsmount *);
75455 + num1 = va_arg(ap, int);
75456 + num2 = va_arg(ap, int);
75457 + str1 = va_arg(ap, char *);
75458 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
75459 + break;
75460 + case GR_TEXTREL:
75461 + file = va_arg(ap, struct file *);
75462 + ulong1 = va_arg(ap, unsigned long);
75463 + ulong2 = va_arg(ap, unsigned long);
75464 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
75465 + break;
75466 + case GR_PTRACE:
75467 + task = va_arg(ap, struct task_struct *);
75468 + 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));
75469 + break;
75470 + case GR_RESOURCE:
75471 + task = va_arg(ap, struct task_struct *);
75472 + cred = __task_cred(task);
75473 + pcred = __task_cred(task->real_parent);
75474 + ulong1 = va_arg(ap, unsigned long);
75475 + str1 = va_arg(ap, char *);
75476 + ulong2 = va_arg(ap, unsigned long);
75477 + 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));
75478 + break;
75479 + case GR_CAP:
75480 + task = va_arg(ap, struct task_struct *);
75481 + cred = __task_cred(task);
75482 + pcred = __task_cred(task->real_parent);
75483 + str1 = va_arg(ap, char *);
75484 + 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));
75485 + break;
75486 + case GR_SIG:
75487 + str1 = va_arg(ap, char *);
75488 + voidptr = va_arg(ap, void *);
75489 + gr_log_middle_varargs(audit, msg, str1, voidptr);
75490 + break;
75491 + case GR_SIG2:
75492 + task = va_arg(ap, struct task_struct *);
75493 + cred = __task_cred(task);
75494 + pcred = __task_cred(task->real_parent);
75495 + num1 = va_arg(ap, int);
75496 + 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));
75497 + break;
75498 + case GR_CRASH1:
75499 + task = va_arg(ap, struct task_struct *);
75500 + cred = __task_cred(task);
75501 + pcred = __task_cred(task->real_parent);
75502 + ulong1 = va_arg(ap, unsigned long);
75503 + 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);
75504 + break;
75505 + case GR_CRASH2:
75506 + task = va_arg(ap, struct task_struct *);
75507 + cred = __task_cred(task);
75508 + pcred = __task_cred(task->real_parent);
75509 + ulong1 = va_arg(ap, unsigned long);
75510 + 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);
75511 + break;
75512 + case GR_RWXMAP:
75513 + file = va_arg(ap, struct file *);
75514 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
75515 + break;
75516 + case GR_RWXMAPVMA:
75517 + vma = va_arg(ap, struct vm_area_struct *);
75518 + if (vma->vm_file)
75519 + str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
75520 + else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
75521 + str1 = "<stack>";
75522 + else if (vma->vm_start <= current->mm->brk &&
75523 + vma->vm_end >= current->mm->start_brk)
75524 + str1 = "<heap>";
75525 + else
75526 + str1 = "<anonymous mapping>";
75527 + gr_log_middle_varargs(audit, msg, str1);
75528 + break;
75529 + case GR_PSACCT:
75530 + {
75531 + unsigned int wday, cday;
75532 + __u8 whr, chr;
75533 + __u8 wmin, cmin;
75534 + __u8 wsec, csec;
75535 + char cur_tty[64] = { 0 };
75536 + char parent_tty[64] = { 0 };
75537 +
75538 + task = va_arg(ap, struct task_struct *);
75539 + wday = va_arg(ap, unsigned int);
75540 + cday = va_arg(ap, unsigned int);
75541 + whr = va_arg(ap, int);
75542 + chr = va_arg(ap, int);
75543 + wmin = va_arg(ap, int);
75544 + cmin = va_arg(ap, int);
75545 + wsec = va_arg(ap, int);
75546 + csec = va_arg(ap, int);
75547 + ulong1 = va_arg(ap, unsigned long);
75548 + cred = __task_cred(task);
75549 + pcred = __task_cred(task->real_parent);
75550 +
75551 + 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));
75552 + }
75553 + break;
75554 + default:
75555 + gr_log_middle(audit, msg, ap);
75556 + }
75557 + va_end(ap);
75558 + // these don't need DEFAULTSECARGS printed on the end
75559 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
75560 + gr_log_end(audit, 0);
75561 + else
75562 + gr_log_end(audit, 1);
75563 + END_LOCKS(audit);
75564 +}
75565 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
75566 new file mode 100644
75567 index 0000000..0e39d8c
75568 --- /dev/null
75569 +++ b/grsecurity/grsec_mem.c
75570 @@ -0,0 +1,48 @@
75571 +#include <linux/kernel.h>
75572 +#include <linux/sched.h>
75573 +#include <linux/mm.h>
75574 +#include <linux/mman.h>
75575 +#include <linux/module.h>
75576 +#include <linux/grinternal.h>
75577 +
75578 +void gr_handle_msr_write(void)
75579 +{
75580 + gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
75581 + return;
75582 +}
75583 +EXPORT_SYMBOL_GPL(gr_handle_msr_write);
75584 +
75585 +void
75586 +gr_handle_ioperm(void)
75587 +{
75588 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
75589 + return;
75590 +}
75591 +
75592 +void
75593 +gr_handle_iopl(void)
75594 +{
75595 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
75596 + return;
75597 +}
75598 +
75599 +void
75600 +gr_handle_mem_readwrite(u64 from, u64 to)
75601 +{
75602 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
75603 + return;
75604 +}
75605 +
75606 +void
75607 +gr_handle_vm86(void)
75608 +{
75609 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
75610 + return;
75611 +}
75612 +
75613 +void
75614 +gr_log_badprocpid(const char *entry)
75615 +{
75616 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
75617 + return;
75618 +}
75619 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
75620 new file mode 100644
75621 index 0000000..cd9e124
75622 --- /dev/null
75623 +++ b/grsecurity/grsec_mount.c
75624 @@ -0,0 +1,65 @@
75625 +#include <linux/kernel.h>
75626 +#include <linux/sched.h>
75627 +#include <linux/mount.h>
75628 +#include <linux/major.h>
75629 +#include <linux/grsecurity.h>
75630 +#include <linux/grinternal.h>
75631 +
75632 +void
75633 +gr_log_remount(const char *devname, const int retval)
75634 +{
75635 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75636 + if (grsec_enable_mount && (retval >= 0))
75637 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
75638 +#endif
75639 + return;
75640 +}
75641 +
75642 +void
75643 +gr_log_unmount(const char *devname, const int retval)
75644 +{
75645 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75646 + if (grsec_enable_mount && (retval >= 0))
75647 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
75648 +#endif
75649 + return;
75650 +}
75651 +
75652 +void
75653 +gr_log_mount(const char *from, const char *to, const int retval)
75654 +{
75655 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75656 + if (grsec_enable_mount && (retval >= 0))
75657 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
75658 +#endif
75659 + return;
75660 +}
75661 +
75662 +int
75663 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
75664 +{
75665 +#ifdef CONFIG_GRKERNSEC_ROFS
75666 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
75667 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
75668 + return -EPERM;
75669 + } else
75670 + return 0;
75671 +#endif
75672 + return 0;
75673 +}
75674 +
75675 +int
75676 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
75677 +{
75678 +#ifdef CONFIG_GRKERNSEC_ROFS
75679 + struct inode *inode = dentry->d_inode;
75680 +
75681 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
75682 + inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
75683 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
75684 + return -EPERM;
75685 + } else
75686 + return 0;
75687 +#endif
75688 + return 0;
75689 +}
75690 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
75691 new file mode 100644
75692 index 0000000..6ee9d50
75693 --- /dev/null
75694 +++ b/grsecurity/grsec_pax.c
75695 @@ -0,0 +1,45 @@
75696 +#include <linux/kernel.h>
75697 +#include <linux/sched.h>
75698 +#include <linux/mm.h>
75699 +#include <linux/file.h>
75700 +#include <linux/grinternal.h>
75701 +#include <linux/grsecurity.h>
75702 +
75703 +void
75704 +gr_log_textrel(struct vm_area_struct * vma)
75705 +{
75706 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75707 + if (grsec_enable_log_rwxmaps)
75708 + gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
75709 +#endif
75710 + return;
75711 +}
75712 +
75713 +void gr_log_ptgnustack(struct file *file)
75714 +{
75715 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75716 + if (grsec_enable_log_rwxmaps)
75717 + gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
75718 +#endif
75719 + return;
75720 +}
75721 +
75722 +void
75723 +gr_log_rwxmmap(struct file *file)
75724 +{
75725 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75726 + if (grsec_enable_log_rwxmaps)
75727 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
75728 +#endif
75729 + return;
75730 +}
75731 +
75732 +void
75733 +gr_log_rwxmprotect(struct vm_area_struct *vma)
75734 +{
75735 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75736 + if (grsec_enable_log_rwxmaps)
75737 + gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
75738 +#endif
75739 + return;
75740 +}
75741 diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
75742 new file mode 100644
75743 index 0000000..2005a3a
75744 --- /dev/null
75745 +++ b/grsecurity/grsec_proc.c
75746 @@ -0,0 +1,20 @@
75747 +#include <linux/kernel.h>
75748 +#include <linux/sched.h>
75749 +#include <linux/grsecurity.h>
75750 +#include <linux/grinternal.h>
75751 +
75752 +int gr_proc_is_restricted(void)
75753 +{
75754 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75755 + const struct cred *cred = current_cred();
75756 +#endif
75757 +
75758 +#ifdef CONFIG_GRKERNSEC_PROC_USER
75759 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
75760 + return -EACCES;
75761 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75762 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
75763 + return -EACCES;
75764 +#endif
75765 + return 0;
75766 +}
75767 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
75768 new file mode 100644
75769 index 0000000..f7f29aa
75770 --- /dev/null
75771 +++ b/grsecurity/grsec_ptrace.c
75772 @@ -0,0 +1,30 @@
75773 +#include <linux/kernel.h>
75774 +#include <linux/sched.h>
75775 +#include <linux/grinternal.h>
75776 +#include <linux/security.h>
75777 +
75778 +void
75779 +gr_audit_ptrace(struct task_struct *task)
75780 +{
75781 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
75782 + if (grsec_enable_audit_ptrace)
75783 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
75784 +#endif
75785 + return;
75786 +}
75787 +
75788 +int
75789 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
75790 +{
75791 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
75792 + const struct dentry *dentry = file->f_path.dentry;
75793 + const struct vfsmount *mnt = file->f_path.mnt;
75794 +
75795 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
75796 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
75797 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
75798 + return -EACCES;
75799 + }
75800 +#endif
75801 + return 0;
75802 +}
75803 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
75804 new file mode 100644
75805 index 0000000..3860c7e
75806 --- /dev/null
75807 +++ b/grsecurity/grsec_sig.c
75808 @@ -0,0 +1,236 @@
75809 +#include <linux/kernel.h>
75810 +#include <linux/sched.h>
75811 +#include <linux/fs.h>
75812 +#include <linux/delay.h>
75813 +#include <linux/grsecurity.h>
75814 +#include <linux/grinternal.h>
75815 +#include <linux/hardirq.h>
75816 +
75817 +char *signames[] = {
75818 + [SIGSEGV] = "Segmentation fault",
75819 + [SIGILL] = "Illegal instruction",
75820 + [SIGABRT] = "Abort",
75821 + [SIGBUS] = "Invalid alignment/Bus error"
75822 +};
75823 +
75824 +void
75825 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
75826 +{
75827 +#ifdef CONFIG_GRKERNSEC_SIGNAL
75828 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
75829 + (sig == SIGABRT) || (sig == SIGBUS))) {
75830 + if (task_pid_nr(t) == task_pid_nr(current)) {
75831 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
75832 + } else {
75833 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
75834 + }
75835 + }
75836 +#endif
75837 + return;
75838 +}
75839 +
75840 +int
75841 +gr_handle_signal(const struct task_struct *p, const int sig)
75842 +{
75843 +#ifdef CONFIG_GRKERNSEC
75844 + /* ignore the 0 signal for protected task checks */
75845 + if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
75846 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
75847 + return -EPERM;
75848 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
75849 + return -EPERM;
75850 + }
75851 +#endif
75852 + return 0;
75853 +}
75854 +
75855 +#ifdef CONFIG_GRKERNSEC
75856 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
75857 +
75858 +int gr_fake_force_sig(int sig, struct task_struct *t)
75859 +{
75860 + unsigned long int flags;
75861 + int ret, blocked, ignored;
75862 + struct k_sigaction *action;
75863 +
75864 + spin_lock_irqsave(&t->sighand->siglock, flags);
75865 + action = &t->sighand->action[sig-1];
75866 + ignored = action->sa.sa_handler == SIG_IGN;
75867 + blocked = sigismember(&t->blocked, sig);
75868 + if (blocked || ignored) {
75869 + action->sa.sa_handler = SIG_DFL;
75870 + if (blocked) {
75871 + sigdelset(&t->blocked, sig);
75872 + recalc_sigpending_and_wake(t);
75873 + }
75874 + }
75875 + if (action->sa.sa_handler == SIG_DFL)
75876 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
75877 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
75878 +
75879 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
75880 +
75881 + return ret;
75882 +}
75883 +#endif
75884 +
75885 +#define GR_USER_BAN_TIME (15 * 60)
75886 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
75887 +
75888 +void gr_handle_brute_attach(int dumpable)
75889 +{
75890 +#ifdef CONFIG_GRKERNSEC_BRUTE
75891 + struct task_struct *p = current;
75892 + kuid_t uid = GLOBAL_ROOT_UID;
75893 + int daemon = 0;
75894 +
75895 + if (!grsec_enable_brute)
75896 + return;
75897 +
75898 + rcu_read_lock();
75899 + read_lock(&tasklist_lock);
75900 + read_lock(&grsec_exec_file_lock);
75901 + if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
75902 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
75903 + p->real_parent->brute = 1;
75904 + daemon = 1;
75905 + } else {
75906 + const struct cred *cred = __task_cred(p), *cred2;
75907 + struct task_struct *tsk, *tsk2;
75908 +
75909 + if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
75910 + struct user_struct *user;
75911 +
75912 + uid = cred->uid;
75913 +
75914 + /* this is put upon execution past expiration */
75915 + user = find_user(uid);
75916 + if (user == NULL)
75917 + goto unlock;
75918 + user->suid_banned = 1;
75919 + user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
75920 + if (user->suid_ban_expires == ~0UL)
75921 + user->suid_ban_expires--;
75922 +
75923 + /* only kill other threads of the same binary, from the same user */
75924 + do_each_thread(tsk2, tsk) {
75925 + cred2 = __task_cred(tsk);
75926 + if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
75927 + gr_fake_force_sig(SIGKILL, tsk);
75928 + } while_each_thread(tsk2, tsk);
75929 + }
75930 + }
75931 +unlock:
75932 + read_unlock(&grsec_exec_file_lock);
75933 + read_unlock(&tasklist_lock);
75934 + rcu_read_unlock();
75935 +
75936 + if (gr_is_global_nonroot(uid))
75937 + 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);
75938 + else if (daemon)
75939 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
75940 +
75941 +#endif
75942 + return;
75943 +}
75944 +
75945 +void gr_handle_brute_check(void)
75946 +{
75947 +#ifdef CONFIG_GRKERNSEC_BRUTE
75948 + struct task_struct *p = current;
75949 +
75950 + if (unlikely(p->brute)) {
75951 + if (!grsec_enable_brute)
75952 + p->brute = 0;
75953 + else if (time_before(get_seconds(), p->brute_expires))
75954 + msleep(30 * 1000);
75955 + }
75956 +#endif
75957 + return;
75958 +}
75959 +
75960 +void gr_handle_kernel_exploit(void)
75961 +{
75962 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75963 + const struct cred *cred;
75964 + struct task_struct *tsk, *tsk2;
75965 + struct user_struct *user;
75966 + kuid_t uid;
75967 +
75968 + if (in_irq() || in_serving_softirq() || in_nmi())
75969 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
75970 +
75971 + uid = current_uid();
75972 +
75973 + if (gr_is_global_root(uid))
75974 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
75975 + else {
75976 + /* kill all the processes of this user, hold a reference
75977 + to their creds struct, and prevent them from creating
75978 + another process until system reset
75979 + */
75980 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
75981 + GR_GLOBAL_UID(uid));
75982 + /* we intentionally leak this ref */
75983 + user = get_uid(current->cred->user);
75984 + if (user)
75985 + user->kernel_banned = 1;
75986 +
75987 + /* kill all processes of this user */
75988 + read_lock(&tasklist_lock);
75989 + do_each_thread(tsk2, tsk) {
75990 + cred = __task_cred(tsk);
75991 + if (uid_eq(cred->uid, uid))
75992 + gr_fake_force_sig(SIGKILL, tsk);
75993 + } while_each_thread(tsk2, tsk);
75994 + read_unlock(&tasklist_lock);
75995 + }
75996 +#endif
75997 +}
75998 +
75999 +#ifdef CONFIG_GRKERNSEC_BRUTE
76000 +static bool suid_ban_expired(struct user_struct *user)
76001 +{
76002 + if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
76003 + user->suid_banned = 0;
76004 + user->suid_ban_expires = 0;
76005 + free_uid(user);
76006 + return true;
76007 + }
76008 +
76009 + return false;
76010 +}
76011 +#endif
76012 +
76013 +int gr_process_kernel_exec_ban(void)
76014 +{
76015 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
76016 + if (unlikely(current->cred->user->kernel_banned))
76017 + return -EPERM;
76018 +#endif
76019 + return 0;
76020 +}
76021 +
76022 +int gr_process_kernel_setuid_ban(struct user_struct *user)
76023 +{
76024 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
76025 + if (unlikely(user->kernel_banned))
76026 + gr_fake_force_sig(SIGKILL, current);
76027 +#endif
76028 + return 0;
76029 +}
76030 +
76031 +int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
76032 +{
76033 +#ifdef CONFIG_GRKERNSEC_BRUTE
76034 + struct user_struct *user = current->cred->user;
76035 + if (unlikely(user->suid_banned)) {
76036 + if (suid_ban_expired(user))
76037 + return 0;
76038 + /* disallow execution of suid binaries only */
76039 + else if (!uid_eq(bprm->cred->euid, current->cred->uid))
76040 + return -EPERM;
76041 + }
76042 +#endif
76043 + return 0;
76044 +}
76045 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
76046 new file mode 100644
76047 index 0000000..c0aef3a
76048 --- /dev/null
76049 +++ b/grsecurity/grsec_sock.c
76050 @@ -0,0 +1,244 @@
76051 +#include <linux/kernel.h>
76052 +#include <linux/module.h>
76053 +#include <linux/sched.h>
76054 +#include <linux/file.h>
76055 +#include <linux/net.h>
76056 +#include <linux/in.h>
76057 +#include <linux/ip.h>
76058 +#include <net/sock.h>
76059 +#include <net/inet_sock.h>
76060 +#include <linux/grsecurity.h>
76061 +#include <linux/grinternal.h>
76062 +#include <linux/gracl.h>
76063 +
76064 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
76065 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
76066 +
76067 +EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
76068 +EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
76069 +
76070 +#ifdef CONFIG_UNIX_MODULE
76071 +EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
76072 +EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
76073 +EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
76074 +EXPORT_SYMBOL_GPL(gr_handle_create);
76075 +#endif
76076 +
76077 +#ifdef CONFIG_GRKERNSEC
76078 +#define gr_conn_table_size 32749
76079 +struct conn_table_entry {
76080 + struct conn_table_entry *next;
76081 + struct signal_struct *sig;
76082 +};
76083 +
76084 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
76085 +DEFINE_SPINLOCK(gr_conn_table_lock);
76086 +
76087 +extern const char * gr_socktype_to_name(unsigned char type);
76088 +extern const char * gr_proto_to_name(unsigned char proto);
76089 +extern const char * gr_sockfamily_to_name(unsigned char family);
76090 +
76091 +static __inline__ int
76092 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
76093 +{
76094 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
76095 +}
76096 +
76097 +static __inline__ int
76098 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
76099 + __u16 sport, __u16 dport)
76100 +{
76101 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
76102 + sig->gr_sport == sport && sig->gr_dport == dport))
76103 + return 1;
76104 + else
76105 + return 0;
76106 +}
76107 +
76108 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
76109 +{
76110 + struct conn_table_entry **match;
76111 + unsigned int index;
76112 +
76113 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
76114 + sig->gr_sport, sig->gr_dport,
76115 + gr_conn_table_size);
76116 +
76117 + newent->sig = sig;
76118 +
76119 + match = &gr_conn_table[index];
76120 + newent->next = *match;
76121 + *match = newent;
76122 +
76123 + return;
76124 +}
76125 +
76126 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
76127 +{
76128 + struct conn_table_entry *match, *last = NULL;
76129 + unsigned int index;
76130 +
76131 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
76132 + sig->gr_sport, sig->gr_dport,
76133 + gr_conn_table_size);
76134 +
76135 + match = gr_conn_table[index];
76136 + while (match && !conn_match(match->sig,
76137 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
76138 + sig->gr_dport)) {
76139 + last = match;
76140 + match = match->next;
76141 + }
76142 +
76143 + if (match) {
76144 + if (last)
76145 + last->next = match->next;
76146 + else
76147 + gr_conn_table[index] = NULL;
76148 + kfree(match);
76149 + }
76150 +
76151 + return;
76152 +}
76153 +
76154 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
76155 + __u16 sport, __u16 dport)
76156 +{
76157 + struct conn_table_entry *match;
76158 + unsigned int index;
76159 +
76160 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
76161 +
76162 + match = gr_conn_table[index];
76163 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
76164 + match = match->next;
76165 +
76166 + if (match)
76167 + return match->sig;
76168 + else
76169 + return NULL;
76170 +}
76171 +
76172 +#endif
76173 +
76174 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
76175 +{
76176 +#ifdef CONFIG_GRKERNSEC
76177 + struct signal_struct *sig = task->signal;
76178 + struct conn_table_entry *newent;
76179 +
76180 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
76181 + if (newent == NULL)
76182 + return;
76183 + /* no bh lock needed since we are called with bh disabled */
76184 + spin_lock(&gr_conn_table_lock);
76185 + gr_del_task_from_ip_table_nolock(sig);
76186 + sig->gr_saddr = inet->inet_rcv_saddr;
76187 + sig->gr_daddr = inet->inet_daddr;
76188 + sig->gr_sport = inet->inet_sport;
76189 + sig->gr_dport = inet->inet_dport;
76190 + gr_add_to_task_ip_table_nolock(sig, newent);
76191 + spin_unlock(&gr_conn_table_lock);
76192 +#endif
76193 + return;
76194 +}
76195 +
76196 +void gr_del_task_from_ip_table(struct task_struct *task)
76197 +{
76198 +#ifdef CONFIG_GRKERNSEC
76199 + spin_lock_bh(&gr_conn_table_lock);
76200 + gr_del_task_from_ip_table_nolock(task->signal);
76201 + spin_unlock_bh(&gr_conn_table_lock);
76202 +#endif
76203 + return;
76204 +}
76205 +
76206 +void
76207 +gr_attach_curr_ip(const struct sock *sk)
76208 +{
76209 +#ifdef CONFIG_GRKERNSEC
76210 + struct signal_struct *p, *set;
76211 + const struct inet_sock *inet = inet_sk(sk);
76212 +
76213 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
76214 + return;
76215 +
76216 + set = current->signal;
76217 +
76218 + spin_lock_bh(&gr_conn_table_lock);
76219 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
76220 + inet->inet_dport, inet->inet_sport);
76221 + if (unlikely(p != NULL)) {
76222 + set->curr_ip = p->curr_ip;
76223 + set->used_accept = 1;
76224 + gr_del_task_from_ip_table_nolock(p);
76225 + spin_unlock_bh(&gr_conn_table_lock);
76226 + return;
76227 + }
76228 + spin_unlock_bh(&gr_conn_table_lock);
76229 +
76230 + set->curr_ip = inet->inet_daddr;
76231 + set->used_accept = 1;
76232 +#endif
76233 + return;
76234 +}
76235 +
76236 +int
76237 +gr_handle_sock_all(const int family, const int type, const int protocol)
76238 +{
76239 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
76240 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
76241 + (family != AF_UNIX)) {
76242 + if (family == AF_INET)
76243 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
76244 + else
76245 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
76246 + return -EACCES;
76247 + }
76248 +#endif
76249 + return 0;
76250 +}
76251 +
76252 +int
76253 +gr_handle_sock_server(const struct sockaddr *sck)
76254 +{
76255 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76256 + if (grsec_enable_socket_server &&
76257 + in_group_p(grsec_socket_server_gid) &&
76258 + sck && (sck->sa_family != AF_UNIX) &&
76259 + (sck->sa_family != AF_LOCAL)) {
76260 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
76261 + return -EACCES;
76262 + }
76263 +#endif
76264 + return 0;
76265 +}
76266 +
76267 +int
76268 +gr_handle_sock_server_other(const struct sock *sck)
76269 +{
76270 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76271 + if (grsec_enable_socket_server &&
76272 + in_group_p(grsec_socket_server_gid) &&
76273 + sck && (sck->sk_family != AF_UNIX) &&
76274 + (sck->sk_family != AF_LOCAL)) {
76275 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
76276 + return -EACCES;
76277 + }
76278 +#endif
76279 + return 0;
76280 +}
76281 +
76282 +int
76283 +gr_handle_sock_client(const struct sockaddr *sck)
76284 +{
76285 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
76286 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
76287 + sck && (sck->sa_family != AF_UNIX) &&
76288 + (sck->sa_family != AF_LOCAL)) {
76289 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
76290 + return -EACCES;
76291 + }
76292 +#endif
76293 + return 0;
76294 +}
76295 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
76296 new file mode 100644
76297 index 0000000..8159888
76298 --- /dev/null
76299 +++ b/grsecurity/grsec_sysctl.c
76300 @@ -0,0 +1,479 @@
76301 +#include <linux/kernel.h>
76302 +#include <linux/sched.h>
76303 +#include <linux/sysctl.h>
76304 +#include <linux/grsecurity.h>
76305 +#include <linux/grinternal.h>
76306 +
76307 +int
76308 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
76309 +{
76310 +#ifdef CONFIG_GRKERNSEC_SYSCTL
76311 + if (dirname == NULL || name == NULL)
76312 + return 0;
76313 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
76314 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
76315 + return -EACCES;
76316 + }
76317 +#endif
76318 + return 0;
76319 +}
76320 +
76321 +#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
76322 +static int __maybe_unused __read_only one = 1;
76323 +#endif
76324 +
76325 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
76326 + defined(CONFIG_GRKERNSEC_DENYUSB)
76327 +struct ctl_table grsecurity_table[] = {
76328 +#ifdef CONFIG_GRKERNSEC_SYSCTL
76329 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
76330 +#ifdef CONFIG_GRKERNSEC_IO
76331 + {
76332 + .procname = "disable_priv_io",
76333 + .data = &grsec_disable_privio,
76334 + .maxlen = sizeof(int),
76335 + .mode = 0600,
76336 + .proc_handler = &proc_dointvec,
76337 + },
76338 +#endif
76339 +#endif
76340 +#ifdef CONFIG_GRKERNSEC_LINK
76341 + {
76342 + .procname = "linking_restrictions",
76343 + .data = &grsec_enable_link,
76344 + .maxlen = sizeof(int),
76345 + .mode = 0600,
76346 + .proc_handler = &proc_dointvec,
76347 + },
76348 +#endif
76349 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
76350 + {
76351 + .procname = "enforce_symlinksifowner",
76352 + .data = &grsec_enable_symlinkown,
76353 + .maxlen = sizeof(int),
76354 + .mode = 0600,
76355 + .proc_handler = &proc_dointvec,
76356 + },
76357 + {
76358 + .procname = "symlinkown_gid",
76359 + .data = &grsec_symlinkown_gid,
76360 + .maxlen = sizeof(int),
76361 + .mode = 0600,
76362 + .proc_handler = &proc_dointvec,
76363 + },
76364 +#endif
76365 +#ifdef CONFIG_GRKERNSEC_BRUTE
76366 + {
76367 + .procname = "deter_bruteforce",
76368 + .data = &grsec_enable_brute,
76369 + .maxlen = sizeof(int),
76370 + .mode = 0600,
76371 + .proc_handler = &proc_dointvec,
76372 + },
76373 +#endif
76374 +#ifdef CONFIG_GRKERNSEC_FIFO
76375 + {
76376 + .procname = "fifo_restrictions",
76377 + .data = &grsec_enable_fifo,
76378 + .maxlen = sizeof(int),
76379 + .mode = 0600,
76380 + .proc_handler = &proc_dointvec,
76381 + },
76382 +#endif
76383 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
76384 + {
76385 + .procname = "ptrace_readexec",
76386 + .data = &grsec_enable_ptrace_readexec,
76387 + .maxlen = sizeof(int),
76388 + .mode = 0600,
76389 + .proc_handler = &proc_dointvec,
76390 + },
76391 +#endif
76392 +#ifdef CONFIG_GRKERNSEC_SETXID
76393 + {
76394 + .procname = "consistent_setxid",
76395 + .data = &grsec_enable_setxid,
76396 + .maxlen = sizeof(int),
76397 + .mode = 0600,
76398 + .proc_handler = &proc_dointvec,
76399 + },
76400 +#endif
76401 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76402 + {
76403 + .procname = "ip_blackhole",
76404 + .data = &grsec_enable_blackhole,
76405 + .maxlen = sizeof(int),
76406 + .mode = 0600,
76407 + .proc_handler = &proc_dointvec,
76408 + },
76409 + {
76410 + .procname = "lastack_retries",
76411 + .data = &grsec_lastack_retries,
76412 + .maxlen = sizeof(int),
76413 + .mode = 0600,
76414 + .proc_handler = &proc_dointvec,
76415 + },
76416 +#endif
76417 +#ifdef CONFIG_GRKERNSEC_EXECLOG
76418 + {
76419 + .procname = "exec_logging",
76420 + .data = &grsec_enable_execlog,
76421 + .maxlen = sizeof(int),
76422 + .mode = 0600,
76423 + .proc_handler = &proc_dointvec,
76424 + },
76425 +#endif
76426 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
76427 + {
76428 + .procname = "rwxmap_logging",
76429 + .data = &grsec_enable_log_rwxmaps,
76430 + .maxlen = sizeof(int),
76431 + .mode = 0600,
76432 + .proc_handler = &proc_dointvec,
76433 + },
76434 +#endif
76435 +#ifdef CONFIG_GRKERNSEC_SIGNAL
76436 + {
76437 + .procname = "signal_logging",
76438 + .data = &grsec_enable_signal,
76439 + .maxlen = sizeof(int),
76440 + .mode = 0600,
76441 + .proc_handler = &proc_dointvec,
76442 + },
76443 +#endif
76444 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
76445 + {
76446 + .procname = "forkfail_logging",
76447 + .data = &grsec_enable_forkfail,
76448 + .maxlen = sizeof(int),
76449 + .mode = 0600,
76450 + .proc_handler = &proc_dointvec,
76451 + },
76452 +#endif
76453 +#ifdef CONFIG_GRKERNSEC_TIME
76454 + {
76455 + .procname = "timechange_logging",
76456 + .data = &grsec_enable_time,
76457 + .maxlen = sizeof(int),
76458 + .mode = 0600,
76459 + .proc_handler = &proc_dointvec,
76460 + },
76461 +#endif
76462 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
76463 + {
76464 + .procname = "chroot_deny_shmat",
76465 + .data = &grsec_enable_chroot_shmat,
76466 + .maxlen = sizeof(int),
76467 + .mode = 0600,
76468 + .proc_handler = &proc_dointvec,
76469 + },
76470 +#endif
76471 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
76472 + {
76473 + .procname = "chroot_deny_unix",
76474 + .data = &grsec_enable_chroot_unix,
76475 + .maxlen = sizeof(int),
76476 + .mode = 0600,
76477 + .proc_handler = &proc_dointvec,
76478 + },
76479 +#endif
76480 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
76481 + {
76482 + .procname = "chroot_deny_mount",
76483 + .data = &grsec_enable_chroot_mount,
76484 + .maxlen = sizeof(int),
76485 + .mode = 0600,
76486 + .proc_handler = &proc_dointvec,
76487 + },
76488 +#endif
76489 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76490 + {
76491 + .procname = "chroot_deny_fchdir",
76492 + .data = &grsec_enable_chroot_fchdir,
76493 + .maxlen = sizeof(int),
76494 + .mode = 0600,
76495 + .proc_handler = &proc_dointvec,
76496 + },
76497 +#endif
76498 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
76499 + {
76500 + .procname = "chroot_deny_chroot",
76501 + .data = &grsec_enable_chroot_double,
76502 + .maxlen = sizeof(int),
76503 + .mode = 0600,
76504 + .proc_handler = &proc_dointvec,
76505 + },
76506 +#endif
76507 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
76508 + {
76509 + .procname = "chroot_deny_pivot",
76510 + .data = &grsec_enable_chroot_pivot,
76511 + .maxlen = sizeof(int),
76512 + .mode = 0600,
76513 + .proc_handler = &proc_dointvec,
76514 + },
76515 +#endif
76516 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
76517 + {
76518 + .procname = "chroot_enforce_chdir",
76519 + .data = &grsec_enable_chroot_chdir,
76520 + .maxlen = sizeof(int),
76521 + .mode = 0600,
76522 + .proc_handler = &proc_dointvec,
76523 + },
76524 +#endif
76525 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
76526 + {
76527 + .procname = "chroot_deny_chmod",
76528 + .data = &grsec_enable_chroot_chmod,
76529 + .maxlen = sizeof(int),
76530 + .mode = 0600,
76531 + .proc_handler = &proc_dointvec,
76532 + },
76533 +#endif
76534 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
76535 + {
76536 + .procname = "chroot_deny_mknod",
76537 + .data = &grsec_enable_chroot_mknod,
76538 + .maxlen = sizeof(int),
76539 + .mode = 0600,
76540 + .proc_handler = &proc_dointvec,
76541 + },
76542 +#endif
76543 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76544 + {
76545 + .procname = "chroot_restrict_nice",
76546 + .data = &grsec_enable_chroot_nice,
76547 + .maxlen = sizeof(int),
76548 + .mode = 0600,
76549 + .proc_handler = &proc_dointvec,
76550 + },
76551 +#endif
76552 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
76553 + {
76554 + .procname = "chroot_execlog",
76555 + .data = &grsec_enable_chroot_execlog,
76556 + .maxlen = sizeof(int),
76557 + .mode = 0600,
76558 + .proc_handler = &proc_dointvec,
76559 + },
76560 +#endif
76561 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76562 + {
76563 + .procname = "chroot_caps",
76564 + .data = &grsec_enable_chroot_caps,
76565 + .maxlen = sizeof(int),
76566 + .mode = 0600,
76567 + .proc_handler = &proc_dointvec,
76568 + },
76569 +#endif
76570 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
76571 + {
76572 + .procname = "chroot_deny_sysctl",
76573 + .data = &grsec_enable_chroot_sysctl,
76574 + .maxlen = sizeof(int),
76575 + .mode = 0600,
76576 + .proc_handler = &proc_dointvec,
76577 + },
76578 +#endif
76579 +#ifdef CONFIG_GRKERNSEC_TPE
76580 + {
76581 + .procname = "tpe",
76582 + .data = &grsec_enable_tpe,
76583 + .maxlen = sizeof(int),
76584 + .mode = 0600,
76585 + .proc_handler = &proc_dointvec,
76586 + },
76587 + {
76588 + .procname = "tpe_gid",
76589 + .data = &grsec_tpe_gid,
76590 + .maxlen = sizeof(int),
76591 + .mode = 0600,
76592 + .proc_handler = &proc_dointvec,
76593 + },
76594 +#endif
76595 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76596 + {
76597 + .procname = "tpe_invert",
76598 + .data = &grsec_enable_tpe_invert,
76599 + .maxlen = sizeof(int),
76600 + .mode = 0600,
76601 + .proc_handler = &proc_dointvec,
76602 + },
76603 +#endif
76604 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
76605 + {
76606 + .procname = "tpe_restrict_all",
76607 + .data = &grsec_enable_tpe_all,
76608 + .maxlen = sizeof(int),
76609 + .mode = 0600,
76610 + .proc_handler = &proc_dointvec,
76611 + },
76612 +#endif
76613 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
76614 + {
76615 + .procname = "socket_all",
76616 + .data = &grsec_enable_socket_all,
76617 + .maxlen = sizeof(int),
76618 + .mode = 0600,
76619 + .proc_handler = &proc_dointvec,
76620 + },
76621 + {
76622 + .procname = "socket_all_gid",
76623 + .data = &grsec_socket_all_gid,
76624 + .maxlen = sizeof(int),
76625 + .mode = 0600,
76626 + .proc_handler = &proc_dointvec,
76627 + },
76628 +#endif
76629 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
76630 + {
76631 + .procname = "socket_client",
76632 + .data = &grsec_enable_socket_client,
76633 + .maxlen = sizeof(int),
76634 + .mode = 0600,
76635 + .proc_handler = &proc_dointvec,
76636 + },
76637 + {
76638 + .procname = "socket_client_gid",
76639 + .data = &grsec_socket_client_gid,
76640 + .maxlen = sizeof(int),
76641 + .mode = 0600,
76642 + .proc_handler = &proc_dointvec,
76643 + },
76644 +#endif
76645 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76646 + {
76647 + .procname = "socket_server",
76648 + .data = &grsec_enable_socket_server,
76649 + .maxlen = sizeof(int),
76650 + .mode = 0600,
76651 + .proc_handler = &proc_dointvec,
76652 + },
76653 + {
76654 + .procname = "socket_server_gid",
76655 + .data = &grsec_socket_server_gid,
76656 + .maxlen = sizeof(int),
76657 + .mode = 0600,
76658 + .proc_handler = &proc_dointvec,
76659 + },
76660 +#endif
76661 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
76662 + {
76663 + .procname = "audit_group",
76664 + .data = &grsec_enable_group,
76665 + .maxlen = sizeof(int),
76666 + .mode = 0600,
76667 + .proc_handler = &proc_dointvec,
76668 + },
76669 + {
76670 + .procname = "audit_gid",
76671 + .data = &grsec_audit_gid,
76672 + .maxlen = sizeof(int),
76673 + .mode = 0600,
76674 + .proc_handler = &proc_dointvec,
76675 + },
76676 +#endif
76677 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
76678 + {
76679 + .procname = "audit_chdir",
76680 + .data = &grsec_enable_chdir,
76681 + .maxlen = sizeof(int),
76682 + .mode = 0600,
76683 + .proc_handler = &proc_dointvec,
76684 + },
76685 +#endif
76686 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
76687 + {
76688 + .procname = "audit_mount",
76689 + .data = &grsec_enable_mount,
76690 + .maxlen = sizeof(int),
76691 + .mode = 0600,
76692 + .proc_handler = &proc_dointvec,
76693 + },
76694 +#endif
76695 +#ifdef CONFIG_GRKERNSEC_DMESG
76696 + {
76697 + .procname = "dmesg",
76698 + .data = &grsec_enable_dmesg,
76699 + .maxlen = sizeof(int),
76700 + .mode = 0600,
76701 + .proc_handler = &proc_dointvec,
76702 + },
76703 +#endif
76704 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76705 + {
76706 + .procname = "chroot_findtask",
76707 + .data = &grsec_enable_chroot_findtask,
76708 + .maxlen = sizeof(int),
76709 + .mode = 0600,
76710 + .proc_handler = &proc_dointvec,
76711 + },
76712 +#endif
76713 +#ifdef CONFIG_GRKERNSEC_RESLOG
76714 + {
76715 + .procname = "resource_logging",
76716 + .data = &grsec_resource_logging,
76717 + .maxlen = sizeof(int),
76718 + .mode = 0600,
76719 + .proc_handler = &proc_dointvec,
76720 + },
76721 +#endif
76722 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
76723 + {
76724 + .procname = "audit_ptrace",
76725 + .data = &grsec_enable_audit_ptrace,
76726 + .maxlen = sizeof(int),
76727 + .mode = 0600,
76728 + .proc_handler = &proc_dointvec,
76729 + },
76730 +#endif
76731 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
76732 + {
76733 + .procname = "harden_ptrace",
76734 + .data = &grsec_enable_harden_ptrace,
76735 + .maxlen = sizeof(int),
76736 + .mode = 0600,
76737 + .proc_handler = &proc_dointvec,
76738 + },
76739 +#endif
76740 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
76741 + {
76742 + .procname = "harden_ipc",
76743 + .data = &grsec_enable_harden_ipc,
76744 + .maxlen = sizeof(int),
76745 + .mode = 0600,
76746 + .proc_handler = &proc_dointvec,
76747 + },
76748 +#endif
76749 + {
76750 + .procname = "grsec_lock",
76751 + .data = &grsec_lock,
76752 + .maxlen = sizeof(int),
76753 + .mode = 0600,
76754 + .proc_handler = &proc_dointvec,
76755 + },
76756 +#endif
76757 +#ifdef CONFIG_GRKERNSEC_ROFS
76758 + {
76759 + .procname = "romount_protect",
76760 + .data = &grsec_enable_rofs,
76761 + .maxlen = sizeof(int),
76762 + .mode = 0600,
76763 + .proc_handler = &proc_dointvec_minmax,
76764 + .extra1 = &one,
76765 + .extra2 = &one,
76766 + },
76767 +#endif
76768 +#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
76769 + {
76770 + .procname = "deny_new_usb",
76771 + .data = &grsec_deny_new_usb,
76772 + .maxlen = sizeof(int),
76773 + .mode = 0600,
76774 + .proc_handler = &proc_dointvec,
76775 + },
76776 +#endif
76777 + { }
76778 +};
76779 +#endif
76780 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
76781 new file mode 100644
76782 index 0000000..61b514e
76783 --- /dev/null
76784 +++ b/grsecurity/grsec_time.c
76785 @@ -0,0 +1,16 @@
76786 +#include <linux/kernel.h>
76787 +#include <linux/sched.h>
76788 +#include <linux/grinternal.h>
76789 +#include <linux/module.h>
76790 +
76791 +void
76792 +gr_log_timechange(void)
76793 +{
76794 +#ifdef CONFIG_GRKERNSEC_TIME
76795 + if (grsec_enable_time)
76796 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
76797 +#endif
76798 + return;
76799 +}
76800 +
76801 +EXPORT_SYMBOL_GPL(gr_log_timechange);
76802 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
76803 new file mode 100644
76804 index 0000000..d1953de
76805 --- /dev/null
76806 +++ b/grsecurity/grsec_tpe.c
76807 @@ -0,0 +1,78 @@
76808 +#include <linux/kernel.h>
76809 +#include <linux/sched.h>
76810 +#include <linux/file.h>
76811 +#include <linux/fs.h>
76812 +#include <linux/grinternal.h>
76813 +
76814 +extern int gr_acl_tpe_check(void);
76815 +
76816 +int
76817 +gr_tpe_allow(const struct file *file)
76818 +{
76819 +#ifdef CONFIG_GRKERNSEC
76820 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
76821 + struct inode *file_inode = file->f_path.dentry->d_inode;
76822 + const struct cred *cred = current_cred();
76823 + char *msg = NULL;
76824 + char *msg2 = NULL;
76825 +
76826 + // never restrict root
76827 + if (gr_is_global_root(cred->uid))
76828 + return 1;
76829 +
76830 + if (grsec_enable_tpe) {
76831 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76832 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
76833 + msg = "not being in trusted group";
76834 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
76835 + msg = "being in untrusted group";
76836 +#else
76837 + if (in_group_p(grsec_tpe_gid))
76838 + msg = "being in untrusted group";
76839 +#endif
76840 + }
76841 + if (!msg && gr_acl_tpe_check())
76842 + msg = "being in untrusted role";
76843 +
76844 + // not in any affected group/role
76845 + if (!msg)
76846 + goto next_check;
76847 +
76848 + if (gr_is_global_nonroot(inode->i_uid))
76849 + msg2 = "file in non-root-owned directory";
76850 + else if (inode->i_mode & S_IWOTH)
76851 + msg2 = "file in world-writable directory";
76852 + else if (inode->i_mode & S_IWGRP)
76853 + msg2 = "file in group-writable directory";
76854 + else if (file_inode->i_mode & S_IWOTH)
76855 + msg2 = "file is world-writable";
76856 +
76857 + if (msg && msg2) {
76858 + char fullmsg[70] = {0};
76859 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
76860 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
76861 + return 0;
76862 + }
76863 + msg = NULL;
76864 +next_check:
76865 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
76866 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
76867 + return 1;
76868 +
76869 + if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
76870 + msg = "directory not owned by user";
76871 + else if (inode->i_mode & S_IWOTH)
76872 + msg = "file in world-writable directory";
76873 + else if (inode->i_mode & S_IWGRP)
76874 + msg = "file in group-writable directory";
76875 + else if (file_inode->i_mode & S_IWOTH)
76876 + msg = "file is world-writable";
76877 +
76878 + if (msg) {
76879 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
76880 + return 0;
76881 + }
76882 +#endif
76883 +#endif
76884 + return 1;
76885 +}
76886 diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
76887 new file mode 100644
76888 index 0000000..ae02d8e
76889 --- /dev/null
76890 +++ b/grsecurity/grsec_usb.c
76891 @@ -0,0 +1,15 @@
76892 +#include <linux/kernel.h>
76893 +#include <linux/grinternal.h>
76894 +#include <linux/module.h>
76895 +
76896 +int gr_handle_new_usb(void)
76897 +{
76898 +#ifdef CONFIG_GRKERNSEC_DENYUSB
76899 + if (grsec_deny_new_usb) {
76900 + printk(KERN_ALERT "grsec: denied insert of new USB device\n");
76901 + return 1;
76902 + }
76903 +#endif
76904 + return 0;
76905 +}
76906 +EXPORT_SYMBOL_GPL(gr_handle_new_usb);
76907 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
76908 new file mode 100644
76909 index 0000000..158b330
76910 --- /dev/null
76911 +++ b/grsecurity/grsum.c
76912 @@ -0,0 +1,64 @@
76913 +#include <linux/err.h>
76914 +#include <linux/kernel.h>
76915 +#include <linux/sched.h>
76916 +#include <linux/mm.h>
76917 +#include <linux/scatterlist.h>
76918 +#include <linux/crypto.h>
76919 +#include <linux/gracl.h>
76920 +
76921 +
76922 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
76923 +#error "crypto and sha256 must be built into the kernel"
76924 +#endif
76925 +
76926 +int
76927 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
76928 +{
76929 + struct crypto_hash *tfm;
76930 + struct hash_desc desc;
76931 + struct scatterlist sg[2];
76932 + unsigned char temp_sum[GR_SHA_LEN] __attribute__((aligned(__alignof__(unsigned long))));
76933 + unsigned long *tmpsumptr = (unsigned long *)temp_sum;
76934 + unsigned long *sumptr = (unsigned long *)sum;
76935 + int cryptres;
76936 + int retval = 1;
76937 + volatile int mismatched = 0;
76938 + volatile int dummy = 0;
76939 + unsigned int i;
76940 +
76941 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
76942 + if (IS_ERR(tfm)) {
76943 + /* should never happen, since sha256 should be built in */
76944 + memset(entry->pw, 0, GR_PW_LEN);
76945 + return 1;
76946 + }
76947 +
76948 + sg_init_table(sg, 2);
76949 + sg_set_buf(&sg[0], salt, GR_SALT_LEN);
76950 + sg_set_buf(&sg[1], entry->pw, strlen(entry->pw));
76951 +
76952 + desc.tfm = tfm;
76953 + desc.flags = 0;
76954 +
76955 + cryptres = crypto_hash_digest(&desc, sg, GR_SALT_LEN + strlen(entry->pw),
76956 + temp_sum);
76957 +
76958 + memset(entry->pw, 0, GR_PW_LEN);
76959 +
76960 + if (cryptres)
76961 + goto out;
76962 +
76963 + for (i = 0; i < GR_SHA_LEN/sizeof(tmpsumptr[0]); i++)
76964 + if (sumptr[i] != tmpsumptr[i])
76965 + mismatched = 1;
76966 + else
76967 + dummy = 1; // waste a cycle
76968 +
76969 + if (!mismatched)
76970 + retval = dummy - 1;
76971 +
76972 +out:
76973 + crypto_free_hash(tfm);
76974 +
76975 + return retval;
76976 +}
76977 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
76978 index 77ff547..181834f 100644
76979 --- a/include/asm-generic/4level-fixup.h
76980 +++ b/include/asm-generic/4level-fixup.h
76981 @@ -13,8 +13,10 @@
76982 #define pmd_alloc(mm, pud, address) \
76983 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
76984 NULL: pmd_offset(pud, address))
76985 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
76986
76987 #define pud_alloc(mm, pgd, address) (pgd)
76988 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
76989 #define pud_offset(pgd, start) (pgd)
76990 #define pud_none(pud) 0
76991 #define pud_bad(pud) 0
76992 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
76993 index b7babf0..97f4c4f 100644
76994 --- a/include/asm-generic/atomic-long.h
76995 +++ b/include/asm-generic/atomic-long.h
76996 @@ -22,6 +22,12 @@
76997
76998 typedef atomic64_t atomic_long_t;
76999
77000 +#ifdef CONFIG_PAX_REFCOUNT
77001 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
77002 +#else
77003 +typedef atomic64_t atomic_long_unchecked_t;
77004 +#endif
77005 +
77006 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
77007
77008 static inline long atomic_long_read(atomic_long_t *l)
77009 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
77010 return (long)atomic64_read(v);
77011 }
77012
77013 +#ifdef CONFIG_PAX_REFCOUNT
77014 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
77015 +{
77016 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77017 +
77018 + return (long)atomic64_read_unchecked(v);
77019 +}
77020 +#endif
77021 +
77022 static inline void atomic_long_set(atomic_long_t *l, long i)
77023 {
77024 atomic64_t *v = (atomic64_t *)l;
77025 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
77026 atomic64_set(v, i);
77027 }
77028
77029 +#ifdef CONFIG_PAX_REFCOUNT
77030 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
77031 +{
77032 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77033 +
77034 + atomic64_set_unchecked(v, i);
77035 +}
77036 +#endif
77037 +
77038 static inline void atomic_long_inc(atomic_long_t *l)
77039 {
77040 atomic64_t *v = (atomic64_t *)l;
77041 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
77042 atomic64_inc(v);
77043 }
77044
77045 +#ifdef CONFIG_PAX_REFCOUNT
77046 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
77047 +{
77048 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77049 +
77050 + atomic64_inc_unchecked(v);
77051 +}
77052 +#endif
77053 +
77054 static inline void atomic_long_dec(atomic_long_t *l)
77055 {
77056 atomic64_t *v = (atomic64_t *)l;
77057 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
77058 atomic64_dec(v);
77059 }
77060
77061 +#ifdef CONFIG_PAX_REFCOUNT
77062 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
77063 +{
77064 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77065 +
77066 + atomic64_dec_unchecked(v);
77067 +}
77068 +#endif
77069 +
77070 static inline void atomic_long_add(long i, atomic_long_t *l)
77071 {
77072 atomic64_t *v = (atomic64_t *)l;
77073 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
77074 atomic64_add(i, v);
77075 }
77076
77077 +#ifdef CONFIG_PAX_REFCOUNT
77078 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
77079 +{
77080 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77081 +
77082 + atomic64_add_unchecked(i, v);
77083 +}
77084 +#endif
77085 +
77086 static inline void atomic_long_sub(long i, atomic_long_t *l)
77087 {
77088 atomic64_t *v = (atomic64_t *)l;
77089 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
77090 atomic64_sub(i, v);
77091 }
77092
77093 +#ifdef CONFIG_PAX_REFCOUNT
77094 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
77095 +{
77096 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77097 +
77098 + atomic64_sub_unchecked(i, v);
77099 +}
77100 +#endif
77101 +
77102 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
77103 {
77104 atomic64_t *v = (atomic64_t *)l;
77105 @@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
77106 return atomic64_add_negative(i, v);
77107 }
77108
77109 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
77110 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
77111 {
77112 atomic64_t *v = (atomic64_t *)l;
77113
77114 return (long)atomic64_add_return(i, v);
77115 }
77116
77117 +#ifdef CONFIG_PAX_REFCOUNT
77118 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
77119 +{
77120 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77121 +
77122 + return (long)atomic64_add_return_unchecked(i, v);
77123 +}
77124 +#endif
77125 +
77126 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
77127 {
77128 atomic64_t *v = (atomic64_t *)l;
77129 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
77130 return (long)atomic64_inc_return(v);
77131 }
77132
77133 +#ifdef CONFIG_PAX_REFCOUNT
77134 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
77135 +{
77136 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77137 +
77138 + return (long)atomic64_inc_return_unchecked(v);
77139 +}
77140 +#endif
77141 +
77142 static inline long atomic_long_dec_return(atomic_long_t *l)
77143 {
77144 atomic64_t *v = (atomic64_t *)l;
77145 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
77146
77147 typedef atomic_t atomic_long_t;
77148
77149 +#ifdef CONFIG_PAX_REFCOUNT
77150 +typedef atomic_unchecked_t atomic_long_unchecked_t;
77151 +#else
77152 +typedef atomic_t atomic_long_unchecked_t;
77153 +#endif
77154 +
77155 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
77156 static inline long atomic_long_read(atomic_long_t *l)
77157 {
77158 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
77159 return (long)atomic_read(v);
77160 }
77161
77162 +#ifdef CONFIG_PAX_REFCOUNT
77163 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
77164 +{
77165 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77166 +
77167 + return (long)atomic_read_unchecked(v);
77168 +}
77169 +#endif
77170 +
77171 static inline void atomic_long_set(atomic_long_t *l, long i)
77172 {
77173 atomic_t *v = (atomic_t *)l;
77174 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
77175 atomic_set(v, i);
77176 }
77177
77178 +#ifdef CONFIG_PAX_REFCOUNT
77179 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
77180 +{
77181 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77182 +
77183 + atomic_set_unchecked(v, i);
77184 +}
77185 +#endif
77186 +
77187 static inline void atomic_long_inc(atomic_long_t *l)
77188 {
77189 atomic_t *v = (atomic_t *)l;
77190 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
77191 atomic_inc(v);
77192 }
77193
77194 +#ifdef CONFIG_PAX_REFCOUNT
77195 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
77196 +{
77197 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77198 +
77199 + atomic_inc_unchecked(v);
77200 +}
77201 +#endif
77202 +
77203 static inline void atomic_long_dec(atomic_long_t *l)
77204 {
77205 atomic_t *v = (atomic_t *)l;
77206 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
77207 atomic_dec(v);
77208 }
77209
77210 +#ifdef CONFIG_PAX_REFCOUNT
77211 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
77212 +{
77213 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77214 +
77215 + atomic_dec_unchecked(v);
77216 +}
77217 +#endif
77218 +
77219 static inline void atomic_long_add(long i, atomic_long_t *l)
77220 {
77221 atomic_t *v = (atomic_t *)l;
77222 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
77223 atomic_add(i, v);
77224 }
77225
77226 +#ifdef CONFIG_PAX_REFCOUNT
77227 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
77228 +{
77229 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77230 +
77231 + atomic_add_unchecked(i, v);
77232 +}
77233 +#endif
77234 +
77235 static inline void atomic_long_sub(long i, atomic_long_t *l)
77236 {
77237 atomic_t *v = (atomic_t *)l;
77238 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
77239 atomic_sub(i, v);
77240 }
77241
77242 +#ifdef CONFIG_PAX_REFCOUNT
77243 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
77244 +{
77245 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77246 +
77247 + atomic_sub_unchecked(i, v);
77248 +}
77249 +#endif
77250 +
77251 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
77252 {
77253 atomic_t *v = (atomic_t *)l;
77254 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
77255 return (long)atomic_add_return(i, v);
77256 }
77257
77258 +#ifdef CONFIG_PAX_REFCOUNT
77259 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
77260 +{
77261 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77262 +
77263 + return (long)atomic_add_return_unchecked(i, v);
77264 +}
77265 +
77266 +#endif
77267 +
77268 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
77269 {
77270 atomic_t *v = (atomic_t *)l;
77271 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
77272 return (long)atomic_inc_return(v);
77273 }
77274
77275 +#ifdef CONFIG_PAX_REFCOUNT
77276 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
77277 +{
77278 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77279 +
77280 + return (long)atomic_inc_return_unchecked(v);
77281 +}
77282 +#endif
77283 +
77284 static inline long atomic_long_dec_return(atomic_long_t *l)
77285 {
77286 atomic_t *v = (atomic_t *)l;
77287 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
77288
77289 #endif /* BITS_PER_LONG == 64 */
77290
77291 +#ifdef CONFIG_PAX_REFCOUNT
77292 +static inline void pax_refcount_needs_these_functions(void)
77293 +{
77294 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
77295 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
77296 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
77297 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
77298 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
77299 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
77300 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
77301 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
77302 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
77303 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
77304 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
77305 +#ifdef CONFIG_X86
77306 + atomic_clear_mask_unchecked(0, NULL);
77307 + atomic_set_mask_unchecked(0, NULL);
77308 +#endif
77309 +
77310 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
77311 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
77312 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
77313 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
77314 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
77315 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
77316 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
77317 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
77318 +}
77319 +#else
77320 +#define atomic_read_unchecked(v) atomic_read(v)
77321 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
77322 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
77323 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
77324 +#define atomic_inc_unchecked(v) atomic_inc(v)
77325 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
77326 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
77327 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
77328 +#define atomic_dec_unchecked(v) atomic_dec(v)
77329 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
77330 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
77331 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
77332 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
77333 +
77334 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
77335 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
77336 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
77337 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
77338 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
77339 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
77340 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
77341 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
77342 +#endif
77343 +
77344 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
77345 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
77346 index 33bd2de..f31bff97 100644
77347 --- a/include/asm-generic/atomic.h
77348 +++ b/include/asm-generic/atomic.h
77349 @@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
77350 * Atomically clears the bits set in @mask from @v
77351 */
77352 #ifndef atomic_clear_mask
77353 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
77354 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
77355 {
77356 unsigned long flags;
77357
77358 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
77359 index b18ce4f..2ee2843 100644
77360 --- a/include/asm-generic/atomic64.h
77361 +++ b/include/asm-generic/atomic64.h
77362 @@ -16,6 +16,8 @@ typedef struct {
77363 long long counter;
77364 } atomic64_t;
77365
77366 +typedef atomic64_t atomic64_unchecked_t;
77367 +
77368 #define ATOMIC64_INIT(i) { (i) }
77369
77370 extern long long atomic64_read(const atomic64_t *v);
77371 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
77372 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
77373 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
77374
77375 +#define atomic64_read_unchecked(v) atomic64_read(v)
77376 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
77377 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
77378 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
77379 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
77380 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
77381 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
77382 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
77383 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
77384 +
77385 #endif /* _ASM_GENERIC_ATOMIC64_H */
77386 diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h
77387 index 6f692f8..2ad9dd2 100644
77388 --- a/include/asm-generic/barrier.h
77389 +++ b/include/asm-generic/barrier.h
77390 @@ -66,7 +66,7 @@
77391 do { \
77392 compiletime_assert_atomic_type(*p); \
77393 smp_mb(); \
77394 - ACCESS_ONCE(*p) = (v); \
77395 + ACCESS_ONCE_RW(*p) = (v); \
77396 } while (0)
77397
77398 #define smp_load_acquire(p) \
77399 diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
77400 index a60a7cc..0fe12f2 100644
77401 --- a/include/asm-generic/bitops/__fls.h
77402 +++ b/include/asm-generic/bitops/__fls.h
77403 @@ -9,7 +9,7 @@
77404 *
77405 * Undefined if no set bit exists, so code should check against 0 first.
77406 */
77407 -static __always_inline unsigned long __fls(unsigned long word)
77408 +static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
77409 {
77410 int num = BITS_PER_LONG - 1;
77411
77412 diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
77413 index 0576d1f..dad6c71 100644
77414 --- a/include/asm-generic/bitops/fls.h
77415 +++ b/include/asm-generic/bitops/fls.h
77416 @@ -9,7 +9,7 @@
77417 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
77418 */
77419
77420 -static __always_inline int fls(int x)
77421 +static __always_inline int __intentional_overflow(-1) fls(int x)
77422 {
77423 int r = 32;
77424
77425 diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
77426 index b097cf8..3d40e14 100644
77427 --- a/include/asm-generic/bitops/fls64.h
77428 +++ b/include/asm-generic/bitops/fls64.h
77429 @@ -15,7 +15,7 @@
77430 * at position 64.
77431 */
77432 #if BITS_PER_LONG == 32
77433 -static __always_inline int fls64(__u64 x)
77434 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
77435 {
77436 __u32 h = x >> 32;
77437 if (h)
77438 @@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
77439 return fls(x);
77440 }
77441 #elif BITS_PER_LONG == 64
77442 -static __always_inline int fls64(__u64 x)
77443 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
77444 {
77445 if (x == 0)
77446 return 0;
77447 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
77448 index 1bfcfe5..e04c5c9 100644
77449 --- a/include/asm-generic/cache.h
77450 +++ b/include/asm-generic/cache.h
77451 @@ -6,7 +6,7 @@
77452 * cache lines need to provide their own cache.h.
77453 */
77454
77455 -#define L1_CACHE_SHIFT 5
77456 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
77457 +#define L1_CACHE_SHIFT 5UL
77458 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
77459
77460 #endif /* __ASM_GENERIC_CACHE_H */
77461 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
77462 index 0d68a1e..b74a761 100644
77463 --- a/include/asm-generic/emergency-restart.h
77464 +++ b/include/asm-generic/emergency-restart.h
77465 @@ -1,7 +1,7 @@
77466 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
77467 #define _ASM_GENERIC_EMERGENCY_RESTART_H
77468
77469 -static inline void machine_emergency_restart(void)
77470 +static inline __noreturn void machine_emergency_restart(void)
77471 {
77472 machine_restart(NULL);
77473 }
77474 diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
77475 index 975e1cc..0b8a083 100644
77476 --- a/include/asm-generic/io.h
77477 +++ b/include/asm-generic/io.h
77478 @@ -289,7 +289,7 @@ static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
77479 * These are pretty trivial
77480 */
77481 #ifndef virt_to_phys
77482 -static inline unsigned long virt_to_phys(volatile void *address)
77483 +static inline unsigned long __intentional_overflow(-1) virt_to_phys(volatile void *address)
77484 {
77485 return __pa((unsigned long)address);
77486 }
77487 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
77488 index 90f99c7..00ce236 100644
77489 --- a/include/asm-generic/kmap_types.h
77490 +++ b/include/asm-generic/kmap_types.h
77491 @@ -2,9 +2,9 @@
77492 #define _ASM_GENERIC_KMAP_TYPES_H
77493
77494 #ifdef __WITH_KM_FENCE
77495 -# define KM_TYPE_NR 41
77496 +# define KM_TYPE_NR 42
77497 #else
77498 -# define KM_TYPE_NR 20
77499 +# define KM_TYPE_NR 21
77500 #endif
77501
77502 #endif
77503 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
77504 index 9ceb03b..62b0b8f 100644
77505 --- a/include/asm-generic/local.h
77506 +++ b/include/asm-generic/local.h
77507 @@ -23,24 +23,37 @@ typedef struct
77508 atomic_long_t a;
77509 } local_t;
77510
77511 +typedef struct {
77512 + atomic_long_unchecked_t a;
77513 +} local_unchecked_t;
77514 +
77515 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
77516
77517 #define local_read(l) atomic_long_read(&(l)->a)
77518 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
77519 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
77520 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
77521 #define local_inc(l) atomic_long_inc(&(l)->a)
77522 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
77523 #define local_dec(l) atomic_long_dec(&(l)->a)
77524 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
77525 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
77526 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
77527 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
77528 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
77529
77530 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
77531 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
77532 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
77533 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
77534 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
77535 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
77536 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
77537 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
77538 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
77539
77540 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
77541 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
77542 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
77543 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
77544 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
77545 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
77546 index 725612b..9cc513a 100644
77547 --- a/include/asm-generic/pgtable-nopmd.h
77548 +++ b/include/asm-generic/pgtable-nopmd.h
77549 @@ -1,14 +1,19 @@
77550 #ifndef _PGTABLE_NOPMD_H
77551 #define _PGTABLE_NOPMD_H
77552
77553 -#ifndef __ASSEMBLY__
77554 -
77555 #include <asm-generic/pgtable-nopud.h>
77556
77557 -struct mm_struct;
77558 -
77559 #define __PAGETABLE_PMD_FOLDED
77560
77561 +#define PMD_SHIFT PUD_SHIFT
77562 +#define PTRS_PER_PMD 1
77563 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
77564 +#define PMD_MASK (~(PMD_SIZE-1))
77565 +
77566 +#ifndef __ASSEMBLY__
77567 +
77568 +struct mm_struct;
77569 +
77570 /*
77571 * Having the pmd type consist of a pud gets the size right, and allows
77572 * us to conceptually access the pud entry that this pmd is folded into
77573 @@ -16,11 +21,6 @@ struct mm_struct;
77574 */
77575 typedef struct { pud_t pud; } pmd_t;
77576
77577 -#define PMD_SHIFT PUD_SHIFT
77578 -#define PTRS_PER_PMD 1
77579 -#define PMD_SIZE (1UL << PMD_SHIFT)
77580 -#define PMD_MASK (~(PMD_SIZE-1))
77581 -
77582 /*
77583 * The "pud_xxx()" functions here are trivial for a folded two-level
77584 * setup: the pmd is never bad, and a pmd always exists (as it's folded
77585 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
77586 index 810431d..0ec4804f 100644
77587 --- a/include/asm-generic/pgtable-nopud.h
77588 +++ b/include/asm-generic/pgtable-nopud.h
77589 @@ -1,10 +1,15 @@
77590 #ifndef _PGTABLE_NOPUD_H
77591 #define _PGTABLE_NOPUD_H
77592
77593 -#ifndef __ASSEMBLY__
77594 -
77595 #define __PAGETABLE_PUD_FOLDED
77596
77597 +#define PUD_SHIFT PGDIR_SHIFT
77598 +#define PTRS_PER_PUD 1
77599 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
77600 +#define PUD_MASK (~(PUD_SIZE-1))
77601 +
77602 +#ifndef __ASSEMBLY__
77603 +
77604 /*
77605 * Having the pud type consist of a pgd gets the size right, and allows
77606 * us to conceptually access the pgd entry that this pud is folded into
77607 @@ -12,11 +17,6 @@
77608 */
77609 typedef struct { pgd_t pgd; } pud_t;
77610
77611 -#define PUD_SHIFT PGDIR_SHIFT
77612 -#define PTRS_PER_PUD 1
77613 -#define PUD_SIZE (1UL << PUD_SHIFT)
77614 -#define PUD_MASK (~(PUD_SIZE-1))
77615 -
77616 /*
77617 * The "pgd_xxx()" functions here are trivial for a folded two-level
77618 * setup: the pud is never bad, and a pud always exists (as it's folded
77619 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
77620 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
77621
77622 #define pgd_populate(mm, pgd, pud) do { } while (0)
77623 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
77624 /*
77625 * (puds are folded into pgds so this doesn't get actually called,
77626 * but the define is needed for a generic inline function.)
77627 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
77628 index a8015a7..7a4407b 100644
77629 --- a/include/asm-generic/pgtable.h
77630 +++ b/include/asm-generic/pgtable.h
77631 @@ -815,6 +815,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
77632 }
77633 #endif /* CONFIG_NUMA_BALANCING */
77634
77635 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
77636 +#ifdef CONFIG_PAX_KERNEXEC
77637 +#error KERNEXEC requires pax_open_kernel
77638 +#else
77639 +static inline unsigned long pax_open_kernel(void) { return 0; }
77640 +#endif
77641 +#endif
77642 +
77643 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
77644 +#ifdef CONFIG_PAX_KERNEXEC
77645 +#error KERNEXEC requires pax_close_kernel
77646 +#else
77647 +static inline unsigned long pax_close_kernel(void) { return 0; }
77648 +#endif
77649 +#endif
77650 +
77651 #endif /* CONFIG_MMU */
77652
77653 #endif /* !__ASSEMBLY__ */
77654 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
77655 index 72d8803..cb9749c 100644
77656 --- a/include/asm-generic/uaccess.h
77657 +++ b/include/asm-generic/uaccess.h
77658 @@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
77659 return __clear_user(to, n);
77660 }
77661
77662 +#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
77663 +#ifdef CONFIG_PAX_MEMORY_UDEREF
77664 +#error UDEREF requires pax_open_userland
77665 +#else
77666 +static inline unsigned long pax_open_userland(void) { return 0; }
77667 +#endif
77668 +#endif
77669 +
77670 +#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
77671 +#ifdef CONFIG_PAX_MEMORY_UDEREF
77672 +#error UDEREF requires pax_close_userland
77673 +#else
77674 +static inline unsigned long pax_close_userland(void) { return 0; }
77675 +#endif
77676 +#endif
77677 +
77678 #endif /* __ASM_GENERIC_UACCESS_H */
77679 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
77680 index 146e4ff..f4f9609 100644
77681 --- a/include/asm-generic/vmlinux.lds.h
77682 +++ b/include/asm-generic/vmlinux.lds.h
77683 @@ -251,6 +251,7 @@
77684 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
77685 VMLINUX_SYMBOL(__start_rodata) = .; \
77686 *(.rodata) *(.rodata.*) \
77687 + *(.data..read_only) \
77688 *(__vermagic) /* Kernel version magic */ \
77689 . = ALIGN(8); \
77690 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
77691 @@ -737,17 +738,18 @@
77692 * section in the linker script will go there too. @phdr should have
77693 * a leading colon.
77694 *
77695 - * Note that this macros defines __per_cpu_load as an absolute symbol.
77696 + * Note that this macros defines per_cpu_load as an absolute symbol.
77697 * If there is no need to put the percpu section at a predetermined
77698 * address, use PERCPU_SECTION.
77699 */
77700 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
77701 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
77702 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
77703 + per_cpu_load = .; \
77704 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
77705 - LOAD_OFFSET) { \
77706 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
77707 PERCPU_INPUT(cacheline) \
77708 } phdr \
77709 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
77710 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
77711
77712 /**
77713 * PERCPU_SECTION - define output section for percpu area, simple version
77714 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
77715 index 016c2f1..c4baa98 100644
77716 --- a/include/crypto/algapi.h
77717 +++ b/include/crypto/algapi.h
77718 @@ -34,7 +34,7 @@ struct crypto_type {
77719 unsigned int maskclear;
77720 unsigned int maskset;
77721 unsigned int tfmsize;
77722 -};
77723 +} __do_const;
77724
77725 struct crypto_instance {
77726 struct crypto_alg alg;
77727 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
77728 index a7c2a86..078f1b6 100644
77729 --- a/include/drm/drmP.h
77730 +++ b/include/drm/drmP.h
77731 @@ -68,6 +68,7 @@
77732 #include <linux/workqueue.h>
77733 #include <linux/poll.h>
77734 #include <asm/pgalloc.h>
77735 +#include <asm/local.h>
77736 #include <drm/drm.h>
77737 #include <drm/drm_sarea.h>
77738 #include <drm/drm_vma_manager.h>
77739 @@ -268,10 +269,12 @@ do { \
77740 * \param cmd command.
77741 * \param arg argument.
77742 */
77743 -typedef int drm_ioctl_t(struct drm_device *dev, void *data,
77744 +typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
77745 + struct drm_file *file_priv);
77746 +typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
77747 struct drm_file *file_priv);
77748
77749 -typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
77750 +typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
77751 unsigned long arg);
77752
77753 #define DRM_IOCTL_NR(n) _IOC_NR(n)
77754 @@ -287,10 +290,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
77755 struct drm_ioctl_desc {
77756 unsigned int cmd;
77757 int flags;
77758 - drm_ioctl_t *func;
77759 + drm_ioctl_t func;
77760 unsigned int cmd_drv;
77761 const char *name;
77762 -};
77763 +} __do_const;
77764
77765 /**
77766 * Creates a driver or general drm_ioctl_desc array entry for the given
77767 @@ -1001,7 +1004,8 @@ struct drm_info_list {
77768 int (*show)(struct seq_file*, void*); /** show callback */
77769 u32 driver_features; /**< Required driver features for this entry */
77770 void *data;
77771 -};
77772 +} __do_const;
77773 +typedef struct drm_info_list __no_const drm_info_list_no_const;
77774
77775 /**
77776 * debugfs node structure. This structure represents a debugfs file.
77777 @@ -1083,7 +1087,7 @@ struct drm_device {
77778
77779 /** \name Usage Counters */
77780 /*@{ */
77781 - int open_count; /**< Outstanding files open */
77782 + local_t open_count; /**< Outstanding files open */
77783 int buf_use; /**< Buffers in use -- cannot alloc */
77784 atomic_t buf_alloc; /**< Buffer allocation in progress */
77785 /*@} */
77786 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
77787 index 36a5feb..d9f01aa 100644
77788 --- a/include/drm/drm_crtc_helper.h
77789 +++ b/include/drm/drm_crtc_helper.h
77790 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
77791 struct drm_connector *connector);
77792 /* disable encoder when not in use - more explicit than dpms off */
77793 void (*disable)(struct drm_encoder *encoder);
77794 -};
77795 +} __no_const;
77796
77797 /**
77798 * drm_connector_helper_funcs - helper operations for connectors
77799 diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
77800 index 012d58f..d0a0642 100644
77801 --- a/include/drm/i915_pciids.h
77802 +++ b/include/drm/i915_pciids.h
77803 @@ -37,7 +37,7 @@
77804 */
77805 #define INTEL_VGA_DEVICE(id, info) { \
77806 0x8086, id, \
77807 - ~0, ~0, \
77808 + PCI_ANY_ID, PCI_ANY_ID, \
77809 0x030000, 0xff0000, \
77810 (unsigned long) info }
77811
77812 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
77813 index 72dcbe8..8db58d7 100644
77814 --- a/include/drm/ttm/ttm_memory.h
77815 +++ b/include/drm/ttm/ttm_memory.h
77816 @@ -48,7 +48,7 @@
77817
77818 struct ttm_mem_shrink {
77819 int (*do_shrink) (struct ttm_mem_shrink *);
77820 -};
77821 +} __no_const;
77822
77823 /**
77824 * struct ttm_mem_global - Global memory accounting structure.
77825 diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
77826 index 49a8284..9643967 100644
77827 --- a/include/drm/ttm/ttm_page_alloc.h
77828 +++ b/include/drm/ttm/ttm_page_alloc.h
77829 @@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
77830 */
77831 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
77832
77833 +struct device;
77834 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
77835 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
77836
77837 diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
77838 index 4b840e8..155d235 100644
77839 --- a/include/keys/asymmetric-subtype.h
77840 +++ b/include/keys/asymmetric-subtype.h
77841 @@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
77842 /* Verify the signature on a key of this subtype (optional) */
77843 int (*verify_signature)(const struct key *key,
77844 const struct public_key_signature *sig);
77845 -};
77846 +} __do_const;
77847
77848 /**
77849 * asymmetric_key_subtype - Get the subtype from an asymmetric key
77850 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
77851 index c1da539..1dcec55 100644
77852 --- a/include/linux/atmdev.h
77853 +++ b/include/linux/atmdev.h
77854 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
77855 #endif
77856
77857 struct k_atm_aal_stats {
77858 -#define __HANDLE_ITEM(i) atomic_t i
77859 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
77860 __AAL_STAT_ITEMS
77861 #undef __HANDLE_ITEM
77862 };
77863 @@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
77864 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
77865 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
77866 struct module *owner;
77867 -};
77868 +} __do_const ;
77869
77870 struct atmphy_ops {
77871 int (*start)(struct atm_dev *dev);
77872 diff --git a/include/linux/audit.h b/include/linux/audit.h
77873 index 22cfddb..ab759e8 100644
77874 --- a/include/linux/audit.h
77875 +++ b/include/linux/audit.h
77876 @@ -210,7 +210,7 @@ static inline void audit_ptrace(struct task_struct *t)
77877 extern unsigned int audit_serial(void);
77878 extern int auditsc_get_stamp(struct audit_context *ctx,
77879 struct timespec *t, unsigned int *serial);
77880 -extern int audit_set_loginuid(kuid_t loginuid);
77881 +extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
77882
77883 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
77884 {
77885 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
77886 index 61f29e5..e67c658 100644
77887 --- a/include/linux/binfmts.h
77888 +++ b/include/linux/binfmts.h
77889 @@ -44,7 +44,7 @@ struct linux_binprm {
77890 unsigned interp_flags;
77891 unsigned interp_data;
77892 unsigned long loader, exec;
77893 -};
77894 +} __randomize_layout;
77895
77896 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
77897 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
77898 @@ -73,8 +73,10 @@ struct linux_binfmt {
77899 int (*load_binary)(struct linux_binprm *);
77900 int (*load_shlib)(struct file *);
77901 int (*core_dump)(struct coredump_params *cprm);
77902 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
77903 + void (*handle_mmap)(struct file *);
77904 unsigned long min_coredump; /* minimal dump size */
77905 -};
77906 +} __do_const __randomize_layout;
77907
77908 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
77909
77910 diff --git a/include/linux/bitops.h b/include/linux/bitops.h
77911 index be5fd38..d71192a 100644
77912 --- a/include/linux/bitops.h
77913 +++ b/include/linux/bitops.h
77914 @@ -102,7 +102,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
77915 * @word: value to rotate
77916 * @shift: bits to roll
77917 */
77918 -static inline __u32 rol32(__u32 word, unsigned int shift)
77919 +static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
77920 {
77921 return (word << shift) | (word >> (32 - shift));
77922 }
77923 @@ -112,7 +112,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
77924 * @word: value to rotate
77925 * @shift: bits to roll
77926 */
77927 -static inline __u32 ror32(__u32 word, unsigned int shift)
77928 +static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
77929 {
77930 return (word >> shift) | (word << (32 - shift));
77931 }
77932 @@ -168,7 +168,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
77933 return (__s32)(value << shift) >> shift;
77934 }
77935
77936 -static inline unsigned fls_long(unsigned long l)
77937 +static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
77938 {
77939 if (sizeof(l) == 4)
77940 return fls(l);
77941 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
77942 index 0d84981..bb741c0 100644
77943 --- a/include/linux/blkdev.h
77944 +++ b/include/linux/blkdev.h
77945 @@ -1584,7 +1584,7 @@ struct block_device_operations {
77946 /* this callback is with swap_lock and sometimes page table lock held */
77947 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
77948 struct module *owner;
77949 -};
77950 +} __do_const;
77951
77952 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
77953 unsigned long);
77954 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
77955 index afc1343..9735539 100644
77956 --- a/include/linux/blktrace_api.h
77957 +++ b/include/linux/blktrace_api.h
77958 @@ -25,7 +25,7 @@ struct blk_trace {
77959 struct dentry *dropped_file;
77960 struct dentry *msg_file;
77961 struct list_head running_list;
77962 - atomic_t dropped;
77963 + atomic_unchecked_t dropped;
77964 };
77965
77966 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
77967 diff --git a/include/linux/cache.h b/include/linux/cache.h
77968 index 17e7e82..1d7da26 100644
77969 --- a/include/linux/cache.h
77970 +++ b/include/linux/cache.h
77971 @@ -16,6 +16,14 @@
77972 #define __read_mostly
77973 #endif
77974
77975 +#ifndef __read_only
77976 +#ifdef CONFIG_PAX_KERNEXEC
77977 +#error KERNEXEC requires __read_only
77978 +#else
77979 +#define __read_only __read_mostly
77980 +#endif
77981 +#endif
77982 +
77983 #ifndef ____cacheline_aligned
77984 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
77985 #endif
77986 diff --git a/include/linux/capability.h b/include/linux/capability.h
77987 index 84b13ad..172cdee 100644
77988 --- a/include/linux/capability.h
77989 +++ b/include/linux/capability.h
77990 @@ -211,9 +211,14 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
77991 extern bool capable(int cap);
77992 extern bool ns_capable(struct user_namespace *ns, int cap);
77993 extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap);
77994 +extern bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap);
77995 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
77996 +extern bool capable_nolog(int cap);
77997 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
77998
77999 /* audit system wants to get cap info from files as well */
78000 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
78001
78002 +extern int is_privileged_binary(const struct dentry *dentry);
78003 +
78004 #endif /* !_LINUX_CAPABILITY_H */
78005 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
78006 index 8609d57..86e4d79 100644
78007 --- a/include/linux/cdrom.h
78008 +++ b/include/linux/cdrom.h
78009 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
78010
78011 /* driver specifications */
78012 const int capability; /* capability flags */
78013 - int n_minors; /* number of active minor devices */
78014 /* handle uniform packets for scsi type devices (scsi,atapi) */
78015 int (*generic_packet) (struct cdrom_device_info *,
78016 struct packet_command *);
78017 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
78018 index 4ce9056..86caac6 100644
78019 --- a/include/linux/cleancache.h
78020 +++ b/include/linux/cleancache.h
78021 @@ -31,7 +31,7 @@ struct cleancache_ops {
78022 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
78023 void (*invalidate_inode)(int, struct cleancache_filekey);
78024 void (*invalidate_fs)(int);
78025 -};
78026 +} __no_const;
78027
78028 extern struct cleancache_ops *
78029 cleancache_register_ops(struct cleancache_ops *ops);
78030 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
78031 index 5119174..8e264f8 100644
78032 --- a/include/linux/clk-provider.h
78033 +++ b/include/linux/clk-provider.h
78034 @@ -174,6 +174,7 @@ struct clk_ops {
78035 void (*init)(struct clk_hw *hw);
78036 int (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
78037 };
78038 +typedef struct clk_ops __no_const clk_ops_no_const;
78039
78040 /**
78041 * struct clk_init_data - holds init data that's common to all clocks and is
78042 diff --git a/include/linux/compat.h b/include/linux/compat.h
78043 index e649426..a74047b 100644
78044 --- a/include/linux/compat.h
78045 +++ b/include/linux/compat.h
78046 @@ -316,7 +316,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
78047 compat_size_t __user *len_ptr);
78048
78049 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
78050 -asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
78051 +asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
78052 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
78053 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
78054 compat_ssize_t msgsz, int msgflg);
78055 @@ -436,7 +436,7 @@ extern int compat_ptrace_request(struct task_struct *child,
78056 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
78057 compat_ulong_t addr, compat_ulong_t data);
78058 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
78059 - compat_long_t addr, compat_long_t data);
78060 + compat_ulong_t addr, compat_ulong_t data);
78061
78062 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
78063 /*
78064 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
78065 index 2507fd2..55203f8 100644
78066 --- a/include/linux/compiler-gcc4.h
78067 +++ b/include/linux/compiler-gcc4.h
78068 @@ -39,9 +39,34 @@
78069 # define __compiletime_warning(message) __attribute__((warning(message)))
78070 # define __compiletime_error(message) __attribute__((error(message)))
78071 #endif /* __CHECKER__ */
78072 +
78073 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
78074 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
78075 +#define __bos0(ptr) __bos((ptr), 0)
78076 +#define __bos1(ptr) __bos((ptr), 1)
78077 #endif /* GCC_VERSION >= 40300 */
78078
78079 #if GCC_VERSION >= 40500
78080 +
78081 +#ifdef RANDSTRUCT_PLUGIN
78082 +#define __randomize_layout __attribute__((randomize_layout))
78083 +#define __no_randomize_layout __attribute__((no_randomize_layout))
78084 +#endif
78085 +
78086 +#ifdef CONSTIFY_PLUGIN
78087 +#define __no_const __attribute__((no_const))
78088 +#define __do_const __attribute__((do_const))
78089 +#endif
78090 +
78091 +#ifdef SIZE_OVERFLOW_PLUGIN
78092 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
78093 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
78094 +#endif
78095 +
78096 +#ifdef LATENT_ENTROPY_PLUGIN
78097 +#define __latent_entropy __attribute__((latent_entropy))
78098 +#endif
78099 +
78100 /*
78101 * Mark a position in code as unreachable. This can be used to
78102 * suppress control flow warnings after asm blocks that transfer
78103 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
78104 index ee7239e..7c11769 100644
78105 --- a/include/linux/compiler.h
78106 +++ b/include/linux/compiler.h
78107 @@ -5,11 +5,14 @@
78108
78109 #ifdef __CHECKER__
78110 # define __user __attribute__((noderef, address_space(1)))
78111 +# define __force_user __force __user
78112 # define __kernel __attribute__((address_space(0)))
78113 +# define __force_kernel __force __kernel
78114 # define __safe __attribute__((safe))
78115 # define __force __attribute__((force))
78116 # define __nocast __attribute__((nocast))
78117 # define __iomem __attribute__((noderef, address_space(2)))
78118 +# define __force_iomem __force __iomem
78119 # define __must_hold(x) __attribute__((context(x,1,1)))
78120 # define __acquires(x) __attribute__((context(x,0,1)))
78121 # define __releases(x) __attribute__((context(x,1,0)))
78122 @@ -17,20 +20,37 @@
78123 # define __release(x) __context__(x,-1)
78124 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
78125 # define __percpu __attribute__((noderef, address_space(3)))
78126 +# define __force_percpu __force __percpu
78127 #ifdef CONFIG_SPARSE_RCU_POINTER
78128 # define __rcu __attribute__((noderef, address_space(4)))
78129 +# define __force_rcu __force __rcu
78130 #else
78131 # define __rcu
78132 +# define __force_rcu
78133 #endif
78134 extern void __chk_user_ptr(const volatile void __user *);
78135 extern void __chk_io_ptr(const volatile void __iomem *);
78136 #else
78137 -# define __user
78138 -# define __kernel
78139 +# ifdef CHECKER_PLUGIN
78140 +//# define __user
78141 +//# define __force_user
78142 +//# define __kernel
78143 +//# define __force_kernel
78144 +# else
78145 +# ifdef STRUCTLEAK_PLUGIN
78146 +# define __user __attribute__((user))
78147 +# else
78148 +# define __user
78149 +# endif
78150 +# define __force_user
78151 +# define __kernel
78152 +# define __force_kernel
78153 +# endif
78154 # define __safe
78155 # define __force
78156 # define __nocast
78157 # define __iomem
78158 +# define __force_iomem
78159 # define __chk_user_ptr(x) (void)0
78160 # define __chk_io_ptr(x) (void)0
78161 # define __builtin_warning(x, y...) (1)
78162 @@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
78163 # define __release(x) (void)0
78164 # define __cond_lock(x,c) (c)
78165 # define __percpu
78166 +# define __force_percpu
78167 # define __rcu
78168 +# define __force_rcu
78169 #endif
78170
78171 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
78172 @@ -286,6 +308,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
78173 # define __attribute_const__ /* unimplemented */
78174 #endif
78175
78176 +#ifndef __randomize_layout
78177 +# define __randomize_layout
78178 +#endif
78179 +
78180 +#ifndef __no_randomize_layout
78181 +# define __no_randomize_layout
78182 +#endif
78183 +
78184 +#ifndef __no_const
78185 +# define __no_const
78186 +#endif
78187 +
78188 +#ifndef __do_const
78189 +# define __do_const
78190 +#endif
78191 +
78192 +#ifndef __size_overflow
78193 +# define __size_overflow(...)
78194 +#endif
78195 +
78196 +#ifndef __intentional_overflow
78197 +# define __intentional_overflow(...)
78198 +#endif
78199 +
78200 +#ifndef __latent_entropy
78201 +# define __latent_entropy
78202 +#endif
78203 +
78204 /*
78205 * Tell gcc if a function is cold. The compiler will assume any path
78206 * directly leading to the call is unlikely.
78207 @@ -295,6 +345,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
78208 #define __cold
78209 #endif
78210
78211 +#ifndef __alloc_size
78212 +#define __alloc_size(...)
78213 +#endif
78214 +
78215 +#ifndef __bos
78216 +#define __bos(ptr, arg)
78217 +#endif
78218 +
78219 +#ifndef __bos0
78220 +#define __bos0(ptr)
78221 +#endif
78222 +
78223 +#ifndef __bos1
78224 +#define __bos1(ptr)
78225 +#endif
78226 +
78227 /* Simple shorthand for a section definition */
78228 #ifndef __section
78229 # define __section(S) __attribute__ ((__section__(#S)))
78230 @@ -369,7 +435,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
78231 * use is to mediate communication between process-level code and irq/NMI
78232 * handlers, all running on the same CPU.
78233 */
78234 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
78235 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
78236 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
78237
78238 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
78239 #ifdef CONFIG_KPROBES
78240 diff --git a/include/linux/completion.h b/include/linux/completion.h
78241 index 5d5aaae..0ea9b84 100644
78242 --- a/include/linux/completion.h
78243 +++ b/include/linux/completion.h
78244 @@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
78245
78246 extern void wait_for_completion(struct completion *);
78247 extern void wait_for_completion_io(struct completion *);
78248 -extern int wait_for_completion_interruptible(struct completion *x);
78249 -extern int wait_for_completion_killable(struct completion *x);
78250 +extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
78251 +extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
78252 extern unsigned long wait_for_completion_timeout(struct completion *x,
78253 - unsigned long timeout);
78254 + unsigned long timeout) __intentional_overflow(-1);
78255 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
78256 - unsigned long timeout);
78257 + unsigned long timeout) __intentional_overflow(-1);
78258 extern long wait_for_completion_interruptible_timeout(
78259 - struct completion *x, unsigned long timeout);
78260 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
78261 extern long wait_for_completion_killable_timeout(
78262 - struct completion *x, unsigned long timeout);
78263 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
78264 extern bool try_wait_for_completion(struct completion *x);
78265 extern bool completion_done(struct completion *x);
78266
78267 diff --git a/include/linux/configfs.h b/include/linux/configfs.h
78268 index 34025df..d94bbbc 100644
78269 --- a/include/linux/configfs.h
78270 +++ b/include/linux/configfs.h
78271 @@ -125,7 +125,7 @@ struct configfs_attribute {
78272 const char *ca_name;
78273 struct module *ca_owner;
78274 umode_t ca_mode;
78275 -};
78276 +} __do_const;
78277
78278 /*
78279 * Users often need to create attribute structures for their configurable
78280 diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
78281 index 5ae5100..b809662 100644
78282 --- a/include/linux/cpufreq.h
78283 +++ b/include/linux/cpufreq.h
78284 @@ -200,6 +200,7 @@ struct global_attr {
78285 ssize_t (*store)(struct kobject *a, struct attribute *b,
78286 const char *c, size_t count);
78287 };
78288 +typedef struct global_attr __no_const global_attr_no_const;
78289
78290 #define define_one_global_ro(_name) \
78291 static struct global_attr _name = \
78292 @@ -242,7 +243,7 @@ struct cpufreq_driver {
78293 bool boost_supported;
78294 bool boost_enabled;
78295 int (*set_boost) (int state);
78296 -};
78297 +} __do_const;
78298
78299 /* flags */
78300 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
78301 diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
78302 index b0238cb..db89e1e 100644
78303 --- a/include/linux/cpuidle.h
78304 +++ b/include/linux/cpuidle.h
78305 @@ -50,7 +50,8 @@ struct cpuidle_state {
78306 int index);
78307
78308 int (*enter_dead) (struct cpuidle_device *dev, int index);
78309 -};
78310 +} __do_const;
78311 +typedef struct cpuidle_state __no_const cpuidle_state_no_const;
78312
78313 /* Idle State Flags */
78314 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
78315 @@ -211,7 +212,7 @@ struct cpuidle_governor {
78316 void (*reflect) (struct cpuidle_device *dev, int index);
78317
78318 struct module *owner;
78319 -};
78320 +} __do_const;
78321
78322 #ifdef CONFIG_CPU_IDLE
78323 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
78324 diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
78325 index d08e4d2..95fad61 100644
78326 --- a/include/linux/cpumask.h
78327 +++ b/include/linux/cpumask.h
78328 @@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
78329 }
78330
78331 /* Valid inputs for n are -1 and 0. */
78332 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
78333 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
78334 {
78335 return n+1;
78336 }
78337
78338 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
78339 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
78340 {
78341 return n+1;
78342 }
78343
78344 -static inline unsigned int cpumask_next_and(int n,
78345 +static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
78346 const struct cpumask *srcp,
78347 const struct cpumask *andp)
78348 {
78349 @@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
78350 *
78351 * Returns >= nr_cpu_ids if no further cpus set.
78352 */
78353 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
78354 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
78355 {
78356 /* -1 is a legal arg here. */
78357 if (n != -1)
78358 @@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
78359 *
78360 * Returns >= nr_cpu_ids if no further cpus unset.
78361 */
78362 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
78363 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
78364 {
78365 /* -1 is a legal arg here. */
78366 if (n != -1)
78367 @@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
78368 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
78369 }
78370
78371 -int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
78372 +int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
78373 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
78374
78375 /**
78376 diff --git a/include/linux/cred.h b/include/linux/cred.h
78377 index f61d6c8..d372d95 100644
78378 --- a/include/linux/cred.h
78379 +++ b/include/linux/cred.h
78380 @@ -35,7 +35,7 @@ struct group_info {
78381 int nblocks;
78382 kgid_t small_block[NGROUPS_SMALL];
78383 kgid_t *blocks[0];
78384 -};
78385 +} __randomize_layout;
78386
78387 /**
78388 * get_group_info - Get a reference to a group info structure
78389 @@ -136,7 +136,7 @@ struct cred {
78390 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
78391 struct group_info *group_info; /* supplementary groups for euid/fsgid */
78392 struct rcu_head rcu; /* RCU deletion hook */
78393 -};
78394 +} __randomize_layout;
78395
78396 extern void __put_cred(struct cred *);
78397 extern void exit_creds(struct task_struct *);
78398 @@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
78399 static inline void validate_process_creds(void)
78400 {
78401 }
78402 +static inline void validate_task_creds(struct task_struct *task)
78403 +{
78404 +}
78405 #endif
78406
78407 /**
78408 @@ -322,6 +325,7 @@ static inline void put_cred(const struct cred *_cred)
78409
78410 #define task_uid(task) (task_cred_xxx((task), uid))
78411 #define task_euid(task) (task_cred_xxx((task), euid))
78412 +#define task_securebits(task) (task_cred_xxx((task), securebits))
78413
78414 #define current_cred_xxx(xxx) \
78415 ({ \
78416 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
78417 index b92eadf..b4ecdc1 100644
78418 --- a/include/linux/crypto.h
78419 +++ b/include/linux/crypto.h
78420 @@ -373,7 +373,7 @@ struct cipher_tfm {
78421 const u8 *key, unsigned int keylen);
78422 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
78423 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
78424 -};
78425 +} __no_const;
78426
78427 struct hash_tfm {
78428 int (*init)(struct hash_desc *desc);
78429 @@ -394,13 +394,13 @@ struct compress_tfm {
78430 int (*cot_decompress)(struct crypto_tfm *tfm,
78431 const u8 *src, unsigned int slen,
78432 u8 *dst, unsigned int *dlen);
78433 -};
78434 +} __no_const;
78435
78436 struct rng_tfm {
78437 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
78438 unsigned int dlen);
78439 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
78440 -};
78441 +} __no_const;
78442
78443 #define crt_ablkcipher crt_u.ablkcipher
78444 #define crt_aead crt_u.aead
78445 diff --git a/include/linux/ctype.h b/include/linux/ctype.h
78446 index 653589e..4ef254a 100644
78447 --- a/include/linux/ctype.h
78448 +++ b/include/linux/ctype.h
78449 @@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
78450 * Fast implementation of tolower() for internal usage. Do not use in your
78451 * code.
78452 */
78453 -static inline char _tolower(const char c)
78454 +static inline unsigned char _tolower(const unsigned char c)
78455 {
78456 return c | 0x20;
78457 }
78458 diff --git a/include/linux/dcache.h b/include/linux/dcache.h
78459 index 3c7ec32..4ca97cc 100644
78460 --- a/include/linux/dcache.h
78461 +++ b/include/linux/dcache.h
78462 @@ -133,7 +133,7 @@ struct dentry {
78463 } d_u;
78464 struct list_head d_subdirs; /* our children */
78465 struct hlist_node d_alias; /* inode alias list */
78466 -};
78467 +} __randomize_layout;
78468
78469 /*
78470 * dentry->d_lock spinlock nesting subclasses:
78471 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
78472 index 7925bf0..d5143d2 100644
78473 --- a/include/linux/decompress/mm.h
78474 +++ b/include/linux/decompress/mm.h
78475 @@ -77,7 +77,7 @@ static void free(void *where)
78476 * warnings when not needed (indeed large_malloc / large_free are not
78477 * needed by inflate */
78478
78479 -#define malloc(a) kmalloc(a, GFP_KERNEL)
78480 +#define malloc(a) kmalloc((a), GFP_KERNEL)
78481 #define free(a) kfree(a)
78482
78483 #define large_malloc(a) vmalloc(a)
78484 diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
78485 index d48dc00..211ee54 100644
78486 --- a/include/linux/devfreq.h
78487 +++ b/include/linux/devfreq.h
78488 @@ -114,7 +114,7 @@ struct devfreq_governor {
78489 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
78490 int (*event_handler)(struct devfreq *devfreq,
78491 unsigned int event, void *data);
78492 -};
78493 +} __do_const;
78494
78495 /**
78496 * struct devfreq - Device devfreq structure
78497 diff --git a/include/linux/device.h b/include/linux/device.h
78498 index d1d1c05..a90fdb0 100644
78499 --- a/include/linux/device.h
78500 +++ b/include/linux/device.h
78501 @@ -310,7 +310,7 @@ struct subsys_interface {
78502 struct list_head node;
78503 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
78504 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
78505 -};
78506 +} __do_const;
78507
78508 int subsys_interface_register(struct subsys_interface *sif);
78509 void subsys_interface_unregister(struct subsys_interface *sif);
78510 @@ -506,7 +506,7 @@ struct device_type {
78511 void (*release)(struct device *dev);
78512
78513 const struct dev_pm_ops *pm;
78514 -};
78515 +} __do_const;
78516
78517 /* interface for exporting device attributes */
78518 struct device_attribute {
78519 @@ -516,11 +516,12 @@ struct device_attribute {
78520 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
78521 const char *buf, size_t count);
78522 };
78523 +typedef struct device_attribute __no_const device_attribute_no_const;
78524
78525 struct dev_ext_attribute {
78526 struct device_attribute attr;
78527 void *var;
78528 -};
78529 +} __do_const;
78530
78531 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
78532 char *buf);
78533 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
78534 index fd4aee2..1f28db9 100644
78535 --- a/include/linux/dma-mapping.h
78536 +++ b/include/linux/dma-mapping.h
78537 @@ -54,7 +54,7 @@ struct dma_map_ops {
78538 u64 (*get_required_mask)(struct device *dev);
78539 #endif
78540 int is_phys;
78541 -};
78542 +} __do_const;
78543
78544 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
78545
78546 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
78547 index 72cb0dd..7fe9a4b 100644
78548 --- a/include/linux/dmaengine.h
78549 +++ b/include/linux/dmaengine.h
78550 @@ -1147,9 +1147,9 @@ struct dma_pinned_list {
78551 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
78552 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
78553
78554 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
78555 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
78556 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
78557 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
78558 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
78559 struct dma_pinned_list *pinned_list, struct page *page,
78560 unsigned int offset, size_t len);
78561
78562 diff --git a/include/linux/efi.h b/include/linux/efi.h
78563 index 6c100ff..e3289b4 100644
78564 --- a/include/linux/efi.h
78565 +++ b/include/linux/efi.h
78566 @@ -1009,6 +1009,7 @@ struct efivar_operations {
78567 efi_set_variable_t *set_variable;
78568 efi_query_variable_store_t *query_variable_store;
78569 };
78570 +typedef struct efivar_operations __no_const efivar_operations_no_const;
78571
78572 struct efivars {
78573 /*
78574 diff --git a/include/linux/elf.h b/include/linux/elf.h
78575 index 67a5fa7..b817372 100644
78576 --- a/include/linux/elf.h
78577 +++ b/include/linux/elf.h
78578 @@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
78579 #define elf_note elf32_note
78580 #define elf_addr_t Elf32_Off
78581 #define Elf_Half Elf32_Half
78582 +#define elf_dyn Elf32_Dyn
78583
78584 #else
78585
78586 @@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
78587 #define elf_note elf64_note
78588 #define elf_addr_t Elf64_Off
78589 #define Elf_Half Elf64_Half
78590 +#define elf_dyn Elf64_Dyn
78591
78592 #endif
78593
78594 diff --git a/include/linux/err.h b/include/linux/err.h
78595 index a729120..6ede2c9 100644
78596 --- a/include/linux/err.h
78597 +++ b/include/linux/err.h
78598 @@ -20,12 +20,12 @@
78599
78600 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
78601
78602 -static inline void * __must_check ERR_PTR(long error)
78603 +static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
78604 {
78605 return (void *) error;
78606 }
78607
78608 -static inline long __must_check PTR_ERR(__force const void *ptr)
78609 +static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
78610 {
78611 return (long) ptr;
78612 }
78613 diff --git a/include/linux/extcon.h b/include/linux/extcon.h
78614 index f488145..3b6b04e 100644
78615 --- a/include/linux/extcon.h
78616 +++ b/include/linux/extcon.h
78617 @@ -135,7 +135,7 @@ struct extcon_dev {
78618 /* /sys/class/extcon/.../mutually_exclusive/... */
78619 struct attribute_group attr_g_muex;
78620 struct attribute **attrs_muex;
78621 - struct device_attribute *d_attrs_muex;
78622 + device_attribute_no_const *d_attrs_muex;
78623 };
78624
78625 /**
78626 diff --git a/include/linux/fb.h b/include/linux/fb.h
78627 index fe6ac95..898d41d 100644
78628 --- a/include/linux/fb.h
78629 +++ b/include/linux/fb.h
78630 @@ -304,7 +304,7 @@ struct fb_ops {
78631 /* called at KDB enter and leave time to prepare the console */
78632 int (*fb_debug_enter)(struct fb_info *info);
78633 int (*fb_debug_leave)(struct fb_info *info);
78634 -};
78635 +} __do_const;
78636
78637 #ifdef CONFIG_FB_TILEBLITTING
78638 #define FB_TILE_CURSOR_NONE 0
78639 diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
78640 index 230f87b..1fd0485 100644
78641 --- a/include/linux/fdtable.h
78642 +++ b/include/linux/fdtable.h
78643 @@ -100,7 +100,7 @@ struct files_struct *get_files_struct(struct task_struct *);
78644 void put_files_struct(struct files_struct *fs);
78645 void reset_files_struct(struct files_struct *);
78646 int unshare_files(struct files_struct **);
78647 -struct files_struct *dup_fd(struct files_struct *, int *);
78648 +struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
78649 void do_close_on_exec(struct files_struct *);
78650 int iterate_fd(struct files_struct *, unsigned,
78651 int (*)(const void *, struct file *, unsigned),
78652 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
78653 index 8293262..2b3b8bd 100644
78654 --- a/include/linux/frontswap.h
78655 +++ b/include/linux/frontswap.h
78656 @@ -11,7 +11,7 @@ struct frontswap_ops {
78657 int (*load)(unsigned, pgoff_t, struct page *);
78658 void (*invalidate_page)(unsigned, pgoff_t);
78659 void (*invalidate_area)(unsigned);
78660 -};
78661 +} __no_const;
78662
78663 extern bool frontswap_enabled;
78664 extern struct frontswap_ops *
78665 diff --git a/include/linux/fs.h b/include/linux/fs.h
78666 index 8780312..425cc22 100644
78667 --- a/include/linux/fs.h
78668 +++ b/include/linux/fs.h
78669 @@ -398,7 +398,7 @@ struct address_space {
78670 spinlock_t private_lock; /* for use by the address_space */
78671 struct list_head private_list; /* ditto */
78672 void *private_data; /* ditto */
78673 -} __attribute__((aligned(sizeof(long))));
78674 +} __attribute__((aligned(sizeof(long)))) __randomize_layout;
78675 /*
78676 * On most architectures that alignment is already the case; but
78677 * must be enforced here for CRIS, to let the least significant bit
78678 @@ -441,7 +441,7 @@ struct block_device {
78679 int bd_fsfreeze_count;
78680 /* Mutex for freeze */
78681 struct mutex bd_fsfreeze_mutex;
78682 -};
78683 +} __randomize_layout;
78684
78685 /*
78686 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
78687 @@ -585,7 +585,7 @@ struct inode {
78688 #endif
78689
78690 void *i_private; /* fs or device private pointer */
78691 -};
78692 +} __randomize_layout;
78693
78694 static inline int inode_unhashed(struct inode *inode)
78695 {
78696 @@ -778,7 +778,7 @@ struct file {
78697 struct list_head f_tfile_llink;
78698 #endif /* #ifdef CONFIG_EPOLL */
78699 struct address_space *f_mapping;
78700 -} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
78701 +} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
78702
78703 struct file_handle {
78704 __u32 handle_bytes;
78705 @@ -906,7 +906,7 @@ struct file_lock {
78706 int state; /* state of grant or error if -ve */
78707 } afs;
78708 } fl_u;
78709 -};
78710 +} __randomize_layout;
78711
78712 /* The following constant reflects the upper bound of the file/locking space */
78713 #ifndef OFFSET_MAX
78714 @@ -1255,7 +1255,7 @@ struct super_block {
78715 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
78716 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
78717 struct rcu_head rcu;
78718 -};
78719 +} __randomize_layout;
78720
78721 extern struct timespec current_fs_time(struct super_block *sb);
78722
78723 @@ -1477,7 +1477,8 @@ struct file_operations {
78724 long (*fallocate)(struct file *file, int mode, loff_t offset,
78725 loff_t len);
78726 int (*show_fdinfo)(struct seq_file *m, struct file *f);
78727 -};
78728 +} __do_const __randomize_layout;
78729 +typedef struct file_operations __no_const file_operations_no_const;
78730
78731 struct inode_operations {
78732 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
78733 @@ -2757,4 +2758,14 @@ static inline bool dir_relax(struct inode *inode)
78734 return !IS_DEADDIR(inode);
78735 }
78736
78737 +static inline bool is_sidechannel_device(const struct inode *inode)
78738 +{
78739 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
78740 + umode_t mode = inode->i_mode;
78741 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
78742 +#else
78743 + return false;
78744 +#endif
78745 +}
78746 +
78747 #endif /* _LINUX_FS_H */
78748 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
78749 index 0efc3e6..fd23610 100644
78750 --- a/include/linux/fs_struct.h
78751 +++ b/include/linux/fs_struct.h
78752 @@ -6,13 +6,13 @@
78753 #include <linux/seqlock.h>
78754
78755 struct fs_struct {
78756 - int users;
78757 + atomic_t users;
78758 spinlock_t lock;
78759 seqcount_t seq;
78760 int umask;
78761 int in_exec;
78762 struct path root, pwd;
78763 -};
78764 +} __randomize_layout;
78765
78766 extern struct kmem_cache *fs_cachep;
78767
78768 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
78769 index 7714849..a4a5c7a 100644
78770 --- a/include/linux/fscache-cache.h
78771 +++ b/include/linux/fscache-cache.h
78772 @@ -113,7 +113,7 @@ struct fscache_operation {
78773 fscache_operation_release_t release;
78774 };
78775
78776 -extern atomic_t fscache_op_debug_id;
78777 +extern atomic_unchecked_t fscache_op_debug_id;
78778 extern void fscache_op_work_func(struct work_struct *work);
78779
78780 extern void fscache_enqueue_operation(struct fscache_operation *);
78781 @@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
78782 INIT_WORK(&op->work, fscache_op_work_func);
78783 atomic_set(&op->usage, 1);
78784 op->state = FSCACHE_OP_ST_INITIALISED;
78785 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
78786 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
78787 op->processor = processor;
78788 op->release = release;
78789 INIT_LIST_HEAD(&op->pend_link);
78790 diff --git a/include/linux/fscache.h b/include/linux/fscache.h
78791 index 115bb81..e7b812b 100644
78792 --- a/include/linux/fscache.h
78793 +++ b/include/linux/fscache.h
78794 @@ -152,7 +152,7 @@ struct fscache_cookie_def {
78795 * - this is mandatory for any object that may have data
78796 */
78797 void (*now_uncached)(void *cookie_netfs_data);
78798 -};
78799 +} __do_const;
78800
78801 /*
78802 * fscache cached network filesystem type
78803 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
78804 index 1c804b0..1432c2b 100644
78805 --- a/include/linux/fsnotify.h
78806 +++ b/include/linux/fsnotify.h
78807 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
78808 struct inode *inode = file_inode(file);
78809 __u32 mask = FS_ACCESS;
78810
78811 + if (is_sidechannel_device(inode))
78812 + return;
78813 +
78814 if (S_ISDIR(inode->i_mode))
78815 mask |= FS_ISDIR;
78816
78817 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
78818 struct inode *inode = file_inode(file);
78819 __u32 mask = FS_MODIFY;
78820
78821 + if (is_sidechannel_device(inode))
78822 + return;
78823 +
78824 if (S_ISDIR(inode->i_mode))
78825 mask |= FS_ISDIR;
78826
78827 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
78828 */
78829 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
78830 {
78831 - return kstrdup(name, GFP_KERNEL);
78832 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
78833 }
78834
78835 /*
78836 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
78837 index 9f3c275..8bdff5d 100644
78838 --- a/include/linux/genhd.h
78839 +++ b/include/linux/genhd.h
78840 @@ -194,7 +194,7 @@ struct gendisk {
78841 struct kobject *slave_dir;
78842
78843 struct timer_rand_state *random;
78844 - atomic_t sync_io; /* RAID */
78845 + atomic_unchecked_t sync_io; /* RAID */
78846 struct disk_events *ev;
78847 #ifdef CONFIG_BLK_DEV_INTEGRITY
78848 struct blk_integrity *integrity;
78849 @@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
78850 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
78851
78852 /* drivers/char/random.c */
78853 -extern void add_disk_randomness(struct gendisk *disk);
78854 +extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
78855 extern void rand_initialize_disk(struct gendisk *disk);
78856
78857 static inline sector_t get_start_sect(struct block_device *bdev)
78858 diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
78859 index c0894dd..2fbf10c 100644
78860 --- a/include/linux/genl_magic_func.h
78861 +++ b/include/linux/genl_magic_func.h
78862 @@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
78863 },
78864
78865 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
78866 -static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
78867 +static struct genl_ops ZZZ_genl_ops[] = {
78868 #include GENL_MAGIC_INCLUDE_FILE
78869 };
78870
78871 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
78872 index 39b81dc..819dc51 100644
78873 --- a/include/linux/gfp.h
78874 +++ b/include/linux/gfp.h
78875 @@ -36,6 +36,13 @@ struct vm_area_struct;
78876 #define ___GFP_NO_KSWAPD 0x400000u
78877 #define ___GFP_OTHER_NODE 0x800000u
78878 #define ___GFP_WRITE 0x1000000u
78879 +
78880 +#ifdef CONFIG_PAX_USERCOPY_SLABS
78881 +#define ___GFP_USERCOPY 0x2000000u
78882 +#else
78883 +#define ___GFP_USERCOPY 0
78884 +#endif
78885 +
78886 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
78887
78888 /*
78889 @@ -93,6 +100,7 @@ struct vm_area_struct;
78890 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
78891 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
78892 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
78893 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
78894
78895 /*
78896 * This may seem redundant, but it's a way of annotating false positives vs.
78897 @@ -100,7 +108,7 @@ struct vm_area_struct;
78898 */
78899 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
78900
78901 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
78902 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
78903 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
78904
78905 /* This equals 0, but use constants in case they ever change */
78906 @@ -158,6 +166,8 @@ struct vm_area_struct;
78907 /* 4GB DMA on some platforms */
78908 #define GFP_DMA32 __GFP_DMA32
78909
78910 +#define GFP_USERCOPY __GFP_USERCOPY
78911 +
78912 /* Convert GFP flags to their corresponding migrate type */
78913 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
78914 {
78915 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
78916 new file mode 100644
78917 index 0000000..edb2cb6
78918 --- /dev/null
78919 +++ b/include/linux/gracl.h
78920 @@ -0,0 +1,340 @@
78921 +#ifndef GR_ACL_H
78922 +#define GR_ACL_H
78923 +
78924 +#include <linux/grdefs.h>
78925 +#include <linux/resource.h>
78926 +#include <linux/capability.h>
78927 +#include <linux/dcache.h>
78928 +#include <asm/resource.h>
78929 +
78930 +/* Major status information */
78931 +
78932 +#define GR_VERSION "grsecurity 3.0"
78933 +#define GRSECURITY_VERSION 0x3000
78934 +
78935 +enum {
78936 + GR_SHUTDOWN = 0,
78937 + GR_ENABLE = 1,
78938 + GR_SPROLE = 2,
78939 + GR_OLDRELOAD = 3,
78940 + GR_SEGVMOD = 4,
78941 + GR_STATUS = 5,
78942 + GR_UNSPROLE = 6,
78943 + GR_PASSSET = 7,
78944 + GR_SPROLEPAM = 8,
78945 + GR_RELOAD = 9,
78946 +};
78947 +
78948 +/* Password setup definitions
78949 + * kernel/grhash.c */
78950 +enum {
78951 + GR_PW_LEN = 128,
78952 + GR_SALT_LEN = 16,
78953 + GR_SHA_LEN = 32,
78954 +};
78955 +
78956 +enum {
78957 + GR_SPROLE_LEN = 64,
78958 +};
78959 +
78960 +enum {
78961 + GR_NO_GLOB = 0,
78962 + GR_REG_GLOB,
78963 + GR_CREATE_GLOB
78964 +};
78965 +
78966 +#define GR_NLIMITS 32
78967 +
78968 +/* Begin Data Structures */
78969 +
78970 +struct sprole_pw {
78971 + unsigned char *rolename;
78972 + unsigned char salt[GR_SALT_LEN];
78973 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
78974 +};
78975 +
78976 +struct name_entry {
78977 + __u32 key;
78978 + ino_t inode;
78979 + dev_t device;
78980 + char *name;
78981 + __u16 len;
78982 + __u8 deleted;
78983 + struct name_entry *prev;
78984 + struct name_entry *next;
78985 +};
78986 +
78987 +struct inodev_entry {
78988 + struct name_entry *nentry;
78989 + struct inodev_entry *prev;
78990 + struct inodev_entry *next;
78991 +};
78992 +
78993 +struct acl_role_db {
78994 + struct acl_role_label **r_hash;
78995 + __u32 r_size;
78996 +};
78997 +
78998 +struct inodev_db {
78999 + struct inodev_entry **i_hash;
79000 + __u32 i_size;
79001 +};
79002 +
79003 +struct name_db {
79004 + struct name_entry **n_hash;
79005 + __u32 n_size;
79006 +};
79007 +
79008 +struct crash_uid {
79009 + uid_t uid;
79010 + unsigned long expires;
79011 +};
79012 +
79013 +struct gr_hash_struct {
79014 + void **table;
79015 + void **nametable;
79016 + void *first;
79017 + __u32 table_size;
79018 + __u32 used_size;
79019 + int type;
79020 +};
79021 +
79022 +/* Userspace Grsecurity ACL data structures */
79023 +
79024 +struct acl_subject_label {
79025 + char *filename;
79026 + ino_t inode;
79027 + dev_t device;
79028 + __u32 mode;
79029 + kernel_cap_t cap_mask;
79030 + kernel_cap_t cap_lower;
79031 + kernel_cap_t cap_invert_audit;
79032 +
79033 + struct rlimit res[GR_NLIMITS];
79034 + __u32 resmask;
79035 +
79036 + __u8 user_trans_type;
79037 + __u8 group_trans_type;
79038 + uid_t *user_transitions;
79039 + gid_t *group_transitions;
79040 + __u16 user_trans_num;
79041 + __u16 group_trans_num;
79042 +
79043 + __u32 sock_families[2];
79044 + __u32 ip_proto[8];
79045 + __u32 ip_type;
79046 + struct acl_ip_label **ips;
79047 + __u32 ip_num;
79048 + __u32 inaddr_any_override;
79049 +
79050 + __u32 crashes;
79051 + unsigned long expires;
79052 +
79053 + struct acl_subject_label *parent_subject;
79054 + struct gr_hash_struct *hash;
79055 + struct acl_subject_label *prev;
79056 + struct acl_subject_label *next;
79057 +
79058 + struct acl_object_label **obj_hash;
79059 + __u32 obj_hash_size;
79060 + __u16 pax_flags;
79061 +};
79062 +
79063 +struct role_allowed_ip {
79064 + __u32 addr;
79065 + __u32 netmask;
79066 +
79067 + struct role_allowed_ip *prev;
79068 + struct role_allowed_ip *next;
79069 +};
79070 +
79071 +struct role_transition {
79072 + char *rolename;
79073 +
79074 + struct role_transition *prev;
79075 + struct role_transition *next;
79076 +};
79077 +
79078 +struct acl_role_label {
79079 + char *rolename;
79080 + uid_t uidgid;
79081 + __u16 roletype;
79082 +
79083 + __u16 auth_attempts;
79084 + unsigned long expires;
79085 +
79086 + struct acl_subject_label *root_label;
79087 + struct gr_hash_struct *hash;
79088 +
79089 + struct acl_role_label *prev;
79090 + struct acl_role_label *next;
79091 +
79092 + struct role_transition *transitions;
79093 + struct role_allowed_ip *allowed_ips;
79094 + uid_t *domain_children;
79095 + __u16 domain_child_num;
79096 +
79097 + umode_t umask;
79098 +
79099 + struct acl_subject_label **subj_hash;
79100 + __u32 subj_hash_size;
79101 +};
79102 +
79103 +struct user_acl_role_db {
79104 + struct acl_role_label **r_table;
79105 + __u32 num_pointers; /* Number of allocations to track */
79106 + __u32 num_roles; /* Number of roles */
79107 + __u32 num_domain_children; /* Number of domain children */
79108 + __u32 num_subjects; /* Number of subjects */
79109 + __u32 num_objects; /* Number of objects */
79110 +};
79111 +
79112 +struct acl_object_label {
79113 + char *filename;
79114 + ino_t inode;
79115 + dev_t device;
79116 + __u32 mode;
79117 +
79118 + struct acl_subject_label *nested;
79119 + struct acl_object_label *globbed;
79120 +
79121 + /* next two structures not used */
79122 +
79123 + struct acl_object_label *prev;
79124 + struct acl_object_label *next;
79125 +};
79126 +
79127 +struct acl_ip_label {
79128 + char *iface;
79129 + __u32 addr;
79130 + __u32 netmask;
79131 + __u16 low, high;
79132 + __u8 mode;
79133 + __u32 type;
79134 + __u32 proto[8];
79135 +
79136 + /* next two structures not used */
79137 +
79138 + struct acl_ip_label *prev;
79139 + struct acl_ip_label *next;
79140 +};
79141 +
79142 +struct gr_arg {
79143 + struct user_acl_role_db role_db;
79144 + unsigned char pw[GR_PW_LEN];
79145 + unsigned char salt[GR_SALT_LEN];
79146 + unsigned char sum[GR_SHA_LEN];
79147 + unsigned char sp_role[GR_SPROLE_LEN];
79148 + struct sprole_pw *sprole_pws;
79149 + dev_t segv_device;
79150 + ino_t segv_inode;
79151 + uid_t segv_uid;
79152 + __u16 num_sprole_pws;
79153 + __u16 mode;
79154 +};
79155 +
79156 +struct gr_arg_wrapper {
79157 + struct gr_arg *arg;
79158 + __u32 version;
79159 + __u32 size;
79160 +};
79161 +
79162 +struct subject_map {
79163 + struct acl_subject_label *user;
79164 + struct acl_subject_label *kernel;
79165 + struct subject_map *prev;
79166 + struct subject_map *next;
79167 +};
79168 +
79169 +struct acl_subj_map_db {
79170 + struct subject_map **s_hash;
79171 + __u32 s_size;
79172 +};
79173 +
79174 +struct gr_policy_state {
79175 + struct sprole_pw **acl_special_roles;
79176 + __u16 num_sprole_pws;
79177 + struct acl_role_label *kernel_role;
79178 + struct acl_role_label *role_list;
79179 + struct acl_role_label *default_role;
79180 + struct acl_role_db acl_role_set;
79181 + struct acl_subj_map_db subj_map_set;
79182 + struct name_db name_set;
79183 + struct inodev_db inodev_set;
79184 +};
79185 +
79186 +struct gr_alloc_state {
79187 + unsigned long alloc_stack_next;
79188 + unsigned long alloc_stack_size;
79189 + void **alloc_stack;
79190 +};
79191 +
79192 +struct gr_reload_state {
79193 + struct gr_policy_state oldpolicy;
79194 + struct gr_alloc_state oldalloc;
79195 + struct gr_policy_state newpolicy;
79196 + struct gr_alloc_state newalloc;
79197 + struct gr_policy_state *oldpolicy_ptr;
79198 + struct gr_alloc_state *oldalloc_ptr;
79199 + unsigned char oldmode;
79200 +};
79201 +
79202 +/* End Data Structures Section */
79203 +
79204 +/* Hash functions generated by empirical testing by Brad Spengler
79205 + Makes good use of the low bits of the inode. Generally 0-1 times
79206 + in loop for successful match. 0-3 for unsuccessful match.
79207 + Shift/add algorithm with modulus of table size and an XOR*/
79208 +
79209 +static __inline__ unsigned int
79210 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
79211 +{
79212 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
79213 +}
79214 +
79215 + static __inline__ unsigned int
79216 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
79217 +{
79218 + return ((const unsigned long)userp % sz);
79219 +}
79220 +
79221 +static __inline__ unsigned int
79222 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
79223 +{
79224 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
79225 +}
79226 +
79227 +static __inline__ unsigned int
79228 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
79229 +{
79230 + return full_name_hash((const unsigned char *)name, len) % sz;
79231 +}
79232 +
79233 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
79234 + subj = NULL; \
79235 + iter = 0; \
79236 + while (iter < role->subj_hash_size) { \
79237 + if (subj == NULL) \
79238 + subj = role->subj_hash[iter]; \
79239 + if (subj == NULL) { \
79240 + iter++; \
79241 + continue; \
79242 + }
79243 +
79244 +#define FOR_EACH_SUBJECT_END(subj,iter) \
79245 + subj = subj->next; \
79246 + if (subj == NULL) \
79247 + iter++; \
79248 + }
79249 +
79250 +
79251 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
79252 + subj = role->hash->first; \
79253 + while (subj != NULL) {
79254 +
79255 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
79256 + subj = subj->next; \
79257 + }
79258 +
79259 +#endif
79260 +
79261 diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
79262 new file mode 100644
79263 index 0000000..33ebd1f
79264 --- /dev/null
79265 +++ b/include/linux/gracl_compat.h
79266 @@ -0,0 +1,156 @@
79267 +#ifndef GR_ACL_COMPAT_H
79268 +#define GR_ACL_COMPAT_H
79269 +
79270 +#include <linux/resource.h>
79271 +#include <asm/resource.h>
79272 +
79273 +struct sprole_pw_compat {
79274 + compat_uptr_t rolename;
79275 + unsigned char salt[GR_SALT_LEN];
79276 + unsigned char sum[GR_SHA_LEN];
79277 +};
79278 +
79279 +struct gr_hash_struct_compat {
79280 + compat_uptr_t table;
79281 + compat_uptr_t nametable;
79282 + compat_uptr_t first;
79283 + __u32 table_size;
79284 + __u32 used_size;
79285 + int type;
79286 +};
79287 +
79288 +struct acl_subject_label_compat {
79289 + compat_uptr_t filename;
79290 + compat_ino_t inode;
79291 + __u32 device;
79292 + __u32 mode;
79293 + kernel_cap_t cap_mask;
79294 + kernel_cap_t cap_lower;
79295 + kernel_cap_t cap_invert_audit;
79296 +
79297 + struct compat_rlimit res[GR_NLIMITS];
79298 + __u32 resmask;
79299 +
79300 + __u8 user_trans_type;
79301 + __u8 group_trans_type;
79302 + compat_uptr_t user_transitions;
79303 + compat_uptr_t group_transitions;
79304 + __u16 user_trans_num;
79305 + __u16 group_trans_num;
79306 +
79307 + __u32 sock_families[2];
79308 + __u32 ip_proto[8];
79309 + __u32 ip_type;
79310 + compat_uptr_t ips;
79311 + __u32 ip_num;
79312 + __u32 inaddr_any_override;
79313 +
79314 + __u32 crashes;
79315 + compat_ulong_t expires;
79316 +
79317 + compat_uptr_t parent_subject;
79318 + compat_uptr_t hash;
79319 + compat_uptr_t prev;
79320 + compat_uptr_t next;
79321 +
79322 + compat_uptr_t obj_hash;
79323 + __u32 obj_hash_size;
79324 + __u16 pax_flags;
79325 +};
79326 +
79327 +struct role_allowed_ip_compat {
79328 + __u32 addr;
79329 + __u32 netmask;
79330 +
79331 + compat_uptr_t prev;
79332 + compat_uptr_t next;
79333 +};
79334 +
79335 +struct role_transition_compat {
79336 + compat_uptr_t rolename;
79337 +
79338 + compat_uptr_t prev;
79339 + compat_uptr_t next;
79340 +};
79341 +
79342 +struct acl_role_label_compat {
79343 + compat_uptr_t rolename;
79344 + uid_t uidgid;
79345 + __u16 roletype;
79346 +
79347 + __u16 auth_attempts;
79348 + compat_ulong_t expires;
79349 +
79350 + compat_uptr_t root_label;
79351 + compat_uptr_t hash;
79352 +
79353 + compat_uptr_t prev;
79354 + compat_uptr_t next;
79355 +
79356 + compat_uptr_t transitions;
79357 + compat_uptr_t allowed_ips;
79358 + compat_uptr_t domain_children;
79359 + __u16 domain_child_num;
79360 +
79361 + umode_t umask;
79362 +
79363 + compat_uptr_t subj_hash;
79364 + __u32 subj_hash_size;
79365 +};
79366 +
79367 +struct user_acl_role_db_compat {
79368 + compat_uptr_t r_table;
79369 + __u32 num_pointers;
79370 + __u32 num_roles;
79371 + __u32 num_domain_children;
79372 + __u32 num_subjects;
79373 + __u32 num_objects;
79374 +};
79375 +
79376 +struct acl_object_label_compat {
79377 + compat_uptr_t filename;
79378 + compat_ino_t inode;
79379 + __u32 device;
79380 + __u32 mode;
79381 +
79382 + compat_uptr_t nested;
79383 + compat_uptr_t globbed;
79384 +
79385 + compat_uptr_t prev;
79386 + compat_uptr_t next;
79387 +};
79388 +
79389 +struct acl_ip_label_compat {
79390 + compat_uptr_t iface;
79391 + __u32 addr;
79392 + __u32 netmask;
79393 + __u16 low, high;
79394 + __u8 mode;
79395 + __u32 type;
79396 + __u32 proto[8];
79397 +
79398 + compat_uptr_t prev;
79399 + compat_uptr_t next;
79400 +};
79401 +
79402 +struct gr_arg_compat {
79403 + struct user_acl_role_db_compat role_db;
79404 + unsigned char pw[GR_PW_LEN];
79405 + unsigned char salt[GR_SALT_LEN];
79406 + unsigned char sum[GR_SHA_LEN];
79407 + unsigned char sp_role[GR_SPROLE_LEN];
79408 + compat_uptr_t sprole_pws;
79409 + __u32 segv_device;
79410 + compat_ino_t segv_inode;
79411 + uid_t segv_uid;
79412 + __u16 num_sprole_pws;
79413 + __u16 mode;
79414 +};
79415 +
79416 +struct gr_arg_wrapper_compat {
79417 + compat_uptr_t arg;
79418 + __u32 version;
79419 + __u32 size;
79420 +};
79421 +
79422 +#endif
79423 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
79424 new file mode 100644
79425 index 0000000..323ecf2
79426 --- /dev/null
79427 +++ b/include/linux/gralloc.h
79428 @@ -0,0 +1,9 @@
79429 +#ifndef __GRALLOC_H
79430 +#define __GRALLOC_H
79431 +
79432 +void acl_free_all(void);
79433 +int acl_alloc_stack_init(unsigned long size);
79434 +void *acl_alloc(unsigned long len);
79435 +void *acl_alloc_num(unsigned long num, unsigned long len);
79436 +
79437 +#endif
79438 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
79439 new file mode 100644
79440 index 0000000..be66033
79441 --- /dev/null
79442 +++ b/include/linux/grdefs.h
79443 @@ -0,0 +1,140 @@
79444 +#ifndef GRDEFS_H
79445 +#define GRDEFS_H
79446 +
79447 +/* Begin grsecurity status declarations */
79448 +
79449 +enum {
79450 + GR_READY = 0x01,
79451 + GR_STATUS_INIT = 0x00 // disabled state
79452 +};
79453 +
79454 +/* Begin ACL declarations */
79455 +
79456 +/* Role flags */
79457 +
79458 +enum {
79459 + GR_ROLE_USER = 0x0001,
79460 + GR_ROLE_GROUP = 0x0002,
79461 + GR_ROLE_DEFAULT = 0x0004,
79462 + GR_ROLE_SPECIAL = 0x0008,
79463 + GR_ROLE_AUTH = 0x0010,
79464 + GR_ROLE_NOPW = 0x0020,
79465 + GR_ROLE_GOD = 0x0040,
79466 + GR_ROLE_LEARN = 0x0080,
79467 + GR_ROLE_TPE = 0x0100,
79468 + GR_ROLE_DOMAIN = 0x0200,
79469 + GR_ROLE_PAM = 0x0400,
79470 + GR_ROLE_PERSIST = 0x0800
79471 +};
79472 +
79473 +/* ACL Subject and Object mode flags */
79474 +enum {
79475 + GR_DELETED = 0x80000000
79476 +};
79477 +
79478 +/* ACL Object-only mode flags */
79479 +enum {
79480 + GR_READ = 0x00000001,
79481 + GR_APPEND = 0x00000002,
79482 + GR_WRITE = 0x00000004,
79483 + GR_EXEC = 0x00000008,
79484 + GR_FIND = 0x00000010,
79485 + GR_INHERIT = 0x00000020,
79486 + GR_SETID = 0x00000040,
79487 + GR_CREATE = 0x00000080,
79488 + GR_DELETE = 0x00000100,
79489 + GR_LINK = 0x00000200,
79490 + GR_AUDIT_READ = 0x00000400,
79491 + GR_AUDIT_APPEND = 0x00000800,
79492 + GR_AUDIT_WRITE = 0x00001000,
79493 + GR_AUDIT_EXEC = 0x00002000,
79494 + GR_AUDIT_FIND = 0x00004000,
79495 + GR_AUDIT_INHERIT= 0x00008000,
79496 + GR_AUDIT_SETID = 0x00010000,
79497 + GR_AUDIT_CREATE = 0x00020000,
79498 + GR_AUDIT_DELETE = 0x00040000,
79499 + GR_AUDIT_LINK = 0x00080000,
79500 + GR_PTRACERD = 0x00100000,
79501 + GR_NOPTRACE = 0x00200000,
79502 + GR_SUPPRESS = 0x00400000,
79503 + GR_NOLEARN = 0x00800000,
79504 + GR_INIT_TRANSFER= 0x01000000
79505 +};
79506 +
79507 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
79508 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
79509 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
79510 +
79511 +/* ACL subject-only mode flags */
79512 +enum {
79513 + GR_KILL = 0x00000001,
79514 + GR_VIEW = 0x00000002,
79515 + GR_PROTECTED = 0x00000004,
79516 + GR_LEARN = 0x00000008,
79517 + GR_OVERRIDE = 0x00000010,
79518 + /* just a placeholder, this mode is only used in userspace */
79519 + GR_DUMMY = 0x00000020,
79520 + GR_PROTSHM = 0x00000040,
79521 + GR_KILLPROC = 0x00000080,
79522 + GR_KILLIPPROC = 0x00000100,
79523 + /* just a placeholder, this mode is only used in userspace */
79524 + GR_NOTROJAN = 0x00000200,
79525 + GR_PROTPROCFD = 0x00000400,
79526 + GR_PROCACCT = 0x00000800,
79527 + GR_RELAXPTRACE = 0x00001000,
79528 + //GR_NESTED = 0x00002000,
79529 + GR_INHERITLEARN = 0x00004000,
79530 + GR_PROCFIND = 0x00008000,
79531 + GR_POVERRIDE = 0x00010000,
79532 + GR_KERNELAUTH = 0x00020000,
79533 + GR_ATSECURE = 0x00040000,
79534 + GR_SHMEXEC = 0x00080000
79535 +};
79536 +
79537 +enum {
79538 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
79539 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
79540 + GR_PAX_ENABLE_MPROTECT = 0x0004,
79541 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
79542 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
79543 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
79544 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
79545 + GR_PAX_DISABLE_MPROTECT = 0x0400,
79546 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
79547 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
79548 +};
79549 +
79550 +enum {
79551 + GR_ID_USER = 0x01,
79552 + GR_ID_GROUP = 0x02,
79553 +};
79554 +
79555 +enum {
79556 + GR_ID_ALLOW = 0x01,
79557 + GR_ID_DENY = 0x02,
79558 +};
79559 +
79560 +#define GR_CRASH_RES 31
79561 +#define GR_UIDTABLE_MAX 500
79562 +
79563 +/* begin resource learning section */
79564 +enum {
79565 + GR_RLIM_CPU_BUMP = 60,
79566 + GR_RLIM_FSIZE_BUMP = 50000,
79567 + GR_RLIM_DATA_BUMP = 10000,
79568 + GR_RLIM_STACK_BUMP = 1000,
79569 + GR_RLIM_CORE_BUMP = 10000,
79570 + GR_RLIM_RSS_BUMP = 500000,
79571 + GR_RLIM_NPROC_BUMP = 1,
79572 + GR_RLIM_NOFILE_BUMP = 5,
79573 + GR_RLIM_MEMLOCK_BUMP = 50000,
79574 + GR_RLIM_AS_BUMP = 500000,
79575 + GR_RLIM_LOCKS_BUMP = 2,
79576 + GR_RLIM_SIGPENDING_BUMP = 5,
79577 + GR_RLIM_MSGQUEUE_BUMP = 10000,
79578 + GR_RLIM_NICE_BUMP = 1,
79579 + GR_RLIM_RTPRIO_BUMP = 1,
79580 + GR_RLIM_RTTIME_BUMP = 1000000
79581 +};
79582 +
79583 +#endif
79584 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
79585 new file mode 100644
79586 index 0000000..d25522e
79587 --- /dev/null
79588 +++ b/include/linux/grinternal.h
79589 @@ -0,0 +1,229 @@
79590 +#ifndef __GRINTERNAL_H
79591 +#define __GRINTERNAL_H
79592 +
79593 +#ifdef CONFIG_GRKERNSEC
79594 +
79595 +#include <linux/fs.h>
79596 +#include <linux/mnt_namespace.h>
79597 +#include <linux/nsproxy.h>
79598 +#include <linux/gracl.h>
79599 +#include <linux/grdefs.h>
79600 +#include <linux/grmsg.h>
79601 +
79602 +void gr_add_learn_entry(const char *fmt, ...)
79603 + __attribute__ ((format (printf, 1, 2)));
79604 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
79605 + const struct vfsmount *mnt);
79606 +__u32 gr_check_create(const struct dentry *new_dentry,
79607 + const struct dentry *parent,
79608 + const struct vfsmount *mnt, const __u32 mode);
79609 +int gr_check_protected_task(const struct task_struct *task);
79610 +__u32 to_gr_audit(const __u32 reqmode);
79611 +int gr_set_acls(const int type);
79612 +int gr_acl_is_enabled(void);
79613 +char gr_roletype_to_char(void);
79614 +
79615 +void gr_handle_alertkill(struct task_struct *task);
79616 +char *gr_to_filename(const struct dentry *dentry,
79617 + const struct vfsmount *mnt);
79618 +char *gr_to_filename1(const struct dentry *dentry,
79619 + const struct vfsmount *mnt);
79620 +char *gr_to_filename2(const struct dentry *dentry,
79621 + const struct vfsmount *mnt);
79622 +char *gr_to_filename3(const struct dentry *dentry,
79623 + const struct vfsmount *mnt);
79624 +
79625 +extern int grsec_enable_ptrace_readexec;
79626 +extern int grsec_enable_harden_ptrace;
79627 +extern int grsec_enable_link;
79628 +extern int grsec_enable_fifo;
79629 +extern int grsec_enable_execve;
79630 +extern int grsec_enable_shm;
79631 +extern int grsec_enable_execlog;
79632 +extern int grsec_enable_signal;
79633 +extern int grsec_enable_audit_ptrace;
79634 +extern int grsec_enable_forkfail;
79635 +extern int grsec_enable_time;
79636 +extern int grsec_enable_rofs;
79637 +extern int grsec_deny_new_usb;
79638 +extern int grsec_enable_chroot_shmat;
79639 +extern int grsec_enable_chroot_mount;
79640 +extern int grsec_enable_chroot_double;
79641 +extern int grsec_enable_chroot_pivot;
79642 +extern int grsec_enable_chroot_chdir;
79643 +extern int grsec_enable_chroot_chmod;
79644 +extern int grsec_enable_chroot_mknod;
79645 +extern int grsec_enable_chroot_fchdir;
79646 +extern int grsec_enable_chroot_nice;
79647 +extern int grsec_enable_chroot_execlog;
79648 +extern int grsec_enable_chroot_caps;
79649 +extern int grsec_enable_chroot_sysctl;
79650 +extern int grsec_enable_chroot_unix;
79651 +extern int grsec_enable_symlinkown;
79652 +extern kgid_t grsec_symlinkown_gid;
79653 +extern int grsec_enable_tpe;
79654 +extern kgid_t grsec_tpe_gid;
79655 +extern int grsec_enable_tpe_all;
79656 +extern int grsec_enable_tpe_invert;
79657 +extern int grsec_enable_socket_all;
79658 +extern kgid_t grsec_socket_all_gid;
79659 +extern int grsec_enable_socket_client;
79660 +extern kgid_t grsec_socket_client_gid;
79661 +extern int grsec_enable_socket_server;
79662 +extern kgid_t grsec_socket_server_gid;
79663 +extern kgid_t grsec_audit_gid;
79664 +extern int grsec_enable_group;
79665 +extern int grsec_enable_log_rwxmaps;
79666 +extern int grsec_enable_mount;
79667 +extern int grsec_enable_chdir;
79668 +extern int grsec_resource_logging;
79669 +extern int grsec_enable_blackhole;
79670 +extern int grsec_lastack_retries;
79671 +extern int grsec_enable_brute;
79672 +extern int grsec_enable_harden_ipc;
79673 +extern int grsec_lock;
79674 +
79675 +extern spinlock_t grsec_alert_lock;
79676 +extern unsigned long grsec_alert_wtime;
79677 +extern unsigned long grsec_alert_fyet;
79678 +
79679 +extern spinlock_t grsec_audit_lock;
79680 +
79681 +extern rwlock_t grsec_exec_file_lock;
79682 +
79683 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
79684 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
79685 + (tsk)->exec_file->f_path.mnt) : "/")
79686 +
79687 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
79688 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
79689 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
79690 +
79691 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
79692 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
79693 + (tsk)->exec_file->f_path.mnt) : "/")
79694 +
79695 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
79696 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
79697 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
79698 +
79699 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
79700 +
79701 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
79702 +
79703 +static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
79704 +{
79705 + if (file1 && file2) {
79706 + const struct inode *inode1 = file1->f_path.dentry->d_inode;
79707 + const struct inode *inode2 = file2->f_path.dentry->d_inode;
79708 + if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
79709 + return true;
79710 + }
79711 +
79712 + return false;
79713 +}
79714 +
79715 +#define GR_CHROOT_CAPS {{ \
79716 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
79717 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
79718 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
79719 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
79720 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
79721 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
79722 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
79723 +
79724 +#define security_learn(normal_msg,args...) \
79725 +({ \
79726 + read_lock(&grsec_exec_file_lock); \
79727 + gr_add_learn_entry(normal_msg "\n", ## args); \
79728 + read_unlock(&grsec_exec_file_lock); \
79729 +})
79730 +
79731 +enum {
79732 + GR_DO_AUDIT,
79733 + GR_DONT_AUDIT,
79734 + /* used for non-audit messages that we shouldn't kill the task on */
79735 + GR_DONT_AUDIT_GOOD
79736 +};
79737 +
79738 +enum {
79739 + GR_TTYSNIFF,
79740 + GR_RBAC,
79741 + GR_RBAC_STR,
79742 + GR_STR_RBAC,
79743 + GR_RBAC_MODE2,
79744 + GR_RBAC_MODE3,
79745 + GR_FILENAME,
79746 + GR_SYSCTL_HIDDEN,
79747 + GR_NOARGS,
79748 + GR_ONE_INT,
79749 + GR_ONE_INT_TWO_STR,
79750 + GR_ONE_STR,
79751 + GR_STR_INT,
79752 + GR_TWO_STR_INT,
79753 + GR_TWO_INT,
79754 + GR_TWO_U64,
79755 + GR_THREE_INT,
79756 + GR_FIVE_INT_TWO_STR,
79757 + GR_TWO_STR,
79758 + GR_THREE_STR,
79759 + GR_FOUR_STR,
79760 + GR_STR_FILENAME,
79761 + GR_FILENAME_STR,
79762 + GR_FILENAME_TWO_INT,
79763 + GR_FILENAME_TWO_INT_STR,
79764 + GR_TEXTREL,
79765 + GR_PTRACE,
79766 + GR_RESOURCE,
79767 + GR_CAP,
79768 + GR_SIG,
79769 + GR_SIG2,
79770 + GR_CRASH1,
79771 + GR_CRASH2,
79772 + GR_PSACCT,
79773 + GR_RWXMAP,
79774 + GR_RWXMAPVMA
79775 +};
79776 +
79777 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
79778 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
79779 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
79780 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
79781 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
79782 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
79783 +#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)
79784 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
79785 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
79786 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
79787 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
79788 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
79789 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
79790 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
79791 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
79792 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
79793 +#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)
79794 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
79795 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
79796 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
79797 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
79798 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
79799 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
79800 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
79801 +#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)
79802 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
79803 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
79804 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
79805 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
79806 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
79807 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
79808 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
79809 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
79810 +#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)
79811 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
79812 +#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
79813 +
79814 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
79815 +
79816 +#endif
79817 +
79818 +#endif
79819 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
79820 new file mode 100644
79821 index 0000000..b02ba9d
79822 --- /dev/null
79823 +++ b/include/linux/grmsg.h
79824 @@ -0,0 +1,117 @@
79825 +#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"
79826 +#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"
79827 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
79828 +#define GR_STOPMOD_MSG "denied modification of module state by "
79829 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
79830 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
79831 +#define GR_IOPERM_MSG "denied use of ioperm() by "
79832 +#define GR_IOPL_MSG "denied use of iopl() by "
79833 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
79834 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
79835 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
79836 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
79837 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
79838 +#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"
79839 +#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"
79840 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
79841 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
79842 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
79843 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
79844 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
79845 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
79846 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
79847 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
79848 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
79849 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
79850 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
79851 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
79852 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
79853 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
79854 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
79855 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
79856 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
79857 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
79858 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
79859 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
79860 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
79861 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
79862 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
79863 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
79864 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
79865 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
79866 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
79867 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
79868 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
79869 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
79870 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
79871 +#define GR_CHROOT_FHANDLE_MSG "denied use of file handles inside chroot by "
79872 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
79873 +#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
79874 +#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
79875 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
79876 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
79877 +#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"
79878 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
79879 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
79880 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
79881 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
79882 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
79883 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
79884 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
79885 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
79886 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
79887 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
79888 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
79889 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
79890 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
79891 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
79892 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
79893 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
79894 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
79895 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
79896 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
79897 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
79898 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
79899 +#define GR_NICE_CHROOT_MSG "denied priority change by "
79900 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
79901 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
79902 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
79903 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
79904 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
79905 +#define GR_TIME_MSG "time set by "
79906 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
79907 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
79908 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
79909 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
79910 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
79911 +#define GR_BIND_MSG "denied bind() by "
79912 +#define GR_CONNECT_MSG "denied connect() by "
79913 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
79914 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
79915 +#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"
79916 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
79917 +#define GR_CAP_ACL_MSG "use of %s denied for "
79918 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
79919 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
79920 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
79921 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
79922 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
79923 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
79924 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
79925 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
79926 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
79927 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
79928 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
79929 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
79930 +#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
79931 +#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
79932 +#define GR_VM86_MSG "denied use of vm86 by "
79933 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
79934 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
79935 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
79936 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
79937 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
79938 +#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 "
79939 +#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 "
79940 +#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
79941 +#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
79942 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
79943 new file mode 100644
79944 index 0000000..e6d120f
79945 --- /dev/null
79946 +++ b/include/linux/grsecurity.h
79947 @@ -0,0 +1,252 @@
79948 +#ifndef GR_SECURITY_H
79949 +#define GR_SECURITY_H
79950 +#include <linux/fs.h>
79951 +#include <linux/fs_struct.h>
79952 +#include <linux/binfmts.h>
79953 +#include <linux/gracl.h>
79954 +
79955 +/* notify of brain-dead configs */
79956 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79957 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
79958 +#endif
79959 +#if defined(CONFIG_GRKERNSEC_PROC) && !defined(CONFIG_GRKERNSEC_PROC_USER) && !defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79960 +#error "CONFIG_GRKERNSEC_PROC enabled, but neither CONFIG_GRKERNSEC_PROC_USER nor CONFIG_GRKERNSEC_PROC_USERGROUP enabled"
79961 +#endif
79962 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
79963 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
79964 +#endif
79965 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
79966 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
79967 +#endif
79968 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
79969 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
79970 +#endif
79971 +
79972 +int gr_handle_new_usb(void);
79973 +
79974 +void gr_handle_brute_attach(int dumpable);
79975 +void gr_handle_brute_check(void);
79976 +void gr_handle_kernel_exploit(void);
79977 +
79978 +char gr_roletype_to_char(void);
79979 +
79980 +int gr_proc_is_restricted(void);
79981 +
79982 +int gr_acl_enable_at_secure(void);
79983 +
79984 +int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
79985 +int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
79986 +
79987 +void gr_del_task_from_ip_table(struct task_struct *p);
79988 +
79989 +int gr_pid_is_chrooted(struct task_struct *p);
79990 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
79991 +int gr_handle_chroot_nice(void);
79992 +int gr_handle_chroot_sysctl(const int op);
79993 +int gr_handle_chroot_setpriority(struct task_struct *p,
79994 + const int niceval);
79995 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
79996 +int gr_chroot_fhandle(void);
79997 +int gr_handle_chroot_chroot(const struct dentry *dentry,
79998 + const struct vfsmount *mnt);
79999 +void gr_handle_chroot_chdir(const struct path *path);
80000 +int gr_handle_chroot_chmod(const struct dentry *dentry,
80001 + const struct vfsmount *mnt, const int mode);
80002 +int gr_handle_chroot_mknod(const struct dentry *dentry,
80003 + const struct vfsmount *mnt, const int mode);
80004 +int gr_handle_chroot_mount(const struct dentry *dentry,
80005 + const struct vfsmount *mnt,
80006 + const char *dev_name);
80007 +int gr_handle_chroot_pivot(void);
80008 +int gr_handle_chroot_unix(const pid_t pid);
80009 +
80010 +int gr_handle_rawio(const struct inode *inode);
80011 +
80012 +void gr_handle_ioperm(void);
80013 +void gr_handle_iopl(void);
80014 +void gr_handle_msr_write(void);
80015 +
80016 +umode_t gr_acl_umask(void);
80017 +
80018 +int gr_tpe_allow(const struct file *file);
80019 +
80020 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
80021 +void gr_clear_chroot_entries(struct task_struct *task);
80022 +
80023 +void gr_log_forkfail(const int retval);
80024 +void gr_log_timechange(void);
80025 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
80026 +void gr_log_chdir(const struct dentry *dentry,
80027 + const struct vfsmount *mnt);
80028 +void gr_log_chroot_exec(const struct dentry *dentry,
80029 + const struct vfsmount *mnt);
80030 +void gr_log_remount(const char *devname, const int retval);
80031 +void gr_log_unmount(const char *devname, const int retval);
80032 +void gr_log_mount(const char *from, const char *to, const int retval);
80033 +void gr_log_textrel(struct vm_area_struct *vma);
80034 +void gr_log_ptgnustack(struct file *file);
80035 +void gr_log_rwxmmap(struct file *file);
80036 +void gr_log_rwxmprotect(struct vm_area_struct *vma);
80037 +
80038 +int gr_handle_follow_link(const struct inode *parent,
80039 + const struct inode *inode,
80040 + const struct dentry *dentry,
80041 + const struct vfsmount *mnt);
80042 +int gr_handle_fifo(const struct dentry *dentry,
80043 + const struct vfsmount *mnt,
80044 + const struct dentry *dir, const int flag,
80045 + const int acc_mode);
80046 +int gr_handle_hardlink(const struct dentry *dentry,
80047 + const struct vfsmount *mnt,
80048 + struct inode *inode,
80049 + const int mode, const struct filename *to);
80050 +
80051 +int gr_is_capable(const int cap);
80052 +int gr_is_capable_nolog(const int cap);
80053 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
80054 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
80055 +
80056 +void gr_copy_label(struct task_struct *tsk);
80057 +void gr_handle_crash(struct task_struct *task, const int sig);
80058 +int gr_handle_signal(const struct task_struct *p, const int sig);
80059 +int gr_check_crash_uid(const kuid_t uid);
80060 +int gr_check_protected_task(const struct task_struct *task);
80061 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
80062 +int gr_acl_handle_mmap(const struct file *file,
80063 + const unsigned long prot);
80064 +int gr_acl_handle_mprotect(const struct file *file,
80065 + const unsigned long prot);
80066 +int gr_check_hidden_task(const struct task_struct *tsk);
80067 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
80068 + const struct vfsmount *mnt);
80069 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
80070 + const struct vfsmount *mnt);
80071 +__u32 gr_acl_handle_access(const struct dentry *dentry,
80072 + const struct vfsmount *mnt, const int fmode);
80073 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
80074 + const struct vfsmount *mnt, umode_t *mode);
80075 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
80076 + const struct vfsmount *mnt);
80077 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
80078 + const struct vfsmount *mnt);
80079 +__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
80080 + const struct vfsmount *mnt);
80081 +int gr_handle_ptrace(struct task_struct *task, const long request);
80082 +int gr_handle_proc_ptrace(struct task_struct *task);
80083 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
80084 + const struct vfsmount *mnt);
80085 +int gr_check_crash_exec(const struct file *filp);
80086 +int gr_acl_is_enabled(void);
80087 +void gr_set_role_label(struct task_struct *task, const kuid_t uid,
80088 + const kgid_t gid);
80089 +int gr_set_proc_label(const struct dentry *dentry,
80090 + const struct vfsmount *mnt,
80091 + const int unsafe_flags);
80092 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
80093 + const struct vfsmount *mnt);
80094 +__u32 gr_acl_handle_open(const struct dentry *dentry,
80095 + const struct vfsmount *mnt, int acc_mode);
80096 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
80097 + const struct dentry *p_dentry,
80098 + const struct vfsmount *p_mnt,
80099 + int open_flags, int acc_mode, const int imode);
80100 +void gr_handle_create(const struct dentry *dentry,
80101 + const struct vfsmount *mnt);
80102 +void gr_handle_proc_create(const struct dentry *dentry,
80103 + const struct inode *inode);
80104 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
80105 + const struct dentry *parent_dentry,
80106 + const struct vfsmount *parent_mnt,
80107 + const int mode);
80108 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
80109 + const struct dentry *parent_dentry,
80110 + const struct vfsmount *parent_mnt);
80111 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
80112 + const struct vfsmount *mnt);
80113 +void gr_handle_delete(const ino_t ino, const dev_t dev);
80114 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
80115 + const struct vfsmount *mnt);
80116 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
80117 + const struct dentry *parent_dentry,
80118 + const struct vfsmount *parent_mnt,
80119 + const struct filename *from);
80120 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
80121 + const struct dentry *parent_dentry,
80122 + const struct vfsmount *parent_mnt,
80123 + const struct dentry *old_dentry,
80124 + const struct vfsmount *old_mnt, const struct filename *to);
80125 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
80126 +int gr_acl_handle_rename(struct dentry *new_dentry,
80127 + struct dentry *parent_dentry,
80128 + const struct vfsmount *parent_mnt,
80129 + struct dentry *old_dentry,
80130 + struct inode *old_parent_inode,
80131 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags);
80132 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
80133 + struct dentry *old_dentry,
80134 + struct dentry *new_dentry,
80135 + struct vfsmount *mnt, const __u8 replace, unsigned int flags);
80136 +__u32 gr_check_link(const struct dentry *new_dentry,
80137 + const struct dentry *parent_dentry,
80138 + const struct vfsmount *parent_mnt,
80139 + const struct dentry *old_dentry,
80140 + const struct vfsmount *old_mnt);
80141 +int gr_acl_handle_filldir(const struct file *file, const char *name,
80142 + const unsigned int namelen, const ino_t ino);
80143 +
80144 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
80145 + const struct vfsmount *mnt);
80146 +void gr_acl_handle_exit(void);
80147 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
80148 +int gr_acl_handle_procpidmem(const struct task_struct *task);
80149 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
80150 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
80151 +void gr_audit_ptrace(struct task_struct *task);
80152 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
80153 +void gr_put_exec_file(struct task_struct *task);
80154 +
80155 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
80156 +
80157 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
80158 +extern void gr_learn_resource(const struct task_struct *task, const int res,
80159 + const unsigned long wanted, const int gt);
80160 +#else
80161 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
80162 + const unsigned long wanted, const int gt)
80163 +{
80164 +}
80165 +#endif
80166 +
80167 +#ifdef CONFIG_GRKERNSEC_RESLOG
80168 +extern void gr_log_resource(const struct task_struct *task, const int res,
80169 + const unsigned long wanted, const int gt);
80170 +#else
80171 +static inline void gr_log_resource(const struct task_struct *task, const int res,
80172 + const unsigned long wanted, const int gt)
80173 +{
80174 +}
80175 +#endif
80176 +
80177 +#ifdef CONFIG_GRKERNSEC
80178 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
80179 +void gr_handle_vm86(void);
80180 +void gr_handle_mem_readwrite(u64 from, u64 to);
80181 +
80182 +void gr_log_badprocpid(const char *entry);
80183 +
80184 +extern int grsec_enable_dmesg;
80185 +extern int grsec_disable_privio;
80186 +
80187 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
80188 +extern kgid_t grsec_proc_gid;
80189 +#endif
80190 +
80191 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
80192 +extern int grsec_enable_chroot_findtask;
80193 +#endif
80194 +#ifdef CONFIG_GRKERNSEC_SETXID
80195 +extern int grsec_enable_setxid;
80196 +#endif
80197 +#endif
80198 +
80199 +#endif
80200 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
80201 new file mode 100644
80202 index 0000000..e7ffaaf
80203 --- /dev/null
80204 +++ b/include/linux/grsock.h
80205 @@ -0,0 +1,19 @@
80206 +#ifndef __GRSOCK_H
80207 +#define __GRSOCK_H
80208 +
80209 +extern void gr_attach_curr_ip(const struct sock *sk);
80210 +extern int gr_handle_sock_all(const int family, const int type,
80211 + const int protocol);
80212 +extern int gr_handle_sock_server(const struct sockaddr *sck);
80213 +extern int gr_handle_sock_server_other(const struct sock *sck);
80214 +extern int gr_handle_sock_client(const struct sockaddr *sck);
80215 +extern int gr_search_connect(struct socket * sock,
80216 + struct sockaddr_in * addr);
80217 +extern int gr_search_bind(struct socket * sock,
80218 + struct sockaddr_in * addr);
80219 +extern int gr_search_listen(struct socket * sock);
80220 +extern int gr_search_accept(struct socket * sock);
80221 +extern int gr_search_socket(const int domain, const int type,
80222 + const int protocol);
80223 +
80224 +#endif
80225 diff --git a/include/linux/hash.h b/include/linux/hash.h
80226 index bd1754c..8240892 100644
80227 --- a/include/linux/hash.h
80228 +++ b/include/linux/hash.h
80229 @@ -83,7 +83,7 @@ static inline u32 hash32_ptr(const void *ptr)
80230 struct fast_hash_ops {
80231 u32 (*hash)(const void *data, u32 len, u32 seed);
80232 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
80233 -};
80234 +} __no_const;
80235
80236 /**
80237 * arch_fast_hash - Caclulates a hash over a given buffer that can have
80238 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
80239 index 7fb31da..08b5114 100644
80240 --- a/include/linux/highmem.h
80241 +++ b/include/linux/highmem.h
80242 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
80243 kunmap_atomic(kaddr);
80244 }
80245
80246 +static inline void sanitize_highpage(struct page *page)
80247 +{
80248 + void *kaddr;
80249 + unsigned long flags;
80250 +
80251 + local_irq_save(flags);
80252 + kaddr = kmap_atomic(page);
80253 + clear_page(kaddr);
80254 + kunmap_atomic(kaddr);
80255 + local_irq_restore(flags);
80256 +}
80257 +
80258 static inline void zero_user_segments(struct page *page,
80259 unsigned start1, unsigned end1,
80260 unsigned start2, unsigned end2)
80261 diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
80262 index 1c7b89a..7dda400 100644
80263 --- a/include/linux/hwmon-sysfs.h
80264 +++ b/include/linux/hwmon-sysfs.h
80265 @@ -25,7 +25,8 @@
80266 struct sensor_device_attribute{
80267 struct device_attribute dev_attr;
80268 int index;
80269 -};
80270 +} __do_const;
80271 +typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
80272 #define to_sensor_dev_attr(_dev_attr) \
80273 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
80274
80275 @@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
80276 struct device_attribute dev_attr;
80277 u8 index;
80278 u8 nr;
80279 -};
80280 +} __do_const;
80281 +typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
80282 #define to_sensor_dev_attr_2(_dev_attr) \
80283 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
80284
80285 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
80286 index b556e0a..c10a515 100644
80287 --- a/include/linux/i2c.h
80288 +++ b/include/linux/i2c.h
80289 @@ -378,6 +378,7 @@ struct i2c_algorithm {
80290 /* To determine what the adapter supports */
80291 u32 (*functionality) (struct i2c_adapter *);
80292 };
80293 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
80294
80295 /**
80296 * struct i2c_bus_recovery_info - I2C bus recovery information
80297 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
80298 index d23c3c2..eb63c81 100644
80299 --- a/include/linux/i2o.h
80300 +++ b/include/linux/i2o.h
80301 @@ -565,7 +565,7 @@ struct i2o_controller {
80302 struct i2o_device *exec; /* Executive */
80303 #if BITS_PER_LONG == 64
80304 spinlock_t context_list_lock; /* lock for context_list */
80305 - atomic_t context_list_counter; /* needed for unique contexts */
80306 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
80307 struct list_head context_list; /* list of context id's
80308 and pointers */
80309 #endif
80310 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
80311 index aff7ad8..3942bbd 100644
80312 --- a/include/linux/if_pppox.h
80313 +++ b/include/linux/if_pppox.h
80314 @@ -76,7 +76,7 @@ struct pppox_proto {
80315 int (*ioctl)(struct socket *sock, unsigned int cmd,
80316 unsigned long arg);
80317 struct module *owner;
80318 -};
80319 +} __do_const;
80320
80321 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
80322 extern void unregister_pppox_proto(int proto_num);
80323 diff --git a/include/linux/init.h b/include/linux/init.h
80324 index a3ba270..a1b6604 100644
80325 --- a/include/linux/init.h
80326 +++ b/include/linux/init.h
80327 @@ -37,9 +37,17 @@
80328 * section.
80329 */
80330
80331 +#define add_init_latent_entropy __latent_entropy
80332 +
80333 +#ifdef CONFIG_MEMORY_HOTPLUG
80334 +#define add_meminit_latent_entropy
80335 +#else
80336 +#define add_meminit_latent_entropy __latent_entropy
80337 +#endif
80338 +
80339 /* These are for everybody (although not all archs will actually
80340 discard it in modules) */
80341 -#define __init __section(.init.text) __cold notrace
80342 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
80343 #define __initdata __section(.init.data)
80344 #define __initconst __constsection(.init.rodata)
80345 #define __exitdata __section(.exit.data)
80346 @@ -100,7 +108,7 @@
80347 #define __cpuexitconst
80348
80349 /* Used for MEMORY_HOTPLUG */
80350 -#define __meminit __section(.meminit.text) __cold notrace
80351 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
80352 #define __meminitdata __section(.meminit.data)
80353 #define __meminitconst __constsection(.meminit.rodata)
80354 #define __memexit __section(.memexit.text) __exitused __cold notrace
80355 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
80356 index 6df7f9f..d0bf699 100644
80357 --- a/include/linux/init_task.h
80358 +++ b/include/linux/init_task.h
80359 @@ -156,6 +156,12 @@ extern struct task_group root_task_group;
80360
80361 #define INIT_TASK_COMM "swapper"
80362
80363 +#ifdef CONFIG_X86
80364 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
80365 +#else
80366 +#define INIT_TASK_THREAD_INFO
80367 +#endif
80368 +
80369 #ifdef CONFIG_RT_MUTEXES
80370 # define INIT_RT_MUTEXES(tsk) \
80371 .pi_waiters = RB_ROOT, \
80372 @@ -203,6 +209,7 @@ extern struct task_group root_task_group;
80373 RCU_POINTER_INITIALIZER(cred, &init_cred), \
80374 .comm = INIT_TASK_COMM, \
80375 .thread = INIT_THREAD, \
80376 + INIT_TASK_THREAD_INFO \
80377 .fs = &init_fs, \
80378 .files = &init_files, \
80379 .signal = &init_signals, \
80380 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
80381 index 051c850..431f83a 100644
80382 --- a/include/linux/interrupt.h
80383 +++ b/include/linux/interrupt.h
80384 @@ -412,8 +412,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
80385
80386 struct softirq_action
80387 {
80388 - void (*action)(struct softirq_action *);
80389 -};
80390 + void (*action)(void);
80391 +} __no_const;
80392
80393 asmlinkage void do_softirq(void);
80394 asmlinkage void __do_softirq(void);
80395 @@ -427,7 +427,7 @@ static inline void do_softirq_own_stack(void)
80396 }
80397 #endif
80398
80399 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
80400 +extern void open_softirq(int nr, void (*action)(void));
80401 extern void softirq_init(void);
80402 extern void __raise_softirq_irqoff(unsigned int nr);
80403
80404 diff --git a/include/linux/iommu.h b/include/linux/iommu.h
80405 index b96a5b2..2732d1c 100644
80406 --- a/include/linux/iommu.h
80407 +++ b/include/linux/iommu.h
80408 @@ -131,7 +131,7 @@ struct iommu_ops {
80409 u32 (*domain_get_windows)(struct iommu_domain *domain);
80410
80411 unsigned long pgsize_bitmap;
80412 -};
80413 +} __do_const;
80414
80415 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
80416 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
80417 diff --git a/include/linux/ioport.h b/include/linux/ioport.h
80418 index 5e3a906..3131d0f 100644
80419 --- a/include/linux/ioport.h
80420 +++ b/include/linux/ioport.h
80421 @@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
80422 int adjust_resource(struct resource *res, resource_size_t start,
80423 resource_size_t size);
80424 resource_size_t resource_alignment(struct resource *res);
80425 -static inline resource_size_t resource_size(const struct resource *res)
80426 +static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
80427 {
80428 return res->end - res->start + 1;
80429 }
80430 diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
80431 index 35e7eca..6afb7ad 100644
80432 --- a/include/linux/ipc_namespace.h
80433 +++ b/include/linux/ipc_namespace.h
80434 @@ -69,7 +69,7 @@ struct ipc_namespace {
80435 struct user_namespace *user_ns;
80436
80437 unsigned int proc_inum;
80438 -};
80439 +} __randomize_layout;
80440
80441 extern struct ipc_namespace init_ipc_ns;
80442 extern atomic_t nr_ipc_ns;
80443 diff --git a/include/linux/irq.h b/include/linux/irq.h
80444 index 5c57efb..965a62b 100644
80445 --- a/include/linux/irq.h
80446 +++ b/include/linux/irq.h
80447 @@ -344,7 +344,8 @@ struct irq_chip {
80448 void (*irq_release_resources)(struct irq_data *data);
80449
80450 unsigned long flags;
80451 -};
80452 +} __do_const;
80453 +typedef struct irq_chip __no_const irq_chip_no_const;
80454
80455 /*
80456 * irq_chip specific flags
80457 diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
80458 index 7ed92d0..589abf5 100644
80459 --- a/include/linux/irqchip/arm-gic.h
80460 +++ b/include/linux/irqchip/arm-gic.h
80461 @@ -73,9 +73,11 @@
80462
80463 #ifndef __ASSEMBLY__
80464
80465 +#include <linux/irq.h>
80466 +
80467 struct device_node;
80468
80469 -extern struct irq_chip gic_arch_extn;
80470 +extern irq_chip_no_const gic_arch_extn;
80471
80472 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
80473 u32 offset, struct device_node *);
80474 diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
80475 index 1f44466..b481806 100644
80476 --- a/include/linux/jiffies.h
80477 +++ b/include/linux/jiffies.h
80478 @@ -292,20 +292,20 @@ extern unsigned long preset_lpj;
80479 /*
80480 * Convert various time units to each other:
80481 */
80482 -extern unsigned int jiffies_to_msecs(const unsigned long j);
80483 -extern unsigned int jiffies_to_usecs(const unsigned long j);
80484 +extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
80485 +extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
80486
80487 -static inline u64 jiffies_to_nsecs(const unsigned long j)
80488 +static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
80489 {
80490 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
80491 }
80492
80493 -extern unsigned long msecs_to_jiffies(const unsigned int m);
80494 -extern unsigned long usecs_to_jiffies(const unsigned int u);
80495 +extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
80496 +extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
80497 extern unsigned long timespec_to_jiffies(const struct timespec *value);
80498 extern void jiffies_to_timespec(const unsigned long jiffies,
80499 - struct timespec *value);
80500 -extern unsigned long timeval_to_jiffies(const struct timeval *value);
80501 + struct timespec *value) __intentional_overflow(-1);
80502 +extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
80503 extern void jiffies_to_timeval(const unsigned long jiffies,
80504 struct timeval *value);
80505
80506 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
80507 index 6883e19..e854fcb 100644
80508 --- a/include/linux/kallsyms.h
80509 +++ b/include/linux/kallsyms.h
80510 @@ -15,7 +15,8 @@
80511
80512 struct module;
80513
80514 -#ifdef CONFIG_KALLSYMS
80515 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
80516 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
80517 /* Lookup the address for a symbol. Returns 0 if not found. */
80518 unsigned long kallsyms_lookup_name(const char *name);
80519
80520 @@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
80521 /* Stupid that this does nothing, but I didn't create this mess. */
80522 #define __print_symbol(fmt, addr)
80523 #endif /*CONFIG_KALLSYMS*/
80524 +#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
80525 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
80526 +extern unsigned long kallsyms_lookup_name(const char *name);
80527 +extern void __print_symbol(const char *fmt, unsigned long address);
80528 +extern int sprint_backtrace(char *buffer, unsigned long address);
80529 +extern int sprint_symbol(char *buffer, unsigned long address);
80530 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
80531 +const char *kallsyms_lookup(unsigned long addr,
80532 + unsigned long *symbolsize,
80533 + unsigned long *offset,
80534 + char **modname, char *namebuf);
80535 +extern int kallsyms_lookup_size_offset(unsigned long addr,
80536 + unsigned long *symbolsize,
80537 + unsigned long *offset);
80538 +#endif
80539
80540 /* This macro allows us to keep printk typechecking */
80541 static __printf(1, 2)
80542 diff --git a/include/linux/key-type.h b/include/linux/key-type.h
80543 index a74c3a8..28d3f21 100644
80544 --- a/include/linux/key-type.h
80545 +++ b/include/linux/key-type.h
80546 @@ -131,7 +131,7 @@ struct key_type {
80547 /* internal fields */
80548 struct list_head link; /* link in types list */
80549 struct lock_class_key lock_class; /* key->sem lock class */
80550 -};
80551 +} __do_const;
80552
80553 extern struct key_type key_type_keyring;
80554
80555 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
80556 index 6b06d37..c134867 100644
80557 --- a/include/linux/kgdb.h
80558 +++ b/include/linux/kgdb.h
80559 @@ -52,7 +52,7 @@ extern int kgdb_connected;
80560 extern int kgdb_io_module_registered;
80561
80562 extern atomic_t kgdb_setting_breakpoint;
80563 -extern atomic_t kgdb_cpu_doing_single_step;
80564 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
80565
80566 extern struct task_struct *kgdb_usethread;
80567 extern struct task_struct *kgdb_contthread;
80568 @@ -254,7 +254,7 @@ struct kgdb_arch {
80569 void (*correct_hw_break)(void);
80570
80571 void (*enable_nmi)(bool on);
80572 -};
80573 +} __do_const;
80574
80575 /**
80576 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
80577 @@ -279,7 +279,7 @@ struct kgdb_io {
80578 void (*pre_exception) (void);
80579 void (*post_exception) (void);
80580 int is_console;
80581 -};
80582 +} __do_const;
80583
80584 extern struct kgdb_arch arch_kgdb_ops;
80585
80586 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
80587 index 0555cc6..40116ce 100644
80588 --- a/include/linux/kmod.h
80589 +++ b/include/linux/kmod.h
80590 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
80591 * usually useless though. */
80592 extern __printf(2, 3)
80593 int __request_module(bool wait, const char *name, ...);
80594 +extern __printf(3, 4)
80595 +int ___request_module(bool wait, char *param_name, const char *name, ...);
80596 #define request_module(mod...) __request_module(true, mod)
80597 #define request_module_nowait(mod...) __request_module(false, mod)
80598 #define try_then_request_module(x, mod...) \
80599 @@ -57,6 +59,9 @@ struct subprocess_info {
80600 struct work_struct work;
80601 struct completion *complete;
80602 char *path;
80603 +#ifdef CONFIG_GRKERNSEC
80604 + char *origpath;
80605 +#endif
80606 char **argv;
80607 char **envp;
80608 int wait;
80609 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
80610 index f896a33..f2eb10f 100644
80611 --- a/include/linux/kobject.h
80612 +++ b/include/linux/kobject.h
80613 @@ -116,7 +116,7 @@ struct kobj_type {
80614 struct attribute **default_attrs;
80615 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
80616 const void *(*namespace)(struct kobject *kobj);
80617 -};
80618 +} __do_const;
80619
80620 struct kobj_uevent_env {
80621 char *argv[3];
80622 @@ -140,6 +140,7 @@ struct kobj_attribute {
80623 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
80624 const char *buf, size_t count);
80625 };
80626 +typedef struct kobj_attribute __no_const kobj_attribute_no_const;
80627
80628 extern const struct sysfs_ops kobj_sysfs_ops;
80629
80630 @@ -167,7 +168,7 @@ struct kset {
80631 spinlock_t list_lock;
80632 struct kobject kobj;
80633 const struct kset_uevent_ops *uevent_ops;
80634 -};
80635 +} __randomize_layout;
80636
80637 extern void kset_init(struct kset *kset);
80638 extern int __must_check kset_register(struct kset *kset);
80639 diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
80640 index df32d25..fb52e27 100644
80641 --- a/include/linux/kobject_ns.h
80642 +++ b/include/linux/kobject_ns.h
80643 @@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
80644 const void *(*netlink_ns)(struct sock *sk);
80645 const void *(*initial_ns)(void);
80646 void (*drop_ns)(void *);
80647 -};
80648 +} __do_const;
80649
80650 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
80651 int kobj_ns_type_registered(enum kobj_ns_type type);
80652 diff --git a/include/linux/kref.h b/include/linux/kref.h
80653 index 484604d..0f6c5b6 100644
80654 --- a/include/linux/kref.h
80655 +++ b/include/linux/kref.h
80656 @@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
80657 static inline int kref_sub(struct kref *kref, unsigned int count,
80658 void (*release)(struct kref *kref))
80659 {
80660 - WARN_ON(release == NULL);
80661 + BUG_ON(release == NULL);
80662
80663 if (atomic_sub_and_test((int) count, &kref->refcount)) {
80664 release(kref);
80665 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
80666 index 7d21cf9..bc0c81f 100644
80667 --- a/include/linux/kvm_host.h
80668 +++ b/include/linux/kvm_host.h
80669 @@ -466,7 +466,7 @@ static inline void kvm_irqfd_exit(void)
80670 {
80671 }
80672 #endif
80673 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80674 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80675 struct module *module);
80676 void kvm_exit(void);
80677
80678 @@ -632,7 +632,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
80679 struct kvm_guest_debug *dbg);
80680 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
80681
80682 -int kvm_arch_init(void *opaque);
80683 +int kvm_arch_init(const void *opaque);
80684 void kvm_arch_exit(void);
80685
80686 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
80687 diff --git a/include/linux/libata.h b/include/linux/libata.h
80688 index 92abb49..e7fff2a 100644
80689 --- a/include/linux/libata.h
80690 +++ b/include/linux/libata.h
80691 @@ -976,7 +976,7 @@ struct ata_port_operations {
80692 * fields must be pointers.
80693 */
80694 const struct ata_port_operations *inherits;
80695 -};
80696 +} __do_const;
80697
80698 struct ata_port_info {
80699 unsigned long flags;
80700 diff --git a/include/linux/linkage.h b/include/linux/linkage.h
80701 index a6a42dd..6c5ebce 100644
80702 --- a/include/linux/linkage.h
80703 +++ b/include/linux/linkage.h
80704 @@ -36,6 +36,7 @@
80705 #endif
80706
80707 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
80708 +#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
80709 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
80710
80711 /*
80712 diff --git a/include/linux/list.h b/include/linux/list.h
80713 index ef95941..82db65a 100644
80714 --- a/include/linux/list.h
80715 +++ b/include/linux/list.h
80716 @@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
80717 extern void list_del(struct list_head *entry);
80718 #endif
80719
80720 +extern void __pax_list_add(struct list_head *new,
80721 + struct list_head *prev,
80722 + struct list_head *next);
80723 +static inline void pax_list_add(struct list_head *new, struct list_head *head)
80724 +{
80725 + __pax_list_add(new, head, head->next);
80726 +}
80727 +static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
80728 +{
80729 + __pax_list_add(new, head->prev, head);
80730 +}
80731 +extern void pax_list_del(struct list_head *entry);
80732 +
80733 /**
80734 * list_replace - replace old entry by new one
80735 * @old : the element to be replaced
80736 @@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
80737 INIT_LIST_HEAD(entry);
80738 }
80739
80740 +extern void pax_list_del_init(struct list_head *entry);
80741 +
80742 /**
80743 * list_move - delete from one list and add as another's head
80744 * @list: the entry to move
80745 diff --git a/include/linux/math64.h b/include/linux/math64.h
80746 index c45c089..298841c 100644
80747 --- a/include/linux/math64.h
80748 +++ b/include/linux/math64.h
80749 @@ -15,7 +15,7 @@
80750 * This is commonly provided by 32bit archs to provide an optimized 64bit
80751 * divide.
80752 */
80753 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80754 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80755 {
80756 *remainder = dividend % divisor;
80757 return dividend / divisor;
80758 @@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
80759 /**
80760 * div64_u64 - unsigned 64bit divide with 64bit divisor
80761 */
80762 -static inline u64 div64_u64(u64 dividend, u64 divisor)
80763 +static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
80764 {
80765 return dividend / divisor;
80766 }
80767 @@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
80768 #define div64_ul(x, y) div_u64((x), (y))
80769
80770 #ifndef div_u64_rem
80771 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80772 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80773 {
80774 *remainder = do_div(dividend, divisor);
80775 return dividend;
80776 @@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
80777 #endif
80778
80779 #ifndef div64_u64
80780 -extern u64 div64_u64(u64 dividend, u64 divisor);
80781 +extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
80782 #endif
80783
80784 #ifndef div64_s64
80785 @@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
80786 * divide.
80787 */
80788 #ifndef div_u64
80789 -static inline u64 div_u64(u64 dividend, u32 divisor)
80790 +static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
80791 {
80792 u32 remainder;
80793 return div_u64_rem(dividend, divisor, &remainder);
80794 diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
80795 index f230a97..714c006 100644
80796 --- a/include/linux/mempolicy.h
80797 +++ b/include/linux/mempolicy.h
80798 @@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
80799 }
80800
80801 #define vma_policy(vma) ((vma)->vm_policy)
80802 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
80803 +{
80804 + vma->vm_policy = pol;
80805 +}
80806
80807 static inline void mpol_get(struct mempolicy *pol)
80808 {
80809 @@ -228,6 +232,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
80810 }
80811
80812 #define vma_policy(vma) NULL
80813 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
80814 +{
80815 +}
80816
80817 static inline int
80818 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
80819 diff --git a/include/linux/mm.h b/include/linux/mm.h
80820 index d677706..673408c 100644
80821 --- a/include/linux/mm.h
80822 +++ b/include/linux/mm.h
80823 @@ -127,6 +127,11 @@ extern unsigned int kobjsize(const void *objp);
80824 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
80825 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
80826 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
80827 +
80828 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
80829 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
80830 +#endif
80831 +
80832 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
80833
80834 #ifdef CONFIG_MEM_SOFT_DIRTY
80835 @@ -237,8 +242,8 @@ struct vm_operations_struct {
80836 /* called by access_process_vm when get_user_pages() fails, typically
80837 * for use by special VMAs that can switch between memory and hardware
80838 */
80839 - int (*access)(struct vm_area_struct *vma, unsigned long addr,
80840 - void *buf, int len, int write);
80841 + ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
80842 + void *buf, size_t len, int write);
80843 #ifdef CONFIG_NUMA
80844 /*
80845 * set_policy() op must add a reference to any non-NULL @new mempolicy
80846 @@ -268,6 +273,7 @@ struct vm_operations_struct {
80847 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
80848 unsigned long size, pgoff_t pgoff);
80849 };
80850 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
80851
80852 struct mmu_gather;
80853 struct inode;
80854 @@ -1133,8 +1139,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
80855 unsigned long *pfn);
80856 int follow_phys(struct vm_area_struct *vma, unsigned long address,
80857 unsigned int flags, unsigned long *prot, resource_size_t *phys);
80858 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
80859 - void *buf, int len, int write);
80860 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
80861 + void *buf, size_t len, int write);
80862
80863 static inline void unmap_shared_mapping_range(struct address_space *mapping,
80864 loff_t const holebegin, loff_t const holelen)
80865 @@ -1173,9 +1179,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
80866 }
80867 #endif
80868
80869 -extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
80870 -extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
80871 - void *buf, int len, int write);
80872 +extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
80873 +extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
80874 + void *buf, size_t len, int write);
80875
80876 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
80877 unsigned long start, unsigned long nr_pages,
80878 @@ -1208,34 +1214,6 @@ int set_page_dirty_lock(struct page *page);
80879 int clear_page_dirty_for_io(struct page *page);
80880 int get_cmdline(struct task_struct *task, char *buffer, int buflen);
80881
80882 -/* Is the vma a continuation of the stack vma above it? */
80883 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
80884 -{
80885 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
80886 -}
80887 -
80888 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
80889 - unsigned long addr)
80890 -{
80891 - return (vma->vm_flags & VM_GROWSDOWN) &&
80892 - (vma->vm_start == addr) &&
80893 - !vma_growsdown(vma->vm_prev, addr);
80894 -}
80895 -
80896 -/* Is the vma a continuation of the stack vma below it? */
80897 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
80898 -{
80899 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
80900 -}
80901 -
80902 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
80903 - unsigned long addr)
80904 -{
80905 - return (vma->vm_flags & VM_GROWSUP) &&
80906 - (vma->vm_end == addr) &&
80907 - !vma_growsup(vma->vm_next, addr);
80908 -}
80909 -
80910 extern pid_t
80911 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
80912
80913 @@ -1335,6 +1313,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
80914 }
80915 #endif
80916
80917 +#ifdef CONFIG_MMU
80918 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
80919 +#else
80920 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
80921 +{
80922 + return __pgprot(0);
80923 +}
80924 +#endif
80925 +
80926 int vma_wants_writenotify(struct vm_area_struct *vma);
80927
80928 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
80929 @@ -1353,8 +1340,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
80930 {
80931 return 0;
80932 }
80933 +
80934 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
80935 + unsigned long address)
80936 +{
80937 + return 0;
80938 +}
80939 #else
80940 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80941 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80942 #endif
80943
80944 #ifdef __PAGETABLE_PMD_FOLDED
80945 @@ -1363,8 +1357,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
80946 {
80947 return 0;
80948 }
80949 +
80950 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
80951 + unsigned long address)
80952 +{
80953 + return 0;
80954 +}
80955 #else
80956 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
80957 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
80958 #endif
80959
80960 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
80961 @@ -1382,11 +1383,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
80962 NULL: pud_offset(pgd, address);
80963 }
80964
80965 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
80966 +{
80967 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
80968 + NULL: pud_offset(pgd, address);
80969 +}
80970 +
80971 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
80972 {
80973 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
80974 NULL: pmd_offset(pud, address);
80975 }
80976 +
80977 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
80978 +{
80979 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
80980 + NULL: pmd_offset(pud, address);
80981 +}
80982 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
80983
80984 #if USE_SPLIT_PTE_PTLOCKS
80985 @@ -1783,7 +1796,7 @@ extern int install_special_mapping(struct mm_struct *mm,
80986 unsigned long addr, unsigned long len,
80987 unsigned long flags, struct page **pages);
80988
80989 -extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
80990 +extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
80991
80992 extern unsigned long mmap_region(struct file *file, unsigned long addr,
80993 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
80994 @@ -1791,6 +1804,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80995 unsigned long len, unsigned long prot, unsigned long flags,
80996 unsigned long pgoff, unsigned long *populate);
80997 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
80998 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
80999
81000 #ifdef CONFIG_MMU
81001 extern int __mm_populate(unsigned long addr, unsigned long len,
81002 @@ -1819,10 +1833,11 @@ struct vm_unmapped_area_info {
81003 unsigned long high_limit;
81004 unsigned long align_mask;
81005 unsigned long align_offset;
81006 + unsigned long threadstack_offset;
81007 };
81008
81009 -extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
81010 -extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
81011 +extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
81012 +extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
81013
81014 /*
81015 * Search for an unmapped address range.
81016 @@ -1834,7 +1849,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
81017 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
81018 */
81019 static inline unsigned long
81020 -vm_unmapped_area(struct vm_unmapped_area_info *info)
81021 +vm_unmapped_area(const struct vm_unmapped_area_info *info)
81022 {
81023 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
81024 return unmapped_area(info);
81025 @@ -1896,6 +1911,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
81026 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
81027 struct vm_area_struct **pprev);
81028
81029 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
81030 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
81031 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
81032 +
81033 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
81034 NULL if none. Assume start_addr < end_addr. */
81035 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
81036 @@ -1924,15 +1943,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
81037 return vma;
81038 }
81039
81040 -#ifdef CONFIG_MMU
81041 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
81042 -#else
81043 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
81044 -{
81045 - return __pgprot(0);
81046 -}
81047 -#endif
81048 -
81049 #ifdef CONFIG_NUMA_BALANCING
81050 unsigned long change_prot_numa(struct vm_area_struct *vma,
81051 unsigned long start, unsigned long end);
81052 @@ -1984,6 +1994,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
81053 static inline void vm_stat_account(struct mm_struct *mm,
81054 unsigned long flags, struct file *file, long pages)
81055 {
81056 +
81057 +#ifdef CONFIG_PAX_RANDMMAP
81058 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
81059 +#endif
81060 +
81061 mm->total_vm += pages;
81062 }
81063 #endif /* CONFIG_PROC_FS */
81064 @@ -2065,7 +2080,7 @@ extern int unpoison_memory(unsigned long pfn);
81065 extern int sysctl_memory_failure_early_kill;
81066 extern int sysctl_memory_failure_recovery;
81067 extern void shake_page(struct page *p, int access);
81068 -extern atomic_long_t num_poisoned_pages;
81069 +extern atomic_long_unchecked_t num_poisoned_pages;
81070 extern int soft_offline_page(struct page *page, int flags);
81071
81072 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
81073 @@ -2100,5 +2115,11 @@ void __init setup_nr_node_ids(void);
81074 static inline void setup_nr_node_ids(void) {}
81075 #endif
81076
81077 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
81078 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
81079 +#else
81080 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
81081 +#endif
81082 +
81083 #endif /* __KERNEL__ */
81084 #endif /* _LINUX_MM_H */
81085 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
81086 index 8967e20..61f7900 100644
81087 --- a/include/linux/mm_types.h
81088 +++ b/include/linux/mm_types.h
81089 @@ -308,7 +308,9 @@ struct vm_area_struct {
81090 #ifdef CONFIG_NUMA
81091 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
81092 #endif
81093 -};
81094 +
81095 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
81096 +} __randomize_layout;
81097
81098 struct core_thread {
81099 struct task_struct *task;
81100 @@ -454,7 +456,25 @@ struct mm_struct {
81101 bool tlb_flush_pending;
81102 #endif
81103 struct uprobes_state uprobes_state;
81104 -};
81105 +
81106 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
81107 + unsigned long pax_flags;
81108 +#endif
81109 +
81110 +#ifdef CONFIG_PAX_DLRESOLVE
81111 + unsigned long call_dl_resolve;
81112 +#endif
81113 +
81114 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
81115 + unsigned long call_syscall;
81116 +#endif
81117 +
81118 +#ifdef CONFIG_PAX_ASLR
81119 + unsigned long delta_mmap; /* randomized offset */
81120 + unsigned long delta_stack; /* randomized offset */
81121 +#endif
81122 +
81123 +} __randomize_layout;
81124
81125 static inline void mm_init_cpumask(struct mm_struct *mm)
81126 {
81127 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
81128 index c5d5278..f0b68c8 100644
81129 --- a/include/linux/mmiotrace.h
81130 +++ b/include/linux/mmiotrace.h
81131 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
81132 /* Called from ioremap.c */
81133 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
81134 void __iomem *addr);
81135 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
81136 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
81137
81138 /* For anyone to insert markers. Remember trailing newline. */
81139 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
81140 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
81141 {
81142 }
81143
81144 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
81145 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
81146 {
81147 }
81148
81149 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
81150 index 835aa3d..676b387 100644
81151 --- a/include/linux/mmzone.h
81152 +++ b/include/linux/mmzone.h
81153 @@ -406,7 +406,7 @@ struct zone {
81154 unsigned long flags; /* zone flags, see below */
81155
81156 /* Zone statistics */
81157 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
81158 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
81159
81160 /*
81161 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
81162 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
81163 index 44eeef0..a92d3f9 100644
81164 --- a/include/linux/mod_devicetable.h
81165 +++ b/include/linux/mod_devicetable.h
81166 @@ -139,7 +139,7 @@ struct usb_device_id {
81167 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
81168 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
81169
81170 -#define HID_ANY_ID (~0)
81171 +#define HID_ANY_ID (~0U)
81172 #define HID_BUS_ANY 0xffff
81173 #define HID_GROUP_ANY 0x0000
81174
81175 @@ -475,7 +475,7 @@ struct dmi_system_id {
81176 const char *ident;
81177 struct dmi_strmatch matches[4];
81178 void *driver_data;
81179 -};
81180 +} __do_const;
81181 /*
81182 * struct dmi_device_id appears during expansion of
81183 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
81184 diff --git a/include/linux/module.h b/include/linux/module.h
81185 index f520a76..5f898ef 100644
81186 --- a/include/linux/module.h
81187 +++ b/include/linux/module.h
81188 @@ -17,9 +17,11 @@
81189 #include <linux/moduleparam.h>
81190 #include <linux/jump_label.h>
81191 #include <linux/export.h>
81192 +#include <linux/fs.h>
81193
81194 #include <linux/percpu.h>
81195 #include <asm/module.h>
81196 +#include <asm/pgtable.h>
81197
81198 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
81199 #define MODULE_SIG_STRING "~Module signature appended~\n"
81200 @@ -42,7 +44,7 @@ struct module_kobject {
81201 struct kobject *drivers_dir;
81202 struct module_param_attrs *mp;
81203 struct completion *kobj_completion;
81204 -};
81205 +} __randomize_layout;
81206
81207 struct module_attribute {
81208 struct attribute attr;
81209 @@ -54,12 +56,13 @@ struct module_attribute {
81210 int (*test)(struct module *);
81211 void (*free)(struct module *);
81212 };
81213 +typedef struct module_attribute __no_const module_attribute_no_const;
81214
81215 struct module_version_attribute {
81216 struct module_attribute mattr;
81217 const char *module_name;
81218 const char *version;
81219 -} __attribute__ ((__aligned__(sizeof(void *))));
81220 +} __do_const __attribute__ ((__aligned__(sizeof(void *))));
81221
81222 extern ssize_t __modver_version_show(struct module_attribute *,
81223 struct module_kobject *, char *);
81224 @@ -235,7 +238,7 @@ struct module {
81225
81226 /* Sysfs stuff. */
81227 struct module_kobject mkobj;
81228 - struct module_attribute *modinfo_attrs;
81229 + module_attribute_no_const *modinfo_attrs;
81230 const char *version;
81231 const char *srcversion;
81232 struct kobject *holders_dir;
81233 @@ -284,19 +287,16 @@ struct module {
81234 int (*init)(void);
81235
81236 /* If this is non-NULL, vfree after init() returns */
81237 - void *module_init;
81238 + void *module_init_rx, *module_init_rw;
81239
81240 /* Here is the actual code + data, vfree'd on unload. */
81241 - void *module_core;
81242 + void *module_core_rx, *module_core_rw;
81243
81244 /* Here are the sizes of the init and core sections */
81245 - unsigned int init_size, core_size;
81246 + unsigned int init_size_rw, core_size_rw;
81247
81248 /* The size of the executable code in each section. */
81249 - unsigned int init_text_size, core_text_size;
81250 -
81251 - /* Size of RO sections of the module (text+rodata) */
81252 - unsigned int init_ro_size, core_ro_size;
81253 + unsigned int init_size_rx, core_size_rx;
81254
81255 /* Arch-specific module values */
81256 struct mod_arch_specific arch;
81257 @@ -352,6 +352,10 @@ struct module {
81258 #ifdef CONFIG_EVENT_TRACING
81259 struct ftrace_event_call **trace_events;
81260 unsigned int num_trace_events;
81261 + struct file_operations trace_id;
81262 + struct file_operations trace_enable;
81263 + struct file_operations trace_format;
81264 + struct file_operations trace_filter;
81265 #endif
81266 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
81267 unsigned int num_ftrace_callsites;
81268 @@ -375,7 +379,7 @@ struct module {
81269 ctor_fn_t *ctors;
81270 unsigned int num_ctors;
81271 #endif
81272 -};
81273 +} __randomize_layout;
81274 #ifndef MODULE_ARCH_INIT
81275 #define MODULE_ARCH_INIT {}
81276 #endif
81277 @@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
81278 bool is_module_percpu_address(unsigned long addr);
81279 bool is_module_text_address(unsigned long addr);
81280
81281 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
81282 +{
81283 +
81284 +#ifdef CONFIG_PAX_KERNEXEC
81285 + if (ktla_ktva(addr) >= (unsigned long)start &&
81286 + ktla_ktva(addr) < (unsigned long)start + size)
81287 + return 1;
81288 +#endif
81289 +
81290 + return ((void *)addr >= start && (void *)addr < start + size);
81291 +}
81292 +
81293 +static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
81294 +{
81295 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
81296 +}
81297 +
81298 +static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
81299 +{
81300 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
81301 +}
81302 +
81303 +static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
81304 +{
81305 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
81306 +}
81307 +
81308 +static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
81309 +{
81310 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
81311 +}
81312 +
81313 static inline int within_module_core(unsigned long addr, const struct module *mod)
81314 {
81315 - return (unsigned long)mod->module_core <= addr &&
81316 - addr < (unsigned long)mod->module_core + mod->core_size;
81317 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
81318 }
81319
81320 static inline int within_module_init(unsigned long addr, const struct module *mod)
81321 {
81322 - return (unsigned long)mod->module_init <= addr &&
81323 - addr < (unsigned long)mod->module_init + mod->init_size;
81324 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
81325 }
81326
81327 /* Search for module by name: must hold module_mutex. */
81328 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
81329 index 560ca53..ef621ef 100644
81330 --- a/include/linux/moduleloader.h
81331 +++ b/include/linux/moduleloader.h
81332 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
81333 sections. Returns NULL on failure. */
81334 void *module_alloc(unsigned long size);
81335
81336 +#ifdef CONFIG_PAX_KERNEXEC
81337 +void *module_alloc_exec(unsigned long size);
81338 +#else
81339 +#define module_alloc_exec(x) module_alloc(x)
81340 +#endif
81341 +
81342 /* Free memory returned from module_alloc. */
81343 void module_free(struct module *mod, void *module_region);
81344
81345 +#ifdef CONFIG_PAX_KERNEXEC
81346 +void module_free_exec(struct module *mod, void *module_region);
81347 +#else
81348 +#define module_free_exec(x, y) module_free((x), (y))
81349 +#endif
81350 +
81351 /*
81352 * Apply the given relocation to the (simplified) ELF. Return -error
81353 * or 0.
81354 @@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
81355 unsigned int relsec,
81356 struct module *me)
81357 {
81358 +#ifdef CONFIG_MODULES
81359 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
81360 +#endif
81361 return -ENOEXEC;
81362 }
81363 #endif
81364 @@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
81365 unsigned int relsec,
81366 struct module *me)
81367 {
81368 +#ifdef CONFIG_MODULES
81369 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
81370 +#endif
81371 return -ENOEXEC;
81372 }
81373 #endif
81374 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
81375 index 204a677..e9b486a 100644
81376 --- a/include/linux/moduleparam.h
81377 +++ b/include/linux/moduleparam.h
81378 @@ -293,7 +293,7 @@ static inline void __kernel_param_unlock(void)
81379 * @len is usually just sizeof(string).
81380 */
81381 #define module_param_string(name, string, len, perm) \
81382 - static const struct kparam_string __param_string_##name \
81383 + static const struct kparam_string __param_string_##name __used \
81384 = { len, string }; \
81385 __module_param_call(MODULE_PARAM_PREFIX, name, \
81386 &param_ops_string, \
81387 @@ -432,7 +432,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
81388 */
81389 #define module_param_array_named(name, array, type, nump, perm) \
81390 param_check_##type(name, &(array)[0]); \
81391 - static const struct kparam_array __param_arr_##name \
81392 + static const struct kparam_array __param_arr_##name __used \
81393 = { .max = ARRAY_SIZE(array), .num = nump, \
81394 .ops = &param_ops_##type, \
81395 .elemsize = sizeof(array[0]), .elem = array }; \
81396 diff --git a/include/linux/mount.h b/include/linux/mount.h
81397 index 839bac2..a96b37c 100644
81398 --- a/include/linux/mount.h
81399 +++ b/include/linux/mount.h
81400 @@ -59,7 +59,7 @@ struct vfsmount {
81401 struct dentry *mnt_root; /* root of the mounted tree */
81402 struct super_block *mnt_sb; /* pointer to superblock */
81403 int mnt_flags;
81404 -};
81405 +} __randomize_layout;
81406
81407 struct file; /* forward dec */
81408
81409 diff --git a/include/linux/namei.h b/include/linux/namei.h
81410 index 492de72..1bddcd4 100644
81411 --- a/include/linux/namei.h
81412 +++ b/include/linux/namei.h
81413 @@ -19,7 +19,7 @@ struct nameidata {
81414 unsigned seq, m_seq;
81415 int last_type;
81416 unsigned depth;
81417 - char *saved_names[MAX_NESTED_LINKS + 1];
81418 + const char *saved_names[MAX_NESTED_LINKS + 1];
81419 };
81420
81421 /*
81422 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
81423
81424 extern void nd_jump_link(struct nameidata *nd, struct path *path);
81425
81426 -static inline void nd_set_link(struct nameidata *nd, char *path)
81427 +static inline void nd_set_link(struct nameidata *nd, const char *path)
81428 {
81429 nd->saved_names[nd->depth] = path;
81430 }
81431
81432 -static inline char *nd_get_link(struct nameidata *nd)
81433 +static inline const char *nd_get_link(const struct nameidata *nd)
81434 {
81435 return nd->saved_names[nd->depth];
81436 }
81437 diff --git a/include/linux/net.h b/include/linux/net.h
81438 index 17d8339..81656c0 100644
81439 --- a/include/linux/net.h
81440 +++ b/include/linux/net.h
81441 @@ -192,7 +192,7 @@ struct net_proto_family {
81442 int (*create)(struct net *net, struct socket *sock,
81443 int protocol, int kern);
81444 struct module *owner;
81445 -};
81446 +} __do_const;
81447
81448 struct iovec;
81449 struct kvec;
81450 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
81451 index b42d07b..7f45ae2 100644
81452 --- a/include/linux/netdevice.h
81453 +++ b/include/linux/netdevice.h
81454 @@ -1146,6 +1146,7 @@ struct net_device_ops {
81455 void *priv);
81456 int (*ndo_get_lock_subclass)(struct net_device *dev);
81457 };
81458 +typedef struct net_device_ops __no_const net_device_ops_no_const;
81459
81460 /**
81461 * enum net_device_priv_flags - &struct net_device priv_flags
81462 @@ -1313,11 +1314,11 @@ struct net_device {
81463 struct net_device_stats stats;
81464
81465 /* dropped packets by core network, Do not use this in drivers */
81466 - atomic_long_t rx_dropped;
81467 - atomic_long_t tx_dropped;
81468 + atomic_long_unchecked_t rx_dropped;
81469 + atomic_long_unchecked_t tx_dropped;
81470
81471 /* Stats to monitor carrier on<->off transitions */
81472 - atomic_t carrier_changes;
81473 + atomic_unchecked_t carrier_changes;
81474
81475 #ifdef CONFIG_WIRELESS_EXT
81476 /* List of functions to handle Wireless Extensions (instead of ioctl).
81477 diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
81478 index 2077489..a15e561 100644
81479 --- a/include/linux/netfilter.h
81480 +++ b/include/linux/netfilter.h
81481 @@ -84,7 +84,7 @@ struct nf_sockopt_ops {
81482 #endif
81483 /* Use the module struct to lock set/get code in place */
81484 struct module *owner;
81485 -};
81486 +} __do_const;
81487
81488 /* Function to register/unregister hook points. */
81489 int nf_register_hook(struct nf_hook_ops *reg);
81490 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
81491 index e955d47..04a5338 100644
81492 --- a/include/linux/netfilter/nfnetlink.h
81493 +++ b/include/linux/netfilter/nfnetlink.h
81494 @@ -19,7 +19,7 @@ struct nfnl_callback {
81495 const struct nlattr * const cda[]);
81496 const struct nla_policy *policy; /* netlink attribute policy */
81497 const u_int16_t attr_count; /* number of nlattr's */
81498 -};
81499 +} __do_const;
81500
81501 struct nfnetlink_subsystem {
81502 const char *name;
81503 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
81504 new file mode 100644
81505 index 0000000..33f4af8
81506 --- /dev/null
81507 +++ b/include/linux/netfilter/xt_gradm.h
81508 @@ -0,0 +1,9 @@
81509 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
81510 +#define _LINUX_NETFILTER_XT_GRADM_H 1
81511 +
81512 +struct xt_gradm_mtinfo {
81513 + __u16 flags;
81514 + __u16 invflags;
81515 +};
81516 +
81517 +#endif
81518 diff --git a/include/linux/nls.h b/include/linux/nls.h
81519 index 520681b..1d67ed2 100644
81520 --- a/include/linux/nls.h
81521 +++ b/include/linux/nls.h
81522 @@ -31,7 +31,7 @@ struct nls_table {
81523 const unsigned char *charset2upper;
81524 struct module *owner;
81525 struct nls_table *next;
81526 -};
81527 +} __do_const;
81528
81529 /* this value hold the maximum octet of charset */
81530 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
81531 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
81532 index d14a4c3..a078786 100644
81533 --- a/include/linux/notifier.h
81534 +++ b/include/linux/notifier.h
81535 @@ -54,7 +54,8 @@ struct notifier_block {
81536 notifier_fn_t notifier_call;
81537 struct notifier_block __rcu *next;
81538 int priority;
81539 -};
81540 +} __do_const;
81541 +typedef struct notifier_block __no_const notifier_block_no_const;
81542
81543 struct atomic_notifier_head {
81544 spinlock_t lock;
81545 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
81546 index b2a0f15..4d7da32 100644
81547 --- a/include/linux/oprofile.h
81548 +++ b/include/linux/oprofile.h
81549 @@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
81550 int oprofilefs_create_ro_ulong(struct dentry * root,
81551 char const * name, ulong * val);
81552
81553 -/** Create a file for read-only access to an atomic_t. */
81554 +/** Create a file for read-only access to an atomic_unchecked_t. */
81555 int oprofilefs_create_ro_atomic(struct dentry * root,
81556 - char const * name, atomic_t * val);
81557 + char const * name, atomic_unchecked_t * val);
81558
81559 /** create a directory */
81560 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
81561 diff --git a/include/linux/padata.h b/include/linux/padata.h
81562 index 4386946..f50c615 100644
81563 --- a/include/linux/padata.h
81564 +++ b/include/linux/padata.h
81565 @@ -129,7 +129,7 @@ struct parallel_data {
81566 struct padata_serial_queue __percpu *squeue;
81567 atomic_t reorder_objects;
81568 atomic_t refcnt;
81569 - atomic_t seq_nr;
81570 + atomic_unchecked_t seq_nr;
81571 struct padata_cpumask cpumask;
81572 spinlock_t lock ____cacheline_aligned;
81573 unsigned int processed;
81574 diff --git a/include/linux/path.h b/include/linux/path.h
81575 index d137218..be0c176 100644
81576 --- a/include/linux/path.h
81577 +++ b/include/linux/path.h
81578 @@ -1,13 +1,15 @@
81579 #ifndef _LINUX_PATH_H
81580 #define _LINUX_PATH_H
81581
81582 +#include <linux/compiler.h>
81583 +
81584 struct dentry;
81585 struct vfsmount;
81586
81587 struct path {
81588 struct vfsmount *mnt;
81589 struct dentry *dentry;
81590 -};
81591 +} __randomize_layout;
81592
81593 extern void path_get(const struct path *);
81594 extern void path_put(const struct path *);
81595 diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
81596 index 5f2e559..7d59314 100644
81597 --- a/include/linux/pci_hotplug.h
81598 +++ b/include/linux/pci_hotplug.h
81599 @@ -71,7 +71,8 @@ struct hotplug_slot_ops {
81600 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
81601 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
81602 int (*reset_slot) (struct hotplug_slot *slot, int probe);
81603 -};
81604 +} __do_const;
81605 +typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
81606
81607 /**
81608 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
81609 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
81610 index 3ef6ea1..ed1a248 100644
81611 --- a/include/linux/perf_event.h
81612 +++ b/include/linux/perf_event.h
81613 @@ -328,8 +328,8 @@ struct perf_event {
81614
81615 enum perf_event_active_state state;
81616 unsigned int attach_state;
81617 - local64_t count;
81618 - atomic64_t child_count;
81619 + local64_t count; /* PaX: fix it one day */
81620 + atomic64_unchecked_t child_count;
81621
81622 /*
81623 * These are the total time in nanoseconds that the event
81624 @@ -380,8 +380,8 @@ struct perf_event {
81625 * These accumulate total time (in nanoseconds) that children
81626 * events have been enabled and running, respectively.
81627 */
81628 - atomic64_t child_total_time_enabled;
81629 - atomic64_t child_total_time_running;
81630 + atomic64_unchecked_t child_total_time_enabled;
81631 + atomic64_unchecked_t child_total_time_running;
81632
81633 /*
81634 * Protect attach/detach and child_list:
81635 @@ -710,7 +710,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
81636 entry->ip[entry->nr++] = ip;
81637 }
81638
81639 -extern int sysctl_perf_event_paranoid;
81640 +extern int sysctl_perf_event_legitimately_concerned;
81641 extern int sysctl_perf_event_mlock;
81642 extern int sysctl_perf_event_sample_rate;
81643 extern int sysctl_perf_cpu_time_max_percent;
81644 @@ -725,19 +725,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
81645 loff_t *ppos);
81646
81647
81648 +static inline bool perf_paranoid_any(void)
81649 +{
81650 + return sysctl_perf_event_legitimately_concerned > 2;
81651 +}
81652 +
81653 static inline bool perf_paranoid_tracepoint_raw(void)
81654 {
81655 - return sysctl_perf_event_paranoid > -1;
81656 + return sysctl_perf_event_legitimately_concerned > -1;
81657 }
81658
81659 static inline bool perf_paranoid_cpu(void)
81660 {
81661 - return sysctl_perf_event_paranoid > 0;
81662 + return sysctl_perf_event_legitimately_concerned > 0;
81663 }
81664
81665 static inline bool perf_paranoid_kernel(void)
81666 {
81667 - return sysctl_perf_event_paranoid > 1;
81668 + return sysctl_perf_event_legitimately_concerned > 1;
81669 }
81670
81671 extern void perf_event_init(void);
81672 @@ -867,7 +872,7 @@ struct perf_pmu_events_attr {
81673 struct device_attribute attr;
81674 u64 id;
81675 const char *event_str;
81676 -};
81677 +} __do_const;
81678
81679 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
81680 static struct perf_pmu_events_attr _var = { \
81681 diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
81682 index 7246ef3..1539ea4 100644
81683 --- a/include/linux/pid_namespace.h
81684 +++ b/include/linux/pid_namespace.h
81685 @@ -43,7 +43,7 @@ struct pid_namespace {
81686 int hide_pid;
81687 int reboot; /* group exit code if this pidns was rebooted */
81688 unsigned int proc_inum;
81689 -};
81690 +} __randomize_layout;
81691
81692 extern struct pid_namespace init_pid_ns;
81693
81694 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
81695 index eb8b8ac..62649e1 100644
81696 --- a/include/linux/pipe_fs_i.h
81697 +++ b/include/linux/pipe_fs_i.h
81698 @@ -47,10 +47,10 @@ struct pipe_inode_info {
81699 struct mutex mutex;
81700 wait_queue_head_t wait;
81701 unsigned int nrbufs, curbuf, buffers;
81702 - unsigned int readers;
81703 - unsigned int writers;
81704 - unsigned int files;
81705 - unsigned int waiting_writers;
81706 + atomic_t readers;
81707 + atomic_t writers;
81708 + atomic_t files;
81709 + atomic_t waiting_writers;
81710 unsigned int r_counter;
81711 unsigned int w_counter;
81712 struct page *tmp_page;
81713 diff --git a/include/linux/pm.h b/include/linux/pm.h
81714 index d915d03..0531037 100644
81715 --- a/include/linux/pm.h
81716 +++ b/include/linux/pm.h
81717 @@ -600,6 +600,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
81718 struct dev_pm_domain {
81719 struct dev_pm_ops ops;
81720 };
81721 +typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
81722
81723 /*
81724 * The PM_EVENT_ messages are also used by drivers implementing the legacy
81725 diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
81726 index 7c1d252..0e7061d 100644
81727 --- a/include/linux/pm_domain.h
81728 +++ b/include/linux/pm_domain.h
81729 @@ -44,11 +44,11 @@ struct gpd_dev_ops {
81730 int (*thaw_early)(struct device *dev);
81731 int (*thaw)(struct device *dev);
81732 bool (*active_wakeup)(struct device *dev);
81733 -};
81734 +} __no_const;
81735
81736 struct gpd_cpu_data {
81737 unsigned int saved_exit_latency;
81738 - struct cpuidle_state *idle_state;
81739 + cpuidle_state_no_const *idle_state;
81740 };
81741
81742 struct generic_pm_domain {
81743 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
81744 index 2a5897a..4f9af63 100644
81745 --- a/include/linux/pm_runtime.h
81746 +++ b/include/linux/pm_runtime.h
81747 @@ -113,7 +113,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
81748
81749 static inline void pm_runtime_mark_last_busy(struct device *dev)
81750 {
81751 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
81752 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
81753 }
81754
81755 #else /* !CONFIG_PM_RUNTIME */
81756 diff --git a/include/linux/pnp.h b/include/linux/pnp.h
81757 index 195aafc..49a7bc2 100644
81758 --- a/include/linux/pnp.h
81759 +++ b/include/linux/pnp.h
81760 @@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
81761 struct pnp_fixup {
81762 char id[7];
81763 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
81764 -};
81765 +} __do_const;
81766
81767 /* config parameters */
81768 #define PNP_CONFIG_NORMAL 0x0001
81769 diff --git a/include/linux/poison.h b/include/linux/poison.h
81770 index 2110a81..13a11bb 100644
81771 --- a/include/linux/poison.h
81772 +++ b/include/linux/poison.h
81773 @@ -19,8 +19,8 @@
81774 * under normal circumstances, used to verify that nobody uses
81775 * non-initialized list entries.
81776 */
81777 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
81778 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
81779 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
81780 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
81781
81782 /********** include/linux/timer.h **********/
81783 /*
81784 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
81785 index d8b187c3..9a9257a 100644
81786 --- a/include/linux/power/smartreflex.h
81787 +++ b/include/linux/power/smartreflex.h
81788 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
81789 int (*notify)(struct omap_sr *sr, u32 status);
81790 u8 notify_flags;
81791 u8 class_type;
81792 -};
81793 +} __do_const;
81794
81795 /**
81796 * struct omap_sr_nvalue_table - Smartreflex n-target value info
81797 diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
81798 index 4ea1d37..80f4b33 100644
81799 --- a/include/linux/ppp-comp.h
81800 +++ b/include/linux/ppp-comp.h
81801 @@ -84,7 +84,7 @@ struct compressor {
81802 struct module *owner;
81803 /* Extra skb space needed by the compressor algorithm */
81804 unsigned int comp_extra;
81805 -};
81806 +} __do_const;
81807
81808 /*
81809 * The return value from decompress routine is the length of the
81810 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
81811 index de83b4e..c4b997d 100644
81812 --- a/include/linux/preempt.h
81813 +++ b/include/linux/preempt.h
81814 @@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
81815 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
81816 #endif
81817
81818 +#define raw_preempt_count_add(val) __preempt_count_add(val)
81819 +#define raw_preempt_count_sub(val) __preempt_count_sub(val)
81820 +
81821 #define __preempt_count_inc() __preempt_count_add(1)
81822 #define __preempt_count_dec() __preempt_count_sub(1)
81823
81824 #define preempt_count_inc() preempt_count_add(1)
81825 +#define raw_preempt_count_inc() raw_preempt_count_add(1)
81826 #define preempt_count_dec() preempt_count_sub(1)
81827 +#define raw_preempt_count_dec() raw_preempt_count_sub(1)
81828
81829 #ifdef CONFIG_PREEMPT_COUNT
81830
81831 @@ -41,6 +46,12 @@ do { \
81832 barrier(); \
81833 } while (0)
81834
81835 +#define raw_preempt_disable() \
81836 +do { \
81837 + raw_preempt_count_inc(); \
81838 + barrier(); \
81839 +} while (0)
81840 +
81841 #define sched_preempt_enable_no_resched() \
81842 do { \
81843 barrier(); \
81844 @@ -49,6 +60,12 @@ do { \
81845
81846 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
81847
81848 +#define raw_preempt_enable_no_resched() \
81849 +do { \
81850 + barrier(); \
81851 + raw_preempt_count_dec(); \
81852 +} while (0)
81853 +
81854 #ifdef CONFIG_PREEMPT
81855 #define preempt_enable() \
81856 do { \
81857 @@ -113,8 +130,10 @@ do { \
81858 * region.
81859 */
81860 #define preempt_disable() barrier()
81861 +#define raw_preempt_disable() barrier()
81862 #define sched_preempt_enable_no_resched() barrier()
81863 #define preempt_enable_no_resched() barrier()
81864 +#define raw_preempt_enable_no_resched() barrier()
81865 #define preempt_enable() barrier()
81866 #define preempt_check_resched() do { } while (0)
81867
81868 @@ -128,11 +147,13 @@ do { \
81869 /*
81870 * Modules have no business playing preemption tricks.
81871 */
81872 +#ifndef CONFIG_PAX_KERNEXEC
81873 #undef sched_preempt_enable_no_resched
81874 #undef preempt_enable_no_resched
81875 #undef preempt_enable_no_resched_notrace
81876 #undef preempt_check_resched
81877 #endif
81878 +#endif
81879
81880 #define preempt_set_need_resched() \
81881 do { \
81882 diff --git a/include/linux/printk.h b/include/linux/printk.h
81883 index 7847301..29cd406 100644
81884 --- a/include/linux/printk.h
81885 +++ b/include/linux/printk.h
81886 @@ -110,6 +110,8 @@ static inline __printf(1, 2) __cold
81887 void early_printk(const char *s, ...) { }
81888 #endif
81889
81890 +extern int kptr_restrict;
81891 +
81892 #ifdef CONFIG_PRINTK
81893 asmlinkage __printf(5, 0)
81894 int vprintk_emit(int facility, int level,
81895 @@ -144,7 +146,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
81896
81897 extern int printk_delay_msec;
81898 extern int dmesg_restrict;
81899 -extern int kptr_restrict;
81900
81901 extern void wake_up_klogd(void);
81902
81903 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
81904 index 608e60a..79cfb18 100644
81905 --- a/include/linux/proc_fs.h
81906 +++ b/include/linux/proc_fs.h
81907 @@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
81908 extern struct proc_dir_entry *proc_symlink(const char *,
81909 struct proc_dir_entry *, const char *);
81910 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
81911 +extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
81912 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
81913 struct proc_dir_entry *, void *);
81914 +extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
81915 + struct proc_dir_entry *, void *);
81916 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
81917 struct proc_dir_entry *);
81918
81919 @@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
81920 return proc_create_data(name, mode, parent, proc_fops, NULL);
81921 }
81922
81923 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
81924 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
81925 +{
81926 +#ifdef CONFIG_GRKERNSEC_PROC_USER
81927 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
81928 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
81929 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
81930 +#else
81931 + return proc_create_data(name, mode, parent, proc_fops, NULL);
81932 +#endif
81933 +}
81934 +
81935 +
81936 extern void proc_set_size(struct proc_dir_entry *, loff_t);
81937 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
81938 extern void *PDE_DATA(const struct inode *);
81939 @@ -52,8 +68,12 @@ static inline struct proc_dir_entry *proc_symlink(const char *name,
81940 struct proc_dir_entry *parent,const char *dest) { return NULL;}
81941 static inline struct proc_dir_entry *proc_mkdir(const char *name,
81942 struct proc_dir_entry *parent) {return NULL;}
81943 +static inline struct proc_dir_entry *proc_mkdir_restrict(const char *name,
81944 + struct proc_dir_entry *parent) { return NULL; }
81945 static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
81946 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
81947 +static inline struct proc_dir_entry *proc_mkdir_data_restrict(const char *name,
81948 + umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
81949 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
81950 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
81951 #define proc_create(name, mode, parent, proc_fops) ({NULL;})
81952 @@ -73,7 +93,7 @@ static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *p
81953 static inline struct proc_dir_entry *proc_net_mkdir(
81954 struct net *net, const char *name, struct proc_dir_entry *parent)
81955 {
81956 - return proc_mkdir_data(name, 0, parent, net);
81957 + return proc_mkdir_data_restrict(name, 0, parent, net);
81958 }
81959
81960 #endif /* _LINUX_PROC_FS_H */
81961 diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
81962 index 34a1e10..70f6bde 100644
81963 --- a/include/linux/proc_ns.h
81964 +++ b/include/linux/proc_ns.h
81965 @@ -14,7 +14,7 @@ struct proc_ns_operations {
81966 void (*put)(void *ns);
81967 int (*install)(struct nsproxy *nsproxy, void *ns);
81968 unsigned int (*inum)(void *ns);
81969 -};
81970 +} __do_const __randomize_layout;
81971
81972 struct proc_ns {
81973 void *ns;
81974 diff --git a/include/linux/quota.h b/include/linux/quota.h
81975 index cc7494a..1e27036 100644
81976 --- a/include/linux/quota.h
81977 +++ b/include/linux/quota.h
81978 @@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
81979
81980 extern bool qid_eq(struct kqid left, struct kqid right);
81981 extern bool qid_lt(struct kqid left, struct kqid right);
81982 -extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
81983 +extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
81984 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
81985 extern bool qid_valid(struct kqid qid);
81986
81987 diff --git a/include/linux/random.h b/include/linux/random.h
81988 index 57fbbff..2170304 100644
81989 --- a/include/linux/random.h
81990 +++ b/include/linux/random.h
81991 @@ -9,9 +9,19 @@
81992 #include <uapi/linux/random.h>
81993
81994 extern void add_device_randomness(const void *, unsigned int);
81995 +
81996 +static inline void add_latent_entropy(void)
81997 +{
81998 +
81999 +#ifdef LATENT_ENTROPY_PLUGIN
82000 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
82001 +#endif
82002 +
82003 +}
82004 +
82005 extern void add_input_randomness(unsigned int type, unsigned int code,
82006 - unsigned int value);
82007 -extern void add_interrupt_randomness(int irq, int irq_flags);
82008 + unsigned int value) __latent_entropy;
82009 +extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
82010
82011 extern void get_random_bytes(void *buf, int nbytes);
82012 extern void get_random_bytes_arch(void *buf, int nbytes);
82013 @@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
82014 extern const struct file_operations random_fops, urandom_fops;
82015 #endif
82016
82017 -unsigned int get_random_int(void);
82018 +unsigned int __intentional_overflow(-1) get_random_int(void);
82019 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
82020
82021 -u32 prandom_u32(void);
82022 +u32 prandom_u32(void) __intentional_overflow(-1);
82023 void prandom_bytes(void *buf, int nbytes);
82024 void prandom_seed(u32 seed);
82025 void prandom_reseed_late(void);
82026 @@ -37,6 +47,11 @@ struct rnd_state {
82027 u32 prandom_u32_state(struct rnd_state *state);
82028 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
82029
82030 +static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
82031 +{
82032 + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
82033 +}
82034 +
82035 /**
82036 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
82037 * @ep_ro: right open interval endpoint
82038 @@ -49,7 +64,7 @@ void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
82039 *
82040 * Returns: pseudo-random number in interval [0, ep_ro)
82041 */
82042 -static inline u32 prandom_u32_max(u32 ep_ro)
82043 +static inline u32 __intentional_overflow(-1) prandom_u32_max(u32 ep_ro)
82044 {
82045 return (u32)(((u64) prandom_u32() * ep_ro) >> 32);
82046 }
82047 diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
82048 index fea49b5..2ac22bb 100644
82049 --- a/include/linux/rbtree_augmented.h
82050 +++ b/include/linux/rbtree_augmented.h
82051 @@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
82052 old->rbaugmented = rbcompute(old); \
82053 } \
82054 rbstatic const struct rb_augment_callbacks rbname = { \
82055 - rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
82056 + .propagate = rbname ## _propagate, \
82057 + .copy = rbname ## _copy, \
82058 + .rotate = rbname ## _rotate \
82059 };
82060
82061
82062 diff --git a/include/linux/rculist.h b/include/linux/rculist.h
82063 index 8183b46..a388711 100644
82064 --- a/include/linux/rculist.h
82065 +++ b/include/linux/rculist.h
82066 @@ -29,8 +29,8 @@
82067 */
82068 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
82069 {
82070 - ACCESS_ONCE(list->next) = list;
82071 - ACCESS_ONCE(list->prev) = list;
82072 + ACCESS_ONCE_RW(list->next) = list;
82073 + ACCESS_ONCE_RW(list->prev) = list;
82074 }
82075
82076 /*
82077 @@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
82078 struct list_head *prev, struct list_head *next);
82079 #endif
82080
82081 +void __pax_list_add_rcu(struct list_head *new,
82082 + struct list_head *prev, struct list_head *next);
82083 +
82084 /**
82085 * list_add_rcu - add a new entry to rcu-protected list
82086 * @new: new entry to be added
82087 @@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
82088 __list_add_rcu(new, head, head->next);
82089 }
82090
82091 +static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
82092 +{
82093 + __pax_list_add_rcu(new, head, head->next);
82094 +}
82095 +
82096 /**
82097 * list_add_tail_rcu - add a new entry to rcu-protected list
82098 * @new: new entry to be added
82099 @@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
82100 __list_add_rcu(new, head->prev, head);
82101 }
82102
82103 +static inline void pax_list_add_tail_rcu(struct list_head *new,
82104 + struct list_head *head)
82105 +{
82106 + __pax_list_add_rcu(new, head->prev, head);
82107 +}
82108 +
82109 /**
82110 * list_del_rcu - deletes entry from list without re-initialization
82111 * @entry: the element to delete from the list.
82112 @@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
82113 entry->prev = LIST_POISON2;
82114 }
82115
82116 +extern void pax_list_del_rcu(struct list_head *entry);
82117 +
82118 /**
82119 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
82120 * @n: the element to delete from the hash list.
82121 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
82122 index 48bf152..d38b785 100644
82123 --- a/include/linux/reboot.h
82124 +++ b/include/linux/reboot.h
82125 @@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
82126 */
82127
82128 extern void migrate_to_reboot_cpu(void);
82129 -extern void machine_restart(char *cmd);
82130 -extern void machine_halt(void);
82131 -extern void machine_power_off(void);
82132 +extern void machine_restart(char *cmd) __noreturn;
82133 +extern void machine_halt(void) __noreturn;
82134 +extern void machine_power_off(void) __noreturn;
82135
82136 extern void machine_shutdown(void);
82137 struct pt_regs;
82138 @@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
82139 */
82140
82141 extern void kernel_restart_prepare(char *cmd);
82142 -extern void kernel_restart(char *cmd);
82143 -extern void kernel_halt(void);
82144 -extern void kernel_power_off(void);
82145 +extern void kernel_restart(char *cmd) __noreturn;
82146 +extern void kernel_halt(void) __noreturn;
82147 +extern void kernel_power_off(void) __noreturn;
82148
82149 extern int C_A_D; /* for sysctl */
82150 void ctrl_alt_del(void);
82151 @@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
82152 * Emergency restart, callable from an interrupt handler.
82153 */
82154
82155 -extern void emergency_restart(void);
82156 +extern void emergency_restart(void) __noreturn;
82157 #include <asm/emergency-restart.h>
82158
82159 #endif /* _LINUX_REBOOT_H */
82160 diff --git a/include/linux/regset.h b/include/linux/regset.h
82161 index 8e0c9fe..ac4d221 100644
82162 --- a/include/linux/regset.h
82163 +++ b/include/linux/regset.h
82164 @@ -161,7 +161,8 @@ struct user_regset {
82165 unsigned int align;
82166 unsigned int bias;
82167 unsigned int core_note_type;
82168 -};
82169 +} __do_const;
82170 +typedef struct user_regset __no_const user_regset_no_const;
82171
82172 /**
82173 * struct user_regset_view - available regsets
82174 diff --git a/include/linux/relay.h b/include/linux/relay.h
82175 index d7c8359..818daf5 100644
82176 --- a/include/linux/relay.h
82177 +++ b/include/linux/relay.h
82178 @@ -157,7 +157,7 @@ struct rchan_callbacks
82179 * The callback should return 0 if successful, negative if not.
82180 */
82181 int (*remove_buf_file)(struct dentry *dentry);
82182 -};
82183 +} __no_const;
82184
82185 /*
82186 * CONFIG_RELAY kernel API, kernel/relay.c
82187 diff --git a/include/linux/rio.h b/include/linux/rio.h
82188 index 6bda06f..bf39a9b 100644
82189 --- a/include/linux/rio.h
82190 +++ b/include/linux/rio.h
82191 @@ -358,7 +358,7 @@ struct rio_ops {
82192 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
82193 u64 rstart, u32 size, u32 flags);
82194 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
82195 -};
82196 +} __no_const;
82197
82198 #define RIO_RESOURCE_MEM 0x00000100
82199 #define RIO_RESOURCE_DOORBELL 0x00000200
82200 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
82201 index b66c211..13d2915 100644
82202 --- a/include/linux/rmap.h
82203 +++ b/include/linux/rmap.h
82204 @@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
82205 void anon_vma_init(void); /* create anon_vma_cachep */
82206 int anon_vma_prepare(struct vm_area_struct *);
82207 void unlink_anon_vmas(struct vm_area_struct *);
82208 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
82209 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
82210 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
82211 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
82212
82213 static inline void anon_vma_merge(struct vm_area_struct *vma,
82214 struct vm_area_struct *next)
82215 diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
82216 index a964f72..b475afb 100644
82217 --- a/include/linux/scatterlist.h
82218 +++ b/include/linux/scatterlist.h
82219 @@ -1,6 +1,7 @@
82220 #ifndef _LINUX_SCATTERLIST_H
82221 #define _LINUX_SCATTERLIST_H
82222
82223 +#include <linux/sched.h>
82224 #include <linux/string.h>
82225 #include <linux/bug.h>
82226 #include <linux/mm.h>
82227 @@ -114,6 +115,12 @@ static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
82228 #ifdef CONFIG_DEBUG_SG
82229 BUG_ON(!virt_addr_valid(buf));
82230 #endif
82231 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
82232 + if (object_starts_on_stack(buf)) {
82233 + void *adjbuf = buf - current->stack + current->lowmem_stack;
82234 + sg_set_page(sg, virt_to_page(adjbuf), buflen, offset_in_page(adjbuf));
82235 + } else
82236 +#endif
82237 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
82238 }
82239
82240 diff --git a/include/linux/sched.h b/include/linux/sched.h
82241 index 221b2bd..e2e5f82 100644
82242 --- a/include/linux/sched.h
82243 +++ b/include/linux/sched.h
82244 @@ -131,6 +131,7 @@ struct fs_struct;
82245 struct perf_event_context;
82246 struct blk_plug;
82247 struct filename;
82248 +struct linux_binprm;
82249
82250 #define VMACACHE_BITS 2
82251 #define VMACACHE_SIZE (1U << VMACACHE_BITS)
82252 @@ -380,7 +381,7 @@ extern char __sched_text_start[], __sched_text_end[];
82253 extern int in_sched_functions(unsigned long addr);
82254
82255 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
82256 -extern signed long schedule_timeout(signed long timeout);
82257 +extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
82258 extern signed long schedule_timeout_interruptible(signed long timeout);
82259 extern signed long schedule_timeout_killable(signed long timeout);
82260 extern signed long schedule_timeout_uninterruptible(signed long timeout);
82261 @@ -391,6 +392,19 @@ struct nsproxy;
82262 struct user_namespace;
82263
82264 #ifdef CONFIG_MMU
82265 +
82266 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
82267 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
82268 +#else
82269 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
82270 +{
82271 + return 0;
82272 +}
82273 +#endif
82274 +
82275 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
82276 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
82277 +
82278 extern void arch_pick_mmap_layout(struct mm_struct *mm);
82279 extern unsigned long
82280 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
82281 @@ -688,6 +702,17 @@ struct signal_struct {
82282 #ifdef CONFIG_TASKSTATS
82283 struct taskstats *stats;
82284 #endif
82285 +
82286 +#ifdef CONFIG_GRKERNSEC
82287 + u32 curr_ip;
82288 + u32 saved_ip;
82289 + u32 gr_saddr;
82290 + u32 gr_daddr;
82291 + u16 gr_sport;
82292 + u16 gr_dport;
82293 + u8 used_accept:1;
82294 +#endif
82295 +
82296 #ifdef CONFIG_AUDIT
82297 unsigned audit_tty;
82298 unsigned audit_tty_log_passwd;
82299 @@ -714,7 +739,7 @@ struct signal_struct {
82300 struct mutex cred_guard_mutex; /* guard against foreign influences on
82301 * credential calculations
82302 * (notably. ptrace) */
82303 -};
82304 +} __randomize_layout;
82305
82306 /*
82307 * Bits in flags field of signal_struct.
82308 @@ -768,6 +793,14 @@ struct user_struct {
82309 struct key *session_keyring; /* UID's default session keyring */
82310 #endif
82311
82312 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
82313 + unsigned char kernel_banned;
82314 +#endif
82315 +#ifdef CONFIG_GRKERNSEC_BRUTE
82316 + unsigned char suid_banned;
82317 + unsigned long suid_ban_expires;
82318 +#endif
82319 +
82320 /* Hash table maintenance information */
82321 struct hlist_node uidhash_node;
82322 kuid_t uid;
82323 @@ -775,7 +808,7 @@ struct user_struct {
82324 #ifdef CONFIG_PERF_EVENTS
82325 atomic_long_t locked_vm;
82326 #endif
82327 -};
82328 +} __randomize_layout;
82329
82330 extern int uids_sysfs_init(void);
82331
82332 @@ -1179,6 +1212,9 @@ enum perf_event_task_context {
82333 struct task_struct {
82334 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
82335 void *stack;
82336 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
82337 + void *lowmem_stack;
82338 +#endif
82339 atomic_t usage;
82340 unsigned int flags; /* per process flags, defined below */
82341 unsigned int ptrace;
82342 @@ -1304,8 +1340,8 @@ struct task_struct {
82343 struct list_head thread_node;
82344
82345 struct completion *vfork_done; /* for vfork() */
82346 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
82347 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
82348 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
82349 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
82350
82351 cputime_t utime, stime, utimescaled, stimescaled;
82352 cputime_t gtime;
82353 @@ -1330,11 +1366,6 @@ struct task_struct {
82354 struct task_cputime cputime_expires;
82355 struct list_head cpu_timers[3];
82356
82357 -/* process credentials */
82358 - const struct cred __rcu *real_cred; /* objective and real subjective task
82359 - * credentials (COW) */
82360 - const struct cred __rcu *cred; /* effective (overridable) subjective task
82361 - * credentials (COW) */
82362 char comm[TASK_COMM_LEN]; /* executable name excluding path
82363 - access with [gs]et_task_comm (which lock
82364 it with task_lock())
82365 @@ -1351,6 +1382,10 @@ struct task_struct {
82366 #endif
82367 /* CPU-specific state of this task */
82368 struct thread_struct thread;
82369 +/* thread_info moved to task_struct */
82370 +#ifdef CONFIG_X86
82371 + struct thread_info tinfo;
82372 +#endif
82373 /* filesystem information */
82374 struct fs_struct *fs;
82375 /* open file information */
82376 @@ -1427,6 +1462,10 @@ struct task_struct {
82377 gfp_t lockdep_reclaim_gfp;
82378 #endif
82379
82380 +/* process credentials */
82381 + const struct cred __rcu *real_cred; /* objective and real subjective task
82382 + * credentials (COW) */
82383 +
82384 /* journalling filesystem info */
82385 void *journal_info;
82386
82387 @@ -1465,6 +1504,10 @@ struct task_struct {
82388 /* cg_list protected by css_set_lock and tsk->alloc_lock */
82389 struct list_head cg_list;
82390 #endif
82391 +
82392 + const struct cred __rcu *cred; /* effective (overridable) subjective task
82393 + * credentials (COW) */
82394 +
82395 #ifdef CONFIG_FUTEX
82396 struct robust_list_head __user *robust_list;
82397 #ifdef CONFIG_COMPAT
82398 @@ -1610,7 +1653,78 @@ struct task_struct {
82399 unsigned int sequential_io;
82400 unsigned int sequential_io_avg;
82401 #endif
82402 -};
82403 +
82404 +#ifdef CONFIG_GRKERNSEC
82405 + /* grsecurity */
82406 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82407 + u64 exec_id;
82408 +#endif
82409 +#ifdef CONFIG_GRKERNSEC_SETXID
82410 + const struct cred *delayed_cred;
82411 +#endif
82412 + struct dentry *gr_chroot_dentry;
82413 + struct acl_subject_label *acl;
82414 + struct acl_subject_label *tmpacl;
82415 + struct acl_role_label *role;
82416 + struct file *exec_file;
82417 + unsigned long brute_expires;
82418 + u16 acl_role_id;
82419 + u8 inherited;
82420 + /* is this the task that authenticated to the special role */
82421 + u8 acl_sp_role;
82422 + u8 is_writable;
82423 + u8 brute;
82424 + u8 gr_is_chrooted;
82425 +#endif
82426 +
82427 +} __randomize_layout;
82428 +
82429 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
82430 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
82431 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
82432 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
82433 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
82434 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
82435 +
82436 +#ifdef CONFIG_PAX_SOFTMODE
82437 +extern int pax_softmode;
82438 +#endif
82439 +
82440 +extern int pax_check_flags(unsigned long *);
82441 +#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
82442 +
82443 +/* if tsk != current then task_lock must be held on it */
82444 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
82445 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
82446 +{
82447 + if (likely(tsk->mm))
82448 + return tsk->mm->pax_flags;
82449 + else
82450 + return 0UL;
82451 +}
82452 +
82453 +/* if tsk != current then task_lock must be held on it */
82454 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
82455 +{
82456 + if (likely(tsk->mm)) {
82457 + tsk->mm->pax_flags = flags;
82458 + return 0;
82459 + }
82460 + return -EINVAL;
82461 +}
82462 +#endif
82463 +
82464 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
82465 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
82466 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
82467 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
82468 +#endif
82469 +
82470 +struct path;
82471 +extern char *pax_get_path(const struct path *path, char *buf, int buflen);
82472 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
82473 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
82474 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
82475
82476 /* Future-safe accessor for struct task_struct's cpus_allowed. */
82477 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
82478 @@ -1692,7 +1806,7 @@ struct pid_namespace;
82479 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
82480 struct pid_namespace *ns);
82481
82482 -static inline pid_t task_pid_nr(struct task_struct *tsk)
82483 +static inline pid_t task_pid_nr(const struct task_struct *tsk)
82484 {
82485 return tsk->pid;
82486 }
82487 @@ -2039,6 +2153,25 @@ extern u64 sched_clock_cpu(int cpu);
82488
82489 extern void sched_clock_init(void);
82490
82491 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
82492 +static inline void populate_stack(void)
82493 +{
82494 + struct task_struct *curtask = current;
82495 + int c;
82496 + int *ptr = curtask->stack;
82497 + int *end = curtask->stack + THREAD_SIZE;
82498 +
82499 + while (ptr < end) {
82500 + c = *(volatile int *)ptr;
82501 + ptr += PAGE_SIZE/sizeof(int);
82502 + }
82503 +}
82504 +#else
82505 +static inline void populate_stack(void)
82506 +{
82507 +}
82508 +#endif
82509 +
82510 #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
82511 static inline void sched_clock_tick(void)
82512 {
82513 @@ -2172,7 +2305,9 @@ void yield(void);
82514 extern struct exec_domain default_exec_domain;
82515
82516 union thread_union {
82517 +#ifndef CONFIG_X86
82518 struct thread_info thread_info;
82519 +#endif
82520 unsigned long stack[THREAD_SIZE/sizeof(long)];
82521 };
82522
82523 @@ -2205,6 +2340,7 @@ extern struct pid_namespace init_pid_ns;
82524 */
82525
82526 extern struct task_struct *find_task_by_vpid(pid_t nr);
82527 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
82528 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
82529 struct pid_namespace *ns);
82530
82531 @@ -2367,7 +2503,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
82532 extern void exit_itimers(struct signal_struct *);
82533 extern void flush_itimer_signals(void);
82534
82535 -extern void do_group_exit(int);
82536 +extern __noreturn void do_group_exit(int);
82537
82538 extern int allow_signal(int);
82539 extern int disallow_signal(int);
82540 @@ -2568,9 +2704,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
82541
82542 #endif
82543
82544 -static inline int object_is_on_stack(void *obj)
82545 +static inline int object_starts_on_stack(const void *obj)
82546 {
82547 - void *stack = task_stack_page(current);
82548 + const void *stack = task_stack_page(current);
82549
82550 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
82551 }
82552 diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
82553 index 8045a55..c959cd5 100644
82554 --- a/include/linux/sched/sysctl.h
82555 +++ b/include/linux/sched/sysctl.h
82556 @@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
82557 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
82558
82559 extern int sysctl_max_map_count;
82560 +extern unsigned long sysctl_heap_stack_gap;
82561
82562 extern unsigned int sysctl_sched_latency;
82563 extern unsigned int sysctl_sched_min_granularity;
82564 diff --git a/include/linux/security.h b/include/linux/security.h
82565 index 6478ce3..5e6ad6e 100644
82566 --- a/include/linux/security.h
82567 +++ b/include/linux/security.h
82568 @@ -27,6 +27,7 @@
82569 #include <linux/slab.h>
82570 #include <linux/err.h>
82571 #include <linux/string.h>
82572 +#include <linux/grsecurity.h>
82573
82574 struct linux_binprm;
82575 struct cred;
82576 @@ -116,8 +117,6 @@ struct seq_file;
82577
82578 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
82579
82580 -void reset_security_ops(void);
82581 -
82582 #ifdef CONFIG_MMU
82583 extern unsigned long mmap_min_addr;
82584 extern unsigned long dac_mmap_min_addr;
82585 @@ -1719,7 +1718,7 @@ struct security_operations {
82586 struct audit_context *actx);
82587 void (*audit_rule_free) (void *lsmrule);
82588 #endif /* CONFIG_AUDIT */
82589 -};
82590 +} __randomize_layout;
82591
82592 /* prototypes */
82593 extern int security_init(void);
82594 diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
82595 index dc368b8..e895209 100644
82596 --- a/include/linux/semaphore.h
82597 +++ b/include/linux/semaphore.h
82598 @@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
82599 }
82600
82601 extern void down(struct semaphore *sem);
82602 -extern int __must_check down_interruptible(struct semaphore *sem);
82603 +extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
82604 extern int __must_check down_killable(struct semaphore *sem);
82605 extern int __must_check down_trylock(struct semaphore *sem);
82606 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
82607 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
82608 index 52e0097..383f21d 100644
82609 --- a/include/linux/seq_file.h
82610 +++ b/include/linux/seq_file.h
82611 @@ -27,6 +27,9 @@ struct seq_file {
82612 struct mutex lock;
82613 const struct seq_operations *op;
82614 int poll_event;
82615 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82616 + u64 exec_id;
82617 +#endif
82618 #ifdef CONFIG_USER_NS
82619 struct user_namespace *user_ns;
82620 #endif
82621 @@ -39,6 +42,7 @@ struct seq_operations {
82622 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
82623 int (*show) (struct seq_file *m, void *v);
82624 };
82625 +typedef struct seq_operations __no_const seq_operations_no_const;
82626
82627 #define SEQ_SKIP 1
82628
82629 @@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
82630
82631 char *mangle_path(char *s, const char *p, const char *esc);
82632 int seq_open(struct file *, const struct seq_operations *);
82633 +int seq_open_restrict(struct file *, const struct seq_operations *);
82634 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
82635 loff_t seq_lseek(struct file *, loff_t, int);
82636 int seq_release(struct inode *, struct file *);
82637 @@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
82638 }
82639
82640 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
82641 +int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
82642 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
82643 int single_release(struct inode *, struct file *);
82644 void *__seq_open_private(struct file *, const struct seq_operations *, int);
82645 diff --git a/include/linux/shm.h b/include/linux/shm.h
82646 index 1e2cd2e..0288750 100644
82647 --- a/include/linux/shm.h
82648 +++ b/include/linux/shm.h
82649 @@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
82650
82651 /* The task created the shm object. NULL if the task is dead. */
82652 struct task_struct *shm_creator;
82653 +#ifdef CONFIG_GRKERNSEC
82654 + time_t shm_createtime;
82655 + pid_t shm_lapid;
82656 +#endif
82657 };
82658
82659 /* shm_mode upper byte flags */
82660 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
82661 index 08074a8..e2ae280 100644
82662 --- a/include/linux/skbuff.h
82663 +++ b/include/linux/skbuff.h
82664 @@ -717,7 +717,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
82665 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
82666 int node);
82667 struct sk_buff *build_skb(void *data, unsigned int frag_size);
82668 -static inline struct sk_buff *alloc_skb(unsigned int size,
82669 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
82670 gfp_t priority)
82671 {
82672 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
82673 @@ -1825,7 +1825,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
82674 return skb->inner_transport_header - skb->inner_network_header;
82675 }
82676
82677 -static inline int skb_network_offset(const struct sk_buff *skb)
82678 +static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
82679 {
82680 return skb_network_header(skb) - skb->data;
82681 }
82682 @@ -1885,7 +1885,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
82683 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
82684 */
82685 #ifndef NET_SKB_PAD
82686 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
82687 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
82688 #endif
82689
82690 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
82691 @@ -2484,7 +2484,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
82692 int *err);
82693 unsigned int datagram_poll(struct file *file, struct socket *sock,
82694 struct poll_table_struct *wait);
82695 -int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
82696 +int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
82697 struct iovec *to, int size);
82698 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
82699 struct iovec *iov);
82700 @@ -2776,6 +2776,9 @@ static inline void nf_reset(struct sk_buff *skb)
82701 nf_bridge_put(skb->nf_bridge);
82702 skb->nf_bridge = NULL;
82703 #endif
82704 +#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
82705 + skb->nf_trace = 0;
82706 +#endif
82707 }
82708
82709 static inline void nf_reset_trace(struct sk_buff *skb)
82710 diff --git a/include/linux/slab.h b/include/linux/slab.h
82711 index 307bfbe..a999cf3 100644
82712 --- a/include/linux/slab.h
82713 +++ b/include/linux/slab.h
82714 @@ -14,15 +14,29 @@
82715 #include <linux/gfp.h>
82716 #include <linux/types.h>
82717 #include <linux/workqueue.h>
82718 -
82719 +#include <linux/err.h>
82720
82721 /*
82722 * Flags to pass to kmem_cache_create().
82723 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
82724 */
82725 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
82726 +
82727 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82728 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
82729 +#else
82730 +#define SLAB_USERCOPY 0x00000000UL
82731 +#endif
82732 +
82733 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
82734 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
82735 +
82736 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
82737 +#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
82738 +#else
82739 +#define SLAB_NO_SANITIZE 0x00000000UL
82740 +#endif
82741 +
82742 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
82743 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
82744 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
82745 @@ -98,10 +112,13 @@
82746 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
82747 * Both make kfree a no-op.
82748 */
82749 -#define ZERO_SIZE_PTR ((void *)16)
82750 +#define ZERO_SIZE_PTR \
82751 +({ \
82752 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
82753 + (void *)(-MAX_ERRNO-1L); \
82754 +})
82755
82756 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
82757 - (unsigned long)ZERO_SIZE_PTR)
82758 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
82759
82760 #include <linux/kmemleak.h>
82761
82762 @@ -142,6 +159,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
82763 void kfree(const void *);
82764 void kzfree(const void *);
82765 size_t ksize(const void *);
82766 +const char *check_heap_object(const void *ptr, unsigned long n);
82767 +bool is_usercopy_object(const void *ptr);
82768
82769 /*
82770 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
82771 @@ -174,7 +193,7 @@ struct kmem_cache {
82772 unsigned int align; /* Alignment as calculated */
82773 unsigned long flags; /* Active flags on the slab */
82774 const char *name; /* Slab name for sysfs */
82775 - int refcount; /* Use counter */
82776 + atomic_t refcount; /* Use counter */
82777 void (*ctor)(void *); /* Called on object slot creation */
82778 struct list_head list; /* List of all slab caches on the system */
82779 };
82780 @@ -259,6 +278,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
82781 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
82782 #endif
82783
82784 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82785 +extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
82786 +#endif
82787 +
82788 /*
82789 * Figure out which kmalloc slab an allocation of a certain size
82790 * belongs to.
82791 @@ -267,7 +290,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
82792 * 2 = 120 .. 192 bytes
82793 * n = 2^(n-1) .. 2^n -1
82794 */
82795 -static __always_inline int kmalloc_index(size_t size)
82796 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
82797 {
82798 if (!size)
82799 return 0;
82800 @@ -310,11 +333,11 @@ static __always_inline int kmalloc_index(size_t size)
82801 }
82802 #endif /* !CONFIG_SLOB */
82803
82804 -void *__kmalloc(size_t size, gfp_t flags);
82805 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
82806 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
82807
82808 #ifdef CONFIG_NUMA
82809 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
82810 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
82811 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
82812 #else
82813 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
82814 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
82815 index 8235dfb..47ce586 100644
82816 --- a/include/linux/slab_def.h
82817 +++ b/include/linux/slab_def.h
82818 @@ -38,7 +38,7 @@ struct kmem_cache {
82819 /* 4) cache creation/removal */
82820 const char *name;
82821 struct list_head list;
82822 - int refcount;
82823 + atomic_t refcount;
82824 int object_size;
82825 int align;
82826
82827 @@ -54,10 +54,14 @@ struct kmem_cache {
82828 unsigned long node_allocs;
82829 unsigned long node_frees;
82830 unsigned long node_overflow;
82831 - atomic_t allochit;
82832 - atomic_t allocmiss;
82833 - atomic_t freehit;
82834 - atomic_t freemiss;
82835 + atomic_unchecked_t allochit;
82836 + atomic_unchecked_t allocmiss;
82837 + atomic_unchecked_t freehit;
82838 + atomic_unchecked_t freemiss;
82839 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
82840 + atomic_unchecked_t sanitized;
82841 + atomic_unchecked_t not_sanitized;
82842 +#endif
82843
82844 /*
82845 * If debugging is enabled, then the allocator can add additional
82846 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
82847 index d82abd4..408c3a0 100644
82848 --- a/include/linux/slub_def.h
82849 +++ b/include/linux/slub_def.h
82850 @@ -74,7 +74,7 @@ struct kmem_cache {
82851 struct kmem_cache_order_objects max;
82852 struct kmem_cache_order_objects min;
82853 gfp_t allocflags; /* gfp flags to use on each alloc */
82854 - int refcount; /* Refcount for slab cache destroy */
82855 + atomic_t refcount; /* Refcount for slab cache destroy */
82856 void (*ctor)(void *);
82857 int inuse; /* Offset to metadata */
82858 int align; /* Alignment */
82859 diff --git a/include/linux/smp.h b/include/linux/smp.h
82860 index 633f5ed..6c3dc3f 100644
82861 --- a/include/linux/smp.h
82862 +++ b/include/linux/smp.h
82863 @@ -176,7 +176,9 @@ static inline void kick_all_cpus_sync(void) { }
82864 #endif
82865
82866 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
82867 +#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
82868 #define put_cpu() preempt_enable()
82869 +#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
82870
82871 /*
82872 * Callback to arch code if there's nosmp or maxcpus=0 on the
82873 diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
82874 index 46cca4c..3323536 100644
82875 --- a/include/linux/sock_diag.h
82876 +++ b/include/linux/sock_diag.h
82877 @@ -11,7 +11,7 @@ struct sock;
82878 struct sock_diag_handler {
82879 __u8 family;
82880 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
82881 -};
82882 +} __do_const;
82883
82884 int sock_diag_register(const struct sock_diag_handler *h);
82885 void sock_diag_unregister(const struct sock_diag_handler *h);
82886 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
82887 index 680f9a3..f13aeb0 100644
82888 --- a/include/linux/sonet.h
82889 +++ b/include/linux/sonet.h
82890 @@ -7,7 +7,7 @@
82891 #include <uapi/linux/sonet.h>
82892
82893 struct k_sonet_stats {
82894 -#define __HANDLE_ITEM(i) atomic_t i
82895 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
82896 __SONET_ITEMS
82897 #undef __HANDLE_ITEM
82898 };
82899 diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
82900 index 07d8e53..dc934c9 100644
82901 --- a/include/linux/sunrpc/addr.h
82902 +++ b/include/linux/sunrpc/addr.h
82903 @@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
82904 {
82905 switch (sap->sa_family) {
82906 case AF_INET:
82907 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
82908 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
82909 case AF_INET6:
82910 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
82911 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
82912 }
82913 return 0;
82914 }
82915 @@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
82916 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
82917 const struct sockaddr *src)
82918 {
82919 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
82920 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
82921 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
82922
82923 dsin->sin_family = ssin->sin_family;
82924 @@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
82925 if (sa->sa_family != AF_INET6)
82926 return 0;
82927
82928 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
82929 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
82930 }
82931
82932 #endif /* _LINUX_SUNRPC_ADDR_H */
82933 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
82934 index 70736b9..37f33db 100644
82935 --- a/include/linux/sunrpc/clnt.h
82936 +++ b/include/linux/sunrpc/clnt.h
82937 @@ -97,7 +97,7 @@ struct rpc_procinfo {
82938 unsigned int p_timer; /* Which RTT timer to use */
82939 u32 p_statidx; /* Which procedure to account */
82940 const char * p_name; /* name of procedure */
82941 -};
82942 +} __do_const;
82943
82944 #ifdef __KERNEL__
82945
82946 diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
82947 index 04e7632..2e2a8a3 100644
82948 --- a/include/linux/sunrpc/svc.h
82949 +++ b/include/linux/sunrpc/svc.h
82950 @@ -412,7 +412,7 @@ struct svc_procedure {
82951 unsigned int pc_count; /* call count */
82952 unsigned int pc_cachetype; /* cache info (NFS) */
82953 unsigned int pc_xdrressize; /* maximum size of XDR reply */
82954 -};
82955 +} __do_const;
82956
82957 /*
82958 * Function prototypes.
82959 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
82960 index 0b8e3e6..33e0a01 100644
82961 --- a/include/linux/sunrpc/svc_rdma.h
82962 +++ b/include/linux/sunrpc/svc_rdma.h
82963 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
82964 extern unsigned int svcrdma_max_requests;
82965 extern unsigned int svcrdma_max_req_size;
82966
82967 -extern atomic_t rdma_stat_recv;
82968 -extern atomic_t rdma_stat_read;
82969 -extern atomic_t rdma_stat_write;
82970 -extern atomic_t rdma_stat_sq_starve;
82971 -extern atomic_t rdma_stat_rq_starve;
82972 -extern atomic_t rdma_stat_rq_poll;
82973 -extern atomic_t rdma_stat_rq_prod;
82974 -extern atomic_t rdma_stat_sq_poll;
82975 -extern atomic_t rdma_stat_sq_prod;
82976 +extern atomic_unchecked_t rdma_stat_recv;
82977 +extern atomic_unchecked_t rdma_stat_read;
82978 +extern atomic_unchecked_t rdma_stat_write;
82979 +extern atomic_unchecked_t rdma_stat_sq_starve;
82980 +extern atomic_unchecked_t rdma_stat_rq_starve;
82981 +extern atomic_unchecked_t rdma_stat_rq_poll;
82982 +extern atomic_unchecked_t rdma_stat_rq_prod;
82983 +extern atomic_unchecked_t rdma_stat_sq_poll;
82984 +extern atomic_unchecked_t rdma_stat_sq_prod;
82985
82986 #define RPCRDMA_VERSION 1
82987
82988 diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
82989 index 8d71d65..f79586e 100644
82990 --- a/include/linux/sunrpc/svcauth.h
82991 +++ b/include/linux/sunrpc/svcauth.h
82992 @@ -120,7 +120,7 @@ struct auth_ops {
82993 int (*release)(struct svc_rqst *rq);
82994 void (*domain_release)(struct auth_domain *);
82995 int (*set_client)(struct svc_rqst *rq);
82996 -};
82997 +} __do_const;
82998
82999 #define SVC_GARBAGE 1
83000 #define SVC_SYSERR 2
83001 diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
83002 index a5ffd32..0935dea 100644
83003 --- a/include/linux/swiotlb.h
83004 +++ b/include/linux/swiotlb.h
83005 @@ -60,7 +60,8 @@ extern void
83006
83007 extern void
83008 swiotlb_free_coherent(struct device *hwdev, size_t size,
83009 - void *vaddr, dma_addr_t dma_handle);
83010 + void *vaddr, dma_addr_t dma_handle,
83011 + struct dma_attrs *attrs);
83012
83013 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
83014 unsigned long offset, size_t size,
83015 diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
83016 index a4a0588..752870e 100644
83017 --- a/include/linux/syscalls.h
83018 +++ b/include/linux/syscalls.h
83019 @@ -98,10 +98,16 @@ struct sigaltstack;
83020 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
83021
83022 #define __SC_DECL(t, a) t a
83023 +#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))
83024 #define __TYPE_IS_L(t) (__same_type((t)0, 0L))
83025 #define __TYPE_IS_UL(t) (__same_type((t)0, 0UL))
83026 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
83027 -#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
83028 +#define __SC_LONG(t, a) __typeof( \
83029 + __builtin_choose_expr( \
83030 + sizeof(t) > sizeof(int), \
83031 + (t) 0, \
83032 + __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
83033 + )) a
83034 #define __SC_CAST(t, a) (t) a
83035 #define __SC_ARGS(t, a) a
83036 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
83037 @@ -379,11 +385,11 @@ asmlinkage long sys_sync(void);
83038 asmlinkage long sys_fsync(unsigned int fd);
83039 asmlinkage long sys_fdatasync(unsigned int fd);
83040 asmlinkage long sys_bdflush(int func, long data);
83041 -asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
83042 - char __user *type, unsigned long flags,
83043 +asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
83044 + const char __user *type, unsigned long flags,
83045 void __user *data);
83046 -asmlinkage long sys_umount(char __user *name, int flags);
83047 -asmlinkage long sys_oldumount(char __user *name);
83048 +asmlinkage long sys_umount(const char __user *name, int flags);
83049 +asmlinkage long sys_oldumount(const char __user *name);
83050 asmlinkage long sys_truncate(const char __user *path, long length);
83051 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
83052 asmlinkage long sys_stat(const char __user *filename,
83053 @@ -595,7 +601,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
83054 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
83055 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
83056 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
83057 - struct sockaddr __user *, int);
83058 + struct sockaddr __user *, int) __intentional_overflow(0);
83059 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
83060 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
83061 unsigned int vlen, unsigned flags);
83062 diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
83063 index 27b3b0b..e093dd9 100644
83064 --- a/include/linux/syscore_ops.h
83065 +++ b/include/linux/syscore_ops.h
83066 @@ -16,7 +16,7 @@ struct syscore_ops {
83067 int (*suspend)(void);
83068 void (*resume)(void);
83069 void (*shutdown)(void);
83070 -};
83071 +} __do_const;
83072
83073 extern void register_syscore_ops(struct syscore_ops *ops);
83074 extern void unregister_syscore_ops(struct syscore_ops *ops);
83075 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
83076 index 14a8ff2..fa95f3a 100644
83077 --- a/include/linux/sysctl.h
83078 +++ b/include/linux/sysctl.h
83079 @@ -34,13 +34,13 @@ struct ctl_table_root;
83080 struct ctl_table_header;
83081 struct ctl_dir;
83082
83083 -typedef struct ctl_table ctl_table;
83084 -
83085 typedef int proc_handler (struct ctl_table *ctl, int write,
83086 void __user *buffer, size_t *lenp, loff_t *ppos);
83087
83088 extern int proc_dostring(struct ctl_table *, int,
83089 void __user *, size_t *, loff_t *);
83090 +extern int proc_dostring_modpriv(struct ctl_table *, int,
83091 + void __user *, size_t *, loff_t *);
83092 extern int proc_dointvec(struct ctl_table *, int,
83093 void __user *, size_t *, loff_t *);
83094 extern int proc_dointvec_minmax(struct ctl_table *, int,
83095 @@ -115,7 +115,9 @@ struct ctl_table
83096 struct ctl_table_poll *poll;
83097 void *extra1;
83098 void *extra2;
83099 -};
83100 +} __do_const __randomize_layout;
83101 +typedef struct ctl_table __no_const ctl_table_no_const;
83102 +typedef struct ctl_table ctl_table;
83103
83104 struct ctl_node {
83105 struct rb_node node;
83106 diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
83107 index 5ffaa34..fe3e31c 100644
83108 --- a/include/linux/sysfs.h
83109 +++ b/include/linux/sysfs.h
83110 @@ -34,7 +34,8 @@ struct attribute {
83111 struct lock_class_key *key;
83112 struct lock_class_key skey;
83113 #endif
83114 -};
83115 +} __do_const;
83116 +typedef struct attribute __no_const attribute_no_const;
83117
83118 /**
83119 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
83120 @@ -63,7 +64,8 @@ struct attribute_group {
83121 struct attribute *, int);
83122 struct attribute **attrs;
83123 struct bin_attribute **bin_attrs;
83124 -};
83125 +} __do_const;
83126 +typedef struct attribute_group __no_const attribute_group_no_const;
83127
83128 /**
83129 * Use these macros to make defining attributes easier. See include/linux/device.h
83130 @@ -128,7 +130,8 @@ struct bin_attribute {
83131 char *, loff_t, size_t);
83132 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
83133 struct vm_area_struct *vma);
83134 -};
83135 +} __do_const;
83136 +typedef struct bin_attribute __no_const bin_attribute_no_const;
83137
83138 /**
83139 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
83140 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
83141 index 387fa7d..3fcde6b 100644
83142 --- a/include/linux/sysrq.h
83143 +++ b/include/linux/sysrq.h
83144 @@ -16,6 +16,7 @@
83145
83146 #include <linux/errno.h>
83147 #include <linux/types.h>
83148 +#include <linux/compiler.h>
83149
83150 /* Possible values of bitmask for enabling sysrq functions */
83151 /* 0x0001 is reserved for enable everything */
83152 @@ -33,7 +34,7 @@ struct sysrq_key_op {
83153 char *help_msg;
83154 char *action_msg;
83155 int enable_mask;
83156 -};
83157 +} __do_const;
83158
83159 #ifdef CONFIG_MAGIC_SYSRQ
83160
83161 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
83162 index fddbe20..a0e76ab 100644
83163 --- a/include/linux/thread_info.h
83164 +++ b/include/linux/thread_info.h
83165 @@ -161,6 +161,13 @@ static inline bool test_and_clear_restore_sigmask(void)
83166 #error "no set_restore_sigmask() provided and default one won't work"
83167 #endif
83168
83169 +extern void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size);
83170 +
83171 +static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
83172 +{
83173 + __check_object_size(ptr, n, to_user, __builtin_constant_p(n));
83174 +}
83175 +
83176 #endif /* __KERNEL__ */
83177
83178 #endif /* _LINUX_THREAD_INFO_H */
83179 diff --git a/include/linux/tty.h b/include/linux/tty.h
83180 index 1c3316a..ae83b9f 100644
83181 --- a/include/linux/tty.h
83182 +++ b/include/linux/tty.h
83183 @@ -202,7 +202,7 @@ struct tty_port {
83184 const struct tty_port_operations *ops; /* Port operations */
83185 spinlock_t lock; /* Lock protecting tty field */
83186 int blocked_open; /* Waiting to open */
83187 - int count; /* Usage count */
83188 + atomic_t count; /* Usage count */
83189 wait_queue_head_t open_wait; /* Open waiters */
83190 wait_queue_head_t close_wait; /* Close waiters */
83191 wait_queue_head_t delta_msr_wait; /* Modem status change */
83192 @@ -284,7 +284,7 @@ struct tty_struct {
83193 /* If the tty has a pending do_SAK, queue it here - akpm */
83194 struct work_struct SAK_work;
83195 struct tty_port *port;
83196 -};
83197 +} __randomize_layout;
83198
83199 /* Each of a tty's open files has private_data pointing to tty_file_private */
83200 struct tty_file_private {
83201 @@ -550,7 +550,7 @@ extern int tty_port_open(struct tty_port *port,
83202 struct tty_struct *tty, struct file *filp);
83203 static inline int tty_port_users(struct tty_port *port)
83204 {
83205 - return port->count + port->blocked_open;
83206 + return atomic_read(&port->count) + port->blocked_open;
83207 }
83208
83209 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
83210 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
83211 index 756a609..89db85e 100644
83212 --- a/include/linux/tty_driver.h
83213 +++ b/include/linux/tty_driver.h
83214 @@ -285,7 +285,7 @@ struct tty_operations {
83215 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
83216 #endif
83217 const struct file_operations *proc_fops;
83218 -};
83219 +} __do_const __randomize_layout;
83220
83221 struct tty_driver {
83222 int magic; /* magic number for this structure */
83223 @@ -319,7 +319,7 @@ struct tty_driver {
83224
83225 const struct tty_operations *ops;
83226 struct list_head tty_drivers;
83227 -};
83228 +} __randomize_layout;
83229
83230 extern struct list_head tty_drivers;
83231
83232 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
83233 index add26da..22c00bef 100644
83234 --- a/include/linux/tty_ldisc.h
83235 +++ b/include/linux/tty_ldisc.h
83236 @@ -212,7 +212,7 @@ struct tty_ldisc_ops {
83237
83238 struct module *owner;
83239
83240 - int refcount;
83241 + atomic_t refcount;
83242 };
83243
83244 struct tty_ldisc {
83245 diff --git a/include/linux/types.h b/include/linux/types.h
83246 index 4d118ba..c3ee9bf 100644
83247 --- a/include/linux/types.h
83248 +++ b/include/linux/types.h
83249 @@ -176,10 +176,26 @@ typedef struct {
83250 int counter;
83251 } atomic_t;
83252
83253 +#ifdef CONFIG_PAX_REFCOUNT
83254 +typedef struct {
83255 + int counter;
83256 +} atomic_unchecked_t;
83257 +#else
83258 +typedef atomic_t atomic_unchecked_t;
83259 +#endif
83260 +
83261 #ifdef CONFIG_64BIT
83262 typedef struct {
83263 long counter;
83264 } atomic64_t;
83265 +
83266 +#ifdef CONFIG_PAX_REFCOUNT
83267 +typedef struct {
83268 + long counter;
83269 +} atomic64_unchecked_t;
83270 +#else
83271 +typedef atomic64_t atomic64_unchecked_t;
83272 +#endif
83273 #endif
83274
83275 struct list_head {
83276 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
83277 index ecd3319..8a36ded 100644
83278 --- a/include/linux/uaccess.h
83279 +++ b/include/linux/uaccess.h
83280 @@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
83281 long ret; \
83282 mm_segment_t old_fs = get_fs(); \
83283 \
83284 - set_fs(KERNEL_DS); \
83285 pagefault_disable(); \
83286 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
83287 - pagefault_enable(); \
83288 + set_fs(KERNEL_DS); \
83289 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
83290 set_fs(old_fs); \
83291 + pagefault_enable(); \
83292 ret; \
83293 })
83294
83295 diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
83296 index 2d1f9b6..d7a9fce 100644
83297 --- a/include/linux/uidgid.h
83298 +++ b/include/linux/uidgid.h
83299 @@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
83300
83301 #endif /* CONFIG_USER_NS */
83302
83303 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
83304 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
83305 +#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
83306 +#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
83307 +
83308 #endif /* _LINUX_UIDGID_H */
83309 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
83310 index 99c1b4d..562e6f3 100644
83311 --- a/include/linux/unaligned/access_ok.h
83312 +++ b/include/linux/unaligned/access_ok.h
83313 @@ -4,34 +4,34 @@
83314 #include <linux/kernel.h>
83315 #include <asm/byteorder.h>
83316
83317 -static inline u16 get_unaligned_le16(const void *p)
83318 +static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
83319 {
83320 - return le16_to_cpup((__le16 *)p);
83321 + return le16_to_cpup((const __le16 *)p);
83322 }
83323
83324 -static inline u32 get_unaligned_le32(const void *p)
83325 +static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
83326 {
83327 - return le32_to_cpup((__le32 *)p);
83328 + return le32_to_cpup((const __le32 *)p);
83329 }
83330
83331 -static inline u64 get_unaligned_le64(const void *p)
83332 +static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
83333 {
83334 - return le64_to_cpup((__le64 *)p);
83335 + return le64_to_cpup((const __le64 *)p);
83336 }
83337
83338 -static inline u16 get_unaligned_be16(const void *p)
83339 +static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
83340 {
83341 - return be16_to_cpup((__be16 *)p);
83342 + return be16_to_cpup((const __be16 *)p);
83343 }
83344
83345 -static inline u32 get_unaligned_be32(const void *p)
83346 +static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
83347 {
83348 - return be32_to_cpup((__be32 *)p);
83349 + return be32_to_cpup((const __be32 *)p);
83350 }
83351
83352 -static inline u64 get_unaligned_be64(const void *p)
83353 +static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
83354 {
83355 - return be64_to_cpup((__be64 *)p);
83356 + return be64_to_cpup((const __be64 *)p);
83357 }
83358
83359 static inline void put_unaligned_le16(u16 val, void *p)
83360 diff --git a/include/linux/usb.h b/include/linux/usb.h
83361 index 6b7ec37..4428419 100644
83362 --- a/include/linux/usb.h
83363 +++ b/include/linux/usb.h
83364 @@ -569,7 +569,7 @@ struct usb_device {
83365 int maxchild;
83366
83367 u32 quirks;
83368 - atomic_t urbnum;
83369 + atomic_unchecked_t urbnum;
83370
83371 unsigned long active_duration;
83372
83373 @@ -1653,7 +1653,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
83374
83375 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
83376 __u8 request, __u8 requesttype, __u16 value, __u16 index,
83377 - void *data, __u16 size, int timeout);
83378 + void *data, __u16 size, int timeout) __intentional_overflow(-1);
83379 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
83380 void *data, int len, int *actual_length, int timeout);
83381 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
83382 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
83383 index e452ba6..78f8e80 100644
83384 --- a/include/linux/usb/renesas_usbhs.h
83385 +++ b/include/linux/usb/renesas_usbhs.h
83386 @@ -39,7 +39,7 @@ enum {
83387 */
83388 struct renesas_usbhs_driver_callback {
83389 int (*notify_hotplug)(struct platform_device *pdev);
83390 -};
83391 +} __no_const;
83392
83393 /*
83394 * callback functions for platform
83395 diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
83396 index 4836ba3..603f6ee 100644
83397 --- a/include/linux/user_namespace.h
83398 +++ b/include/linux/user_namespace.h
83399 @@ -33,7 +33,7 @@ struct user_namespace {
83400 struct key *persistent_keyring_register;
83401 struct rw_semaphore persistent_keyring_register_sem;
83402 #endif
83403 -};
83404 +} __randomize_layout;
83405
83406 extern struct user_namespace init_user_ns;
83407
83408 diff --git a/include/linux/utsname.h b/include/linux/utsname.h
83409 index 239e277..22a5cf5 100644
83410 --- a/include/linux/utsname.h
83411 +++ b/include/linux/utsname.h
83412 @@ -24,7 +24,7 @@ struct uts_namespace {
83413 struct new_utsname name;
83414 struct user_namespace *user_ns;
83415 unsigned int proc_inum;
83416 -};
83417 +} __randomize_layout;
83418 extern struct uts_namespace init_uts_ns;
83419
83420 #ifdef CONFIG_UTS_NS
83421 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
83422 index 6f8fbcf..4efc177 100644
83423 --- a/include/linux/vermagic.h
83424 +++ b/include/linux/vermagic.h
83425 @@ -25,9 +25,42 @@
83426 #define MODULE_ARCH_VERMAGIC ""
83427 #endif
83428
83429 +#ifdef CONFIG_PAX_REFCOUNT
83430 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
83431 +#else
83432 +#define MODULE_PAX_REFCOUNT ""
83433 +#endif
83434 +
83435 +#ifdef CONSTIFY_PLUGIN
83436 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
83437 +#else
83438 +#define MODULE_CONSTIFY_PLUGIN ""
83439 +#endif
83440 +
83441 +#ifdef STACKLEAK_PLUGIN
83442 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
83443 +#else
83444 +#define MODULE_STACKLEAK_PLUGIN ""
83445 +#endif
83446 +
83447 +#ifdef RANDSTRUCT_PLUGIN
83448 +#include <generated/randomize_layout_hash.h>
83449 +#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
83450 +#else
83451 +#define MODULE_RANDSTRUCT_PLUGIN
83452 +#endif
83453 +
83454 +#ifdef CONFIG_GRKERNSEC
83455 +#define MODULE_GRSEC "GRSEC "
83456 +#else
83457 +#define MODULE_GRSEC ""
83458 +#endif
83459 +
83460 #define VERMAGIC_STRING \
83461 UTS_RELEASE " " \
83462 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
83463 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
83464 - MODULE_ARCH_VERMAGIC
83465 + MODULE_ARCH_VERMAGIC \
83466 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
83467 + MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
83468
83469 diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
83470 index 502073a..a7de024 100644
83471 --- a/include/linux/vga_switcheroo.h
83472 +++ b/include/linux/vga_switcheroo.h
83473 @@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
83474
83475 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
83476
83477 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
83478 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
83479 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
83480 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
83481 #else
83482
83483 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
83484 @@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
83485
83486 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
83487
83488 -static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
83489 -static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
83490 +static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
83491 +static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
83492
83493 #endif
83494 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
83495 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
83496 index 4b8a891..e9a2863 100644
83497 --- a/include/linux/vmalloc.h
83498 +++ b/include/linux/vmalloc.h
83499 @@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
83500 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
83501 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
83502 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
83503 +
83504 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
83505 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
83506 +#endif
83507 +
83508 /* bits [20..32] reserved for arch specific ioremap internals */
83509
83510 /*
83511 @@ -82,6 +87,10 @@ extern void *vmap(struct page **pages, unsigned int count,
83512 unsigned long flags, pgprot_t prot);
83513 extern void vunmap(const void *addr);
83514
83515 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
83516 +extern void unmap_process_stacks(struct task_struct *task);
83517 +#endif
83518 +
83519 extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,
83520 unsigned long uaddr, void *kaddr,
83521 unsigned long size);
83522 @@ -142,7 +151,7 @@ extern void free_vm_area(struct vm_struct *area);
83523
83524 /* for /dev/kmem */
83525 extern long vread(char *buf, char *addr, unsigned long count);
83526 -extern long vwrite(char *buf, char *addr, unsigned long count);
83527 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
83528
83529 /*
83530 * Internals. Dont't use..
83531 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
83532 index 45c9cd1..20bd0bf 100644
83533 --- a/include/linux/vmstat.h
83534 +++ b/include/linux/vmstat.h
83535 @@ -102,18 +102,18 @@ static inline void vm_events_fold_cpu(int cpu)
83536 /*
83537 * Zone based page accounting with per cpu differentials.
83538 */
83539 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83540 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83541
83542 static inline void zone_page_state_add(long x, struct zone *zone,
83543 enum zone_stat_item item)
83544 {
83545 - atomic_long_add(x, &zone->vm_stat[item]);
83546 - atomic_long_add(x, &vm_stat[item]);
83547 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
83548 + atomic_long_add_unchecked(x, &vm_stat[item]);
83549 }
83550
83551 -static inline unsigned long global_page_state(enum zone_stat_item item)
83552 +static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
83553 {
83554 - long x = atomic_long_read(&vm_stat[item]);
83555 + long x = atomic_long_read_unchecked(&vm_stat[item]);
83556 #ifdef CONFIG_SMP
83557 if (x < 0)
83558 x = 0;
83559 @@ -121,10 +121,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
83560 return x;
83561 }
83562
83563 -static inline unsigned long zone_page_state(struct zone *zone,
83564 +static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
83565 enum zone_stat_item item)
83566 {
83567 - long x = atomic_long_read(&zone->vm_stat[item]);
83568 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
83569 #ifdef CONFIG_SMP
83570 if (x < 0)
83571 x = 0;
83572 @@ -141,7 +141,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
83573 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
83574 enum zone_stat_item item)
83575 {
83576 - long x = atomic_long_read(&zone->vm_stat[item]);
83577 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
83578
83579 #ifdef CONFIG_SMP
83580 int cpu;
83581 @@ -228,14 +228,14 @@ static inline void __mod_zone_page_state(struct zone *zone,
83582
83583 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
83584 {
83585 - atomic_long_inc(&zone->vm_stat[item]);
83586 - atomic_long_inc(&vm_stat[item]);
83587 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
83588 + atomic_long_inc_unchecked(&vm_stat[item]);
83589 }
83590
83591 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
83592 {
83593 - atomic_long_dec(&zone->vm_stat[item]);
83594 - atomic_long_dec(&vm_stat[item]);
83595 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
83596 + atomic_long_dec_unchecked(&vm_stat[item]);
83597 }
83598
83599 static inline void __inc_zone_page_state(struct page *page,
83600 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
83601 index 91b0a68..0e9adf6 100644
83602 --- a/include/linux/xattr.h
83603 +++ b/include/linux/xattr.h
83604 @@ -28,7 +28,7 @@ struct xattr_handler {
83605 size_t size, int handler_flags);
83606 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
83607 size_t size, int flags, int handler_flags);
83608 -};
83609 +} __do_const;
83610
83611 struct xattr {
83612 const char *name;
83613 @@ -37,6 +37,9 @@ struct xattr {
83614 };
83615
83616 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
83617 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
83618 +ssize_t pax_getxattr(struct dentry *, void *, size_t);
83619 +#endif
83620 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
83621 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
83622 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
83623 diff --git a/include/linux/zlib.h b/include/linux/zlib.h
83624 index 9c5a6b4..09c9438 100644
83625 --- a/include/linux/zlib.h
83626 +++ b/include/linux/zlib.h
83627 @@ -31,6 +31,7 @@
83628 #define _ZLIB_H
83629
83630 #include <linux/zconf.h>
83631 +#include <linux/compiler.h>
83632
83633 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
83634 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
83635 @@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
83636
83637 /* basic functions */
83638
83639 -extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
83640 +extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
83641 /*
83642 Returns the number of bytes that needs to be allocated for a per-
83643 stream workspace with the specified parameters. A pointer to this
83644 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
83645 index eec6e46..82d5641 100644
83646 --- a/include/media/v4l2-dev.h
83647 +++ b/include/media/v4l2-dev.h
83648 @@ -77,7 +77,7 @@ struct v4l2_file_operations {
83649 int (*mmap) (struct file *, struct vm_area_struct *);
83650 int (*open) (struct file *);
83651 int (*release) (struct file *);
83652 -};
83653 +} __do_const;
83654
83655 /*
83656 * Newer version of video_device, handled by videodev2.c
83657 diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
83658 index c9b1593..a572459 100644
83659 --- a/include/media/v4l2-device.h
83660 +++ b/include/media/v4l2-device.h
83661 @@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
83662 this function returns 0. If the name ends with a digit (e.g. cx18),
83663 then the name will be set to cx18-0 since cx180 looks really odd. */
83664 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
83665 - atomic_t *instance);
83666 + atomic_unchecked_t *instance);
83667
83668 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
83669 Since the parent disappears this ensures that v4l2_dev doesn't have an
83670 diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
83671 index d9fa68f..45c88d1 100644
83672 --- a/include/net/9p/transport.h
83673 +++ b/include/net/9p/transport.h
83674 @@ -63,7 +63,7 @@ struct p9_trans_module {
83675 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
83676 int (*zc_request)(struct p9_client *, struct p9_req_t *,
83677 char *, char *, int , int, int, int);
83678 -};
83679 +} __do_const;
83680
83681 void v9fs_register_trans(struct p9_trans_module *m);
83682 void v9fs_unregister_trans(struct p9_trans_module *m);
83683 diff --git a/include/net/af_unix.h b/include/net/af_unix.h
83684 index a175ba4..196eb82 100644
83685 --- a/include/net/af_unix.h
83686 +++ b/include/net/af_unix.h
83687 @@ -36,7 +36,7 @@ struct unix_skb_parms {
83688 u32 secid; /* Security ID */
83689 #endif
83690 u32 consumed;
83691 -};
83692 +} __randomize_layout;
83693
83694 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
83695 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
83696 diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
83697 index 4abdcb2..945c5cc 100644
83698 --- a/include/net/bluetooth/l2cap.h
83699 +++ b/include/net/bluetooth/l2cap.h
83700 @@ -601,7 +601,7 @@ struct l2cap_ops {
83701 long (*get_sndtimeo) (struct l2cap_chan *chan);
83702 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
83703 unsigned long len, int nb);
83704 -};
83705 +} __do_const;
83706
83707 struct l2cap_conn {
83708 struct hci_conn *hcon;
83709 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
83710 index f2ae33d..c457cf0 100644
83711 --- a/include/net/caif/cfctrl.h
83712 +++ b/include/net/caif/cfctrl.h
83713 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
83714 void (*radioset_rsp)(void);
83715 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
83716 struct cflayer *client_layer);
83717 -};
83718 +} __no_const;
83719
83720 /* Link Setup Parameters for CAIF-Links. */
83721 struct cfctrl_link_param {
83722 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
83723 struct cfctrl {
83724 struct cfsrvl serv;
83725 struct cfctrl_rsp res;
83726 - atomic_t req_seq_no;
83727 - atomic_t rsp_seq_no;
83728 + atomic_unchecked_t req_seq_no;
83729 + atomic_unchecked_t rsp_seq_no;
83730 struct list_head list;
83731 /* Protects from simultaneous access to first_req list */
83732 spinlock_t info_list_lock;
83733 diff --git a/include/net/flow.h b/include/net/flow.h
83734 index 8109a15..504466d 100644
83735 --- a/include/net/flow.h
83736 +++ b/include/net/flow.h
83737 @@ -231,6 +231,6 @@ void flow_cache_fini(struct net *net);
83738
83739 void flow_cache_flush(struct net *net);
83740 void flow_cache_flush_deferred(struct net *net);
83741 -extern atomic_t flow_cache_genid;
83742 +extern atomic_unchecked_t flow_cache_genid;
83743
83744 #endif
83745 diff --git a/include/net/genetlink.h b/include/net/genetlink.h
83746 index 93695f0..766d71c 100644
83747 --- a/include/net/genetlink.h
83748 +++ b/include/net/genetlink.h
83749 @@ -120,7 +120,7 @@ struct genl_ops {
83750 u8 cmd;
83751 u8 internal_flags;
83752 u8 flags;
83753 -};
83754 +} __do_const;
83755
83756 int __genl_register_family(struct genl_family *family);
83757
83758 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
83759 index 734d9b5..48a9a4b 100644
83760 --- a/include/net/gro_cells.h
83761 +++ b/include/net/gro_cells.h
83762 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
83763 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
83764
83765 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
83766 - atomic_long_inc(&dev->rx_dropped);
83767 + atomic_long_inc_unchecked(&dev->rx_dropped);
83768 kfree_skb(skb);
83769 return;
83770 }
83771 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
83772 index 7a43138..bc76865 100644
83773 --- a/include/net/inet_connection_sock.h
83774 +++ b/include/net/inet_connection_sock.h
83775 @@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
83776 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
83777 int (*bind_conflict)(const struct sock *sk,
83778 const struct inet_bind_bucket *tb, bool relax);
83779 -};
83780 +} __do_const;
83781
83782 /** inet_connection_sock - INET connection oriented sock
83783 *
83784 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
83785 index 823ec7b..1af4453 100644
83786 --- a/include/net/inetpeer.h
83787 +++ b/include/net/inetpeer.h
83788 @@ -47,7 +47,7 @@ struct inet_peer {
83789 */
83790 union {
83791 struct {
83792 - atomic_t rid; /* Frag reception counter */
83793 + atomic_unchecked_t rid; /* Frag reception counter */
83794 };
83795 struct rcu_head rcu;
83796 struct inet_peer *gc_next;
83797 diff --git a/include/net/ip.h b/include/net/ip.h
83798 index 54de029..6a28064 100644
83799 --- a/include/net/ip.h
83800 +++ b/include/net/ip.h
83801 @@ -220,7 +220,7 @@ static inline void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
83802
83803 void inet_get_local_port_range(struct net *net, int *low, int *high);
83804
83805 -extern unsigned long *sysctl_local_reserved_ports;
83806 +extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
83807 static inline int inet_is_reserved_local_port(int port)
83808 {
83809 return test_bit(port, sysctl_local_reserved_ports);
83810 @@ -310,7 +310,7 @@ static inline unsigned int ip_skb_dst_mtu(const struct sk_buff *skb)
83811 }
83812 }
83813
83814 -u32 ip_idents_reserve(u32 hash, int segs);
83815 +u32 ip_idents_reserve(u32 hash, int segs) __intentional_overflow(-1);
83816 void __ip_select_ident(struct iphdr *iph, int segs);
83817
83818 static inline void ip_select_ident_segs(struct sk_buff *skb, struct sock *sk, int segs)
83819 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
83820 index 9922093..a1755d6 100644
83821 --- a/include/net/ip_fib.h
83822 +++ b/include/net/ip_fib.h
83823 @@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
83824
83825 #define FIB_RES_SADDR(net, res) \
83826 ((FIB_RES_NH(res).nh_saddr_genid == \
83827 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
83828 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
83829 FIB_RES_NH(res).nh_saddr : \
83830 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
83831 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
83832 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
83833 index 5679d92..2e7a690 100644
83834 --- a/include/net/ip_vs.h
83835 +++ b/include/net/ip_vs.h
83836 @@ -558,7 +558,7 @@ struct ip_vs_conn {
83837 struct ip_vs_conn *control; /* Master control connection */
83838 atomic_t n_control; /* Number of controlled ones */
83839 struct ip_vs_dest *dest; /* real server */
83840 - atomic_t in_pkts; /* incoming packet counter */
83841 + atomic_unchecked_t in_pkts; /* incoming packet counter */
83842
83843 /* packet transmitter for different forwarding methods. If it
83844 mangles the packet, it must return NF_DROP or better NF_STOLEN,
83845 @@ -705,7 +705,7 @@ struct ip_vs_dest {
83846 __be16 port; /* port number of the server */
83847 union nf_inet_addr addr; /* IP address of the server */
83848 volatile unsigned int flags; /* dest status flags */
83849 - atomic_t conn_flags; /* flags to copy to conn */
83850 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
83851 atomic_t weight; /* server weight */
83852
83853 atomic_t refcnt; /* reference counter */
83854 @@ -960,11 +960,11 @@ struct netns_ipvs {
83855 /* ip_vs_lblc */
83856 int sysctl_lblc_expiration;
83857 struct ctl_table_header *lblc_ctl_header;
83858 - struct ctl_table *lblc_ctl_table;
83859 + ctl_table_no_const *lblc_ctl_table;
83860 /* ip_vs_lblcr */
83861 int sysctl_lblcr_expiration;
83862 struct ctl_table_header *lblcr_ctl_header;
83863 - struct ctl_table *lblcr_ctl_table;
83864 + ctl_table_no_const *lblcr_ctl_table;
83865 /* ip_vs_est */
83866 struct list_head est_list; /* estimator list */
83867 spinlock_t est_lock;
83868 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
83869 index 8d4f588..2e37ad2 100644
83870 --- a/include/net/irda/ircomm_tty.h
83871 +++ b/include/net/irda/ircomm_tty.h
83872 @@ -33,6 +33,7 @@
83873 #include <linux/termios.h>
83874 #include <linux/timer.h>
83875 #include <linux/tty.h> /* struct tty_struct */
83876 +#include <asm/local.h>
83877
83878 #include <net/irda/irias_object.h>
83879 #include <net/irda/ircomm_core.h>
83880 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
83881 index 714cc9a..ea05f3e 100644
83882 --- a/include/net/iucv/af_iucv.h
83883 +++ b/include/net/iucv/af_iucv.h
83884 @@ -149,7 +149,7 @@ struct iucv_skb_cb {
83885 struct iucv_sock_list {
83886 struct hlist_head head;
83887 rwlock_t lock;
83888 - atomic_t autobind_name;
83889 + atomic_unchecked_t autobind_name;
83890 };
83891
83892 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
83893 diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
83894 index f3be818..bf46196 100644
83895 --- a/include/net/llc_c_ac.h
83896 +++ b/include/net/llc_c_ac.h
83897 @@ -87,7 +87,7 @@
83898 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
83899 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
83900
83901 -typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
83902 +typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
83903
83904 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
83905 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
83906 diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
83907 index 3948cf1..83b28c4 100644
83908 --- a/include/net/llc_c_ev.h
83909 +++ b/include/net/llc_c_ev.h
83910 @@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
83911 return (struct llc_conn_state_ev *)skb->cb;
83912 }
83913
83914 -typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
83915 -typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
83916 +typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
83917 +typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
83918
83919 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
83920 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
83921 diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
83922 index 0e79cfb..f46db31 100644
83923 --- a/include/net/llc_c_st.h
83924 +++ b/include/net/llc_c_st.h
83925 @@ -37,7 +37,7 @@ struct llc_conn_state_trans {
83926 u8 next_state;
83927 llc_conn_ev_qfyr_t *ev_qualifiers;
83928 llc_conn_action_t *ev_actions;
83929 -};
83930 +} __do_const;
83931
83932 struct llc_conn_state {
83933 u8 current_state;
83934 diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
83935 index a61b98c..aade1eb 100644
83936 --- a/include/net/llc_s_ac.h
83937 +++ b/include/net/llc_s_ac.h
83938 @@ -23,7 +23,7 @@
83939 #define SAP_ACT_TEST_IND 9
83940
83941 /* All action functions must look like this */
83942 -typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
83943 +typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
83944
83945 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
83946 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
83947 diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
83948 index 567c681..cd73ac02 100644
83949 --- a/include/net/llc_s_st.h
83950 +++ b/include/net/llc_s_st.h
83951 @@ -20,7 +20,7 @@ struct llc_sap_state_trans {
83952 llc_sap_ev_t ev;
83953 u8 next_state;
83954 llc_sap_action_t *ev_actions;
83955 -};
83956 +} __do_const;
83957
83958 struct llc_sap_state {
83959 u8 curr_state;
83960 diff --git a/include/net/mac80211.h b/include/net/mac80211.h
83961 index 8248e39..7610eec 100644
83962 --- a/include/net/mac80211.h
83963 +++ b/include/net/mac80211.h
83964 @@ -4467,7 +4467,7 @@ struct rate_control_ops {
83965 void (*add_sta_debugfs)(void *priv, void *priv_sta,
83966 struct dentry *dir);
83967 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
83968 -};
83969 +} __do_const;
83970
83971 static inline int rate_supported(struct ieee80211_sta *sta,
83972 enum ieee80211_band band,
83973 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
83974 index 7277caf..fd095bc 100644
83975 --- a/include/net/neighbour.h
83976 +++ b/include/net/neighbour.h
83977 @@ -163,7 +163,7 @@ struct neigh_ops {
83978 void (*error_report)(struct neighbour *, struct sk_buff *);
83979 int (*output)(struct neighbour *, struct sk_buff *);
83980 int (*connected_output)(struct neighbour *, struct sk_buff *);
83981 -};
83982 +} __do_const;
83983
83984 struct pneigh_entry {
83985 struct pneigh_entry *next;
83986 @@ -203,7 +203,6 @@ struct neigh_table {
83987 void (*proxy_redo)(struct sk_buff *skb);
83988 char *id;
83989 struct neigh_parms parms;
83990 - /* HACK. gc_* should follow parms without a gap! */
83991 int gc_interval;
83992 int gc_thresh1;
83993 int gc_thresh2;
83994 @@ -218,7 +217,7 @@ struct neigh_table {
83995 struct neigh_statistics __percpu *stats;
83996 struct neigh_hash_table __rcu *nht;
83997 struct pneigh_entry **phash_buckets;
83998 -};
83999 +} __randomize_layout;
84000
84001 static inline int neigh_parms_family(struct neigh_parms *p)
84002 {
84003 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
84004 index 5f9eb26..85699c4 100644
84005 --- a/include/net/net_namespace.h
84006 +++ b/include/net/net_namespace.h
84007 @@ -129,8 +129,8 @@ struct net {
84008 struct netns_ipvs *ipvs;
84009 #endif
84010 struct sock *diag_nlsk;
84011 - atomic_t fnhe_genid;
84012 -};
84013 + atomic_unchecked_t fnhe_genid;
84014 +} __randomize_layout;
84015
84016 #include <linux/seq_file_net.h>
84017
84018 @@ -286,7 +286,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
84019 #define __net_init __init
84020 #define __net_exit __exit_refok
84021 #define __net_initdata __initdata
84022 +#ifdef CONSTIFY_PLUGIN
84023 #define __net_initconst __initconst
84024 +#else
84025 +#define __net_initconst __initdata
84026 +#endif
84027 #endif
84028
84029 struct pernet_operations {
84030 @@ -296,7 +300,7 @@ struct pernet_operations {
84031 void (*exit_batch)(struct list_head *net_exit_list);
84032 int *id;
84033 size_t size;
84034 -};
84035 +} __do_const;
84036
84037 /*
84038 * Use these carefully. If you implement a network device and it
84039 @@ -344,23 +348,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
84040
84041 static inline int rt_genid_ipv4(struct net *net)
84042 {
84043 - return atomic_read(&net->ipv4.rt_genid);
84044 + return atomic_read_unchecked(&net->ipv4.rt_genid);
84045 }
84046
84047 static inline void rt_genid_bump_ipv4(struct net *net)
84048 {
84049 - atomic_inc(&net->ipv4.rt_genid);
84050 + atomic_inc_unchecked(&net->ipv4.rt_genid);
84051 }
84052
84053 #if IS_ENABLED(CONFIG_IPV6)
84054 static inline int rt_genid_ipv6(struct net *net)
84055 {
84056 - return atomic_read(&net->ipv6.rt_genid);
84057 + return atomic_read_unchecked(&net->ipv6.rt_genid);
84058 }
84059
84060 static inline void rt_genid_bump_ipv6(struct net *net)
84061 {
84062 - atomic_inc(&net->ipv6.rt_genid);
84063 + atomic_inc_unchecked(&net->ipv6.rt_genid);
84064 }
84065 #else
84066 static inline int rt_genid_ipv6(struct net *net)
84067 @@ -382,12 +386,12 @@ static inline void rt_genid_bump_all(struct net *net)
84068
84069 static inline int fnhe_genid(struct net *net)
84070 {
84071 - return atomic_read(&net->fnhe_genid);
84072 + return atomic_read_unchecked(&net->fnhe_genid);
84073 }
84074
84075 static inline void fnhe_genid_bump(struct net *net)
84076 {
84077 - atomic_inc(&net->fnhe_genid);
84078 + atomic_inc_unchecked(&net->fnhe_genid);
84079 }
84080
84081 #endif /* __NET_NET_NAMESPACE_H */
84082 diff --git a/include/net/netdma.h b/include/net/netdma.h
84083 index 8ba8ce2..99b7fff 100644
84084 --- a/include/net/netdma.h
84085 +++ b/include/net/netdma.h
84086 @@ -24,7 +24,7 @@
84087 #include <linux/dmaengine.h>
84088 #include <linux/skbuff.h>
84089
84090 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
84091 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
84092 struct sk_buff *skb, int offset, struct iovec *to,
84093 size_t len, struct dma_pinned_list *pinned_list);
84094
84095 diff --git a/include/net/netlink.h b/include/net/netlink.h
84096 index 2b47eaa..6d5bcc2 100644
84097 --- a/include/net/netlink.h
84098 +++ b/include/net/netlink.h
84099 @@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
84100 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
84101 {
84102 if (mark)
84103 - skb_trim(skb, (unsigned char *) mark - skb->data);
84104 + skb_trim(skb, (const unsigned char *) mark - skb->data);
84105 }
84106
84107 /**
84108 diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
84109 index 773cce3..6a11852 100644
84110 --- a/include/net/netns/conntrack.h
84111 +++ b/include/net/netns/conntrack.h
84112 @@ -13,10 +13,10 @@ struct nf_conntrack_ecache;
84113 struct nf_proto_net {
84114 #ifdef CONFIG_SYSCTL
84115 struct ctl_table_header *ctl_table_header;
84116 - struct ctl_table *ctl_table;
84117 + ctl_table_no_const *ctl_table;
84118 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
84119 struct ctl_table_header *ctl_compat_header;
84120 - struct ctl_table *ctl_compat_table;
84121 + ctl_table_no_const *ctl_compat_table;
84122 #endif
84123 #endif
84124 unsigned int users;
84125 @@ -59,7 +59,7 @@ struct nf_ip_net {
84126 struct nf_icmp_net icmpv6;
84127 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
84128 struct ctl_table_header *ctl_table_header;
84129 - struct ctl_table *ctl_table;
84130 + ctl_table_no_const *ctl_table;
84131 #endif
84132 };
84133
84134 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
84135 index b2704fd0..421d717 100644
84136 --- a/include/net/netns/ipv4.h
84137 +++ b/include/net/netns/ipv4.h
84138 @@ -79,7 +79,7 @@ struct netns_ipv4 {
84139
84140 struct ping_group_range ping_group_range;
84141
84142 - atomic_t dev_addr_genid;
84143 + atomic_unchecked_t dev_addr_genid;
84144
84145 #ifdef CONFIG_IP_MROUTE
84146 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
84147 @@ -89,6 +89,6 @@ struct netns_ipv4 {
84148 struct fib_rules_ops *mr_rules_ops;
84149 #endif
84150 #endif
84151 - atomic_t rt_genid;
84152 + atomic_unchecked_t rt_genid;
84153 };
84154 #endif
84155 diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
84156 index 21edaf1..4c5faae 100644
84157 --- a/include/net/netns/ipv6.h
84158 +++ b/include/net/netns/ipv6.h
84159 @@ -73,8 +73,8 @@ struct netns_ipv6 {
84160 struct fib_rules_ops *mr6_rules_ops;
84161 #endif
84162 #endif
84163 - atomic_t dev_addr_genid;
84164 - atomic_t rt_genid;
84165 + atomic_unchecked_t dev_addr_genid;
84166 + atomic_unchecked_t rt_genid;
84167 };
84168
84169 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
84170 diff --git a/include/net/netns/xfrm.h b/include/net/netns/xfrm.h
84171 index 3492434..209f58c 100644
84172 --- a/include/net/netns/xfrm.h
84173 +++ b/include/net/netns/xfrm.h
84174 @@ -64,7 +64,7 @@ struct netns_xfrm {
84175
84176 /* flow cache part */
84177 struct flow_cache flow_cache_global;
84178 - atomic_t flow_cache_genid;
84179 + atomic_unchecked_t flow_cache_genid;
84180 struct list_head flow_cache_gc_list;
84181 spinlock_t flow_cache_gc_lock;
84182 struct work_struct flow_cache_gc_work;
84183 diff --git a/include/net/ping.h b/include/net/ping.h
84184 index 026479b..d9b2829 100644
84185 --- a/include/net/ping.h
84186 +++ b/include/net/ping.h
84187 @@ -54,7 +54,7 @@ struct ping_iter_state {
84188
84189 extern struct proto ping_prot;
84190 #if IS_ENABLED(CONFIG_IPV6)
84191 -extern struct pingv6_ops pingv6_ops;
84192 +extern struct pingv6_ops *pingv6_ops;
84193 #endif
84194
84195 struct pingfakehdr {
84196 diff --git a/include/net/protocol.h b/include/net/protocol.h
84197 index a7e986b..dc67bce 100644
84198 --- a/include/net/protocol.h
84199 +++ b/include/net/protocol.h
84200 @@ -49,7 +49,7 @@ struct net_protocol {
84201 * socket lookup?
84202 */
84203 icmp_strict_tag_validation:1;
84204 -};
84205 +} __do_const;
84206
84207 #if IS_ENABLED(CONFIG_IPV6)
84208 struct inet6_protocol {
84209 @@ -62,7 +62,7 @@ struct inet6_protocol {
84210 u8 type, u8 code, int offset,
84211 __be32 info);
84212 unsigned int flags; /* INET6_PROTO_xxx */
84213 -};
84214 +} __do_const;
84215
84216 #define INET6_PROTO_NOPOLICY 0x1
84217 #define INET6_PROTO_FINAL 0x2
84218 diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
84219 index 72240e5..8c14bef 100644
84220 --- a/include/net/rtnetlink.h
84221 +++ b/include/net/rtnetlink.h
84222 @@ -93,7 +93,7 @@ struct rtnl_link_ops {
84223 int (*fill_slave_info)(struct sk_buff *skb,
84224 const struct net_device *dev,
84225 const struct net_device *slave_dev);
84226 -};
84227 +} __do_const;
84228
84229 int __rtnl_link_register(struct rtnl_link_ops *ops);
84230 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
84231 diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
84232 index 4a5b9a3..ca27d73 100644
84233 --- a/include/net/sctp/checksum.h
84234 +++ b/include/net/sctp/checksum.h
84235 @@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
84236 unsigned int offset)
84237 {
84238 struct sctphdr *sh = sctp_hdr(skb);
84239 - __le32 ret, old = sh->checksum;
84240 - const struct skb_checksum_ops ops = {
84241 + __le32 ret, old = sh->checksum;
84242 + static const struct skb_checksum_ops ops = {
84243 .update = sctp_csum_update,
84244 .combine = sctp_csum_combine,
84245 };
84246 diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
84247 index 7f4eeb3..37e8fe1 100644
84248 --- a/include/net/sctp/sm.h
84249 +++ b/include/net/sctp/sm.h
84250 @@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
84251 typedef struct {
84252 sctp_state_fn_t *fn;
84253 const char *name;
84254 -} sctp_sm_table_entry_t;
84255 +} __do_const sctp_sm_table_entry_t;
84256
84257 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
84258 * currently in use.
84259 @@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
84260 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
84261
84262 /* Extern declarations for major data structures. */
84263 -extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
84264 +extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
84265
84266
84267 /* Get the size of a DATA chunk payload. */
84268 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
84269 index 0dfcc92..7967849 100644
84270 --- a/include/net/sctp/structs.h
84271 +++ b/include/net/sctp/structs.h
84272 @@ -507,7 +507,7 @@ struct sctp_pf {
84273 struct sctp_association *asoc);
84274 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
84275 struct sctp_af *af;
84276 -};
84277 +} __do_const;
84278
84279
84280 /* Structure to track chunk fragments that have been acked, but peer
84281 diff --git a/include/net/sock.h b/include/net/sock.h
84282 index f5a7e22..043b85f 100644
84283 --- a/include/net/sock.h
84284 +++ b/include/net/sock.h
84285 @@ -348,7 +348,7 @@ struct sock {
84286 unsigned int sk_napi_id;
84287 unsigned int sk_ll_usec;
84288 #endif
84289 - atomic_t sk_drops;
84290 + atomic_unchecked_t sk_drops;
84291 int sk_rcvbuf;
84292
84293 struct sk_filter __rcu *sk_filter;
84294 @@ -1036,7 +1036,7 @@ struct proto {
84295 void (*destroy_cgroup)(struct mem_cgroup *memcg);
84296 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
84297 #endif
84298 -};
84299 +} __randomize_layout;
84300
84301 /*
84302 * Bits in struct cg_proto.flags
84303 @@ -1223,7 +1223,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
84304 return ret >> PAGE_SHIFT;
84305 }
84306
84307 -static inline long
84308 +static inline long __intentional_overflow(-1)
84309 sk_memory_allocated(const struct sock *sk)
84310 {
84311 struct proto *prot = sk->sk_prot;
84312 @@ -1368,7 +1368,7 @@ struct sock_iocb {
84313 struct scm_cookie *scm;
84314 struct msghdr *msg, async_msg;
84315 struct kiocb *kiocb;
84316 -};
84317 +} __randomize_layout;
84318
84319 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
84320 {
84321 @@ -1803,7 +1803,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
84322 }
84323
84324 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
84325 - char __user *from, char *to,
84326 + char __user *from, unsigned char *to,
84327 int copy, int offset)
84328 {
84329 if (skb->ip_summed == CHECKSUM_NONE) {
84330 @@ -2065,7 +2065,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
84331 }
84332 }
84333
84334 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
84335 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
84336
84337 /**
84338 * sk_page_frag - return an appropriate page_frag
84339 diff --git a/include/net/tcp.h b/include/net/tcp.h
84340 index 87d8774..cf214f8 100644
84341 --- a/include/net/tcp.h
84342 +++ b/include/net/tcp.h
84343 @@ -541,7 +541,7 @@ void tcp_retransmit_timer(struct sock *sk);
84344 void tcp_xmit_retransmit_queue(struct sock *);
84345 void tcp_simple_retransmit(struct sock *);
84346 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
84347 -int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
84348 +int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
84349
84350 void tcp_send_probe0(struct sock *);
84351 void tcp_send_partial(struct sock *);
84352 @@ -715,8 +715,8 @@ struct tcp_skb_cb {
84353 struct inet6_skb_parm h6;
84354 #endif
84355 } header; /* For incoming frames */
84356 - __u32 seq; /* Starting sequence number */
84357 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
84358 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
84359 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
84360 __u32 when; /* used to compute rtt's */
84361 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
84362
84363 @@ -730,7 +730,7 @@ struct tcp_skb_cb {
84364
84365 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
84366 /* 1 byte hole */
84367 - __u32 ack_seq; /* Sequence number ACK'd */
84368 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
84369 };
84370
84371 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
84372 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
84373 index 116e9c7..3070537 100644
84374 --- a/include/net/xfrm.h
84375 +++ b/include/net/xfrm.h
84376 @@ -285,7 +285,6 @@ struct xfrm_dst;
84377 struct xfrm_policy_afinfo {
84378 unsigned short family;
84379 struct dst_ops *dst_ops;
84380 - void (*garbage_collect)(struct net *net);
84381 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
84382 const xfrm_address_t *saddr,
84383 const xfrm_address_t *daddr);
84384 @@ -303,7 +302,7 @@ struct xfrm_policy_afinfo {
84385 struct net_device *dev,
84386 const struct flowi *fl);
84387 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
84388 -};
84389 +} __do_const;
84390
84391 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
84392 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
84393 @@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
84394 int (*transport_finish)(struct sk_buff *skb,
84395 int async);
84396 void (*local_error)(struct sk_buff *skb, u32 mtu);
84397 -};
84398 +} __do_const;
84399
84400 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
84401 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
84402 @@ -437,7 +436,7 @@ struct xfrm_mode {
84403 struct module *owner;
84404 unsigned int encap;
84405 int flags;
84406 -};
84407 +} __do_const;
84408
84409 /* Flags for xfrm_mode. */
84410 enum {
84411 @@ -534,7 +533,7 @@ struct xfrm_policy {
84412 struct timer_list timer;
84413
84414 struct flow_cache_object flo;
84415 - atomic_t genid;
84416 + atomic_unchecked_t genid;
84417 u32 priority;
84418 u32 index;
84419 struct xfrm_mark mark;
84420 @@ -1180,6 +1179,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
84421 }
84422
84423 void xfrm_garbage_collect(struct net *net);
84424 +void xfrm_garbage_collect_deferred(struct net *net);
84425
84426 #else
84427
84428 @@ -1218,6 +1218,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
84429 static inline void xfrm_garbage_collect(struct net *net)
84430 {
84431 }
84432 +static inline void xfrm_garbage_collect_deferred(struct net *net)
84433 +{
84434 +}
84435 #endif
84436
84437 static __inline__
84438 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
84439 index 1017e0b..227aa4d 100644
84440 --- a/include/rdma/iw_cm.h
84441 +++ b/include/rdma/iw_cm.h
84442 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
84443 int backlog);
84444
84445 int (*destroy_listen)(struct iw_cm_id *cm_id);
84446 -};
84447 +} __no_const;
84448
84449 /**
84450 * iw_create_cm_id - Create an IW CM identifier.
84451 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
84452 index 52beadf..598734c 100644
84453 --- a/include/scsi/libfc.h
84454 +++ b/include/scsi/libfc.h
84455 @@ -771,6 +771,7 @@ struct libfc_function_template {
84456 */
84457 void (*disc_stop_final) (struct fc_lport *);
84458 };
84459 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
84460
84461 /**
84462 * struct fc_disc - Discovery context
84463 @@ -875,7 +876,7 @@ struct fc_lport {
84464 struct fc_vport *vport;
84465
84466 /* Operational Information */
84467 - struct libfc_function_template tt;
84468 + libfc_function_template_no_const tt;
84469 u8 link_up;
84470 u8 qfull;
84471 enum fc_lport_state state;
84472 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
84473 index 27ab310..60dc245 100644
84474 --- a/include/scsi/scsi_device.h
84475 +++ b/include/scsi/scsi_device.h
84476 @@ -187,9 +187,9 @@ struct scsi_device {
84477 unsigned int max_device_blocked; /* what device_blocked counts down from */
84478 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
84479
84480 - atomic_t iorequest_cnt;
84481 - atomic_t iodone_cnt;
84482 - atomic_t ioerr_cnt;
84483 + atomic_unchecked_t iorequest_cnt;
84484 + atomic_unchecked_t iodone_cnt;
84485 + atomic_unchecked_t ioerr_cnt;
84486
84487 struct device sdev_gendev,
84488 sdev_dev;
84489 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
84490 index 8c79980..723f6f9 100644
84491 --- a/include/scsi/scsi_transport_fc.h
84492 +++ b/include/scsi/scsi_transport_fc.h
84493 @@ -752,7 +752,8 @@ struct fc_function_template {
84494 unsigned long show_host_system_hostname:1;
84495
84496 unsigned long disable_target_scan:1;
84497 -};
84498 +} __do_const;
84499 +typedef struct fc_function_template __no_const fc_function_template_no_const;
84500
84501
84502 /**
84503 diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
84504 index ae6c3b8..fd748ac 100644
84505 --- a/include/sound/compress_driver.h
84506 +++ b/include/sound/compress_driver.h
84507 @@ -128,7 +128,7 @@ struct snd_compr_ops {
84508 struct snd_compr_caps *caps);
84509 int (*get_codec_caps) (struct snd_compr_stream *stream,
84510 struct snd_compr_codec_caps *codec);
84511 -};
84512 +} __no_const;
84513
84514 /**
84515 * struct snd_compr: Compressed device
84516 diff --git a/include/sound/soc.h b/include/sound/soc.h
84517 index 0b83168..d67280a 100644
84518 --- a/include/sound/soc.h
84519 +++ b/include/sound/soc.h
84520 @@ -782,7 +782,7 @@ struct snd_soc_codec_driver {
84521 /* probe ordering - for components with runtime dependencies */
84522 int probe_order;
84523 int remove_order;
84524 -};
84525 +} __do_const;
84526
84527 /* SoC platform interface */
84528 struct snd_soc_platform_driver {
84529 @@ -828,7 +828,7 @@ struct snd_soc_platform_driver {
84530 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
84531 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
84532 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
84533 -};
84534 +} __do_const;
84535
84536 struct snd_soc_platform {
84537 const char *name;
84538 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
84539 index 9ec9864..e2ee1ee 100644
84540 --- a/include/target/target_core_base.h
84541 +++ b/include/target/target_core_base.h
84542 @@ -761,7 +761,7 @@ struct se_device {
84543 atomic_long_t write_bytes;
84544 /* Active commands on this virtual SE device */
84545 atomic_t simple_cmds;
84546 - atomic_t dev_ordered_id;
84547 + atomic_unchecked_t dev_ordered_id;
84548 atomic_t dev_ordered_sync;
84549 atomic_t dev_qf_count;
84550 int export_count;
84551 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
84552 new file mode 100644
84553 index 0000000..fb634b7
84554 --- /dev/null
84555 +++ b/include/trace/events/fs.h
84556 @@ -0,0 +1,53 @@
84557 +#undef TRACE_SYSTEM
84558 +#define TRACE_SYSTEM fs
84559 +
84560 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
84561 +#define _TRACE_FS_H
84562 +
84563 +#include <linux/fs.h>
84564 +#include <linux/tracepoint.h>
84565 +
84566 +TRACE_EVENT(do_sys_open,
84567 +
84568 + TP_PROTO(const char *filename, int flags, int mode),
84569 +
84570 + TP_ARGS(filename, flags, mode),
84571 +
84572 + TP_STRUCT__entry(
84573 + __string( filename, filename )
84574 + __field( int, flags )
84575 + __field( int, mode )
84576 + ),
84577 +
84578 + TP_fast_assign(
84579 + __assign_str(filename, filename);
84580 + __entry->flags = flags;
84581 + __entry->mode = mode;
84582 + ),
84583 +
84584 + TP_printk("\"%s\" %x %o",
84585 + __get_str(filename), __entry->flags, __entry->mode)
84586 +);
84587 +
84588 +TRACE_EVENT(open_exec,
84589 +
84590 + TP_PROTO(const char *filename),
84591 +
84592 + TP_ARGS(filename),
84593 +
84594 + TP_STRUCT__entry(
84595 + __string( filename, filename )
84596 + ),
84597 +
84598 + TP_fast_assign(
84599 + __assign_str(filename, filename);
84600 + ),
84601 +
84602 + TP_printk("\"%s\"",
84603 + __get_str(filename))
84604 +);
84605 +
84606 +#endif /* _TRACE_FS_H */
84607 +
84608 +/* This part must be outside protection */
84609 +#include <trace/define_trace.h>
84610 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
84611 index 1c09820..7f5ec79 100644
84612 --- a/include/trace/events/irq.h
84613 +++ b/include/trace/events/irq.h
84614 @@ -36,7 +36,7 @@ struct softirq_action;
84615 */
84616 TRACE_EVENT(irq_handler_entry,
84617
84618 - TP_PROTO(int irq, struct irqaction *action),
84619 + TP_PROTO(int irq, const struct irqaction *action),
84620
84621 TP_ARGS(irq, action),
84622
84623 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
84624 */
84625 TRACE_EVENT(irq_handler_exit,
84626
84627 - TP_PROTO(int irq, struct irqaction *action, int ret),
84628 + TP_PROTO(int irq, const struct irqaction *action, int ret),
84629
84630 TP_ARGS(irq, action, ret),
84631
84632 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
84633 index 7caf44c..23c6f27 100644
84634 --- a/include/uapi/linux/a.out.h
84635 +++ b/include/uapi/linux/a.out.h
84636 @@ -39,6 +39,14 @@ enum machine_type {
84637 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
84638 };
84639
84640 +/* Constants for the N_FLAGS field */
84641 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
84642 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
84643 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
84644 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
84645 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
84646 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
84647 +
84648 #if !defined (N_MAGIC)
84649 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
84650 #endif
84651 diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
84652 index 22b6ad3..aeba37e 100644
84653 --- a/include/uapi/linux/bcache.h
84654 +++ b/include/uapi/linux/bcache.h
84655 @@ -5,6 +5,7 @@
84656 * Bcache on disk data structures
84657 */
84658
84659 +#include <linux/compiler.h>
84660 #include <asm/types.h>
84661
84662 #define BITMASK(name, type, field, offset, size) \
84663 @@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
84664 /* Btree keys - all units are in sectors */
84665
84666 struct bkey {
84667 - __u64 high;
84668 - __u64 low;
84669 + __u64 high __intentional_overflow(-1);
84670 + __u64 low __intentional_overflow(-1);
84671 __u64 ptr[];
84672 };
84673
84674 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
84675 index d876736..ccce5c0 100644
84676 --- a/include/uapi/linux/byteorder/little_endian.h
84677 +++ b/include/uapi/linux/byteorder/little_endian.h
84678 @@ -42,51 +42,51 @@
84679
84680 static inline __le64 __cpu_to_le64p(const __u64 *p)
84681 {
84682 - return (__force __le64)*p;
84683 + return (__force const __le64)*p;
84684 }
84685 -static inline __u64 __le64_to_cpup(const __le64 *p)
84686 +static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
84687 {
84688 - return (__force __u64)*p;
84689 + return (__force const __u64)*p;
84690 }
84691 static inline __le32 __cpu_to_le32p(const __u32 *p)
84692 {
84693 - return (__force __le32)*p;
84694 + return (__force const __le32)*p;
84695 }
84696 static inline __u32 __le32_to_cpup(const __le32 *p)
84697 {
84698 - return (__force __u32)*p;
84699 + return (__force const __u32)*p;
84700 }
84701 static inline __le16 __cpu_to_le16p(const __u16 *p)
84702 {
84703 - return (__force __le16)*p;
84704 + return (__force const __le16)*p;
84705 }
84706 static inline __u16 __le16_to_cpup(const __le16 *p)
84707 {
84708 - return (__force __u16)*p;
84709 + return (__force const __u16)*p;
84710 }
84711 static inline __be64 __cpu_to_be64p(const __u64 *p)
84712 {
84713 - return (__force __be64)__swab64p(p);
84714 + return (__force const __be64)__swab64p(p);
84715 }
84716 static inline __u64 __be64_to_cpup(const __be64 *p)
84717 {
84718 - return __swab64p((__u64 *)p);
84719 + return __swab64p((const __u64 *)p);
84720 }
84721 static inline __be32 __cpu_to_be32p(const __u32 *p)
84722 {
84723 - return (__force __be32)__swab32p(p);
84724 + return (__force const __be32)__swab32p(p);
84725 }
84726 -static inline __u32 __be32_to_cpup(const __be32 *p)
84727 +static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
84728 {
84729 - return __swab32p((__u32 *)p);
84730 + return __swab32p((const __u32 *)p);
84731 }
84732 static inline __be16 __cpu_to_be16p(const __u16 *p)
84733 {
84734 - return (__force __be16)__swab16p(p);
84735 + return (__force const __be16)__swab16p(p);
84736 }
84737 static inline __u16 __be16_to_cpup(const __be16 *p)
84738 {
84739 - return __swab16p((__u16 *)p);
84740 + return __swab16p((const __u16 *)p);
84741 }
84742 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
84743 #define __le64_to_cpus(x) do { (void)(x); } while (0)
84744 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
84745 index ef6103b..d4e65dd 100644
84746 --- a/include/uapi/linux/elf.h
84747 +++ b/include/uapi/linux/elf.h
84748 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
84749 #define PT_GNU_EH_FRAME 0x6474e550
84750
84751 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
84752 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
84753 +
84754 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
84755 +
84756 +/* Constants for the e_flags field */
84757 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
84758 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
84759 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
84760 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
84761 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
84762 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
84763
84764 /*
84765 * Extended Numbering
84766 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
84767 #define DT_DEBUG 21
84768 #define DT_TEXTREL 22
84769 #define DT_JMPREL 23
84770 +#define DT_FLAGS 30
84771 + #define DF_TEXTREL 0x00000004
84772 #define DT_ENCODING 32
84773 #define OLD_DT_LOOS 0x60000000
84774 #define DT_LOOS 0x6000000d
84775 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
84776 #define PF_W 0x2
84777 #define PF_X 0x1
84778
84779 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
84780 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
84781 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
84782 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
84783 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
84784 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
84785 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
84786 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
84787 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
84788 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
84789 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
84790 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
84791 +
84792 typedef struct elf32_phdr{
84793 Elf32_Word p_type;
84794 Elf32_Off p_offset;
84795 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
84796 #define EI_OSABI 7
84797 #define EI_PAD 8
84798
84799 +#define EI_PAX 14
84800 +
84801 #define ELFMAG0 0x7f /* EI_MAG */
84802 #define ELFMAG1 'E'
84803 #define ELFMAG2 'L'
84804 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
84805 index aa169c4..6a2771d 100644
84806 --- a/include/uapi/linux/personality.h
84807 +++ b/include/uapi/linux/personality.h
84808 @@ -30,6 +30,7 @@ enum {
84809 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
84810 ADDR_NO_RANDOMIZE | \
84811 ADDR_COMPAT_LAYOUT | \
84812 + ADDR_LIMIT_3GB | \
84813 MMAP_PAGE_ZERO)
84814
84815 /*
84816 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
84817 index 7530e74..e714828 100644
84818 --- a/include/uapi/linux/screen_info.h
84819 +++ b/include/uapi/linux/screen_info.h
84820 @@ -43,7 +43,8 @@ struct screen_info {
84821 __u16 pages; /* 0x32 */
84822 __u16 vesa_attributes; /* 0x34 */
84823 __u32 capabilities; /* 0x36 */
84824 - __u8 _reserved[6]; /* 0x3a */
84825 + __u16 vesapm_size; /* 0x3a */
84826 + __u8 _reserved[4]; /* 0x3c */
84827 } __attribute__((packed));
84828
84829 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
84830 diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
84831 index 0e011eb..82681b1 100644
84832 --- a/include/uapi/linux/swab.h
84833 +++ b/include/uapi/linux/swab.h
84834 @@ -43,7 +43,7 @@
84835 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
84836 */
84837
84838 -static inline __attribute_const__ __u16 __fswab16(__u16 val)
84839 +static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
84840 {
84841 #ifdef __HAVE_BUILTIN_BSWAP16__
84842 return __builtin_bswap16(val);
84843 @@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
84844 #endif
84845 }
84846
84847 -static inline __attribute_const__ __u32 __fswab32(__u32 val)
84848 +static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
84849 {
84850 #ifdef __HAVE_BUILTIN_BSWAP32__
84851 return __builtin_bswap32(val);
84852 @@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
84853 #endif
84854 }
84855
84856 -static inline __attribute_const__ __u64 __fswab64(__u64 val)
84857 +static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
84858 {
84859 #ifdef __HAVE_BUILTIN_BSWAP64__
84860 return __builtin_bswap64(val);
84861 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
84862 index 6d67213..552fdd9 100644
84863 --- a/include/uapi/linux/sysctl.h
84864 +++ b/include/uapi/linux/sysctl.h
84865 @@ -155,8 +155,6 @@ enum
84866 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
84867 };
84868
84869 -
84870 -
84871 /* CTL_VM names: */
84872 enum
84873 {
84874 diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
84875 index ea468ee..4d367a5 100644
84876 --- a/include/uapi/linux/videodev2.h
84877 +++ b/include/uapi/linux/videodev2.h
84878 @@ -1248,7 +1248,7 @@ struct v4l2_ext_control {
84879 union {
84880 __s32 value;
84881 __s64 value64;
84882 - char *string;
84883 + char __user *string;
84884 };
84885 } __attribute__ ((packed));
84886
84887 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
84888 index c38355c..17a57bc 100644
84889 --- a/include/uapi/linux/xattr.h
84890 +++ b/include/uapi/linux/xattr.h
84891 @@ -73,5 +73,9 @@
84892 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
84893 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
84894
84895 +/* User namespace */
84896 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
84897 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
84898 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
84899
84900 #endif /* _UAPI_LINUX_XATTR_H */
84901 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
84902 index f9466fa..f4e2b81 100644
84903 --- a/include/video/udlfb.h
84904 +++ b/include/video/udlfb.h
84905 @@ -53,10 +53,10 @@ struct dlfb_data {
84906 u32 pseudo_palette[256];
84907 int blank_mode; /*one of FB_BLANK_ */
84908 /* blit-only rendering path metrics, exposed through sysfs */
84909 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
84910 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
84911 - atomic_t bytes_sent; /* to usb, after compression including overhead */
84912 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
84913 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
84914 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
84915 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
84916 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
84917 };
84918
84919 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
84920 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
84921 index 30f5362..8ed8ac9 100644
84922 --- a/include/video/uvesafb.h
84923 +++ b/include/video/uvesafb.h
84924 @@ -122,6 +122,7 @@ struct uvesafb_par {
84925 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
84926 u8 pmi_setpal; /* PMI for palette changes */
84927 u16 *pmi_base; /* protected mode interface location */
84928 + u8 *pmi_code; /* protected mode code location */
84929 void *pmi_start;
84930 void *pmi_pal;
84931 u8 *vbe_state_orig; /*
84932 diff --git a/init/Kconfig b/init/Kconfig
84933 index 9d3585b..ad45d34 100644
84934 --- a/init/Kconfig
84935 +++ b/init/Kconfig
84936 @@ -1093,6 +1093,7 @@ endif # CGROUPS
84937
84938 config CHECKPOINT_RESTORE
84939 bool "Checkpoint/restore support" if EXPERT
84940 + depends on !GRKERNSEC
84941 default n
84942 help
84943 Enables additional kernel features in a sake of checkpoint/restore.
84944 @@ -1570,7 +1571,7 @@ config SLUB_DEBUG
84945
84946 config COMPAT_BRK
84947 bool "Disable heap randomization"
84948 - default y
84949 + default n
84950 help
84951 Randomizing heap placement makes heap exploits harder, but it
84952 also breaks ancient binaries (including anything libc5 based).
84953 @@ -1858,7 +1859,7 @@ config INIT_ALL_POSSIBLE
84954 config STOP_MACHINE
84955 bool
84956 default y
84957 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
84958 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
84959 help
84960 Need stop_machine() primitive.
84961
84962 diff --git a/init/Makefile b/init/Makefile
84963 index 7bc47ee..6da2dc7 100644
84964 --- a/init/Makefile
84965 +++ b/init/Makefile
84966 @@ -2,6 +2,9 @@
84967 # Makefile for the linux kernel.
84968 #
84969
84970 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
84971 +asflags-y := $(GCC_PLUGINS_AFLAGS)
84972 +
84973 obj-y := main.o version.o mounts.o
84974 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
84975 obj-y += noinitramfs.o
84976 diff --git a/init/do_mounts.c b/init/do_mounts.c
84977 index 82f2288..ea1430a 100644
84978 --- a/init/do_mounts.c
84979 +++ b/init/do_mounts.c
84980 @@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
84981 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
84982 {
84983 struct super_block *s;
84984 - int err = sys_mount(name, "/root", fs, flags, data);
84985 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
84986 if (err)
84987 return err;
84988
84989 - sys_chdir("/root");
84990 + sys_chdir((const char __force_user *)"/root");
84991 s = current->fs->pwd.dentry->d_sb;
84992 ROOT_DEV = s->s_dev;
84993 printk(KERN_INFO
84994 @@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
84995 va_start(args, fmt);
84996 vsprintf(buf, fmt, args);
84997 va_end(args);
84998 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
84999 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
85000 if (fd >= 0) {
85001 sys_ioctl(fd, FDEJECT, 0);
85002 sys_close(fd);
85003 }
85004 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
85005 - fd = sys_open("/dev/console", O_RDWR, 0);
85006 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
85007 if (fd >= 0) {
85008 sys_ioctl(fd, TCGETS, (long)&termios);
85009 termios.c_lflag &= ~ICANON;
85010 sys_ioctl(fd, TCSETSF, (long)&termios);
85011 - sys_read(fd, &c, 1);
85012 + sys_read(fd, (char __user *)&c, 1);
85013 termios.c_lflag |= ICANON;
85014 sys_ioctl(fd, TCSETSF, (long)&termios);
85015 sys_close(fd);
85016 @@ -589,8 +589,8 @@ void __init prepare_namespace(void)
85017 mount_root();
85018 out:
85019 devtmpfs_mount("dev");
85020 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
85021 - sys_chroot(".");
85022 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
85023 + sys_chroot((const char __force_user *)".");
85024 }
85025
85026 static bool is_tmpfs;
85027 diff --git a/init/do_mounts.h b/init/do_mounts.h
85028 index f5b978a..69dbfe8 100644
85029 --- a/init/do_mounts.h
85030 +++ b/init/do_mounts.h
85031 @@ -15,15 +15,15 @@ extern int root_mountflags;
85032
85033 static inline int create_dev(char *name, dev_t dev)
85034 {
85035 - sys_unlink(name);
85036 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
85037 + sys_unlink((char __force_user *)name);
85038 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
85039 }
85040
85041 #if BITS_PER_LONG == 32
85042 static inline u32 bstat(char *name)
85043 {
85044 struct stat64 stat;
85045 - if (sys_stat64(name, &stat) != 0)
85046 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
85047 return 0;
85048 if (!S_ISBLK(stat.st_mode))
85049 return 0;
85050 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
85051 static inline u32 bstat(char *name)
85052 {
85053 struct stat stat;
85054 - if (sys_newstat(name, &stat) != 0)
85055 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
85056 return 0;
85057 if (!S_ISBLK(stat.st_mode))
85058 return 0;
85059 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
85060 index 3e0878e..8a9d7a0 100644
85061 --- a/init/do_mounts_initrd.c
85062 +++ b/init/do_mounts_initrd.c
85063 @@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
85064 {
85065 sys_unshare(CLONE_FS | CLONE_FILES);
85066 /* stdin/stdout/stderr for /linuxrc */
85067 - sys_open("/dev/console", O_RDWR, 0);
85068 + sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
85069 sys_dup(0);
85070 sys_dup(0);
85071 /* move initrd over / and chdir/chroot in initrd root */
85072 - sys_chdir("/root");
85073 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
85074 - sys_chroot(".");
85075 + sys_chdir((const char __force_user *)"/root");
85076 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
85077 + sys_chroot((const char __force_user *)".");
85078 sys_setsid();
85079 return 0;
85080 }
85081 @@ -59,8 +59,8 @@ static void __init handle_initrd(void)
85082 create_dev("/dev/root.old", Root_RAM0);
85083 /* mount initrd on rootfs' /root */
85084 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
85085 - sys_mkdir("/old", 0700);
85086 - sys_chdir("/old");
85087 + sys_mkdir((const char __force_user *)"/old", 0700);
85088 + sys_chdir((const char __force_user *)"/old");
85089
85090 /* try loading default modules from initrd */
85091 load_default_modules();
85092 @@ -80,31 +80,31 @@ static void __init handle_initrd(void)
85093 current->flags &= ~PF_FREEZER_SKIP;
85094
85095 /* move initrd to rootfs' /old */
85096 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
85097 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
85098 /* switch root and cwd back to / of rootfs */
85099 - sys_chroot("..");
85100 + sys_chroot((const char __force_user *)"..");
85101
85102 if (new_decode_dev(real_root_dev) == Root_RAM0) {
85103 - sys_chdir("/old");
85104 + sys_chdir((const char __force_user *)"/old");
85105 return;
85106 }
85107
85108 - sys_chdir("/");
85109 + sys_chdir((const char __force_user *)"/");
85110 ROOT_DEV = new_decode_dev(real_root_dev);
85111 mount_root();
85112
85113 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
85114 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
85115 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
85116 if (!error)
85117 printk("okay\n");
85118 else {
85119 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
85120 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
85121 if (error == -ENOENT)
85122 printk("/initrd does not exist. Ignored.\n");
85123 else
85124 printk("failed\n");
85125 printk(KERN_NOTICE "Unmounting old root\n");
85126 - sys_umount("/old", MNT_DETACH);
85127 + sys_umount((char __force_user *)"/old", MNT_DETACH);
85128 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
85129 if (fd < 0) {
85130 error = fd;
85131 @@ -127,11 +127,11 @@ int __init initrd_load(void)
85132 * mounted in the normal path.
85133 */
85134 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
85135 - sys_unlink("/initrd.image");
85136 + sys_unlink((const char __force_user *)"/initrd.image");
85137 handle_initrd();
85138 return 1;
85139 }
85140 }
85141 - sys_unlink("/initrd.image");
85142 + sys_unlink((const char __force_user *)"/initrd.image");
85143 return 0;
85144 }
85145 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
85146 index 8cb6db5..d729f50 100644
85147 --- a/init/do_mounts_md.c
85148 +++ b/init/do_mounts_md.c
85149 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
85150 partitioned ? "_d" : "", minor,
85151 md_setup_args[ent].device_names);
85152
85153 - fd = sys_open(name, 0, 0);
85154 + fd = sys_open((char __force_user *)name, 0, 0);
85155 if (fd < 0) {
85156 printk(KERN_ERR "md: open failed - cannot start "
85157 "array %s\n", name);
85158 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
85159 * array without it
85160 */
85161 sys_close(fd);
85162 - fd = sys_open(name, 0, 0);
85163 + fd = sys_open((char __force_user *)name, 0, 0);
85164 sys_ioctl(fd, BLKRRPART, 0);
85165 }
85166 sys_close(fd);
85167 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
85168
85169 wait_for_device_probe();
85170
85171 - fd = sys_open("/dev/md0", 0, 0);
85172 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
85173 if (fd >= 0) {
85174 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
85175 sys_close(fd);
85176 diff --git a/init/init_task.c b/init/init_task.c
85177 index ba0a7f36..2bcf1d5 100644
85178 --- a/init/init_task.c
85179 +++ b/init/init_task.c
85180 @@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
85181 * Initial thread structure. Alignment of this is handled by a special
85182 * linker map entry.
85183 */
85184 +#ifdef CONFIG_X86
85185 +union thread_union init_thread_union __init_task_data;
85186 +#else
85187 union thread_union init_thread_union __init_task_data =
85188 { INIT_THREAD_INFO(init_task) };
85189 +#endif
85190 diff --git a/init/initramfs.c b/init/initramfs.c
85191 index a8497fa..35b3c90 100644
85192 --- a/init/initramfs.c
85193 +++ b/init/initramfs.c
85194 @@ -84,7 +84,7 @@ static void __init free_hash(void)
85195 }
85196 }
85197
85198 -static long __init do_utime(char *filename, time_t mtime)
85199 +static long __init do_utime(char __force_user *filename, time_t mtime)
85200 {
85201 struct timespec t[2];
85202
85203 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
85204 struct dir_entry *de, *tmp;
85205 list_for_each_entry_safe(de, tmp, &dir_list, list) {
85206 list_del(&de->list);
85207 - do_utime(de->name, de->mtime);
85208 + do_utime((char __force_user *)de->name, de->mtime);
85209 kfree(de->name);
85210 kfree(de);
85211 }
85212 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
85213 if (nlink >= 2) {
85214 char *old = find_link(major, minor, ino, mode, collected);
85215 if (old)
85216 - return (sys_link(old, collected) < 0) ? -1 : 1;
85217 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
85218 }
85219 return 0;
85220 }
85221 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
85222 {
85223 struct stat st;
85224
85225 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
85226 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
85227 if (S_ISDIR(st.st_mode))
85228 - sys_rmdir(path);
85229 + sys_rmdir((char __force_user *)path);
85230 else
85231 - sys_unlink(path);
85232 + sys_unlink((char __force_user *)path);
85233 }
85234 }
85235
85236 @@ -315,7 +315,7 @@ static int __init do_name(void)
85237 int openflags = O_WRONLY|O_CREAT;
85238 if (ml != 1)
85239 openflags |= O_TRUNC;
85240 - wfd = sys_open(collected, openflags, mode);
85241 + wfd = sys_open((char __force_user *)collected, openflags, mode);
85242
85243 if (wfd >= 0) {
85244 sys_fchown(wfd, uid, gid);
85245 @@ -327,17 +327,17 @@ static int __init do_name(void)
85246 }
85247 }
85248 } else if (S_ISDIR(mode)) {
85249 - sys_mkdir(collected, mode);
85250 - sys_chown(collected, uid, gid);
85251 - sys_chmod(collected, mode);
85252 + sys_mkdir((char __force_user *)collected, mode);
85253 + sys_chown((char __force_user *)collected, uid, gid);
85254 + sys_chmod((char __force_user *)collected, mode);
85255 dir_add(collected, mtime);
85256 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
85257 S_ISFIFO(mode) || S_ISSOCK(mode)) {
85258 if (maybe_link() == 0) {
85259 - sys_mknod(collected, mode, rdev);
85260 - sys_chown(collected, uid, gid);
85261 - sys_chmod(collected, mode);
85262 - do_utime(collected, mtime);
85263 + sys_mknod((char __force_user *)collected, mode, rdev);
85264 + sys_chown((char __force_user *)collected, uid, gid);
85265 + sys_chmod((char __force_user *)collected, mode);
85266 + do_utime((char __force_user *)collected, mtime);
85267 }
85268 }
85269 return 0;
85270 @@ -346,15 +346,15 @@ static int __init do_name(void)
85271 static int __init do_copy(void)
85272 {
85273 if (count >= body_len) {
85274 - sys_write(wfd, victim, body_len);
85275 + sys_write(wfd, (char __force_user *)victim, body_len);
85276 sys_close(wfd);
85277 - do_utime(vcollected, mtime);
85278 + do_utime((char __force_user *)vcollected, mtime);
85279 kfree(vcollected);
85280 eat(body_len);
85281 state = SkipIt;
85282 return 0;
85283 } else {
85284 - sys_write(wfd, victim, count);
85285 + sys_write(wfd, (char __force_user *)victim, count);
85286 body_len -= count;
85287 eat(count);
85288 return 1;
85289 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
85290 {
85291 collected[N_ALIGN(name_len) + body_len] = '\0';
85292 clean_path(collected, 0);
85293 - sys_symlink(collected + N_ALIGN(name_len), collected);
85294 - sys_lchown(collected, uid, gid);
85295 - do_utime(collected, mtime);
85296 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
85297 + sys_lchown((char __force_user *)collected, uid, gid);
85298 + do_utime((char __force_user *)collected, mtime);
85299 state = SkipIt;
85300 next_state = Reset;
85301 return 0;
85302 diff --git a/init/main.c b/init/main.c
85303 index eb0ea86..b91cd60 100644
85304 --- a/init/main.c
85305 +++ b/init/main.c
85306 @@ -97,6 +97,8 @@ extern void radix_tree_init(void);
85307 static inline void mark_rodata_ro(void) { }
85308 #endif
85309
85310 +extern void grsecurity_init(void);
85311 +
85312 /*
85313 * Debug helper: via this flag we know that we are in 'early bootup code'
85314 * where only the boot processor is running with IRQ disabled. This means
85315 @@ -158,6 +160,75 @@ static int __init set_reset_devices(char *str)
85316
85317 __setup("reset_devices", set_reset_devices);
85318
85319 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
85320 +kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
85321 +static int __init setup_grsec_proc_gid(char *str)
85322 +{
85323 + grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
85324 + return 1;
85325 +}
85326 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
85327 +#endif
85328 +
85329 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
85330 +unsigned long pax_user_shadow_base __read_only;
85331 +EXPORT_SYMBOL(pax_user_shadow_base);
85332 +extern char pax_enter_kernel_user[];
85333 +extern char pax_exit_kernel_user[];
85334 +#endif
85335 +
85336 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
85337 +static int __init setup_pax_nouderef(char *str)
85338 +{
85339 +#ifdef CONFIG_X86_32
85340 + unsigned int cpu;
85341 + struct desc_struct *gdt;
85342 +
85343 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
85344 + gdt = get_cpu_gdt_table(cpu);
85345 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
85346 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
85347 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
85348 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
85349 + }
85350 + loadsegment(ds, __KERNEL_DS);
85351 + loadsegment(es, __KERNEL_DS);
85352 + loadsegment(ss, __KERNEL_DS);
85353 +#else
85354 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
85355 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
85356 + clone_pgd_mask = ~(pgdval_t)0UL;
85357 + pax_user_shadow_base = 0UL;
85358 + setup_clear_cpu_cap(X86_FEATURE_PCID);
85359 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
85360 +#endif
85361 +
85362 + return 0;
85363 +}
85364 +early_param("pax_nouderef", setup_pax_nouderef);
85365 +
85366 +#ifdef CONFIG_X86_64
85367 +static int __init setup_pax_weakuderef(char *str)
85368 +{
85369 + if (clone_pgd_mask != ~(pgdval_t)0UL)
85370 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
85371 + return 1;
85372 +}
85373 +__setup("pax_weakuderef", setup_pax_weakuderef);
85374 +#endif
85375 +#endif
85376 +
85377 +#ifdef CONFIG_PAX_SOFTMODE
85378 +int pax_softmode;
85379 +
85380 +static int __init setup_pax_softmode(char *str)
85381 +{
85382 + get_option(&str, &pax_softmode);
85383 + return 1;
85384 +}
85385 +__setup("pax_softmode=", setup_pax_softmode);
85386 +#endif
85387 +
85388 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
85389 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
85390 static const char *panic_later, *panic_param;
85391 @@ -692,25 +763,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
85392 {
85393 int count = preempt_count();
85394 int ret;
85395 - char msgbuf[64];
85396 + const char *msg1 = "", *msg2 = "";
85397
85398 if (initcall_debug)
85399 ret = do_one_initcall_debug(fn);
85400 else
85401 ret = fn();
85402
85403 - msgbuf[0] = 0;
85404 -
85405 if (preempt_count() != count) {
85406 - sprintf(msgbuf, "preemption imbalance ");
85407 + msg1 = " preemption imbalance";
85408 preempt_count_set(count);
85409 }
85410 if (irqs_disabled()) {
85411 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
85412 + msg2 = " disabled interrupts";
85413 local_irq_enable();
85414 }
85415 - WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
85416 + WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
85417
85418 + add_latent_entropy();
85419 return ret;
85420 }
85421
85422 @@ -817,8 +887,8 @@ static int run_init_process(const char *init_filename)
85423 {
85424 argv_init[0] = init_filename;
85425 return do_execve(getname_kernel(init_filename),
85426 - (const char __user *const __user *)argv_init,
85427 - (const char __user *const __user *)envp_init);
85428 + (const char __user *const __force_user *)argv_init,
85429 + (const char __user *const __force_user *)envp_init);
85430 }
85431
85432 static int try_to_run_init_process(const char *init_filename)
85433 @@ -835,6 +905,10 @@ static int try_to_run_init_process(const char *init_filename)
85434 return ret;
85435 }
85436
85437 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
85438 +extern int gr_init_ran;
85439 +#endif
85440 +
85441 static noinline void __init kernel_init_freeable(void);
85442
85443 static int __ref kernel_init(void *unused)
85444 @@ -859,6 +933,11 @@ static int __ref kernel_init(void *unused)
85445 ramdisk_execute_command, ret);
85446 }
85447
85448 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
85449 + /* if no initrd was used, be extra sure we enforce chroot restrictions */
85450 + gr_init_ran = 1;
85451 +#endif
85452 +
85453 /*
85454 * We try each of these until one succeeds.
85455 *
85456 @@ -914,7 +993,7 @@ static noinline void __init kernel_init_freeable(void)
85457 do_basic_setup();
85458
85459 /* Open the /dev/console on the rootfs, this should never fail */
85460 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
85461 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
85462 pr_err("Warning: unable to open an initial console.\n");
85463
85464 (void) sys_dup(0);
85465 @@ -927,11 +1006,13 @@ static noinline void __init kernel_init_freeable(void)
85466 if (!ramdisk_execute_command)
85467 ramdisk_execute_command = "/init";
85468
85469 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
85470 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
85471 ramdisk_execute_command = NULL;
85472 prepare_namespace();
85473 }
85474
85475 + grsecurity_init();
85476 +
85477 /*
85478 * Ok, we have completed the initial bootup, and
85479 * we're essentially up and running. Get rid of the
85480 diff --git a/ipc/compat.c b/ipc/compat.c
85481 index 45d035d..e4a7f99 100644
85482 --- a/ipc/compat.c
85483 +++ b/ipc/compat.c
85484 @@ -396,7 +396,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
85485 COMPAT_SHMLBA);
85486 if (err < 0)
85487 return err;
85488 - return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
85489 + return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
85490 }
85491 case SHMDT:
85492 return sys_shmdt(compat_ptr(ptr));
85493 diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
85494 index 998d31b..30c24df 100644
85495 --- a/ipc/ipc_sysctl.c
85496 +++ b/ipc/ipc_sysctl.c
85497 @@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
85498 static int proc_ipc_dointvec(ctl_table *table, int write,
85499 void __user *buffer, size_t *lenp, loff_t *ppos)
85500 {
85501 - struct ctl_table ipc_table;
85502 + ctl_table_no_const ipc_table;
85503
85504 memcpy(&ipc_table, table, sizeof(ipc_table));
85505 ipc_table.data = get_ipc(table);
85506 @@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
85507 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
85508 void __user *buffer, size_t *lenp, loff_t *ppos)
85509 {
85510 - struct ctl_table ipc_table;
85511 + ctl_table_no_const ipc_table;
85512
85513 memcpy(&ipc_table, table, sizeof(ipc_table));
85514 ipc_table.data = get_ipc(table);
85515 @@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
85516 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
85517 void __user *buffer, size_t *lenp, loff_t *ppos)
85518 {
85519 - struct ctl_table ipc_table;
85520 + ctl_table_no_const ipc_table;
85521 size_t lenp_bef = *lenp;
85522 int rc;
85523
85524 @@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
85525 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
85526 void __user *buffer, size_t *lenp, loff_t *ppos)
85527 {
85528 - struct ctl_table ipc_table;
85529 + ctl_table_no_const ipc_table;
85530 memcpy(&ipc_table, table, sizeof(ipc_table));
85531 ipc_table.data = get_ipc(table);
85532
85533 @@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
85534 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
85535 void __user *buffer, size_t *lenp, loff_t *ppos)
85536 {
85537 - struct ctl_table ipc_table;
85538 + ctl_table_no_const ipc_table;
85539 size_t lenp_bef = *lenp;
85540 int oldval;
85541 int rc;
85542 diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
85543 index 5bb8bfe..a38ec05 100644
85544 --- a/ipc/mq_sysctl.c
85545 +++ b/ipc/mq_sysctl.c
85546 @@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
85547 static int proc_mq_dointvec(ctl_table *table, int write,
85548 void __user *buffer, size_t *lenp, loff_t *ppos)
85549 {
85550 - struct ctl_table mq_table;
85551 + ctl_table_no_const mq_table;
85552 memcpy(&mq_table, table, sizeof(mq_table));
85553 mq_table.data = get_mq(table);
85554
85555 @@ -35,7 +35,7 @@ static int proc_mq_dointvec(ctl_table *table, int write,
85556 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
85557 void __user *buffer, size_t *lenp, loff_t *ppos)
85558 {
85559 - struct ctl_table mq_table;
85560 + ctl_table_no_const mq_table;
85561 memcpy(&mq_table, table, sizeof(mq_table));
85562 mq_table.data = get_mq(table);
85563
85564 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
85565 index 4fcf39a..d3cc2ec 100644
85566 --- a/ipc/mqueue.c
85567 +++ b/ipc/mqueue.c
85568 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
85569 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
85570 info->attr.mq_msgsize);
85571
85572 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
85573 spin_lock(&mq_lock);
85574 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
85575 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
85576 diff --git a/ipc/msg.c b/ipc/msg.c
85577 index 6498531..b0ff3c8 100644
85578 --- a/ipc/msg.c
85579 +++ b/ipc/msg.c
85580 @@ -303,18 +303,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
85581 return security_msg_queue_associate(msq, msgflg);
85582 }
85583
85584 +static struct ipc_ops msg_ops = {
85585 + .getnew = newque,
85586 + .associate = msg_security,
85587 + .more_checks = NULL
85588 +};
85589 +
85590 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
85591 {
85592 struct ipc_namespace *ns;
85593 - struct ipc_ops msg_ops;
85594 struct ipc_params msg_params;
85595
85596 ns = current->nsproxy->ipc_ns;
85597
85598 - msg_ops.getnew = newque;
85599 - msg_ops.associate = msg_security;
85600 - msg_ops.more_checks = NULL;
85601 -
85602 msg_params.key = key;
85603 msg_params.flg = msgflg;
85604
85605 diff --git a/ipc/sem.c b/ipc/sem.c
85606 index bee5554..e9af81dd 100644
85607 --- a/ipc/sem.c
85608 +++ b/ipc/sem.c
85609 @@ -561,10 +561,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
85610 return 0;
85611 }
85612
85613 +static struct ipc_ops sem_ops = {
85614 + .getnew = newary,
85615 + .associate = sem_security,
85616 + .more_checks = sem_more_checks
85617 +};
85618 +
85619 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
85620 {
85621 struct ipc_namespace *ns;
85622 - struct ipc_ops sem_ops;
85623 struct ipc_params sem_params;
85624
85625 ns = current->nsproxy->ipc_ns;
85626 @@ -572,10 +577,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
85627 if (nsems < 0 || nsems > ns->sc_semmsl)
85628 return -EINVAL;
85629
85630 - sem_ops.getnew = newary;
85631 - sem_ops.associate = sem_security;
85632 - sem_ops.more_checks = sem_more_checks;
85633 -
85634 sem_params.key = key;
85635 sem_params.flg = semflg;
85636 sem_params.u.nsems = nsems;
85637 diff --git a/ipc/shm.c b/ipc/shm.c
85638 index 7645961..afc7f02 100644
85639 --- a/ipc/shm.c
85640 +++ b/ipc/shm.c
85641 @@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
85642 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
85643 #endif
85644
85645 +#ifdef CONFIG_GRKERNSEC
85646 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
85647 + const time_t shm_createtime, const kuid_t cuid,
85648 + const int shmid);
85649 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
85650 + const time_t shm_createtime);
85651 +#endif
85652 +
85653 void shm_init_ns(struct ipc_namespace *ns)
85654 {
85655 ns->shm_ctlmax = SHMMAX;
85656 @@ -553,6 +561,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
85657 shp->shm_lprid = 0;
85658 shp->shm_atim = shp->shm_dtim = 0;
85659 shp->shm_ctim = get_seconds();
85660 +#ifdef CONFIG_GRKERNSEC
85661 + {
85662 + struct timespec timeval;
85663 + do_posix_clock_monotonic_gettime(&timeval);
85664 +
85665 + shp->shm_createtime = timeval.tv_sec;
85666 + }
85667 +#endif
85668 shp->shm_segsz = size;
85669 shp->shm_nattch = 0;
85670 shp->shm_file = file;
85671 @@ -606,18 +622,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
85672 return 0;
85673 }
85674
85675 +static struct ipc_ops shm_ops = {
85676 + .getnew = newseg,
85677 + .associate = shm_security,
85678 + .more_checks = shm_more_checks
85679 +};
85680 +
85681 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
85682 {
85683 struct ipc_namespace *ns;
85684 - struct ipc_ops shm_ops;
85685 struct ipc_params shm_params;
85686
85687 ns = current->nsproxy->ipc_ns;
85688
85689 - shm_ops.getnew = newseg;
85690 - shm_ops.associate = shm_security;
85691 - shm_ops.more_checks = shm_more_checks;
85692 -
85693 shm_params.key = key;
85694 shm_params.flg = shmflg;
85695 shm_params.u.size = size;
85696 @@ -1088,6 +1105,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85697 f_mode = FMODE_READ | FMODE_WRITE;
85698 }
85699 if (shmflg & SHM_EXEC) {
85700 +
85701 +#ifdef CONFIG_PAX_MPROTECT
85702 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
85703 + goto out;
85704 +#endif
85705 +
85706 prot |= PROT_EXEC;
85707 acc_mode |= S_IXUGO;
85708 }
85709 @@ -1112,6 +1135,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85710 if (err)
85711 goto out_unlock;
85712
85713 +#ifdef CONFIG_GRKERNSEC
85714 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
85715 + shp->shm_perm.cuid, shmid) ||
85716 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
85717 + err = -EACCES;
85718 + goto out_unlock;
85719 + }
85720 +#endif
85721 +
85722 ipc_lock_object(&shp->shm_perm);
85723
85724 /* check if shm_destroy() is tearing down shp */
85725 @@ -1124,6 +1156,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85726 path = shp->shm_file->f_path;
85727 path_get(&path);
85728 shp->shm_nattch++;
85729 +#ifdef CONFIG_GRKERNSEC
85730 + shp->shm_lapid = current->pid;
85731 +#endif
85732 size = i_size_read(path.dentry->d_inode);
85733 ipc_unlock_object(&shp->shm_perm);
85734 rcu_read_unlock();
85735 diff --git a/ipc/util.c b/ipc/util.c
85736 index 2eb0d1e..0308564 100644
85737 --- a/ipc/util.c
85738 +++ b/ipc/util.c
85739 @@ -71,6 +71,8 @@ struct ipc_proc_iface {
85740 int (*show)(struct seq_file *, void *);
85741 };
85742
85743 +extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
85744 +
85745 static void ipc_memory_notifier(struct work_struct *work)
85746 {
85747 ipcns_notify(IPCNS_MEMCHANGED);
85748 @@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
85749 granted_mode >>= 6;
85750 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
85751 granted_mode >>= 3;
85752 +
85753 + if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
85754 + return -1;
85755 +
85756 /* is there some bit set in requested_mode but not in granted_mode? */
85757 if ((requested_mode & ~granted_mode & 0007) &&
85758 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
85759 diff --git a/kernel/acct.c b/kernel/acct.c
85760 index 8d6e145..33e0b1e 100644
85761 --- a/kernel/acct.c
85762 +++ b/kernel/acct.c
85763 @@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
85764 */
85765 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
85766 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
85767 - file->f_op->write(file, (char *)&ac,
85768 + file->f_op->write(file, (char __force_user *)&ac,
85769 sizeof(acct_t), &file->f_pos);
85770 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
85771 set_fs(fs);
85772 diff --git a/kernel/audit.c b/kernel/audit.c
85773 index 47845c5..bd9dd5b 100644
85774 --- a/kernel/audit.c
85775 +++ b/kernel/audit.c
85776 @@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
85777 3) suppressed due to audit_rate_limit
85778 4) suppressed due to audit_backlog_limit
85779 */
85780 -static atomic_t audit_lost = ATOMIC_INIT(0);
85781 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
85782
85783 /* The netlink socket. */
85784 static struct sock *audit_sock;
85785 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
85786 unsigned long now;
85787 int print;
85788
85789 - atomic_inc(&audit_lost);
85790 + atomic_inc_unchecked(&audit_lost);
85791
85792 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
85793
85794 @@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
85795 if (print) {
85796 if (printk_ratelimit())
85797 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
85798 - atomic_read(&audit_lost),
85799 + atomic_read_unchecked(&audit_lost),
85800 audit_rate_limit,
85801 audit_backlog_limit);
85802 audit_panic(message);
85803 @@ -808,7 +808,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
85804 s.pid = audit_pid;
85805 s.rate_limit = audit_rate_limit;
85806 s.backlog_limit = audit_backlog_limit;
85807 - s.lost = atomic_read(&audit_lost);
85808 + s.lost = atomic_read_unchecked(&audit_lost);
85809 s.backlog = skb_queue_len(&audit_skb_queue);
85810 s.version = AUDIT_VERSION_LATEST;
85811 s.backlog_wait_time = audit_backlog_wait_time;
85812 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
85813 index 21eae3c..66db239 100644
85814 --- a/kernel/auditsc.c
85815 +++ b/kernel/auditsc.c
85816 @@ -2023,7 +2023,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
85817 }
85818
85819 /* global counter which is incremented every time something logs in */
85820 -static atomic_t session_id = ATOMIC_INIT(0);
85821 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
85822
85823 static int audit_set_loginuid_perm(kuid_t loginuid)
85824 {
85825 @@ -2090,7 +2090,7 @@ int audit_set_loginuid(kuid_t loginuid)
85826
85827 /* are we setting or clearing? */
85828 if (uid_valid(loginuid))
85829 - sessionid = (unsigned int)atomic_inc_return(&session_id);
85830 + sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
85831
85832 task->sessionid = sessionid;
85833 task->loginuid = loginuid;
85834 diff --git a/kernel/capability.c b/kernel/capability.c
85835 index 24663b3..b926ae1 100644
85836 --- a/kernel/capability.c
85837 +++ b/kernel/capability.c
85838 @@ -193,6 +193,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
85839 * before modification is attempted and the application
85840 * fails.
85841 */
85842 + if (tocopy > ARRAY_SIZE(kdata))
85843 + return -EFAULT;
85844 +
85845 if (copy_to_user(dataptr, kdata, tocopy
85846 * sizeof(struct __user_cap_data_struct))) {
85847 return -EFAULT;
85848 @@ -294,10 +297,11 @@ bool has_ns_capability(struct task_struct *t,
85849 int ret;
85850
85851 rcu_read_lock();
85852 - ret = security_capable(__task_cred(t), ns, cap);
85853 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
85854 + gr_task_is_capable(t, __task_cred(t), cap);
85855 rcu_read_unlock();
85856
85857 - return (ret == 0);
85858 + return ret;
85859 }
85860
85861 /**
85862 @@ -334,10 +338,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
85863 int ret;
85864
85865 rcu_read_lock();
85866 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
85867 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
85868 rcu_read_unlock();
85869
85870 - return (ret == 0);
85871 + return ret;
85872 }
85873
85874 /**
85875 @@ -375,7 +379,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
85876 BUG();
85877 }
85878
85879 - if (security_capable(current_cred(), ns, cap) == 0) {
85880 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
85881 current->flags |= PF_SUPERPRIV;
85882 return true;
85883 }
85884 @@ -383,6 +387,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
85885 }
85886 EXPORT_SYMBOL(ns_capable);
85887
85888 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
85889 +{
85890 + if (unlikely(!cap_valid(cap))) {
85891 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
85892 + BUG();
85893 + }
85894 +
85895 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
85896 + current->flags |= PF_SUPERPRIV;
85897 + return true;
85898 + }
85899 + return false;
85900 +}
85901 +EXPORT_SYMBOL(ns_capable_nolog);
85902 +
85903 /**
85904 * file_ns_capable - Determine if the file's opener had a capability in effect
85905 * @file: The file we want to check
85906 @@ -423,6 +442,12 @@ bool capable(int cap)
85907 }
85908 EXPORT_SYMBOL(capable);
85909
85910 +bool capable_nolog(int cap)
85911 +{
85912 + return ns_capable_nolog(&init_user_ns, cap);
85913 +}
85914 +EXPORT_SYMBOL(capable_nolog);
85915 +
85916 /**
85917 * capable_wrt_inode_uidgid - Check nsown_capable and uid and gid mapped
85918 * @inode: The inode in question
85919 @@ -440,3 +465,12 @@ bool capable_wrt_inode_uidgid(const struct inode *inode, int cap)
85920 kgid_has_mapping(ns, inode->i_gid);
85921 }
85922 EXPORT_SYMBOL(capable_wrt_inode_uidgid);
85923 +
85924 +bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap)
85925 +{
85926 + struct user_namespace *ns = current_user_ns();
85927 +
85928 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid) &&
85929 + kgid_has_mapping(ns, inode->i_gid);
85930 +}
85931 +EXPORT_SYMBOL(capable_wrt_inode_uidgid_nolog);
85932 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
85933 index 073226b..969c746 100644
85934 --- a/kernel/cgroup.c
85935 +++ b/kernel/cgroup.c
85936 @@ -4808,7 +4808,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
85937 struct task_struct *task;
85938 int count = 0;
85939
85940 - seq_printf(seq, "css_set %p\n", cset);
85941 + seq_printf(seq, "css_set %pK\n", cset);
85942
85943 list_for_each_entry(task, &cset->tasks, cg_list) {
85944 if (count++ > MAX_TASKS_SHOWN_PER_CSS)
85945 diff --git a/kernel/compat.c b/kernel/compat.c
85946 index e40b043..3da8f51 100644
85947 --- a/kernel/compat.c
85948 +++ b/kernel/compat.c
85949 @@ -13,6 +13,7 @@
85950
85951 #include <linux/linkage.h>
85952 #include <linux/compat.h>
85953 +#include <linux/module.h>
85954 #include <linux/errno.h>
85955 #include <linux/time.h>
85956 #include <linux/signal.h>
85957 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
85958 mm_segment_t oldfs;
85959 long ret;
85960
85961 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
85962 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
85963 oldfs = get_fs();
85964 set_fs(KERNEL_DS);
85965 ret = hrtimer_nanosleep_restart(restart);
85966 @@ -252,7 +253,7 @@ COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp,
85967 oldfs = get_fs();
85968 set_fs(KERNEL_DS);
85969 ret = hrtimer_nanosleep(&tu,
85970 - rmtp ? (struct timespec __user *)&rmt : NULL,
85971 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
85972 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
85973 set_fs(oldfs);
85974
85975 @@ -361,7 +362,7 @@ COMPAT_SYSCALL_DEFINE1(sigpending, compat_old_sigset_t __user *, set)
85976 mm_segment_t old_fs = get_fs();
85977
85978 set_fs(KERNEL_DS);
85979 - ret = sys_sigpending((old_sigset_t __user *) &s);
85980 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
85981 set_fs(old_fs);
85982 if (ret == 0)
85983 ret = put_user(s, set);
85984 @@ -451,7 +452,7 @@ COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
85985 mm_segment_t old_fs = get_fs();
85986
85987 set_fs(KERNEL_DS);
85988 - ret = sys_old_getrlimit(resource, (struct rlimit __user *)&r);
85989 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
85990 set_fs(old_fs);
85991
85992 if (!ret) {
85993 @@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
85994 set_fs (KERNEL_DS);
85995 ret = sys_wait4(pid,
85996 (stat_addr ?
85997 - (unsigned int __user *) &status : NULL),
85998 - options, (struct rusage __user *) &r);
85999 + (unsigned int __force_user *) &status : NULL),
86000 + options, (struct rusage __force_user *) &r);
86001 set_fs (old_fs);
86002
86003 if (ret > 0) {
86004 @@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
86005 memset(&info, 0, sizeof(info));
86006
86007 set_fs(KERNEL_DS);
86008 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
86009 - uru ? (struct rusage __user *)&ru : NULL);
86010 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
86011 + uru ? (struct rusage __force_user *)&ru : NULL);
86012 set_fs(old_fs);
86013
86014 if ((ret < 0) || (info.si_signo == 0))
86015 @@ -695,8 +696,8 @@ COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
86016 oldfs = get_fs();
86017 set_fs(KERNEL_DS);
86018 err = sys_timer_settime(timer_id, flags,
86019 - (struct itimerspec __user *) &newts,
86020 - (struct itimerspec __user *) &oldts);
86021 + (struct itimerspec __force_user *) &newts,
86022 + (struct itimerspec __force_user *) &oldts);
86023 set_fs(oldfs);
86024 if (!err && old && put_compat_itimerspec(old, &oldts))
86025 return -EFAULT;
86026 @@ -713,7 +714,7 @@ COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
86027 oldfs = get_fs();
86028 set_fs(KERNEL_DS);
86029 err = sys_timer_gettime(timer_id,
86030 - (struct itimerspec __user *) &ts);
86031 + (struct itimerspec __force_user *) &ts);
86032 set_fs(oldfs);
86033 if (!err && put_compat_itimerspec(setting, &ts))
86034 return -EFAULT;
86035 @@ -732,7 +733,7 @@ COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock,
86036 oldfs = get_fs();
86037 set_fs(KERNEL_DS);
86038 err = sys_clock_settime(which_clock,
86039 - (struct timespec __user *) &ts);
86040 + (struct timespec __force_user *) &ts);
86041 set_fs(oldfs);
86042 return err;
86043 }
86044 @@ -747,7 +748,7 @@ COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock,
86045 oldfs = get_fs();
86046 set_fs(KERNEL_DS);
86047 err = sys_clock_gettime(which_clock,
86048 - (struct timespec __user *) &ts);
86049 + (struct timespec __force_user *) &ts);
86050 set_fs(oldfs);
86051 if (!err && compat_put_timespec(&ts, tp))
86052 return -EFAULT;
86053 @@ -767,7 +768,7 @@ COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock,
86054
86055 oldfs = get_fs();
86056 set_fs(KERNEL_DS);
86057 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
86058 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
86059 set_fs(oldfs);
86060
86061 err = compat_put_timex(utp, &txc);
86062 @@ -787,7 +788,7 @@ COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock,
86063 oldfs = get_fs();
86064 set_fs(KERNEL_DS);
86065 err = sys_clock_getres(which_clock,
86066 - (struct timespec __user *) &ts);
86067 + (struct timespec __force_user *) &ts);
86068 set_fs(oldfs);
86069 if (!err && tp && compat_put_timespec(&ts, tp))
86070 return -EFAULT;
86071 @@ -801,7 +802,7 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
86072 struct timespec tu;
86073 struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
86074
86075 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
86076 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
86077 oldfs = get_fs();
86078 set_fs(KERNEL_DS);
86079 err = clock_nanosleep_restart(restart);
86080 @@ -833,8 +834,8 @@ COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags,
86081 oldfs = get_fs();
86082 set_fs(KERNEL_DS);
86083 err = sys_clock_nanosleep(which_clock, flags,
86084 - (struct timespec __user *) &in,
86085 - (struct timespec __user *) &out);
86086 + (struct timespec __force_user *) &in,
86087 + (struct timespec __force_user *) &out);
86088 set_fs(oldfs);
86089
86090 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
86091 @@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
86092 mm_segment_t old_fs = get_fs();
86093
86094 set_fs(KERNEL_DS);
86095 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
86096 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
86097 set_fs(old_fs);
86098 if (compat_put_timespec(&t, interval))
86099 return -EFAULT;
86100 diff --git a/kernel/configs.c b/kernel/configs.c
86101 index c18b1f1..b9a0132 100644
86102 --- a/kernel/configs.c
86103 +++ b/kernel/configs.c
86104 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
86105 struct proc_dir_entry *entry;
86106
86107 /* create the current config file */
86108 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
86109 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
86110 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
86111 + &ikconfig_file_ops);
86112 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
86113 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
86114 + &ikconfig_file_ops);
86115 +#endif
86116 +#else
86117 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
86118 &ikconfig_file_ops);
86119 +#endif
86120 +
86121 if (!entry)
86122 return -ENOMEM;
86123
86124 diff --git a/kernel/cred.c b/kernel/cred.c
86125 index e0573a4..26c0fd3 100644
86126 --- a/kernel/cred.c
86127 +++ b/kernel/cred.c
86128 @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
86129 validate_creds(cred);
86130 alter_cred_subscribers(cred, -1);
86131 put_cred(cred);
86132 +
86133 +#ifdef CONFIG_GRKERNSEC_SETXID
86134 + cred = (struct cred *) tsk->delayed_cred;
86135 + if (cred != NULL) {
86136 + tsk->delayed_cred = NULL;
86137 + validate_creds(cred);
86138 + alter_cred_subscribers(cred, -1);
86139 + put_cred(cred);
86140 + }
86141 +#endif
86142 }
86143
86144 /**
86145 @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
86146 * Always returns 0 thus allowing this function to be tail-called at the end
86147 * of, say, sys_setgid().
86148 */
86149 -int commit_creds(struct cred *new)
86150 +static int __commit_creds(struct cred *new)
86151 {
86152 struct task_struct *task = current;
86153 const struct cred *old = task->real_cred;
86154 @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
86155
86156 get_cred(new); /* we will require a ref for the subj creds too */
86157
86158 + gr_set_role_label(task, new->uid, new->gid);
86159 +
86160 /* dumpability changes */
86161 if (!uid_eq(old->euid, new->euid) ||
86162 !gid_eq(old->egid, new->egid) ||
86163 @@ -479,6 +491,105 @@ int commit_creds(struct cred *new)
86164 put_cred(old);
86165 return 0;
86166 }
86167 +#ifdef CONFIG_GRKERNSEC_SETXID
86168 +extern int set_user(struct cred *new);
86169 +
86170 +void gr_delayed_cred_worker(void)
86171 +{
86172 + const struct cred *new = current->delayed_cred;
86173 + struct cred *ncred;
86174 +
86175 + current->delayed_cred = NULL;
86176 +
86177 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
86178 + // from doing get_cred on it when queueing this
86179 + put_cred(new);
86180 + return;
86181 + } else if (new == NULL)
86182 + return;
86183 +
86184 + ncred = prepare_creds();
86185 + if (!ncred)
86186 + goto die;
86187 + // uids
86188 + ncred->uid = new->uid;
86189 + ncred->euid = new->euid;
86190 + ncred->suid = new->suid;
86191 + ncred->fsuid = new->fsuid;
86192 + // gids
86193 + ncred->gid = new->gid;
86194 + ncred->egid = new->egid;
86195 + ncred->sgid = new->sgid;
86196 + ncred->fsgid = new->fsgid;
86197 + // groups
86198 + set_groups(ncred, new->group_info);
86199 + // caps
86200 + ncred->securebits = new->securebits;
86201 + ncred->cap_inheritable = new->cap_inheritable;
86202 + ncred->cap_permitted = new->cap_permitted;
86203 + ncred->cap_effective = new->cap_effective;
86204 + ncred->cap_bset = new->cap_bset;
86205 +
86206 + if (set_user(ncred)) {
86207 + abort_creds(ncred);
86208 + goto die;
86209 + }
86210 +
86211 + // from doing get_cred on it when queueing this
86212 + put_cred(new);
86213 +
86214 + __commit_creds(ncred);
86215 + return;
86216 +die:
86217 + // from doing get_cred on it when queueing this
86218 + put_cred(new);
86219 + do_group_exit(SIGKILL);
86220 +}
86221 +#endif
86222 +
86223 +int commit_creds(struct cred *new)
86224 +{
86225 +#ifdef CONFIG_GRKERNSEC_SETXID
86226 + int ret;
86227 + int schedule_it = 0;
86228 + struct task_struct *t;
86229 + unsigned oldsecurebits = current_cred()->securebits;
86230 +
86231 + /* we won't get called with tasklist_lock held for writing
86232 + and interrupts disabled as the cred struct in that case is
86233 + init_cred
86234 + */
86235 + if (grsec_enable_setxid && !current_is_single_threaded() &&
86236 + uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
86237 + !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
86238 + schedule_it = 1;
86239 + }
86240 + ret = __commit_creds(new);
86241 + if (schedule_it) {
86242 + rcu_read_lock();
86243 + read_lock(&tasklist_lock);
86244 + for (t = next_thread(current); t != current;
86245 + t = next_thread(t)) {
86246 + /* we'll check if the thread has uid 0 in
86247 + * the delayed worker routine
86248 + */
86249 + if (task_securebits(t) == oldsecurebits &&
86250 + t->delayed_cred == NULL) {
86251 + t->delayed_cred = get_cred(new);
86252 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
86253 + set_tsk_need_resched(t);
86254 + }
86255 + }
86256 + read_unlock(&tasklist_lock);
86257 + rcu_read_unlock();
86258 + }
86259 +
86260 + return ret;
86261 +#else
86262 + return __commit_creds(new);
86263 +#endif
86264 +}
86265 +
86266 EXPORT_SYMBOL(commit_creds);
86267
86268 /**
86269 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
86270 index 2956c8d..cfe1e2e 100644
86271 --- a/kernel/debug/debug_core.c
86272 +++ b/kernel/debug/debug_core.c
86273 @@ -124,7 +124,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
86274 */
86275 static atomic_t masters_in_kgdb;
86276 static atomic_t slaves_in_kgdb;
86277 -static atomic_t kgdb_break_tasklet_var;
86278 +static atomic_unchecked_t kgdb_break_tasklet_var;
86279 atomic_t kgdb_setting_breakpoint;
86280
86281 struct task_struct *kgdb_usethread;
86282 @@ -134,7 +134,7 @@ int kgdb_single_step;
86283 static pid_t kgdb_sstep_pid;
86284
86285 /* to keep track of the CPU which is doing the single stepping*/
86286 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
86287 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
86288
86289 /*
86290 * If you are debugging a problem where roundup (the collection of
86291 @@ -549,7 +549,7 @@ return_normal:
86292 * kernel will only try for the value of sstep_tries before
86293 * giving up and continuing on.
86294 */
86295 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
86296 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
86297 (kgdb_info[cpu].task &&
86298 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
86299 atomic_set(&kgdb_active, -1);
86300 @@ -647,8 +647,8 @@ cpu_master_loop:
86301 }
86302
86303 kgdb_restore:
86304 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
86305 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
86306 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
86307 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
86308 if (kgdb_info[sstep_cpu].task)
86309 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
86310 else
86311 @@ -925,18 +925,18 @@ static void kgdb_unregister_callbacks(void)
86312 static void kgdb_tasklet_bpt(unsigned long ing)
86313 {
86314 kgdb_breakpoint();
86315 - atomic_set(&kgdb_break_tasklet_var, 0);
86316 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
86317 }
86318
86319 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
86320
86321 void kgdb_schedule_breakpoint(void)
86322 {
86323 - if (atomic_read(&kgdb_break_tasklet_var) ||
86324 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
86325 atomic_read(&kgdb_active) != -1 ||
86326 atomic_read(&kgdb_setting_breakpoint))
86327 return;
86328 - atomic_inc(&kgdb_break_tasklet_var);
86329 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
86330 tasklet_schedule(&kgdb_tasklet_breakpoint);
86331 }
86332 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
86333 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
86334 index 0b097c8..11dd5c5 100644
86335 --- a/kernel/debug/kdb/kdb_main.c
86336 +++ b/kernel/debug/kdb/kdb_main.c
86337 @@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
86338 continue;
86339
86340 kdb_printf("%-20s%8u 0x%p ", mod->name,
86341 - mod->core_size, (void *)mod);
86342 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
86343 #ifdef CONFIG_MODULE_UNLOAD
86344 kdb_printf("%4ld ", module_refcount(mod));
86345 #endif
86346 @@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
86347 kdb_printf(" (Loading)");
86348 else
86349 kdb_printf(" (Live)");
86350 - kdb_printf(" 0x%p", mod->module_core);
86351 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
86352
86353 #ifdef CONFIG_MODULE_UNLOAD
86354 {
86355 diff --git a/kernel/events/core.c b/kernel/events/core.c
86356 index 935271c..8888f93 100644
86357 --- a/kernel/events/core.c
86358 +++ b/kernel/events/core.c
86359 @@ -158,8 +158,15 @@ static struct srcu_struct pmus_srcu;
86360 * 0 - disallow raw tracepoint access for unpriv
86361 * 1 - disallow cpu events for unpriv
86362 * 2 - disallow kernel profiling for unpriv
86363 + * 3 - disallow all unpriv perf event use
86364 */
86365 -int sysctl_perf_event_paranoid __read_mostly = 1;
86366 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
86367 +int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
86368 +#elif defined(CONFIG_GRKERNSEC_HIDESYM)
86369 +int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
86370 +#else
86371 +int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
86372 +#endif
86373
86374 /* Minimum for 512 kiB + 1 user control page */
86375 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
86376 @@ -185,7 +192,7 @@ void update_perf_cpu_limits(void)
86377
86378 tmp *= sysctl_perf_cpu_time_max_percent;
86379 do_div(tmp, 100);
86380 - ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
86381 + ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
86382 }
86383
86384 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
86385 @@ -291,7 +298,7 @@ void perf_sample_event_took(u64 sample_len_ns)
86386 }
86387 }
86388
86389 -static atomic64_t perf_event_id;
86390 +static atomic64_unchecked_t perf_event_id;
86391
86392 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
86393 enum event_type_t event_type);
86394 @@ -3002,7 +3009,7 @@ static void __perf_event_read(void *info)
86395
86396 static inline u64 perf_event_count(struct perf_event *event)
86397 {
86398 - return local64_read(&event->count) + atomic64_read(&event->child_count);
86399 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
86400 }
86401
86402 static u64 perf_event_read(struct perf_event *event)
86403 @@ -3361,9 +3368,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
86404 mutex_lock(&event->child_mutex);
86405 total += perf_event_read(event);
86406 *enabled += event->total_time_enabled +
86407 - atomic64_read(&event->child_total_time_enabled);
86408 + atomic64_read_unchecked(&event->child_total_time_enabled);
86409 *running += event->total_time_running +
86410 - atomic64_read(&event->child_total_time_running);
86411 + atomic64_read_unchecked(&event->child_total_time_running);
86412
86413 list_for_each_entry(child, &event->child_list, child_list) {
86414 total += perf_event_read(child);
86415 @@ -3792,10 +3799,10 @@ void perf_event_update_userpage(struct perf_event *event)
86416 userpg->offset -= local64_read(&event->hw.prev_count);
86417
86418 userpg->time_enabled = enabled +
86419 - atomic64_read(&event->child_total_time_enabled);
86420 + atomic64_read_unchecked(&event->child_total_time_enabled);
86421
86422 userpg->time_running = running +
86423 - atomic64_read(&event->child_total_time_running);
86424 + atomic64_read_unchecked(&event->child_total_time_running);
86425
86426 arch_perf_update_userpage(userpg, now);
86427
86428 @@ -4359,7 +4366,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
86429
86430 /* Data. */
86431 sp = perf_user_stack_pointer(regs);
86432 - rem = __output_copy_user(handle, (void *) sp, dump_size);
86433 + rem = __output_copy_user(handle, (void __user *) sp, dump_size);
86434 dyn_size = dump_size - rem;
86435
86436 perf_output_skip(handle, rem);
86437 @@ -4450,11 +4457,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
86438 values[n++] = perf_event_count(event);
86439 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
86440 values[n++] = enabled +
86441 - atomic64_read(&event->child_total_time_enabled);
86442 + atomic64_read_unchecked(&event->child_total_time_enabled);
86443 }
86444 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
86445 values[n++] = running +
86446 - atomic64_read(&event->child_total_time_running);
86447 + atomic64_read_unchecked(&event->child_total_time_running);
86448 }
86449 if (read_format & PERF_FORMAT_ID)
86450 values[n++] = primary_event_id(event);
86451 @@ -6733,7 +6740,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
86452 event->parent = parent_event;
86453
86454 event->ns = get_pid_ns(task_active_pid_ns(current));
86455 - event->id = atomic64_inc_return(&perf_event_id);
86456 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
86457
86458 event->state = PERF_EVENT_STATE_INACTIVE;
86459
86460 @@ -7015,6 +7022,11 @@ SYSCALL_DEFINE5(perf_event_open,
86461 if (flags & ~PERF_FLAG_ALL)
86462 return -EINVAL;
86463
86464 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
86465 + if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
86466 + return -EACCES;
86467 +#endif
86468 +
86469 err = perf_copy_attr(attr_uptr, &attr);
86470 if (err)
86471 return err;
86472 @@ -7353,10 +7365,10 @@ static void sync_child_event(struct perf_event *child_event,
86473 /*
86474 * Add back the child's count to the parent's count:
86475 */
86476 - atomic64_add(child_val, &parent_event->child_count);
86477 - atomic64_add(child_event->total_time_enabled,
86478 + atomic64_add_unchecked(child_val, &parent_event->child_count);
86479 + atomic64_add_unchecked(child_event->total_time_enabled,
86480 &parent_event->child_total_time_enabled);
86481 - atomic64_add(child_event->total_time_running,
86482 + atomic64_add_unchecked(child_event->total_time_running,
86483 &parent_event->child_total_time_running);
86484
86485 /*
86486 diff --git a/kernel/events/internal.h b/kernel/events/internal.h
86487 index 569b2187..19940d9 100644
86488 --- a/kernel/events/internal.h
86489 +++ b/kernel/events/internal.h
86490 @@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
86491 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
86492 }
86493
86494 -#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
86495 +#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
86496 static inline unsigned long \
86497 func_name(struct perf_output_handle *handle, \
86498 - const void *buf, unsigned long len) \
86499 + const void user *buf, unsigned long len) \
86500 { \
86501 unsigned long size, written; \
86502 \
86503 @@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
86504 return 0;
86505 }
86506
86507 -DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
86508 +DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
86509
86510 static inline unsigned long
86511 memcpy_skip(void *dst, const void *src, unsigned long n)
86512 @@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
86513 return 0;
86514 }
86515
86516 -DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
86517 +DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
86518
86519 #ifndef arch_perf_out_copy_user
86520 #define arch_perf_out_copy_user arch_perf_out_copy_user
86521 @@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
86522 }
86523 #endif
86524
86525 -DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
86526 +DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
86527
86528 /* Callchain handling */
86529 extern struct perf_callchain_entry *
86530 diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
86531 index 04709b6..d330828 100644
86532 --- a/kernel/events/uprobes.c
86533 +++ b/kernel/events/uprobes.c
86534 @@ -1666,7 +1666,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
86535 {
86536 struct page *page;
86537 uprobe_opcode_t opcode;
86538 - int result;
86539 + long result;
86540
86541 pagefault_disable();
86542 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
86543 diff --git a/kernel/exit.c b/kernel/exit.c
86544 index 6ed6a1d..edecb0e 100644
86545 --- a/kernel/exit.c
86546 +++ b/kernel/exit.c
86547 @@ -173,6 +173,10 @@ void release_task(struct task_struct * p)
86548 struct task_struct *leader;
86549 int zap_leader;
86550 repeat:
86551 +#ifdef CONFIG_NET
86552 + gr_del_task_from_ip_table(p);
86553 +#endif
86554 +
86555 /* don't need to get the RCU readlock here - the process is dead and
86556 * can't be modifying its own credentials. But shut RCU-lockdep up */
86557 rcu_read_lock();
86558 @@ -330,7 +334,7 @@ int allow_signal(int sig)
86559 * know it'll be handled, so that they don't get converted to
86560 * SIGKILL or just silently dropped.
86561 */
86562 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
86563 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
86564 recalc_sigpending();
86565 spin_unlock_irq(&current->sighand->siglock);
86566 return 0;
86567 @@ -699,6 +703,8 @@ void do_exit(long code)
86568 struct task_struct *tsk = current;
86569 int group_dead;
86570
86571 + set_fs(USER_DS);
86572 +
86573 profile_task_exit(tsk);
86574
86575 WARN_ON(blk_needs_flush_plug(tsk));
86576 @@ -715,7 +721,6 @@ void do_exit(long code)
86577 * mm_release()->clear_child_tid() from writing to a user-controlled
86578 * kernel address.
86579 */
86580 - set_fs(USER_DS);
86581
86582 ptrace_event(PTRACE_EVENT_EXIT, code);
86583
86584 @@ -774,6 +779,9 @@ void do_exit(long code)
86585 tsk->exit_code = code;
86586 taskstats_exit(tsk, group_dead);
86587
86588 + gr_acl_handle_psacct(tsk, code);
86589 + gr_acl_handle_exit();
86590 +
86591 exit_mm(tsk);
86592
86593 if (group_dead)
86594 @@ -893,7 +901,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
86595 * Take down every thread in the group. This is called by fatal signals
86596 * as well as by sys_exit_group (below).
86597 */
86598 -void
86599 +__noreturn void
86600 do_group_exit(int exit_code)
86601 {
86602 struct signal_struct *sig = current->signal;
86603 diff --git a/kernel/fork.c b/kernel/fork.c
86604 index 68b9226..0700bf6 100644
86605 --- a/kernel/fork.c
86606 +++ b/kernel/fork.c
86607 @@ -183,6 +183,48 @@ void thread_info_cache_init(void)
86608 # endif
86609 #endif
86610
86611 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86612 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
86613 + int node, void **lowmem_stack)
86614 +{
86615 + struct page *pages[THREAD_SIZE / PAGE_SIZE];
86616 + void *ret = NULL;
86617 + unsigned int i;
86618 +
86619 + *lowmem_stack = alloc_thread_info_node(tsk, node);
86620 + if (*lowmem_stack == NULL)
86621 + goto out;
86622 +
86623 + for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++)
86624 + pages[i] = virt_to_page(*lowmem_stack + (i * PAGE_SIZE));
86625 +
86626 + /* use VM_IOREMAP to gain THREAD_SIZE alignment */
86627 + ret = vmap(pages, THREAD_SIZE / PAGE_SIZE, VM_IOREMAP, PAGE_KERNEL);
86628 + if (ret == NULL) {
86629 + free_thread_info(*lowmem_stack);
86630 + *lowmem_stack = NULL;
86631 + }
86632 +
86633 +out:
86634 + return ret;
86635 +}
86636 +
86637 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
86638 +{
86639 + unmap_process_stacks(tsk);
86640 +}
86641 +#else
86642 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
86643 + int node, void **lowmem_stack)
86644 +{
86645 + return alloc_thread_info_node(tsk, node);
86646 +}
86647 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
86648 +{
86649 + free_thread_info(ti);
86650 +}
86651 +#endif
86652 +
86653 /* SLAB cache for signal_struct structures (tsk->signal) */
86654 static struct kmem_cache *signal_cachep;
86655
86656 @@ -201,18 +243,22 @@ struct kmem_cache *vm_area_cachep;
86657 /* SLAB cache for mm_struct structures (tsk->mm) */
86658 static struct kmem_cache *mm_cachep;
86659
86660 -static void account_kernel_stack(struct thread_info *ti, int account)
86661 +static void account_kernel_stack(struct task_struct *tsk, struct thread_info *ti, int account)
86662 {
86663 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86664 + struct zone *zone = page_zone(virt_to_page(tsk->lowmem_stack));
86665 +#else
86666 struct zone *zone = page_zone(virt_to_page(ti));
86667 +#endif
86668
86669 mod_zone_page_state(zone, NR_KERNEL_STACK, account);
86670 }
86671
86672 void free_task(struct task_struct *tsk)
86673 {
86674 - account_kernel_stack(tsk->stack, -1);
86675 + account_kernel_stack(tsk, tsk->stack, -1);
86676 arch_release_thread_info(tsk->stack);
86677 - free_thread_info(tsk->stack);
86678 + gr_free_thread_info(tsk, tsk->stack);
86679 rt_mutex_debug_task_free(tsk);
86680 ftrace_graph_exit_task(tsk);
86681 put_seccomp_filter(tsk);
86682 @@ -299,6 +345,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86683 struct task_struct *tsk;
86684 struct thread_info *ti;
86685 unsigned long *stackend;
86686 + void *lowmem_stack;
86687 int node = tsk_fork_get_node(orig);
86688 int err;
86689
86690 @@ -306,7 +353,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86691 if (!tsk)
86692 return NULL;
86693
86694 - ti = alloc_thread_info_node(tsk, node);
86695 + ti = gr_alloc_thread_info_node(tsk, node, &lowmem_stack);
86696 if (!ti)
86697 goto free_tsk;
86698
86699 @@ -315,6 +362,9 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86700 goto free_ti;
86701
86702 tsk->stack = ti;
86703 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86704 + tsk->lowmem_stack = lowmem_stack;
86705 +#endif
86706
86707 setup_thread_stack(tsk, orig);
86708 clear_user_return_notifier(tsk);
86709 @@ -323,7 +373,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86710 *stackend = STACK_END_MAGIC; /* for overflow detection */
86711
86712 #ifdef CONFIG_CC_STACKPROTECTOR
86713 - tsk->stack_canary = get_random_int();
86714 + tsk->stack_canary = pax_get_random_long();
86715 #endif
86716
86717 /*
86718 @@ -337,24 +387,92 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86719 tsk->splice_pipe = NULL;
86720 tsk->task_frag.page = NULL;
86721
86722 - account_kernel_stack(ti, 1);
86723 + account_kernel_stack(tsk, ti, 1);
86724
86725 return tsk;
86726
86727 free_ti:
86728 - free_thread_info(ti);
86729 + gr_free_thread_info(tsk, ti);
86730 free_tsk:
86731 free_task_struct(tsk);
86732 return NULL;
86733 }
86734
86735 #ifdef CONFIG_MMU
86736 -static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86737 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
86738 +{
86739 + struct vm_area_struct *tmp;
86740 + unsigned long charge;
86741 + struct file *file;
86742 + int retval;
86743 +
86744 + charge = 0;
86745 + if (mpnt->vm_flags & VM_ACCOUNT) {
86746 + unsigned long len = vma_pages(mpnt);
86747 +
86748 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
86749 + goto fail_nomem;
86750 + charge = len;
86751 + }
86752 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
86753 + if (!tmp)
86754 + goto fail_nomem;
86755 + *tmp = *mpnt;
86756 + tmp->vm_mm = mm;
86757 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
86758 + retval = vma_dup_policy(mpnt, tmp);
86759 + if (retval)
86760 + goto fail_nomem_policy;
86761 + if (anon_vma_fork(tmp, mpnt))
86762 + goto fail_nomem_anon_vma_fork;
86763 + tmp->vm_flags &= ~VM_LOCKED;
86764 + tmp->vm_next = tmp->vm_prev = NULL;
86765 + tmp->vm_mirror = NULL;
86766 + file = tmp->vm_file;
86767 + if (file) {
86768 + struct inode *inode = file_inode(file);
86769 + struct address_space *mapping = file->f_mapping;
86770 +
86771 + get_file(file);
86772 + if (tmp->vm_flags & VM_DENYWRITE)
86773 + atomic_dec(&inode->i_writecount);
86774 + mutex_lock(&mapping->i_mmap_mutex);
86775 + if (tmp->vm_flags & VM_SHARED)
86776 + mapping->i_mmap_writable++;
86777 + flush_dcache_mmap_lock(mapping);
86778 + /* insert tmp into the share list, just after mpnt */
86779 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
86780 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
86781 + else
86782 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
86783 + flush_dcache_mmap_unlock(mapping);
86784 + mutex_unlock(&mapping->i_mmap_mutex);
86785 + }
86786 +
86787 + /*
86788 + * Clear hugetlb-related page reserves for children. This only
86789 + * affects MAP_PRIVATE mappings. Faults generated by the child
86790 + * are not guaranteed to succeed, even if read-only
86791 + */
86792 + if (is_vm_hugetlb_page(tmp))
86793 + reset_vma_resv_huge_pages(tmp);
86794 +
86795 + return tmp;
86796 +
86797 +fail_nomem_anon_vma_fork:
86798 + mpol_put(vma_policy(tmp));
86799 +fail_nomem_policy:
86800 + kmem_cache_free(vm_area_cachep, tmp);
86801 +fail_nomem:
86802 + vm_unacct_memory(charge);
86803 + return NULL;
86804 +}
86805 +
86806 +static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86807 {
86808 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
86809 struct rb_node **rb_link, *rb_parent;
86810 int retval;
86811 - unsigned long charge;
86812
86813 uprobe_start_dup_mmap();
86814 down_write(&oldmm->mmap_sem);
86815 @@ -383,55 +501,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86816
86817 prev = NULL;
86818 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
86819 - struct file *file;
86820 -
86821 if (mpnt->vm_flags & VM_DONTCOPY) {
86822 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
86823 -vma_pages(mpnt));
86824 continue;
86825 }
86826 - charge = 0;
86827 - if (mpnt->vm_flags & VM_ACCOUNT) {
86828 - unsigned long len = vma_pages(mpnt);
86829 -
86830 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
86831 - goto fail_nomem;
86832 - charge = len;
86833 - }
86834 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
86835 - if (!tmp)
86836 - goto fail_nomem;
86837 - *tmp = *mpnt;
86838 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
86839 - retval = vma_dup_policy(mpnt, tmp);
86840 - if (retval)
86841 - goto fail_nomem_policy;
86842 - tmp->vm_mm = mm;
86843 - if (anon_vma_fork(tmp, mpnt))
86844 - goto fail_nomem_anon_vma_fork;
86845 - tmp->vm_flags &= ~VM_LOCKED;
86846 - tmp->vm_next = tmp->vm_prev = NULL;
86847 - file = tmp->vm_file;
86848 - if (file) {
86849 - struct inode *inode = file_inode(file);
86850 - struct address_space *mapping = file->f_mapping;
86851 -
86852 - get_file(file);
86853 - if (tmp->vm_flags & VM_DENYWRITE)
86854 - atomic_dec(&inode->i_writecount);
86855 - mutex_lock(&mapping->i_mmap_mutex);
86856 - if (tmp->vm_flags & VM_SHARED)
86857 - mapping->i_mmap_writable++;
86858 - flush_dcache_mmap_lock(mapping);
86859 - /* insert tmp into the share list, just after mpnt */
86860 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
86861 - vma_nonlinear_insert(tmp,
86862 - &mapping->i_mmap_nonlinear);
86863 - else
86864 - vma_interval_tree_insert_after(tmp, mpnt,
86865 - &mapping->i_mmap);
86866 - flush_dcache_mmap_unlock(mapping);
86867 - mutex_unlock(&mapping->i_mmap_mutex);
86868 + tmp = dup_vma(mm, oldmm, mpnt);
86869 + if (!tmp) {
86870 + retval = -ENOMEM;
86871 + goto out;
86872 }
86873
86874 /*
86875 @@ -463,6 +541,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86876 if (retval)
86877 goto out;
86878 }
86879 +
86880 +#ifdef CONFIG_PAX_SEGMEXEC
86881 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
86882 + struct vm_area_struct *mpnt_m;
86883 +
86884 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
86885 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
86886 +
86887 + if (!mpnt->vm_mirror)
86888 + continue;
86889 +
86890 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
86891 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
86892 + mpnt->vm_mirror = mpnt_m;
86893 + } else {
86894 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
86895 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
86896 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
86897 + mpnt->vm_mirror->vm_mirror = mpnt;
86898 + }
86899 + }
86900 + BUG_ON(mpnt_m);
86901 + }
86902 +#endif
86903 +
86904 /* a new mm has just been created */
86905 arch_dup_mmap(oldmm, mm);
86906 retval = 0;
86907 @@ -472,14 +575,6 @@ out:
86908 up_write(&oldmm->mmap_sem);
86909 uprobe_end_dup_mmap();
86910 return retval;
86911 -fail_nomem_anon_vma_fork:
86912 - mpol_put(vma_policy(tmp));
86913 -fail_nomem_policy:
86914 - kmem_cache_free(vm_area_cachep, tmp);
86915 -fail_nomem:
86916 - retval = -ENOMEM;
86917 - vm_unacct_memory(charge);
86918 - goto out;
86919 }
86920
86921 static inline int mm_alloc_pgd(struct mm_struct *mm)
86922 @@ -698,8 +793,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
86923 return ERR_PTR(err);
86924
86925 mm = get_task_mm(task);
86926 - if (mm && mm != current->mm &&
86927 - !ptrace_may_access(task, mode)) {
86928 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
86929 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
86930 mmput(mm);
86931 mm = ERR_PTR(-EACCES);
86932 }
86933 @@ -918,13 +1013,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
86934 spin_unlock(&fs->lock);
86935 return -EAGAIN;
86936 }
86937 - fs->users++;
86938 + atomic_inc(&fs->users);
86939 spin_unlock(&fs->lock);
86940 return 0;
86941 }
86942 tsk->fs = copy_fs_struct(fs);
86943 if (!tsk->fs)
86944 return -ENOMEM;
86945 + /* Carry through gr_chroot_dentry and is_chrooted instead
86946 + of recomputing it here. Already copied when the task struct
86947 + is duplicated. This allows pivot_root to not be treated as
86948 + a chroot
86949 + */
86950 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
86951 +
86952 return 0;
86953 }
86954
86955 @@ -1133,7 +1235,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
86956 * parts of the process environment (as per the clone
86957 * flags). The actual kick-off is left to the caller.
86958 */
86959 -static struct task_struct *copy_process(unsigned long clone_flags,
86960 +static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
86961 unsigned long stack_start,
86962 unsigned long stack_size,
86963 int __user *child_tidptr,
86964 @@ -1205,6 +1307,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
86965 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
86966 #endif
86967 retval = -EAGAIN;
86968 +
86969 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
86970 +
86971 if (atomic_read(&p->real_cred->user->processes) >=
86972 task_rlimit(p, RLIMIT_NPROC)) {
86973 if (p->real_cred->user != INIT_USER &&
86974 @@ -1452,6 +1557,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
86975 goto bad_fork_free_pid;
86976 }
86977
86978 + /* synchronizes with gr_set_acls()
86979 + we need to call this past the point of no return for fork()
86980 + */
86981 + gr_copy_label(p);
86982 +
86983 if (likely(p->pid)) {
86984 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
86985
86986 @@ -1541,6 +1651,8 @@ bad_fork_cleanup_count:
86987 bad_fork_free:
86988 free_task(p);
86989 fork_out:
86990 + gr_log_forkfail(retval);
86991 +
86992 return ERR_PTR(retval);
86993 }
86994
86995 @@ -1602,6 +1714,7 @@ long do_fork(unsigned long clone_flags,
86996
86997 p = copy_process(clone_flags, stack_start, stack_size,
86998 child_tidptr, NULL, trace);
86999 + add_latent_entropy();
87000 /*
87001 * Do this prior waking up the new thread - the thread pointer
87002 * might get invalid after that point, if the thread exits quickly.
87003 @@ -1618,6 +1731,8 @@ long do_fork(unsigned long clone_flags,
87004 if (clone_flags & CLONE_PARENT_SETTID)
87005 put_user(nr, parent_tidptr);
87006
87007 + gr_handle_brute_check();
87008 +
87009 if (clone_flags & CLONE_VFORK) {
87010 p->vfork_done = &vfork;
87011 init_completion(&vfork);
87012 @@ -1736,7 +1851,7 @@ void __init proc_caches_init(void)
87013 mm_cachep = kmem_cache_create("mm_struct",
87014 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
87015 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
87016 - vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
87017 + vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
87018 mmap_init();
87019 nsproxy_cache_init();
87020 }
87021 @@ -1776,7 +1891,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
87022 return 0;
87023
87024 /* don't need lock here; in the worst case we'll do useless copy */
87025 - if (fs->users == 1)
87026 + if (atomic_read(&fs->users) == 1)
87027 return 0;
87028
87029 *new_fsp = copy_fs_struct(fs);
87030 @@ -1883,7 +1998,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
87031 fs = current->fs;
87032 spin_lock(&fs->lock);
87033 current->fs = new_fs;
87034 - if (--fs->users)
87035 + gr_set_chroot_entries(current, &current->fs->root);
87036 + if (atomic_dec_return(&fs->users))
87037 new_fs = NULL;
87038 else
87039 new_fs = fs;
87040 diff --git a/kernel/futex.c b/kernel/futex.c
87041 index de938d2..c566038 100644
87042 --- a/kernel/futex.c
87043 +++ b/kernel/futex.c
87044 @@ -202,7 +202,7 @@ struct futex_pi_state {
87045 atomic_t refcount;
87046
87047 union futex_key key;
87048 -};
87049 +} __randomize_layout;
87050
87051 /**
87052 * struct futex_q - The hashed futex queue entry, one per waiting task
87053 @@ -236,7 +236,7 @@ struct futex_q {
87054 struct rt_mutex_waiter *rt_waiter;
87055 union futex_key *requeue_pi_key;
87056 u32 bitset;
87057 -};
87058 +} __randomize_layout;
87059
87060 static const struct futex_q futex_q_init = {
87061 /* list gets initialized in queue_me()*/
87062 @@ -394,6 +394,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
87063 struct page *page, *page_head;
87064 int err, ro = 0;
87065
87066 +#ifdef CONFIG_PAX_SEGMEXEC
87067 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
87068 + return -EFAULT;
87069 +#endif
87070 +
87071 /*
87072 * The futex address must be "naturally" aligned.
87073 */
87074 @@ -593,7 +598,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
87075
87076 static int get_futex_value_locked(u32 *dest, u32 __user *from)
87077 {
87078 - int ret;
87079 + unsigned long ret;
87080
87081 pagefault_disable();
87082 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
87083 @@ -3033,6 +3038,7 @@ static void __init futex_detect_cmpxchg(void)
87084 {
87085 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
87086 u32 curval;
87087 + mm_segment_t oldfs;
87088
87089 /*
87090 * This will fail and we want it. Some arch implementations do
87091 @@ -3044,8 +3050,11 @@ static void __init futex_detect_cmpxchg(void)
87092 * implementation, the non-functional ones will return
87093 * -ENOSYS.
87094 */
87095 + oldfs = get_fs();
87096 + set_fs(USER_DS);
87097 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
87098 futex_cmpxchg_enabled = 1;
87099 + set_fs(oldfs);
87100 #endif
87101 }
87102
87103 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
87104 index 55c8c93..9ba7ad6 100644
87105 --- a/kernel/futex_compat.c
87106 +++ b/kernel/futex_compat.c
87107 @@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
87108 return 0;
87109 }
87110
87111 -static void __user *futex_uaddr(struct robust_list __user *entry,
87112 +static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
87113 compat_long_t futex_offset)
87114 {
87115 compat_uptr_t base = ptr_to_compat(entry);
87116 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
87117 index f45b75b..bfac6d5 100644
87118 --- a/kernel/gcov/base.c
87119 +++ b/kernel/gcov/base.c
87120 @@ -108,11 +108,6 @@ void gcov_enable_events(void)
87121 }
87122
87123 #ifdef CONFIG_MODULES
87124 -static inline int within(void *addr, void *start, unsigned long size)
87125 -{
87126 - return ((addr >= start) && (addr < start + size));
87127 -}
87128 -
87129 /* Update list and generate events when modules are unloaded. */
87130 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
87131 void *data)
87132 @@ -127,7 +122,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
87133
87134 /* Remove entries located in module from linked list. */
87135 while ((info = gcov_info_next(info))) {
87136 - if (within(info, mod->module_core, mod->core_size)) {
87137 + if (within_module_core_rw((unsigned long)info, mod)) {
87138 gcov_info_unlink(prev, info);
87139 if (gcov_events_enabled)
87140 gcov_event(GCOV_REMOVE, info);
87141 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
87142 index e0501fe..312edd6 100644
87143 --- a/kernel/hrtimer.c
87144 +++ b/kernel/hrtimer.c
87145 @@ -1448,7 +1448,7 @@ void hrtimer_peek_ahead_timers(void)
87146 local_irq_restore(flags);
87147 }
87148
87149 -static void run_hrtimer_softirq(struct softirq_action *h)
87150 +static __latent_entropy void run_hrtimer_softirq(void)
87151 {
87152 hrtimer_peek_ahead_timers();
87153 }
87154 diff --git a/kernel/irq_work.c b/kernel/irq_work.c
87155 index a82170e..5b01e7f 100644
87156 --- a/kernel/irq_work.c
87157 +++ b/kernel/irq_work.c
87158 @@ -191,12 +191,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
87159 return NOTIFY_OK;
87160 }
87161
87162 -static struct notifier_block cpu_notify;
87163 +static struct notifier_block cpu_notify = {
87164 + .notifier_call = irq_work_cpu_notify,
87165 + .priority = 0,
87166 +};
87167
87168 static __init int irq_work_init_cpu_notifier(void)
87169 {
87170 - cpu_notify.notifier_call = irq_work_cpu_notify;
87171 - cpu_notify.priority = 0;
87172 register_cpu_notifier(&cpu_notify);
87173 return 0;
87174 }
87175 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
87176 index 9019f15..9a3c42e 100644
87177 --- a/kernel/jump_label.c
87178 +++ b/kernel/jump_label.c
87179 @@ -14,6 +14,7 @@
87180 #include <linux/err.h>
87181 #include <linux/static_key.h>
87182 #include <linux/jump_label_ratelimit.h>
87183 +#include <linux/mm.h>
87184
87185 #ifdef HAVE_JUMP_LABEL
87186
87187 @@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
87188
87189 size = (((unsigned long)stop - (unsigned long)start)
87190 / sizeof(struct jump_entry));
87191 + pax_open_kernel();
87192 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
87193 + pax_close_kernel();
87194 }
87195
87196 static void jump_label_update(struct static_key *key, int enable);
87197 @@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
87198 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
87199 struct jump_entry *iter;
87200
87201 + pax_open_kernel();
87202 for (iter = iter_start; iter < iter_stop; iter++) {
87203 if (within_module_init(iter->code, mod))
87204 iter->code = 0;
87205 }
87206 + pax_close_kernel();
87207 }
87208
87209 static int
87210 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
87211 index cb0cf37..b69e161 100644
87212 --- a/kernel/kallsyms.c
87213 +++ b/kernel/kallsyms.c
87214 @@ -11,6 +11,9 @@
87215 * Changed the compression method from stem compression to "table lookup"
87216 * compression (see scripts/kallsyms.c for a more complete description)
87217 */
87218 +#ifdef CONFIG_GRKERNSEC_HIDESYM
87219 +#define __INCLUDED_BY_HIDESYM 1
87220 +#endif
87221 #include <linux/kallsyms.h>
87222 #include <linux/module.h>
87223 #include <linux/init.h>
87224 @@ -54,12 +57,33 @@ extern const unsigned long kallsyms_markers[] __weak;
87225
87226 static inline int is_kernel_inittext(unsigned long addr)
87227 {
87228 + if (system_state != SYSTEM_BOOTING)
87229 + return 0;
87230 +
87231 if (addr >= (unsigned long)_sinittext
87232 && addr <= (unsigned long)_einittext)
87233 return 1;
87234 return 0;
87235 }
87236
87237 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
87238 +#ifdef CONFIG_MODULES
87239 +static inline int is_module_text(unsigned long addr)
87240 +{
87241 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
87242 + return 1;
87243 +
87244 + addr = ktla_ktva(addr);
87245 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
87246 +}
87247 +#else
87248 +static inline int is_module_text(unsigned long addr)
87249 +{
87250 + return 0;
87251 +}
87252 +#endif
87253 +#endif
87254 +
87255 static inline int is_kernel_text(unsigned long addr)
87256 {
87257 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
87258 @@ -70,13 +94,28 @@ static inline int is_kernel_text(unsigned long addr)
87259
87260 static inline int is_kernel(unsigned long addr)
87261 {
87262 +
87263 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
87264 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
87265 + return 1;
87266 +
87267 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
87268 +#else
87269 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
87270 +#endif
87271 +
87272 return 1;
87273 return in_gate_area_no_mm(addr);
87274 }
87275
87276 static int is_ksym_addr(unsigned long addr)
87277 {
87278 +
87279 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
87280 + if (is_module_text(addr))
87281 + return 0;
87282 +#endif
87283 +
87284 if (all_var)
87285 return is_kernel(addr);
87286
87287 @@ -481,7 +520,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
87288
87289 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
87290 {
87291 - iter->name[0] = '\0';
87292 iter->nameoff = get_symbol_offset(new_pos);
87293 iter->pos = new_pos;
87294 }
87295 @@ -529,6 +567,11 @@ static int s_show(struct seq_file *m, void *p)
87296 {
87297 struct kallsym_iter *iter = m->private;
87298
87299 +#ifdef CONFIG_GRKERNSEC_HIDESYM
87300 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
87301 + return 0;
87302 +#endif
87303 +
87304 /* Some debugging symbols have no name. Ignore them. */
87305 if (!iter->name[0])
87306 return 0;
87307 @@ -542,6 +585,7 @@ static int s_show(struct seq_file *m, void *p)
87308 */
87309 type = iter->exported ? toupper(iter->type) :
87310 tolower(iter->type);
87311 +
87312 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
87313 type, iter->name, iter->module_name);
87314 } else
87315 @@ -567,7 +611,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
87316 struct kallsym_iter *iter;
87317 int ret;
87318
87319 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
87320 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
87321 if (!iter)
87322 return -ENOMEM;
87323 reset_iter(iter, 0);
87324 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
87325 index e30ac0f..3528cac 100644
87326 --- a/kernel/kcmp.c
87327 +++ b/kernel/kcmp.c
87328 @@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
87329 struct task_struct *task1, *task2;
87330 int ret;
87331
87332 +#ifdef CONFIG_GRKERNSEC
87333 + return -ENOSYS;
87334 +#endif
87335 +
87336 rcu_read_lock();
87337
87338 /*
87339 diff --git a/kernel/kexec.c b/kernel/kexec.c
87340 index 28c5706..bfc8388 100644
87341 --- a/kernel/kexec.c
87342 +++ b/kernel/kexec.c
87343 @@ -1046,7 +1046,8 @@ COMPAT_SYSCALL_DEFINE4(kexec_load, compat_ulong_t, entry,
87344 compat_ulong_t, flags)
87345 {
87346 struct compat_kexec_segment in;
87347 - struct kexec_segment out, __user *ksegments;
87348 + struct kexec_segment out;
87349 + struct kexec_segment __user *ksegments;
87350 unsigned long i, result;
87351
87352 /* Don't allow clients that don't understand the native
87353 diff --git a/kernel/kmod.c b/kernel/kmod.c
87354 index 6b375af..eaff670 100644
87355 --- a/kernel/kmod.c
87356 +++ b/kernel/kmod.c
87357 @@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
87358 kfree(info->argv);
87359 }
87360
87361 -static int call_modprobe(char *module_name, int wait)
87362 +static int call_modprobe(char *module_name, char *module_param, int wait)
87363 {
87364 struct subprocess_info *info;
87365 static char *envp[] = {
87366 @@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
87367 NULL
87368 };
87369
87370 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
87371 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
87372 if (!argv)
87373 goto out;
87374
87375 @@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
87376 argv[1] = "-q";
87377 argv[2] = "--";
87378 argv[3] = module_name; /* check free_modprobe_argv() */
87379 - argv[4] = NULL;
87380 + argv[4] = module_param;
87381 + argv[5] = NULL;
87382
87383 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
87384 NULL, free_modprobe_argv, NULL);
87385 @@ -129,9 +130,8 @@ out:
87386 * If module auto-loading support is disabled then this function
87387 * becomes a no-operation.
87388 */
87389 -int __request_module(bool wait, const char *fmt, ...)
87390 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
87391 {
87392 - va_list args;
87393 char module_name[MODULE_NAME_LEN];
87394 unsigned int max_modprobes;
87395 int ret;
87396 @@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
87397 if (!modprobe_path[0])
87398 return 0;
87399
87400 - va_start(args, fmt);
87401 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
87402 - va_end(args);
87403 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
87404 if (ret >= MODULE_NAME_LEN)
87405 return -ENAMETOOLONG;
87406
87407 @@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
87408 if (ret)
87409 return ret;
87410
87411 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
87412 + if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
87413 + /* hack to workaround consolekit/udisks stupidity */
87414 + read_lock(&tasklist_lock);
87415 + if (!strcmp(current->comm, "mount") &&
87416 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
87417 + read_unlock(&tasklist_lock);
87418 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
87419 + return -EPERM;
87420 + }
87421 + read_unlock(&tasklist_lock);
87422 + }
87423 +#endif
87424 +
87425 /* If modprobe needs a service that is in a module, we get a recursive
87426 * loop. Limit the number of running kmod threads to max_threads/2 or
87427 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
87428 @@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
87429
87430 trace_module_request(module_name, wait, _RET_IP_);
87431
87432 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
87433 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
87434
87435 atomic_dec(&kmod_concurrent);
87436 return ret;
87437 }
87438 +
87439 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
87440 +{
87441 + va_list args;
87442 + int ret;
87443 +
87444 + va_start(args, fmt);
87445 + ret = ____request_module(wait, module_param, fmt, args);
87446 + va_end(args);
87447 +
87448 + return ret;
87449 +}
87450 +
87451 +int __request_module(bool wait, const char *fmt, ...)
87452 +{
87453 + va_list args;
87454 + int ret;
87455 +
87456 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
87457 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
87458 + char module_param[MODULE_NAME_LEN];
87459 +
87460 + memset(module_param, 0, sizeof(module_param));
87461 +
87462 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
87463 +
87464 + va_start(args, fmt);
87465 + ret = ____request_module(wait, module_param, fmt, args);
87466 + va_end(args);
87467 +
87468 + return ret;
87469 + }
87470 +#endif
87471 +
87472 + va_start(args, fmt);
87473 + ret = ____request_module(wait, NULL, fmt, args);
87474 + va_end(args);
87475 +
87476 + return ret;
87477 +}
87478 +
87479 EXPORT_SYMBOL(__request_module);
87480 #endif /* CONFIG_MODULES */
87481
87482 @@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
87483 */
87484 set_user_nice(current, 0);
87485
87486 +#ifdef CONFIG_GRKERNSEC
87487 + /* this is race-free as far as userland is concerned as we copied
87488 + out the path to be used prior to this point and are now operating
87489 + on that copy
87490 + */
87491 + if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
87492 + strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
87493 + strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
87494 + printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
87495 + retval = -EPERM;
87496 + goto fail;
87497 + }
87498 +#endif
87499 +
87500 retval = -ENOMEM;
87501 new = prepare_kernel_cred(current);
87502 if (!new)
87503 @@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
87504 commit_creds(new);
87505
87506 retval = do_execve(getname_kernel(sub_info->path),
87507 - (const char __user *const __user *)sub_info->argv,
87508 - (const char __user *const __user *)sub_info->envp);
87509 + (const char __user *const __force_user *)sub_info->argv,
87510 + (const char __user *const __force_user *)sub_info->envp);
87511 if (!retval)
87512 return 0;
87513
87514 @@ -260,6 +327,10 @@ static int call_helper(void *data)
87515
87516 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
87517 {
87518 +#ifdef CONFIG_GRKERNSEC
87519 + kfree(info->path);
87520 + info->path = info->origpath;
87521 +#endif
87522 if (info->cleanup)
87523 (*info->cleanup)(info);
87524 kfree(info);
87525 @@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
87526 *
87527 * Thus the __user pointer cast is valid here.
87528 */
87529 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
87530 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
87531
87532 /*
87533 * If ret is 0, either ____call_usermodehelper failed and the
87534 @@ -542,7 +613,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
87535 goto out;
87536
87537 INIT_WORK(&sub_info->work, __call_usermodehelper);
87538 +#ifdef CONFIG_GRKERNSEC
87539 + sub_info->origpath = path;
87540 + sub_info->path = kstrdup(path, gfp_mask);
87541 +#else
87542 sub_info->path = path;
87543 +#endif
87544 sub_info->argv = argv;
87545 sub_info->envp = envp;
87546
87547 @@ -650,7 +726,7 @@ EXPORT_SYMBOL(call_usermodehelper);
87548 static int proc_cap_handler(struct ctl_table *table, int write,
87549 void __user *buffer, size_t *lenp, loff_t *ppos)
87550 {
87551 - struct ctl_table t;
87552 + ctl_table_no_const t;
87553 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
87554 kernel_cap_t new_cap;
87555 int err, i;
87556 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
87557 index ceeadfc..11c18b6 100644
87558 --- a/kernel/kprobes.c
87559 +++ b/kernel/kprobes.c
87560 @@ -31,6 +31,9 @@
87561 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
87562 * <prasanna@in.ibm.com> added function-return probes.
87563 */
87564 +#ifdef CONFIG_GRKERNSEC_HIDESYM
87565 +#define __INCLUDED_BY_HIDESYM 1
87566 +#endif
87567 #include <linux/kprobes.h>
87568 #include <linux/hash.h>
87569 #include <linux/init.h>
87570 @@ -135,12 +138,12 @@ enum kprobe_slot_state {
87571
87572 static void *alloc_insn_page(void)
87573 {
87574 - return module_alloc(PAGE_SIZE);
87575 + return module_alloc_exec(PAGE_SIZE);
87576 }
87577
87578 static void free_insn_page(void *page)
87579 {
87580 - module_free(NULL, page);
87581 + module_free_exec(NULL, page);
87582 }
87583
87584 struct kprobe_insn_cache kprobe_insn_slots = {
87585 @@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
87586 kprobe_type = "k";
87587
87588 if (sym)
87589 - seq_printf(pi, "%p %s %s+0x%x %s ",
87590 + seq_printf(pi, "%pK %s %s+0x%x %s ",
87591 p->addr, kprobe_type, sym, offset,
87592 (modname ? modname : " "));
87593 else
87594 - seq_printf(pi, "%p %s %p ",
87595 + seq_printf(pi, "%pK %s %pK ",
87596 p->addr, kprobe_type, p->addr);
87597
87598 if (!pp)
87599 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
87600 index 2495a9b..071b906 100644
87601 --- a/kernel/ksysfs.c
87602 +++ b/kernel/ksysfs.c
87603 @@ -49,6 +49,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
87604 {
87605 if (count+1 > UEVENT_HELPER_PATH_LEN)
87606 return -ENOENT;
87607 + if (!capable(CAP_SYS_ADMIN))
87608 + return -EPERM;
87609 memcpy(uevent_helper, buf, count);
87610 uevent_helper[count] = '\0';
87611 if (count && uevent_helper[count-1] == '\n')
87612 @@ -175,7 +177,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
87613 return count;
87614 }
87615
87616 -static struct bin_attribute notes_attr = {
87617 +static bin_attribute_no_const notes_attr __read_only = {
87618 .attr = {
87619 .name = "notes",
87620 .mode = S_IRUGO,
87621 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
87622 index d24e433..fa04fb8 100644
87623 --- a/kernel/locking/lockdep.c
87624 +++ b/kernel/locking/lockdep.c
87625 @@ -597,6 +597,10 @@ static int static_obj(void *obj)
87626 end = (unsigned long) &_end,
87627 addr = (unsigned long) obj;
87628
87629 +#ifdef CONFIG_PAX_KERNEXEC
87630 + start = ktla_ktva(start);
87631 +#endif
87632 +
87633 /*
87634 * static variable?
87635 */
87636 @@ -738,6 +742,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
87637 if (!static_obj(lock->key)) {
87638 debug_locks_off();
87639 printk("INFO: trying to register non-static key.\n");
87640 + printk("lock:%pS key:%pS.\n", lock, lock->key);
87641 printk("the code is fine but needs lockdep annotation.\n");
87642 printk("turning off the locking correctness validator.\n");
87643 dump_stack();
87644 @@ -3079,7 +3084,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
87645 if (!class)
87646 return 0;
87647 }
87648 - atomic_inc((atomic_t *)&class->ops);
87649 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
87650 if (very_verbose(class)) {
87651 printk("\nacquire class [%p] %s", class->key, class->name);
87652 if (class->name_version > 1)
87653 diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
87654 index ef43ac4..2720dfa 100644
87655 --- a/kernel/locking/lockdep_proc.c
87656 +++ b/kernel/locking/lockdep_proc.c
87657 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
87658 return 0;
87659 }
87660
87661 - seq_printf(m, "%p", class->key);
87662 + seq_printf(m, "%pK", class->key);
87663 #ifdef CONFIG_DEBUG_LOCKDEP
87664 seq_printf(m, " OPS:%8ld", class->ops);
87665 #endif
87666 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
87667
87668 list_for_each_entry(entry, &class->locks_after, entry) {
87669 if (entry->distance == 1) {
87670 - seq_printf(m, " -> [%p] ", entry->class->key);
87671 + seq_printf(m, " -> [%pK] ", entry->class->key);
87672 print_name(m, entry->class);
87673 seq_puts(m, "\n");
87674 }
87675 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
87676 if (!class->key)
87677 continue;
87678
87679 - seq_printf(m, "[%p] ", class->key);
87680 + seq_printf(m, "[%pK] ", class->key);
87681 print_name(m, class);
87682 seq_puts(m, "\n");
87683 }
87684 @@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
87685 if (!i)
87686 seq_line(m, '-', 40-namelen, namelen);
87687
87688 - snprintf(ip, sizeof(ip), "[<%p>]",
87689 + snprintf(ip, sizeof(ip), "[<%pK>]",
87690 (void *)class->contention_point[i]);
87691 seq_printf(m, "%40s %14lu %29s %pS\n",
87692 name, stats->contention_point[i],
87693 @@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
87694 if (!i)
87695 seq_line(m, '-', 40-namelen, namelen);
87696
87697 - snprintf(ip, sizeof(ip), "[<%p>]",
87698 + snprintf(ip, sizeof(ip), "[<%pK>]",
87699 (void *)class->contending_point[i]);
87700 seq_printf(m, "%40s %14lu %29s %pS\n",
87701 name, stats->contending_point[i],
87702 diff --git a/kernel/locking/mcs_spinlock.c b/kernel/locking/mcs_spinlock.c
87703 index 838dc9e..760e158 100644
87704 --- a/kernel/locking/mcs_spinlock.c
87705 +++ b/kernel/locking/mcs_spinlock.c
87706 @@ -71,7 +71,7 @@ bool osq_lock(struct optimistic_spin_queue **lock)
87707 if (likely(prev == NULL))
87708 return true;
87709
87710 - ACCESS_ONCE(prev->next) = node;
87711 + ACCESS_ONCE_RW(prev->next) = node;
87712
87713 /*
87714 * Normally @prev is untouchable after the above store; because at that
87715 @@ -143,8 +143,8 @@ unqueue:
87716 * it will wait in Step-A.
87717 */
87718
87719 - ACCESS_ONCE(next->prev) = prev;
87720 - ACCESS_ONCE(prev->next) = next;
87721 + ACCESS_ONCE_RW(next->prev) = prev;
87722 + ACCESS_ONCE_RW(prev->next) = next;
87723
87724 return false;
87725 }
87726 @@ -165,13 +165,13 @@ void osq_unlock(struct optimistic_spin_queue **lock)
87727 */
87728 next = xchg(&node->next, NULL);
87729 if (next) {
87730 - ACCESS_ONCE(next->locked) = 1;
87731 + ACCESS_ONCE_RW(next->locked) = 1;
87732 return;
87733 }
87734
87735 next = osq_wait_next(lock, node, NULL);
87736 if (next)
87737 - ACCESS_ONCE(next->locked) = 1;
87738 + ACCESS_ONCE_RW(next->locked) = 1;
87739 }
87740
87741 #endif
87742 diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h
87743 index a2dbac4..e02a34a 100644
87744 --- a/kernel/locking/mcs_spinlock.h
87745 +++ b/kernel/locking/mcs_spinlock.h
87746 @@ -81,7 +81,7 @@ void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node)
87747 */
87748 return;
87749 }
87750 - ACCESS_ONCE(prev->next) = node;
87751 + ACCESS_ONCE_RW(prev->next) = node;
87752
87753 /* Wait until the lock holder passes the lock down. */
87754 arch_mcs_spin_lock_contended(&node->locked);
87755 diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
87756 index 5cf6731..ce3bc5a 100644
87757 --- a/kernel/locking/mutex-debug.c
87758 +++ b/kernel/locking/mutex-debug.c
87759 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
87760 }
87761
87762 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87763 - struct thread_info *ti)
87764 + struct task_struct *task)
87765 {
87766 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
87767
87768 /* Mark the current thread as blocked on the lock: */
87769 - ti->task->blocked_on = waiter;
87770 + task->blocked_on = waiter;
87771 }
87772
87773 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87774 - struct thread_info *ti)
87775 + struct task_struct *task)
87776 {
87777 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
87778 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
87779 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
87780 - ti->task->blocked_on = NULL;
87781 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
87782 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
87783 + task->blocked_on = NULL;
87784
87785 list_del_init(&waiter->list);
87786 waiter->task = NULL;
87787 diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
87788 index 0799fd3..d06ae3b 100644
87789 --- a/kernel/locking/mutex-debug.h
87790 +++ b/kernel/locking/mutex-debug.h
87791 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
87792 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
87793 extern void debug_mutex_add_waiter(struct mutex *lock,
87794 struct mutex_waiter *waiter,
87795 - struct thread_info *ti);
87796 + struct task_struct *task);
87797 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87798 - struct thread_info *ti);
87799 + struct task_struct *task);
87800 extern void debug_mutex_unlock(struct mutex *lock);
87801 extern void debug_mutex_init(struct mutex *lock, const char *name,
87802 struct lock_class_key *key);
87803 diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
87804 index bc73d33..6f308aa 100644
87805 --- a/kernel/locking/mutex.c
87806 +++ b/kernel/locking/mutex.c
87807 @@ -490,7 +490,7 @@ slowpath:
87808 goto skip_wait;
87809
87810 debug_mutex_lock_common(lock, &waiter);
87811 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
87812 + debug_mutex_add_waiter(lock, &waiter, task);
87813
87814 /* add waiting tasks to the end of the waitqueue (FIFO): */
87815 list_add_tail(&waiter.list, &lock->wait_list);
87816 @@ -534,7 +534,7 @@ slowpath:
87817 schedule_preempt_disabled();
87818 spin_lock_mutex(&lock->wait_lock, flags);
87819 }
87820 - mutex_remove_waiter(lock, &waiter, current_thread_info());
87821 + mutex_remove_waiter(lock, &waiter, task);
87822 /* set it to 0 if there are no waiters left: */
87823 if (likely(list_empty(&lock->wait_list)))
87824 atomic_set(&lock->count, 0);
87825 @@ -571,7 +571,7 @@ skip_wait:
87826 return 0;
87827
87828 err:
87829 - mutex_remove_waiter(lock, &waiter, task_thread_info(task));
87830 + mutex_remove_waiter(lock, &waiter, task);
87831 spin_unlock_mutex(&lock->wait_lock, flags);
87832 debug_mutex_free_waiter(&waiter);
87833 mutex_release(&lock->dep_map, 1, ip);
87834 diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
87835 index 1d96dd0..994ff19 100644
87836 --- a/kernel/locking/rtmutex-tester.c
87837 +++ b/kernel/locking/rtmutex-tester.c
87838 @@ -22,7 +22,7 @@
87839 #define MAX_RT_TEST_MUTEXES 8
87840
87841 static spinlock_t rttest_lock;
87842 -static atomic_t rttest_event;
87843 +static atomic_unchecked_t rttest_event;
87844
87845 struct test_thread_data {
87846 int opcode;
87847 @@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87848
87849 case RTTEST_LOCKCONT:
87850 td->mutexes[td->opdata] = 1;
87851 - td->event = atomic_add_return(1, &rttest_event);
87852 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87853 return 0;
87854
87855 case RTTEST_RESET:
87856 @@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87857 return 0;
87858
87859 case RTTEST_RESETEVENT:
87860 - atomic_set(&rttest_event, 0);
87861 + atomic_set_unchecked(&rttest_event, 0);
87862 return 0;
87863
87864 default:
87865 @@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87866 return ret;
87867
87868 td->mutexes[id] = 1;
87869 - td->event = atomic_add_return(1, &rttest_event);
87870 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87871 rt_mutex_lock(&mutexes[id]);
87872 - td->event = atomic_add_return(1, &rttest_event);
87873 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87874 td->mutexes[id] = 4;
87875 return 0;
87876
87877 @@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87878 return ret;
87879
87880 td->mutexes[id] = 1;
87881 - td->event = atomic_add_return(1, &rttest_event);
87882 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87883 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
87884 - td->event = atomic_add_return(1, &rttest_event);
87885 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87886 td->mutexes[id] = ret ? 0 : 4;
87887 return ret ? -EINTR : 0;
87888
87889 @@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87890 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
87891 return ret;
87892
87893 - td->event = atomic_add_return(1, &rttest_event);
87894 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87895 rt_mutex_unlock(&mutexes[id]);
87896 - td->event = atomic_add_return(1, &rttest_event);
87897 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87898 td->mutexes[id] = 0;
87899 return 0;
87900
87901 @@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87902 break;
87903
87904 td->mutexes[dat] = 2;
87905 - td->event = atomic_add_return(1, &rttest_event);
87906 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87907 break;
87908
87909 default:
87910 @@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87911 return;
87912
87913 td->mutexes[dat] = 3;
87914 - td->event = atomic_add_return(1, &rttest_event);
87915 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87916 break;
87917
87918 case RTTEST_LOCKNOWAIT:
87919 @@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87920 return;
87921
87922 td->mutexes[dat] = 1;
87923 - td->event = atomic_add_return(1, &rttest_event);
87924 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87925 return;
87926
87927 default:
87928 diff --git a/kernel/module.c b/kernel/module.c
87929 index 079c461..741f79c 100644
87930 --- a/kernel/module.c
87931 +++ b/kernel/module.c
87932 @@ -61,6 +61,7 @@
87933 #include <linux/pfn.h>
87934 #include <linux/bsearch.h>
87935 #include <linux/fips.h>
87936 +#include <linux/grsecurity.h>
87937 #include <uapi/linux/module.h>
87938 #include "module-internal.h"
87939
87940 @@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
87941
87942 /* Bounds of module allocation, for speeding __module_address.
87943 * Protected by module_mutex. */
87944 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
87945 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
87946 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
87947
87948 int register_module_notifier(struct notifier_block * nb)
87949 {
87950 @@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
87951 return true;
87952
87953 list_for_each_entry_rcu(mod, &modules, list) {
87954 - struct symsearch arr[] = {
87955 + struct symsearch modarr[] = {
87956 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
87957 NOT_GPL_ONLY, false },
87958 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
87959 @@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
87960 if (mod->state == MODULE_STATE_UNFORMED)
87961 continue;
87962
87963 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
87964 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
87965 return true;
87966 }
87967 return false;
87968 @@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
87969 if (!pcpusec->sh_size)
87970 return 0;
87971
87972 - if (align > PAGE_SIZE) {
87973 + if (align-1 >= PAGE_SIZE) {
87974 pr_warn("%s: per-cpu alignment %li > %li\n",
87975 mod->name, align, PAGE_SIZE);
87976 align = PAGE_SIZE;
87977 @@ -1061,7 +1063,7 @@ struct module_attribute module_uevent =
87978 static ssize_t show_coresize(struct module_attribute *mattr,
87979 struct module_kobject *mk, char *buffer)
87980 {
87981 - return sprintf(buffer, "%u\n", mk->mod->core_size);
87982 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
87983 }
87984
87985 static struct module_attribute modinfo_coresize =
87986 @@ -1070,7 +1072,7 @@ static struct module_attribute modinfo_coresize =
87987 static ssize_t show_initsize(struct module_attribute *mattr,
87988 struct module_kobject *mk, char *buffer)
87989 {
87990 - return sprintf(buffer, "%u\n", mk->mod->init_size);
87991 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
87992 }
87993
87994 static struct module_attribute modinfo_initsize =
87995 @@ -1162,12 +1164,29 @@ static int check_version(Elf_Shdr *sechdrs,
87996 goto bad_version;
87997 }
87998
87999 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
88000 + /*
88001 + * avoid potentially printing jibberish on attempted load
88002 + * of a module randomized with a different seed
88003 + */
88004 + pr_warn("no symbol version for %s\n", symname);
88005 +#else
88006 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
88007 +#endif
88008 return 0;
88009
88010 bad_version:
88011 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
88012 + /*
88013 + * avoid potentially printing jibberish on attempted load
88014 + * of a module randomized with a different seed
88015 + */
88016 + printk("attempted module disagrees about version of symbol %s\n",
88017 + symname);
88018 +#else
88019 printk("%s: disagrees about version of symbol %s\n",
88020 mod->name, symname);
88021 +#endif
88022 return 0;
88023 }
88024
88025 @@ -1283,7 +1302,7 @@ resolve_symbol_wait(struct module *mod,
88026 */
88027 #ifdef CONFIG_SYSFS
88028
88029 -#ifdef CONFIG_KALLSYMS
88030 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
88031 static inline bool sect_empty(const Elf_Shdr *sect)
88032 {
88033 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
88034 @@ -1423,7 +1442,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
88035 {
88036 unsigned int notes, loaded, i;
88037 struct module_notes_attrs *notes_attrs;
88038 - struct bin_attribute *nattr;
88039 + bin_attribute_no_const *nattr;
88040
88041 /* failed to create section attributes, so can't create notes */
88042 if (!mod->sect_attrs)
88043 @@ -1535,7 +1554,7 @@ static void del_usage_links(struct module *mod)
88044 static int module_add_modinfo_attrs(struct module *mod)
88045 {
88046 struct module_attribute *attr;
88047 - struct module_attribute *temp_attr;
88048 + module_attribute_no_const *temp_attr;
88049 int error = 0;
88050 int i;
88051
88052 @@ -1756,21 +1775,21 @@ static void set_section_ro_nx(void *base,
88053
88054 static void unset_module_core_ro_nx(struct module *mod)
88055 {
88056 - set_page_attributes(mod->module_core + mod->core_text_size,
88057 - mod->module_core + mod->core_size,
88058 + set_page_attributes(mod->module_core_rw,
88059 + mod->module_core_rw + mod->core_size_rw,
88060 set_memory_x);
88061 - set_page_attributes(mod->module_core,
88062 - mod->module_core + mod->core_ro_size,
88063 + set_page_attributes(mod->module_core_rx,
88064 + mod->module_core_rx + mod->core_size_rx,
88065 set_memory_rw);
88066 }
88067
88068 static void unset_module_init_ro_nx(struct module *mod)
88069 {
88070 - set_page_attributes(mod->module_init + mod->init_text_size,
88071 - mod->module_init + mod->init_size,
88072 + set_page_attributes(mod->module_init_rw,
88073 + mod->module_init_rw + mod->init_size_rw,
88074 set_memory_x);
88075 - set_page_attributes(mod->module_init,
88076 - mod->module_init + mod->init_ro_size,
88077 + set_page_attributes(mod->module_init_rx,
88078 + mod->module_init_rx + mod->init_size_rx,
88079 set_memory_rw);
88080 }
88081
88082 @@ -1783,14 +1802,14 @@ void set_all_modules_text_rw(void)
88083 list_for_each_entry_rcu(mod, &modules, list) {
88084 if (mod->state == MODULE_STATE_UNFORMED)
88085 continue;
88086 - if ((mod->module_core) && (mod->core_text_size)) {
88087 - set_page_attributes(mod->module_core,
88088 - mod->module_core + mod->core_text_size,
88089 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
88090 + set_page_attributes(mod->module_core_rx,
88091 + mod->module_core_rx + mod->core_size_rx,
88092 set_memory_rw);
88093 }
88094 - if ((mod->module_init) && (mod->init_text_size)) {
88095 - set_page_attributes(mod->module_init,
88096 - mod->module_init + mod->init_text_size,
88097 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
88098 + set_page_attributes(mod->module_init_rx,
88099 + mod->module_init_rx + mod->init_size_rx,
88100 set_memory_rw);
88101 }
88102 }
88103 @@ -1806,14 +1825,14 @@ void set_all_modules_text_ro(void)
88104 list_for_each_entry_rcu(mod, &modules, list) {
88105 if (mod->state == MODULE_STATE_UNFORMED)
88106 continue;
88107 - if ((mod->module_core) && (mod->core_text_size)) {
88108 - set_page_attributes(mod->module_core,
88109 - mod->module_core + mod->core_text_size,
88110 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
88111 + set_page_attributes(mod->module_core_rx,
88112 + mod->module_core_rx + mod->core_size_rx,
88113 set_memory_ro);
88114 }
88115 - if ((mod->module_init) && (mod->init_text_size)) {
88116 - set_page_attributes(mod->module_init,
88117 - mod->module_init + mod->init_text_size,
88118 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
88119 + set_page_attributes(mod->module_init_rx,
88120 + mod->module_init_rx + mod->init_size_rx,
88121 set_memory_ro);
88122 }
88123 }
88124 @@ -1864,16 +1883,19 @@ static void free_module(struct module *mod)
88125
88126 /* This may be NULL, but that's OK */
88127 unset_module_init_ro_nx(mod);
88128 - module_free(mod, mod->module_init);
88129 + module_free(mod, mod->module_init_rw);
88130 + module_free_exec(mod, mod->module_init_rx);
88131 kfree(mod->args);
88132 percpu_modfree(mod);
88133
88134 /* Free lock-classes: */
88135 - lockdep_free_key_range(mod->module_core, mod->core_size);
88136 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
88137 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
88138
88139 /* Finally, free the core (containing the module structure) */
88140 unset_module_core_ro_nx(mod);
88141 - module_free(mod, mod->module_core);
88142 + module_free_exec(mod, mod->module_core_rx);
88143 + module_free(mod, mod->module_core_rw);
88144
88145 #ifdef CONFIG_MPU
88146 update_protections(current->mm);
88147 @@ -1942,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
88148 int ret = 0;
88149 const struct kernel_symbol *ksym;
88150
88151 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
88152 + int is_fs_load = 0;
88153 + int register_filesystem_found = 0;
88154 + char *p;
88155 +
88156 + p = strstr(mod->args, "grsec_modharden_fs");
88157 + if (p) {
88158 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
88159 + /* copy \0 as well */
88160 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
88161 + is_fs_load = 1;
88162 + }
88163 +#endif
88164 +
88165 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
88166 const char *name = info->strtab + sym[i].st_name;
88167
88168 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
88169 + /* it's a real shame this will never get ripped and copied
88170 + upstream! ;(
88171 + */
88172 + if (is_fs_load && !strcmp(name, "register_filesystem"))
88173 + register_filesystem_found = 1;
88174 +#endif
88175 +
88176 switch (sym[i].st_shndx) {
88177 case SHN_COMMON:
88178 /* Ignore common symbols */
88179 @@ -1969,7 +2013,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
88180 ksym = resolve_symbol_wait(mod, info, name);
88181 /* Ok if resolved. */
88182 if (ksym && !IS_ERR(ksym)) {
88183 + pax_open_kernel();
88184 sym[i].st_value = ksym->value;
88185 + pax_close_kernel();
88186 break;
88187 }
88188
88189 @@ -1988,11 +2034,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
88190 secbase = (unsigned long)mod_percpu(mod);
88191 else
88192 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
88193 + pax_open_kernel();
88194 sym[i].st_value += secbase;
88195 + pax_close_kernel();
88196 break;
88197 }
88198 }
88199
88200 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
88201 + if (is_fs_load && !register_filesystem_found) {
88202 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
88203 + ret = -EPERM;
88204 + }
88205 +#endif
88206 +
88207 return ret;
88208 }
88209
88210 @@ -2076,22 +2131,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
88211 || s->sh_entsize != ~0UL
88212 || strstarts(sname, ".init"))
88213 continue;
88214 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
88215 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
88216 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
88217 + else
88218 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
88219 pr_debug("\t%s\n", sname);
88220 }
88221 - switch (m) {
88222 - case 0: /* executable */
88223 - mod->core_size = debug_align(mod->core_size);
88224 - mod->core_text_size = mod->core_size;
88225 - break;
88226 - case 1: /* RO: text and ro-data */
88227 - mod->core_size = debug_align(mod->core_size);
88228 - mod->core_ro_size = mod->core_size;
88229 - break;
88230 - case 3: /* whole core */
88231 - mod->core_size = debug_align(mod->core_size);
88232 - break;
88233 - }
88234 }
88235
88236 pr_debug("Init section allocation order:\n");
88237 @@ -2105,23 +2150,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
88238 || s->sh_entsize != ~0UL
88239 || !strstarts(sname, ".init"))
88240 continue;
88241 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
88242 - | INIT_OFFSET_MASK);
88243 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
88244 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
88245 + else
88246 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
88247 + s->sh_entsize |= INIT_OFFSET_MASK;
88248 pr_debug("\t%s\n", sname);
88249 }
88250 - switch (m) {
88251 - case 0: /* executable */
88252 - mod->init_size = debug_align(mod->init_size);
88253 - mod->init_text_size = mod->init_size;
88254 - break;
88255 - case 1: /* RO: text and ro-data */
88256 - mod->init_size = debug_align(mod->init_size);
88257 - mod->init_ro_size = mod->init_size;
88258 - break;
88259 - case 3: /* whole init */
88260 - mod->init_size = debug_align(mod->init_size);
88261 - break;
88262 - }
88263 }
88264 }
88265
88266 @@ -2294,7 +2329,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
88267
88268 /* Put symbol section at end of init part of module. */
88269 symsect->sh_flags |= SHF_ALLOC;
88270 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
88271 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
88272 info->index.sym) | INIT_OFFSET_MASK;
88273 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
88274
88275 @@ -2311,13 +2346,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
88276 }
88277
88278 /* Append room for core symbols at end of core part. */
88279 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
88280 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
88281 - mod->core_size += strtab_size;
88282 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
88283 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
88284 + mod->core_size_rx += strtab_size;
88285
88286 /* Put string table section at end of init part of module. */
88287 strsect->sh_flags |= SHF_ALLOC;
88288 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
88289 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
88290 info->index.str) | INIT_OFFSET_MASK;
88291 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
88292 }
88293 @@ -2335,12 +2370,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
88294 /* Make sure we get permanent strtab: don't use info->strtab. */
88295 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
88296
88297 + pax_open_kernel();
88298 +
88299 /* Set types up while we still have access to sections. */
88300 for (i = 0; i < mod->num_symtab; i++)
88301 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
88302
88303 - mod->core_symtab = dst = mod->module_core + info->symoffs;
88304 - mod->core_strtab = s = mod->module_core + info->stroffs;
88305 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
88306 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
88307 src = mod->symtab;
88308 for (ndst = i = 0; i < mod->num_symtab; i++) {
88309 if (i == 0 ||
88310 @@ -2352,6 +2389,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
88311 }
88312 }
88313 mod->core_num_syms = ndst;
88314 +
88315 + pax_close_kernel();
88316 }
88317 #else
88318 static inline void layout_symtab(struct module *mod, struct load_info *info)
88319 @@ -2385,17 +2424,33 @@ void * __weak module_alloc(unsigned long size)
88320 return vmalloc_exec(size);
88321 }
88322
88323 -static void *module_alloc_update_bounds(unsigned long size)
88324 +static void *module_alloc_update_bounds_rw(unsigned long size)
88325 {
88326 void *ret = module_alloc(size);
88327
88328 if (ret) {
88329 mutex_lock(&module_mutex);
88330 /* Update module bounds. */
88331 - if ((unsigned long)ret < module_addr_min)
88332 - module_addr_min = (unsigned long)ret;
88333 - if ((unsigned long)ret + size > module_addr_max)
88334 - module_addr_max = (unsigned long)ret + size;
88335 + if ((unsigned long)ret < module_addr_min_rw)
88336 + module_addr_min_rw = (unsigned long)ret;
88337 + if ((unsigned long)ret + size > module_addr_max_rw)
88338 + module_addr_max_rw = (unsigned long)ret + size;
88339 + mutex_unlock(&module_mutex);
88340 + }
88341 + return ret;
88342 +}
88343 +
88344 +static void *module_alloc_update_bounds_rx(unsigned long size)
88345 +{
88346 + void *ret = module_alloc_exec(size);
88347 +
88348 + if (ret) {
88349 + mutex_lock(&module_mutex);
88350 + /* Update module bounds. */
88351 + if ((unsigned long)ret < module_addr_min_rx)
88352 + module_addr_min_rx = (unsigned long)ret;
88353 + if ((unsigned long)ret + size > module_addr_max_rx)
88354 + module_addr_max_rx = (unsigned long)ret + size;
88355 mutex_unlock(&module_mutex);
88356 }
88357 return ret;
88358 @@ -2652,7 +2707,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
88359 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
88360
88361 if (info->index.sym == 0) {
88362 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
88363 + /*
88364 + * avoid potentially printing jibberish on attempted load
88365 + * of a module randomized with a different seed
88366 + */
88367 + pr_warn("module has no symbols (stripped?)\n");
88368 +#else
88369 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
88370 +#endif
88371 return ERR_PTR(-ENOEXEC);
88372 }
88373
88374 @@ -2668,8 +2731,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
88375 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
88376 {
88377 const char *modmagic = get_modinfo(info, "vermagic");
88378 + const char *license = get_modinfo(info, "license");
88379 int err;
88380
88381 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
88382 + if (!license || !license_is_gpl_compatible(license))
88383 + return -ENOEXEC;
88384 +#endif
88385 +
88386 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
88387 modmagic = NULL;
88388
88389 @@ -2694,7 +2763,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
88390 }
88391
88392 /* Set up license info based on the info section */
88393 - set_license(mod, get_modinfo(info, "license"));
88394 + set_license(mod, license);
88395
88396 return 0;
88397 }
88398 @@ -2788,7 +2857,7 @@ static int move_module(struct module *mod, struct load_info *info)
88399 void *ptr;
88400
88401 /* Do the allocs. */
88402 - ptr = module_alloc_update_bounds(mod->core_size);
88403 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
88404 /*
88405 * The pointer to this block is stored in the module structure
88406 * which is inside the block. Just mark it as not being a
88407 @@ -2798,11 +2867,11 @@ static int move_module(struct module *mod, struct load_info *info)
88408 if (!ptr)
88409 return -ENOMEM;
88410
88411 - memset(ptr, 0, mod->core_size);
88412 - mod->module_core = ptr;
88413 + memset(ptr, 0, mod->core_size_rw);
88414 + mod->module_core_rw = ptr;
88415
88416 - if (mod->init_size) {
88417 - ptr = module_alloc_update_bounds(mod->init_size);
88418 + if (mod->init_size_rw) {
88419 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
88420 /*
88421 * The pointer to this block is stored in the module structure
88422 * which is inside the block. This block doesn't need to be
88423 @@ -2811,13 +2880,45 @@ static int move_module(struct module *mod, struct load_info *info)
88424 */
88425 kmemleak_ignore(ptr);
88426 if (!ptr) {
88427 - module_free(mod, mod->module_core);
88428 + module_free(mod, mod->module_core_rw);
88429 return -ENOMEM;
88430 }
88431 - memset(ptr, 0, mod->init_size);
88432 - mod->module_init = ptr;
88433 + memset(ptr, 0, mod->init_size_rw);
88434 + mod->module_init_rw = ptr;
88435 } else
88436 - mod->module_init = NULL;
88437 + mod->module_init_rw = NULL;
88438 +
88439 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
88440 + kmemleak_not_leak(ptr);
88441 + if (!ptr) {
88442 + if (mod->module_init_rw)
88443 + module_free(mod, mod->module_init_rw);
88444 + module_free(mod, mod->module_core_rw);
88445 + return -ENOMEM;
88446 + }
88447 +
88448 + pax_open_kernel();
88449 + memset(ptr, 0, mod->core_size_rx);
88450 + pax_close_kernel();
88451 + mod->module_core_rx = ptr;
88452 +
88453 + if (mod->init_size_rx) {
88454 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
88455 + kmemleak_ignore(ptr);
88456 + if (!ptr && mod->init_size_rx) {
88457 + module_free_exec(mod, mod->module_core_rx);
88458 + if (mod->module_init_rw)
88459 + module_free(mod, mod->module_init_rw);
88460 + module_free(mod, mod->module_core_rw);
88461 + return -ENOMEM;
88462 + }
88463 +
88464 + pax_open_kernel();
88465 + memset(ptr, 0, mod->init_size_rx);
88466 + pax_close_kernel();
88467 + mod->module_init_rx = ptr;
88468 + } else
88469 + mod->module_init_rx = NULL;
88470
88471 /* Transfer each section which specifies SHF_ALLOC */
88472 pr_debug("final section addresses:\n");
88473 @@ -2828,16 +2929,45 @@ static int move_module(struct module *mod, struct load_info *info)
88474 if (!(shdr->sh_flags & SHF_ALLOC))
88475 continue;
88476
88477 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
88478 - dest = mod->module_init
88479 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88480 - else
88481 - dest = mod->module_core + shdr->sh_entsize;
88482 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
88483 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
88484 + dest = mod->module_init_rw
88485 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88486 + else
88487 + dest = mod->module_init_rx
88488 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88489 + } else {
88490 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
88491 + dest = mod->module_core_rw + shdr->sh_entsize;
88492 + else
88493 + dest = mod->module_core_rx + shdr->sh_entsize;
88494 + }
88495 +
88496 + if (shdr->sh_type != SHT_NOBITS) {
88497 +
88498 +#ifdef CONFIG_PAX_KERNEXEC
88499 +#ifdef CONFIG_X86_64
88500 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
88501 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
88502 +#endif
88503 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
88504 + pax_open_kernel();
88505 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
88506 + pax_close_kernel();
88507 + } else
88508 +#endif
88509
88510 - if (shdr->sh_type != SHT_NOBITS)
88511 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
88512 + }
88513 /* Update sh_addr to point to copy in image. */
88514 - shdr->sh_addr = (unsigned long)dest;
88515 +
88516 +#ifdef CONFIG_PAX_KERNEXEC
88517 + if (shdr->sh_flags & SHF_EXECINSTR)
88518 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
88519 + else
88520 +#endif
88521 +
88522 + shdr->sh_addr = (unsigned long)dest;
88523 pr_debug("\t0x%lx %s\n",
88524 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
88525 }
88526 @@ -2894,12 +3024,12 @@ static void flush_module_icache(const struct module *mod)
88527 * Do it before processing of module parameters, so the module
88528 * can provide parameter accessor functions of its own.
88529 */
88530 - if (mod->module_init)
88531 - flush_icache_range((unsigned long)mod->module_init,
88532 - (unsigned long)mod->module_init
88533 - + mod->init_size);
88534 - flush_icache_range((unsigned long)mod->module_core,
88535 - (unsigned long)mod->module_core + mod->core_size);
88536 + if (mod->module_init_rx)
88537 + flush_icache_range((unsigned long)mod->module_init_rx,
88538 + (unsigned long)mod->module_init_rx
88539 + + mod->init_size_rx);
88540 + flush_icache_range((unsigned long)mod->module_core_rx,
88541 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
88542
88543 set_fs(old_fs);
88544 }
88545 @@ -2956,8 +3086,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
88546 static void module_deallocate(struct module *mod, struct load_info *info)
88547 {
88548 percpu_modfree(mod);
88549 - module_free(mod, mod->module_init);
88550 - module_free(mod, mod->module_core);
88551 + module_free_exec(mod, mod->module_init_rx);
88552 + module_free_exec(mod, mod->module_core_rx);
88553 + module_free(mod, mod->module_init_rw);
88554 + module_free(mod, mod->module_core_rw);
88555 }
88556
88557 int __weak module_finalize(const Elf_Ehdr *hdr,
88558 @@ -2970,7 +3102,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
88559 static int post_relocation(struct module *mod, const struct load_info *info)
88560 {
88561 /* Sort exception table now relocations are done. */
88562 + pax_open_kernel();
88563 sort_extable(mod->extable, mod->extable + mod->num_exentries);
88564 + pax_close_kernel();
88565
88566 /* Copy relocated percpu area over. */
88567 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
88568 @@ -3024,16 +3158,16 @@ static int do_init_module(struct module *mod)
88569 MODULE_STATE_COMING, mod);
88570
88571 /* Set RO and NX regions for core */
88572 - set_section_ro_nx(mod->module_core,
88573 - mod->core_text_size,
88574 - mod->core_ro_size,
88575 - mod->core_size);
88576 + set_section_ro_nx(mod->module_core_rx,
88577 + mod->core_size_rx,
88578 + mod->core_size_rx,
88579 + mod->core_size_rx);
88580
88581 /* Set RO and NX regions for init */
88582 - set_section_ro_nx(mod->module_init,
88583 - mod->init_text_size,
88584 - mod->init_ro_size,
88585 - mod->init_size);
88586 + set_section_ro_nx(mod->module_init_rx,
88587 + mod->init_size_rx,
88588 + mod->init_size_rx,
88589 + mod->init_size_rx);
88590
88591 do_mod_ctors(mod);
88592 /* Start the module */
88593 @@ -3094,11 +3228,12 @@ static int do_init_module(struct module *mod)
88594 mod->strtab = mod->core_strtab;
88595 #endif
88596 unset_module_init_ro_nx(mod);
88597 - module_free(mod, mod->module_init);
88598 - mod->module_init = NULL;
88599 - mod->init_size = 0;
88600 - mod->init_ro_size = 0;
88601 - mod->init_text_size = 0;
88602 + module_free(mod, mod->module_init_rw);
88603 + module_free_exec(mod, mod->module_init_rx);
88604 + mod->module_init_rw = NULL;
88605 + mod->module_init_rx = NULL;
88606 + mod->init_size_rw = 0;
88607 + mod->init_size_rx = 0;
88608 mutex_unlock(&module_mutex);
88609 wake_up_all(&module_wq);
88610
88611 @@ -3241,9 +3376,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
88612 if (err)
88613 goto free_unload;
88614
88615 + /* Now copy in args */
88616 + mod->args = strndup_user(uargs, ~0UL >> 1);
88617 + if (IS_ERR(mod->args)) {
88618 + err = PTR_ERR(mod->args);
88619 + goto free_unload;
88620 + }
88621 +
88622 /* Set up MODINFO_ATTR fields */
88623 setup_modinfo(mod, info);
88624
88625 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
88626 + {
88627 + char *p, *p2;
88628 +
88629 + if (strstr(mod->args, "grsec_modharden_netdev")) {
88630 + 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);
88631 + err = -EPERM;
88632 + goto free_modinfo;
88633 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
88634 + p += sizeof("grsec_modharden_normal") - 1;
88635 + p2 = strstr(p, "_");
88636 + if (p2) {
88637 + *p2 = '\0';
88638 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
88639 + *p2 = '_';
88640 + }
88641 + err = -EPERM;
88642 + goto free_modinfo;
88643 + }
88644 + }
88645 +#endif
88646 +
88647 /* Fix up syms, so that st_value is a pointer to location. */
88648 err = simplify_symbols(mod, info);
88649 if (err < 0)
88650 @@ -3259,13 +3423,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
88651
88652 flush_module_icache(mod);
88653
88654 - /* Now copy in args */
88655 - mod->args = strndup_user(uargs, ~0UL >> 1);
88656 - if (IS_ERR(mod->args)) {
88657 - err = PTR_ERR(mod->args);
88658 - goto free_arch_cleanup;
88659 - }
88660 -
88661 dynamic_debug_setup(info->debug, info->num_debug);
88662
88663 /* Ftrace init must be called in the MODULE_STATE_UNFORMED state */
88664 @@ -3303,11 +3460,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
88665 ddebug_cleanup:
88666 dynamic_debug_remove(info->debug);
88667 synchronize_sched();
88668 - kfree(mod->args);
88669 - free_arch_cleanup:
88670 module_arch_cleanup(mod);
88671 free_modinfo:
88672 free_modinfo(mod);
88673 + kfree(mod->args);
88674 free_unload:
88675 module_unload_free(mod);
88676 unlink_mod:
88677 @@ -3390,10 +3546,16 @@ static const char *get_ksymbol(struct module *mod,
88678 unsigned long nextval;
88679
88680 /* At worse, next value is at end of module */
88681 - if (within_module_init(addr, mod))
88682 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
88683 + if (within_module_init_rx(addr, mod))
88684 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
88685 + else if (within_module_init_rw(addr, mod))
88686 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
88687 + else if (within_module_core_rx(addr, mod))
88688 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
88689 + else if (within_module_core_rw(addr, mod))
88690 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
88691 else
88692 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
88693 + return NULL;
88694
88695 /* Scan for closest preceding symbol, and next symbol. (ELF
88696 starts real symbols at 1). */
88697 @@ -3644,7 +3806,7 @@ static int m_show(struct seq_file *m, void *p)
88698 return 0;
88699
88700 seq_printf(m, "%s %u",
88701 - mod->name, mod->init_size + mod->core_size);
88702 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
88703 print_unload_info(m, mod);
88704
88705 /* Informative for users. */
88706 @@ -3653,7 +3815,7 @@ static int m_show(struct seq_file *m, void *p)
88707 mod->state == MODULE_STATE_COMING ? "Loading":
88708 "Live");
88709 /* Used by oprofile and other similar tools. */
88710 - seq_printf(m, " 0x%pK", mod->module_core);
88711 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
88712
88713 /* Taints info */
88714 if (mod->taints)
88715 @@ -3689,7 +3851,17 @@ static const struct file_operations proc_modules_operations = {
88716
88717 static int __init proc_modules_init(void)
88718 {
88719 +#ifndef CONFIG_GRKERNSEC_HIDESYM
88720 +#ifdef CONFIG_GRKERNSEC_PROC_USER
88721 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
88722 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
88723 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
88724 +#else
88725 proc_create("modules", 0, NULL, &proc_modules_operations);
88726 +#endif
88727 +#else
88728 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
88729 +#endif
88730 return 0;
88731 }
88732 module_init(proc_modules_init);
88733 @@ -3750,14 +3922,14 @@ struct module *__module_address(unsigned long addr)
88734 {
88735 struct module *mod;
88736
88737 - if (addr < module_addr_min || addr > module_addr_max)
88738 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
88739 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
88740 return NULL;
88741
88742 list_for_each_entry_rcu(mod, &modules, list) {
88743 if (mod->state == MODULE_STATE_UNFORMED)
88744 continue;
88745 - if (within_module_core(addr, mod)
88746 - || within_module_init(addr, mod))
88747 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
88748 return mod;
88749 }
88750 return NULL;
88751 @@ -3792,11 +3964,20 @@ bool is_module_text_address(unsigned long addr)
88752 */
88753 struct module *__module_text_address(unsigned long addr)
88754 {
88755 - struct module *mod = __module_address(addr);
88756 + struct module *mod;
88757 +
88758 +#ifdef CONFIG_X86_32
88759 + addr = ktla_ktva(addr);
88760 +#endif
88761 +
88762 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
88763 + return NULL;
88764 +
88765 + mod = __module_address(addr);
88766 +
88767 if (mod) {
88768 /* Make sure it's within the text section. */
88769 - if (!within(addr, mod->module_init, mod->init_text_size)
88770 - && !within(addr, mod->module_core, mod->core_text_size))
88771 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
88772 mod = NULL;
88773 }
88774 return mod;
88775 diff --git a/kernel/notifier.c b/kernel/notifier.c
88776 index db4c8b0..ad011c5 100644
88777 --- a/kernel/notifier.c
88778 +++ b/kernel/notifier.c
88779 @@ -5,6 +5,7 @@
88780 #include <linux/rcupdate.h>
88781 #include <linux/vmalloc.h>
88782 #include <linux/reboot.h>
88783 +#include <linux/mm.h>
88784
88785 /*
88786 * Notifier list for kernel code which wants to be called
88787 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
88788 while ((*nl) != NULL) {
88789 if (n->priority > (*nl)->priority)
88790 break;
88791 - nl = &((*nl)->next);
88792 + nl = (struct notifier_block **)&((*nl)->next);
88793 }
88794 - n->next = *nl;
88795 + pax_open_kernel();
88796 + *(const void **)&n->next = *nl;
88797 rcu_assign_pointer(*nl, n);
88798 + pax_close_kernel();
88799 return 0;
88800 }
88801
88802 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
88803 return 0;
88804 if (n->priority > (*nl)->priority)
88805 break;
88806 - nl = &((*nl)->next);
88807 + nl = (struct notifier_block **)&((*nl)->next);
88808 }
88809 - n->next = *nl;
88810 + pax_open_kernel();
88811 + *(const void **)&n->next = *nl;
88812 rcu_assign_pointer(*nl, n);
88813 + pax_close_kernel();
88814 return 0;
88815 }
88816
88817 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
88818 {
88819 while ((*nl) != NULL) {
88820 if ((*nl) == n) {
88821 + pax_open_kernel();
88822 rcu_assign_pointer(*nl, n->next);
88823 + pax_close_kernel();
88824 return 0;
88825 }
88826 - nl = &((*nl)->next);
88827 + nl = (struct notifier_block **)&((*nl)->next);
88828 }
88829 return -ENOENT;
88830 }
88831 diff --git a/kernel/padata.c b/kernel/padata.c
88832 index 161402f..598814c 100644
88833 --- a/kernel/padata.c
88834 +++ b/kernel/padata.c
88835 @@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
88836 * seq_nr mod. number of cpus in use.
88837 */
88838
88839 - seq_nr = atomic_inc_return(&pd->seq_nr);
88840 + seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
88841 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
88842
88843 return padata_index_to_cpu(pd, cpu_index);
88844 @@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
88845 padata_init_pqueues(pd);
88846 padata_init_squeues(pd);
88847 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
88848 - atomic_set(&pd->seq_nr, -1);
88849 + atomic_set_unchecked(&pd->seq_nr, -1);
88850 atomic_set(&pd->reorder_objects, 0);
88851 atomic_set(&pd->refcnt, 0);
88852 pd->pinst = pinst;
88853 diff --git a/kernel/panic.c b/kernel/panic.c
88854 index d02fa9f..9faec0a 100644
88855 --- a/kernel/panic.c
88856 +++ b/kernel/panic.c
88857 @@ -52,7 +52,7 @@ EXPORT_SYMBOL(panic_blink);
88858 /*
88859 * Stop ourself in panic -- architecture code may override this
88860 */
88861 -void __weak panic_smp_self_stop(void)
88862 +void __weak __noreturn panic_smp_self_stop(void)
88863 {
88864 while (1)
88865 cpu_relax();
88866 @@ -408,7 +408,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
88867 disable_trace_on_warning();
88868
88869 pr_warn("------------[ cut here ]------------\n");
88870 - pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
88871 + pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
88872 raw_smp_processor_id(), current->pid, file, line, caller);
88873
88874 if (args)
88875 @@ -462,7 +462,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
88876 */
88877 __visible void __stack_chk_fail(void)
88878 {
88879 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
88880 + dump_stack();
88881 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
88882 __builtin_return_address(0));
88883 }
88884 EXPORT_SYMBOL(__stack_chk_fail);
88885 diff --git a/kernel/pid.c b/kernel/pid.c
88886 index 9b9a266..c20ef80 100644
88887 --- a/kernel/pid.c
88888 +++ b/kernel/pid.c
88889 @@ -33,6 +33,7 @@
88890 #include <linux/rculist.h>
88891 #include <linux/bootmem.h>
88892 #include <linux/hash.h>
88893 +#include <linux/security.h>
88894 #include <linux/pid_namespace.h>
88895 #include <linux/init_task.h>
88896 #include <linux/syscalls.h>
88897 @@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
88898
88899 int pid_max = PID_MAX_DEFAULT;
88900
88901 -#define RESERVED_PIDS 300
88902 +#define RESERVED_PIDS 500
88903
88904 int pid_max_min = RESERVED_PIDS + 1;
88905 int pid_max_max = PID_MAX_LIMIT;
88906 @@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
88907 */
88908 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
88909 {
88910 + struct task_struct *task;
88911 +
88912 rcu_lockdep_assert(rcu_read_lock_held(),
88913 "find_task_by_pid_ns() needs rcu_read_lock()"
88914 " protection");
88915 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
88916 +
88917 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
88918 +
88919 + if (gr_pid_is_chrooted(task))
88920 + return NULL;
88921 +
88922 + return task;
88923 }
88924
88925 struct task_struct *find_task_by_vpid(pid_t vnr)
88926 @@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
88927 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
88928 }
88929
88930 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
88931 +{
88932 + rcu_lockdep_assert(rcu_read_lock_held(),
88933 + "find_task_by_pid_ns() needs rcu_read_lock()"
88934 + " protection");
88935 + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
88936 +}
88937 +
88938 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
88939 {
88940 struct pid *pid;
88941 diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
88942 index db95d8e..a0ca23f 100644
88943 --- a/kernel/pid_namespace.c
88944 +++ b/kernel/pid_namespace.c
88945 @@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
88946 void __user *buffer, size_t *lenp, loff_t *ppos)
88947 {
88948 struct pid_namespace *pid_ns = task_active_pid_ns(current);
88949 - struct ctl_table tmp = *table;
88950 + ctl_table_no_const tmp = *table;
88951
88952 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
88953 return -EPERM;
88954 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
88955 index 3b89464..5e38379 100644
88956 --- a/kernel/posix-cpu-timers.c
88957 +++ b/kernel/posix-cpu-timers.c
88958 @@ -1464,14 +1464,14 @@ struct k_clock clock_posix_cpu = {
88959
88960 static __init int init_posix_cpu_timers(void)
88961 {
88962 - struct k_clock process = {
88963 + static struct k_clock process = {
88964 .clock_getres = process_cpu_clock_getres,
88965 .clock_get = process_cpu_clock_get,
88966 .timer_create = process_cpu_timer_create,
88967 .nsleep = process_cpu_nsleep,
88968 .nsleep_restart = process_cpu_nsleep_restart,
88969 };
88970 - struct k_clock thread = {
88971 + static struct k_clock thread = {
88972 .clock_getres = thread_cpu_clock_getres,
88973 .clock_get = thread_cpu_clock_get,
88974 .timer_create = thread_cpu_timer_create,
88975 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
88976 index 424c2d4..679242f 100644
88977 --- a/kernel/posix-timers.c
88978 +++ b/kernel/posix-timers.c
88979 @@ -43,6 +43,7 @@
88980 #include <linux/hash.h>
88981 #include <linux/posix-clock.h>
88982 #include <linux/posix-timers.h>
88983 +#include <linux/grsecurity.h>
88984 #include <linux/syscalls.h>
88985 #include <linux/wait.h>
88986 #include <linux/workqueue.h>
88987 @@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
88988 * which we beg off on and pass to do_sys_settimeofday().
88989 */
88990
88991 -static struct k_clock posix_clocks[MAX_CLOCKS];
88992 +static struct k_clock *posix_clocks[MAX_CLOCKS];
88993
88994 /*
88995 * These ones are defined below.
88996 @@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
88997 */
88998 static __init int init_posix_timers(void)
88999 {
89000 - struct k_clock clock_realtime = {
89001 + static struct k_clock clock_realtime = {
89002 .clock_getres = hrtimer_get_res,
89003 .clock_get = posix_clock_realtime_get,
89004 .clock_set = posix_clock_realtime_set,
89005 @@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
89006 .timer_get = common_timer_get,
89007 .timer_del = common_timer_del,
89008 };
89009 - struct k_clock clock_monotonic = {
89010 + static struct k_clock clock_monotonic = {
89011 .clock_getres = hrtimer_get_res,
89012 .clock_get = posix_ktime_get_ts,
89013 .nsleep = common_nsleep,
89014 @@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
89015 .timer_get = common_timer_get,
89016 .timer_del = common_timer_del,
89017 };
89018 - struct k_clock clock_monotonic_raw = {
89019 + static struct k_clock clock_monotonic_raw = {
89020 .clock_getres = hrtimer_get_res,
89021 .clock_get = posix_get_monotonic_raw,
89022 };
89023 - struct k_clock clock_realtime_coarse = {
89024 + static struct k_clock clock_realtime_coarse = {
89025 .clock_getres = posix_get_coarse_res,
89026 .clock_get = posix_get_realtime_coarse,
89027 };
89028 - struct k_clock clock_monotonic_coarse = {
89029 + static struct k_clock clock_monotonic_coarse = {
89030 .clock_getres = posix_get_coarse_res,
89031 .clock_get = posix_get_monotonic_coarse,
89032 };
89033 - struct k_clock clock_tai = {
89034 + static struct k_clock clock_tai = {
89035 .clock_getres = hrtimer_get_res,
89036 .clock_get = posix_get_tai,
89037 .nsleep = common_nsleep,
89038 @@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
89039 .timer_get = common_timer_get,
89040 .timer_del = common_timer_del,
89041 };
89042 - struct k_clock clock_boottime = {
89043 + static struct k_clock clock_boottime = {
89044 .clock_getres = hrtimer_get_res,
89045 .clock_get = posix_get_boottime,
89046 .nsleep = common_nsleep,
89047 @@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
89048 return;
89049 }
89050
89051 - posix_clocks[clock_id] = *new_clock;
89052 + posix_clocks[clock_id] = new_clock;
89053 }
89054 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
89055
89056 @@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
89057 return (id & CLOCKFD_MASK) == CLOCKFD ?
89058 &clock_posix_dynamic : &clock_posix_cpu;
89059
89060 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
89061 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
89062 return NULL;
89063 - return &posix_clocks[id];
89064 + return posix_clocks[id];
89065 }
89066
89067 static int common_timer_create(struct k_itimer *new_timer)
89068 @@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
89069 struct k_clock *kc = clockid_to_kclock(which_clock);
89070 struct k_itimer *new_timer;
89071 int error, new_timer_id;
89072 - sigevent_t event;
89073 + sigevent_t event = { };
89074 int it_id_set = IT_ID_NOT_SET;
89075
89076 if (!kc)
89077 @@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
89078 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
89079 return -EFAULT;
89080
89081 + /* only the CLOCK_REALTIME clock can be set, all other clocks
89082 + have their clock_set fptr set to a nosettime dummy function
89083 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
89084 + call common_clock_set, which calls do_sys_settimeofday, which
89085 + we hook
89086 + */
89087 +
89088 return kc->clock_set(which_clock, &new_tp);
89089 }
89090
89091 diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
89092 index 2fac9cc..56fef29 100644
89093 --- a/kernel/power/Kconfig
89094 +++ b/kernel/power/Kconfig
89095 @@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
89096 config HIBERNATION
89097 bool "Hibernation (aka 'suspend to disk')"
89098 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
89099 + depends on !GRKERNSEC_KMEM
89100 + depends on !PAX_MEMORY_SANITIZE
89101 select HIBERNATE_CALLBACKS
89102 select LZO_COMPRESS
89103 select LZO_DECOMPRESS
89104 diff --git a/kernel/power/process.c b/kernel/power/process.c
89105 index 14f9a8d..98ee610 100644
89106 --- a/kernel/power/process.c
89107 +++ b/kernel/power/process.c
89108 @@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
89109 unsigned int elapsed_msecs;
89110 bool wakeup = false;
89111 int sleep_usecs = USEC_PER_MSEC;
89112 + bool timedout = false;
89113
89114 do_gettimeofday(&start);
89115
89116 @@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
89117
89118 while (true) {
89119 todo = 0;
89120 + if (time_after(jiffies, end_time))
89121 + timedout = true;
89122 read_lock(&tasklist_lock);
89123 do_each_thread(g, p) {
89124 if (p == current || !freeze_task(p))
89125 continue;
89126
89127 - if (!freezer_should_skip(p))
89128 + if (!freezer_should_skip(p)) {
89129 todo++;
89130 + if (timedout) {
89131 + printk(KERN_ERR "Task refusing to freeze:\n");
89132 + sched_show_task(p);
89133 + }
89134 + }
89135 } while_each_thread(g, p);
89136 read_unlock(&tasklist_lock);
89137
89138 @@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
89139 todo += wq_busy;
89140 }
89141
89142 - if (!todo || time_after(jiffies, end_time))
89143 + if (!todo || timedout)
89144 break;
89145
89146 if (pm_wakeup_pending()) {
89147 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
89148 index 63594be..8444e0f 100644
89149 --- a/kernel/printk/printk.c
89150 +++ b/kernel/printk/printk.c
89151 @@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
89152 if (from_file && type != SYSLOG_ACTION_OPEN)
89153 return 0;
89154
89155 +#ifdef CONFIG_GRKERNSEC_DMESG
89156 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
89157 + return -EPERM;
89158 +#endif
89159 +
89160 if (syslog_action_restricted(type)) {
89161 if (capable(CAP_SYSLOG))
89162 return 0;
89163 diff --git a/kernel/profile.c b/kernel/profile.c
89164 index cb980f0..ccd8782 100644
89165 --- a/kernel/profile.c
89166 +++ b/kernel/profile.c
89167 @@ -37,7 +37,7 @@ struct profile_hit {
89168 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
89169 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
89170
89171 -static atomic_t *prof_buffer;
89172 +static atomic_unchecked_t *prof_buffer;
89173 static unsigned long prof_len, prof_shift;
89174
89175 int prof_on __read_mostly;
89176 @@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
89177 hits[i].pc = 0;
89178 continue;
89179 }
89180 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
89181 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
89182 hits[i].hits = hits[i].pc = 0;
89183 }
89184 }
89185 @@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
89186 * Add the current hit(s) and flush the write-queue out
89187 * to the global buffer:
89188 */
89189 - atomic_add(nr_hits, &prof_buffer[pc]);
89190 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
89191 for (i = 0; i < NR_PROFILE_HIT; ++i) {
89192 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
89193 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
89194 hits[i].pc = hits[i].hits = 0;
89195 }
89196 out:
89197 @@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
89198 {
89199 unsigned long pc;
89200 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
89201 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
89202 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
89203 }
89204 #endif /* !CONFIG_SMP */
89205
89206 @@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
89207 return -EFAULT;
89208 buf++; p++; count--; read++;
89209 }
89210 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
89211 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
89212 if (copy_to_user(buf, (void *)pnt, count))
89213 return -EFAULT;
89214 read += count;
89215 @@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
89216 }
89217 #endif
89218 profile_discard_flip_buffers();
89219 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
89220 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
89221 return count;
89222 }
89223
89224 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
89225 index adf9862..9d86345 100644
89226 --- a/kernel/ptrace.c
89227 +++ b/kernel/ptrace.c
89228 @@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
89229 if (seize)
89230 flags |= PT_SEIZED;
89231 rcu_read_lock();
89232 - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
89233 + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
89234 flags |= PT_PTRACE_CAP;
89235 rcu_read_unlock();
89236 task->ptrace = flags;
89237 @@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
89238 break;
89239 return -EIO;
89240 }
89241 - if (copy_to_user(dst, buf, retval))
89242 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
89243 return -EFAULT;
89244 copied += retval;
89245 src += retval;
89246 @@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
89247 bool seized = child->ptrace & PT_SEIZED;
89248 int ret = -EIO;
89249 siginfo_t siginfo, *si;
89250 - void __user *datavp = (void __user *) data;
89251 + void __user *datavp = (__force void __user *) data;
89252 unsigned long __user *datalp = datavp;
89253 unsigned long flags;
89254
89255 @@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
89256 goto out;
89257 }
89258
89259 + if (gr_handle_ptrace(child, request)) {
89260 + ret = -EPERM;
89261 + goto out_put_task_struct;
89262 + }
89263 +
89264 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
89265 ret = ptrace_attach(child, request, addr, data);
89266 /*
89267 * Some architectures need to do book-keeping after
89268 * a ptrace attach.
89269 */
89270 - if (!ret)
89271 + if (!ret) {
89272 arch_ptrace_attach(child);
89273 + gr_audit_ptrace(child);
89274 + }
89275 goto out_put_task_struct;
89276 }
89277
89278 @@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
89279 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
89280 if (copied != sizeof(tmp))
89281 return -EIO;
89282 - return put_user(tmp, (unsigned long __user *)data);
89283 + return put_user(tmp, (__force unsigned long __user *)data);
89284 }
89285
89286 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
89287 @@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
89288 }
89289
89290 COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
89291 - compat_long_t, addr, compat_long_t, data)
89292 + compat_ulong_t, addr, compat_ulong_t, data)
89293 {
89294 struct task_struct *child;
89295 long ret;
89296 @@ -1197,14 +1204,21 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
89297 goto out;
89298 }
89299
89300 + if (gr_handle_ptrace(child, request)) {
89301 + ret = -EPERM;
89302 + goto out_put_task_struct;
89303 + }
89304 +
89305 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
89306 ret = ptrace_attach(child, request, addr, data);
89307 /*
89308 * Some architectures need to do book-keeping after
89309 * a ptrace attach.
89310 */
89311 - if (!ret)
89312 + if (!ret) {
89313 arch_ptrace_attach(child);
89314 + gr_audit_ptrace(child);
89315 + }
89316 goto out_put_task_struct;
89317 }
89318
89319 diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
89320 index bd30bc6..dce23da 100644
89321 --- a/kernel/rcu/rcutorture.c
89322 +++ b/kernel/rcu/rcutorture.c
89323 @@ -122,12 +122,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
89324 rcu_torture_count) = { 0 };
89325 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
89326 rcu_torture_batch) = { 0 };
89327 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
89328 -static atomic_t n_rcu_torture_alloc;
89329 -static atomic_t n_rcu_torture_alloc_fail;
89330 -static atomic_t n_rcu_torture_free;
89331 -static atomic_t n_rcu_torture_mberror;
89332 -static atomic_t n_rcu_torture_error;
89333 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
89334 +static atomic_unchecked_t n_rcu_torture_alloc;
89335 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
89336 +static atomic_unchecked_t n_rcu_torture_free;
89337 +static atomic_unchecked_t n_rcu_torture_mberror;
89338 +static atomic_unchecked_t n_rcu_torture_error;
89339 static long n_rcu_torture_barrier_error;
89340 static long n_rcu_torture_boost_ktrerror;
89341 static long n_rcu_torture_boost_rterror;
89342 @@ -186,11 +186,11 @@ rcu_torture_alloc(void)
89343
89344 spin_lock_bh(&rcu_torture_lock);
89345 if (list_empty(&rcu_torture_freelist)) {
89346 - atomic_inc(&n_rcu_torture_alloc_fail);
89347 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
89348 spin_unlock_bh(&rcu_torture_lock);
89349 return NULL;
89350 }
89351 - atomic_inc(&n_rcu_torture_alloc);
89352 + atomic_inc_unchecked(&n_rcu_torture_alloc);
89353 p = rcu_torture_freelist.next;
89354 list_del_init(p);
89355 spin_unlock_bh(&rcu_torture_lock);
89356 @@ -203,7 +203,7 @@ rcu_torture_alloc(void)
89357 static void
89358 rcu_torture_free(struct rcu_torture *p)
89359 {
89360 - atomic_inc(&n_rcu_torture_free);
89361 + atomic_inc_unchecked(&n_rcu_torture_free);
89362 spin_lock_bh(&rcu_torture_lock);
89363 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
89364 spin_unlock_bh(&rcu_torture_lock);
89365 @@ -287,7 +287,7 @@ rcu_torture_cb(struct rcu_head *p)
89366 i = rp->rtort_pipe_count;
89367 if (i > RCU_TORTURE_PIPE_LEN)
89368 i = RCU_TORTURE_PIPE_LEN;
89369 - atomic_inc(&rcu_torture_wcount[i]);
89370 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
89371 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
89372 rp->rtort_mbtest = 0;
89373 rcu_torture_free(rp);
89374 @@ -714,7 +714,7 @@ rcu_torture_writer(void *arg)
89375 i = old_rp->rtort_pipe_count;
89376 if (i > RCU_TORTURE_PIPE_LEN)
89377 i = RCU_TORTURE_PIPE_LEN;
89378 - atomic_inc(&rcu_torture_wcount[i]);
89379 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
89380 old_rp->rtort_pipe_count++;
89381 if (gp_normal == gp_exp)
89382 exp = !!(torture_random(&rand) & 0x80);
89383 @@ -732,7 +732,7 @@ rcu_torture_writer(void *arg)
89384 i = rp->rtort_pipe_count;
89385 if (i > RCU_TORTURE_PIPE_LEN)
89386 i = RCU_TORTURE_PIPE_LEN;
89387 - atomic_inc(&rcu_torture_wcount[i]);
89388 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
89389 if (++rp->rtort_pipe_count >=
89390 RCU_TORTURE_PIPE_LEN) {
89391 rp->rtort_mbtest = 0;
89392 @@ -825,7 +825,7 @@ static void rcu_torture_timer(unsigned long unused)
89393 return;
89394 }
89395 if (p->rtort_mbtest == 0)
89396 - atomic_inc(&n_rcu_torture_mberror);
89397 + atomic_inc_unchecked(&n_rcu_torture_mberror);
89398 spin_lock(&rand_lock);
89399 cur_ops->read_delay(&rand);
89400 n_rcu_torture_timers++;
89401 @@ -895,7 +895,7 @@ rcu_torture_reader(void *arg)
89402 continue;
89403 }
89404 if (p->rtort_mbtest == 0)
89405 - atomic_inc(&n_rcu_torture_mberror);
89406 + atomic_inc_unchecked(&n_rcu_torture_mberror);
89407 cur_ops->read_delay(&rand);
89408 preempt_disable();
89409 pipe_count = p->rtort_pipe_count;
89410 @@ -950,15 +950,15 @@ rcu_torture_printk(char *page)
89411 }
89412 page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG);
89413 page += sprintf(page,
89414 - "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
89415 + "rtc: %pP ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
89416 rcu_torture_current,
89417 rcu_torture_current_version,
89418 list_empty(&rcu_torture_freelist),
89419 - atomic_read(&n_rcu_torture_alloc),
89420 - atomic_read(&n_rcu_torture_alloc_fail),
89421 - atomic_read(&n_rcu_torture_free));
89422 + atomic_read_unchecked(&n_rcu_torture_alloc),
89423 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
89424 + atomic_read_unchecked(&n_rcu_torture_free));
89425 page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ",
89426 - atomic_read(&n_rcu_torture_mberror),
89427 + atomic_read_unchecked(&n_rcu_torture_mberror),
89428 n_rcu_torture_boost_ktrerror,
89429 n_rcu_torture_boost_rterror);
89430 page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ",
89431 @@ -971,14 +971,14 @@ rcu_torture_printk(char *page)
89432 n_barrier_attempts,
89433 n_rcu_torture_barrier_error);
89434 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
89435 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
89436 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
89437 n_rcu_torture_barrier_error != 0 ||
89438 n_rcu_torture_boost_ktrerror != 0 ||
89439 n_rcu_torture_boost_rterror != 0 ||
89440 n_rcu_torture_boost_failure != 0 ||
89441 i > 1) {
89442 page += sprintf(page, "!!! ");
89443 - atomic_inc(&n_rcu_torture_error);
89444 + atomic_inc_unchecked(&n_rcu_torture_error);
89445 WARN_ON_ONCE(1);
89446 }
89447 page += sprintf(page, "Reader Pipe: ");
89448 @@ -992,7 +992,7 @@ rcu_torture_printk(char *page)
89449 page += sprintf(page, "Free-Block Circulation: ");
89450 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
89451 page += sprintf(page, " %d",
89452 - atomic_read(&rcu_torture_wcount[i]));
89453 + atomic_read_unchecked(&rcu_torture_wcount[i]));
89454 }
89455 page += sprintf(page, "\n");
89456 if (cur_ops->stats)
89457 @@ -1341,7 +1341,7 @@ rcu_torture_cleanup(void)
89458
89459 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
89460
89461 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
89462 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
89463 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
89464 else if (torture_onoff_failures())
89465 rcu_torture_print_module_parms(cur_ops,
89466 @@ -1460,18 +1460,18 @@ rcu_torture_init(void)
89467
89468 rcu_torture_current = NULL;
89469 rcu_torture_current_version = 0;
89470 - atomic_set(&n_rcu_torture_alloc, 0);
89471 - atomic_set(&n_rcu_torture_alloc_fail, 0);
89472 - atomic_set(&n_rcu_torture_free, 0);
89473 - atomic_set(&n_rcu_torture_mberror, 0);
89474 - atomic_set(&n_rcu_torture_error, 0);
89475 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
89476 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
89477 + atomic_set_unchecked(&n_rcu_torture_free, 0);
89478 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
89479 + atomic_set_unchecked(&n_rcu_torture_error, 0);
89480 n_rcu_torture_barrier_error = 0;
89481 n_rcu_torture_boost_ktrerror = 0;
89482 n_rcu_torture_boost_rterror = 0;
89483 n_rcu_torture_boost_failure = 0;
89484 n_rcu_torture_boosts = 0;
89485 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
89486 - atomic_set(&rcu_torture_wcount[i], 0);
89487 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
89488 for_each_possible_cpu(cpu) {
89489 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
89490 per_cpu(rcu_torture_count, cpu)[i] = 0;
89491 diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
89492 index c639556..cf0a0d5 100644
89493 --- a/kernel/rcu/srcu.c
89494 +++ b/kernel/rcu/srcu.c
89495 @@ -298,9 +298,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
89496
89497 idx = ACCESS_ONCE(sp->completed) & 0x1;
89498 preempt_disable();
89499 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
89500 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
89501 smp_mb(); /* B */ /* Avoid leaking the critical section. */
89502 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
89503 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
89504 preempt_enable();
89505 return idx;
89506 }
89507 diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
89508 index d9efcc1..ea543e9 100644
89509 --- a/kernel/rcu/tiny.c
89510 +++ b/kernel/rcu/tiny.c
89511 @@ -42,7 +42,7 @@
89512 /* Forward declarations for tiny_plugin.h. */
89513 struct rcu_ctrlblk;
89514 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
89515 -static void rcu_process_callbacks(struct softirq_action *unused);
89516 +static void rcu_process_callbacks(void);
89517 static void __call_rcu(struct rcu_head *head,
89518 void (*func)(struct rcu_head *rcu),
89519 struct rcu_ctrlblk *rcp);
89520 @@ -308,7 +308,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
89521 false));
89522 }
89523
89524 -static void rcu_process_callbacks(struct softirq_action *unused)
89525 +static __latent_entropy void rcu_process_callbacks(void)
89526 {
89527 __rcu_process_callbacks(&rcu_sched_ctrlblk);
89528 __rcu_process_callbacks(&rcu_bh_ctrlblk);
89529 diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
89530 index 0c47e30..a084591 100644
89531 --- a/kernel/rcu/tree.c
89532 +++ b/kernel/rcu/tree.c
89533 @@ -388,9 +388,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
89534 rcu_prepare_for_idle(smp_processor_id());
89535 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
89536 smp_mb__before_atomic_inc(); /* See above. */
89537 - atomic_inc(&rdtp->dynticks);
89538 + atomic_inc_unchecked(&rdtp->dynticks);
89539 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
89540 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
89541 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
89542
89543 /*
89544 * It is illegal to enter an extended quiescent state while
89545 @@ -508,10 +508,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
89546 int user)
89547 {
89548 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
89549 - atomic_inc(&rdtp->dynticks);
89550 + atomic_inc_unchecked(&rdtp->dynticks);
89551 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
89552 smp_mb__after_atomic_inc(); /* See above. */
89553 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
89554 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
89555 rcu_cleanup_after_idle(smp_processor_id());
89556 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
89557 if (!user && !is_idle_task(current)) {
89558 @@ -632,14 +632,14 @@ void rcu_nmi_enter(void)
89559 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
89560
89561 if (rdtp->dynticks_nmi_nesting == 0 &&
89562 - (atomic_read(&rdtp->dynticks) & 0x1))
89563 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
89564 return;
89565 rdtp->dynticks_nmi_nesting++;
89566 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
89567 - atomic_inc(&rdtp->dynticks);
89568 + atomic_inc_unchecked(&rdtp->dynticks);
89569 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
89570 smp_mb__after_atomic_inc(); /* See above. */
89571 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
89572 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
89573 }
89574
89575 /**
89576 @@ -658,9 +658,9 @@ void rcu_nmi_exit(void)
89577 return;
89578 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
89579 smp_mb__before_atomic_inc(); /* See above. */
89580 - atomic_inc(&rdtp->dynticks);
89581 + atomic_inc_unchecked(&rdtp->dynticks);
89582 smp_mb__after_atomic_inc(); /* Force delay to next write. */
89583 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
89584 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
89585 }
89586
89587 /**
89588 @@ -673,7 +673,7 @@ void rcu_nmi_exit(void)
89589 */
89590 bool notrace __rcu_is_watching(void)
89591 {
89592 - return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
89593 + return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
89594 }
89595
89596 /**
89597 @@ -756,7 +756,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
89598 static int dyntick_save_progress_counter(struct rcu_data *rdp,
89599 bool *isidle, unsigned long *maxj)
89600 {
89601 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
89602 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
89603 rcu_sysidle_check_cpu(rdp, isidle, maxj);
89604 return (rdp->dynticks_snap & 0x1) == 0;
89605 }
89606 @@ -779,7 +779,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
89607 unsigned int curr;
89608 unsigned int snap;
89609
89610 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
89611 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
89612 snap = (unsigned int)rdp->dynticks_snap;
89613
89614 /*
89615 @@ -1449,9 +1449,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
89616 rdp = this_cpu_ptr(rsp->rda);
89617 rcu_preempt_check_blocked_tasks(rnp);
89618 rnp->qsmask = rnp->qsmaskinit;
89619 - ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
89620 + ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
89621 WARN_ON_ONCE(rnp->completed != rsp->completed);
89622 - ACCESS_ONCE(rnp->completed) = rsp->completed;
89623 + ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
89624 if (rnp == rdp->mynode)
89625 __note_gp_changes(rsp, rnp, rdp);
89626 rcu_preempt_boost_start_gp(rnp);
89627 @@ -1545,7 +1545,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
89628 rcu_for_each_node_breadth_first(rsp, rnp) {
89629 raw_spin_lock_irq(&rnp->lock);
89630 smp_mb__after_unlock_lock();
89631 - ACCESS_ONCE(rnp->completed) = rsp->gpnum;
89632 + ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
89633 rdp = this_cpu_ptr(rsp->rda);
89634 if (rnp == rdp->mynode)
89635 __note_gp_changes(rsp, rnp, rdp);
89636 @@ -1560,7 +1560,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
89637 rcu_nocb_gp_set(rnp, nocb);
89638
89639 /* Declare grace period done. */
89640 - ACCESS_ONCE(rsp->completed) = rsp->gpnum;
89641 + ACCESS_ONCE_RW(rsp->completed) = rsp->gpnum;
89642 trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end"));
89643 rsp->fqs_state = RCU_GP_IDLE;
89644 rdp = this_cpu_ptr(rsp->rda);
89645 @@ -1912,7 +1912,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
89646 rsp->qlen += rdp->qlen;
89647 rdp->n_cbs_orphaned += rdp->qlen;
89648 rdp->qlen_lazy = 0;
89649 - ACCESS_ONCE(rdp->qlen) = 0;
89650 + ACCESS_ONCE_RW(rdp->qlen) = 0;
89651 }
89652
89653 /*
89654 @@ -2159,7 +2159,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
89655 }
89656 smp_mb(); /* List handling before counting for rcu_barrier(). */
89657 rdp->qlen_lazy -= count_lazy;
89658 - ACCESS_ONCE(rdp->qlen) -= count;
89659 + ACCESS_ONCE_RW(rdp->qlen) -= count;
89660 rdp->n_cbs_invoked += count;
89661
89662 /* Reinstate batch limit if we have worked down the excess. */
89663 @@ -2304,7 +2304,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
89664 if (rnp_old != NULL)
89665 raw_spin_unlock(&rnp_old->fqslock);
89666 if (ret) {
89667 - ACCESS_ONCE(rsp->n_force_qs_lh)++;
89668 + ACCESS_ONCE_RW(rsp->n_force_qs_lh)++;
89669 return;
89670 }
89671 rnp_old = rnp;
89672 @@ -2316,7 +2316,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
89673 smp_mb__after_unlock_lock();
89674 raw_spin_unlock(&rnp_old->fqslock);
89675 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
89676 - ACCESS_ONCE(rsp->n_force_qs_lh)++;
89677 + ACCESS_ONCE_RW(rsp->n_force_qs_lh)++;
89678 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
89679 return; /* Someone beat us to it. */
89680 }
89681 @@ -2362,7 +2362,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
89682 /*
89683 * Do RCU core processing for the current CPU.
89684 */
89685 -static void rcu_process_callbacks(struct softirq_action *unused)
89686 +static void rcu_process_callbacks(void)
89687 {
89688 struct rcu_state *rsp;
89689
89690 @@ -2470,7 +2470,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
89691 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
89692 if (debug_rcu_head_queue(head)) {
89693 /* Probable double call_rcu(), so leak the callback. */
89694 - ACCESS_ONCE(head->func) = rcu_leak_callback;
89695 + ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
89696 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
89697 return;
89698 }
89699 @@ -2498,7 +2498,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
89700 local_irq_restore(flags);
89701 return;
89702 }
89703 - ACCESS_ONCE(rdp->qlen)++;
89704 + ACCESS_ONCE_RW(rdp->qlen)++;
89705 if (lazy)
89706 rdp->qlen_lazy++;
89707 else
89708 @@ -2759,11 +2759,11 @@ void synchronize_sched_expedited(void)
89709 * counter wrap on a 32-bit system. Quite a few more CPUs would of
89710 * course be required on a 64-bit system.
89711 */
89712 - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
89713 + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
89714 (ulong)atomic_long_read(&rsp->expedited_done) +
89715 ULONG_MAX / 8)) {
89716 synchronize_sched();
89717 - atomic_long_inc(&rsp->expedited_wrap);
89718 + atomic_long_inc_unchecked(&rsp->expedited_wrap);
89719 return;
89720 }
89721
89722 @@ -2771,7 +2771,7 @@ void synchronize_sched_expedited(void)
89723 * Take a ticket. Note that atomic_inc_return() implies a
89724 * full memory barrier.
89725 */
89726 - snap = atomic_long_inc_return(&rsp->expedited_start);
89727 + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
89728 firstsnap = snap;
89729 get_online_cpus();
89730 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
89731 @@ -2784,14 +2784,14 @@ void synchronize_sched_expedited(void)
89732 synchronize_sched_expedited_cpu_stop,
89733 NULL) == -EAGAIN) {
89734 put_online_cpus();
89735 - atomic_long_inc(&rsp->expedited_tryfail);
89736 + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
89737
89738 /* Check to see if someone else did our work for us. */
89739 s = atomic_long_read(&rsp->expedited_done);
89740 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
89741 /* ensure test happens before caller kfree */
89742 smp_mb__before_atomic_inc(); /* ^^^ */
89743 - atomic_long_inc(&rsp->expedited_workdone1);
89744 + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
89745 return;
89746 }
89747
89748 @@ -2800,7 +2800,7 @@ void synchronize_sched_expedited(void)
89749 udelay(trycount * num_online_cpus());
89750 } else {
89751 wait_rcu_gp(call_rcu_sched);
89752 - atomic_long_inc(&rsp->expedited_normal);
89753 + atomic_long_inc_unchecked(&rsp->expedited_normal);
89754 return;
89755 }
89756
89757 @@ -2809,7 +2809,7 @@ void synchronize_sched_expedited(void)
89758 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
89759 /* ensure test happens before caller kfree */
89760 smp_mb__before_atomic_inc(); /* ^^^ */
89761 - atomic_long_inc(&rsp->expedited_workdone2);
89762 + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
89763 return;
89764 }
89765
89766 @@ -2821,10 +2821,10 @@ void synchronize_sched_expedited(void)
89767 * period works for us.
89768 */
89769 get_online_cpus();
89770 - snap = atomic_long_read(&rsp->expedited_start);
89771 + snap = atomic_long_read_unchecked(&rsp->expedited_start);
89772 smp_mb(); /* ensure read is before try_stop_cpus(). */
89773 }
89774 - atomic_long_inc(&rsp->expedited_stoppedcpus);
89775 + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
89776
89777 /*
89778 * Everyone up to our most recent fetch is covered by our grace
89779 @@ -2833,16 +2833,16 @@ void synchronize_sched_expedited(void)
89780 * than we did already did their update.
89781 */
89782 do {
89783 - atomic_long_inc(&rsp->expedited_done_tries);
89784 + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
89785 s = atomic_long_read(&rsp->expedited_done);
89786 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
89787 /* ensure test happens before caller kfree */
89788 smp_mb__before_atomic_inc(); /* ^^^ */
89789 - atomic_long_inc(&rsp->expedited_done_lost);
89790 + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
89791 break;
89792 }
89793 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
89794 - atomic_long_inc(&rsp->expedited_done_exit);
89795 + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
89796
89797 put_online_cpus();
89798 }
89799 @@ -3048,7 +3048,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
89800 * ACCESS_ONCE() to prevent the compiler from speculating
89801 * the increment to precede the early-exit check.
89802 */
89803 - ACCESS_ONCE(rsp->n_barrier_done)++;
89804 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
89805 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
89806 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
89807 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
89808 @@ -3098,7 +3098,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
89809
89810 /* Increment ->n_barrier_done to prevent duplicate work. */
89811 smp_mb(); /* Keep increment after above mechanism. */
89812 - ACCESS_ONCE(rsp->n_barrier_done)++;
89813 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
89814 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
89815 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
89816 smp_mb(); /* Keep increment before caller's subsequent code. */
89817 @@ -3143,10 +3143,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
89818 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
89819 init_callback_list(rdp);
89820 rdp->qlen_lazy = 0;
89821 - ACCESS_ONCE(rdp->qlen) = 0;
89822 + ACCESS_ONCE_RW(rdp->qlen) = 0;
89823 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
89824 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
89825 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
89826 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
89827 rdp->cpu = cpu;
89828 rdp->rsp = rsp;
89829 rcu_boot_init_nocb_percpu_data(rdp);
89830 @@ -3180,8 +3180,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
89831 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
89832 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
89833 rcu_sysidle_init_percpu_data(rdp->dynticks);
89834 - atomic_set(&rdp->dynticks->dynticks,
89835 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
89836 + atomic_set_unchecked(&rdp->dynticks->dynticks,
89837 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
89838 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
89839
89840 /* Add CPU to rcu_node bitmasks. */
89841 diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
89842 index 75dc3c3..b95d624 100644
89843 --- a/kernel/rcu/tree.h
89844 +++ b/kernel/rcu/tree.h
89845 @@ -87,11 +87,11 @@ struct rcu_dynticks {
89846 long long dynticks_nesting; /* Track irq/process nesting level. */
89847 /* Process level is worth LLONG_MAX/2. */
89848 int dynticks_nmi_nesting; /* Track NMI nesting level. */
89849 - atomic_t dynticks; /* Even value for idle, else odd. */
89850 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
89851 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
89852 long long dynticks_idle_nesting;
89853 /* irq/process nesting level from idle. */
89854 - atomic_t dynticks_idle; /* Even value for idle, else odd. */
89855 + atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
89856 /* "Idle" excludes userspace execution. */
89857 unsigned long dynticks_idle_jiffies;
89858 /* End of last non-NMI non-idle period. */
89859 @@ -431,17 +431,17 @@ struct rcu_state {
89860 /* _rcu_barrier(). */
89861 /* End of fields guarded by barrier_mutex. */
89862
89863 - atomic_long_t expedited_start; /* Starting ticket. */
89864 - atomic_long_t expedited_done; /* Done ticket. */
89865 - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
89866 - atomic_long_t expedited_tryfail; /* # acquisition failures. */
89867 - atomic_long_t expedited_workdone1; /* # done by others #1. */
89868 - atomic_long_t expedited_workdone2; /* # done by others #2. */
89869 - atomic_long_t expedited_normal; /* # fallbacks to normal. */
89870 - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
89871 - atomic_long_t expedited_done_tries; /* # tries to update _done. */
89872 - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
89873 - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
89874 + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
89875 + atomic_long_t expedited_done; /* Done ticket. */
89876 + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
89877 + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
89878 + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
89879 + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
89880 + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
89881 + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
89882 + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
89883 + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
89884 + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
89885
89886 unsigned long jiffies_force_qs; /* Time at which to invoke */
89887 /* force_quiescent_state(). */
89888 diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
89889 index 962d1d5..c6c62d12d 100644
89890 --- a/kernel/rcu/tree_plugin.h
89891 +++ b/kernel/rcu/tree_plugin.h
89892 @@ -758,7 +758,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
89893 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
89894 {
89895 return !rcu_preempted_readers_exp(rnp) &&
89896 - ACCESS_ONCE(rnp->expmask) == 0;
89897 + ACCESS_ONCE_RW(rnp->expmask) == 0;
89898 }
89899
89900 /*
89901 @@ -920,7 +920,7 @@ void synchronize_rcu_expedited(void)
89902
89903 /* Clean up and exit. */
89904 smp_mb(); /* ensure expedited GP seen before counter increment. */
89905 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
89906 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
89907 unlock_mb_ret:
89908 mutex_unlock(&sync_rcu_preempt_exp_mutex);
89909 mb_ret:
89910 @@ -1496,7 +1496,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
89911 free_cpumask_var(cm);
89912 }
89913
89914 -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
89915 +static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
89916 .store = &rcu_cpu_kthread_task,
89917 .thread_should_run = rcu_cpu_kthread_should_run,
89918 .thread_fn = rcu_cpu_kthread,
89919 @@ -1972,7 +1972,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
89920 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
89921 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
89922 cpu, ticks_value, ticks_title,
89923 - atomic_read(&rdtp->dynticks) & 0xfff,
89924 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
89925 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
89926 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
89927 fast_no_hz);
89928 @@ -2138,7 +2138,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
89929
89930 /* Enqueue the callback on the nocb list and update counts. */
89931 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
89932 - ACCESS_ONCE(*old_rhpp) = rhp;
89933 + ACCESS_ONCE_RW(*old_rhpp) = rhp;
89934 atomic_long_add(rhcount, &rdp->nocb_q_count);
89935 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
89936
89937 @@ -2311,12 +2311,12 @@ static int rcu_nocb_kthread(void *arg)
89938 * Extract queued callbacks, update counts, and wait
89939 * for a grace period to elapse.
89940 */
89941 - ACCESS_ONCE(rdp->nocb_head) = NULL;
89942 + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
89943 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
89944 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
89945 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
89946 - ACCESS_ONCE(rdp->nocb_p_count) += c;
89947 - ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
89948 + ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
89949 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
89950 rcu_nocb_wait_gp(rdp);
89951
89952 /* Each pass through the following loop invokes a callback. */
89953 @@ -2342,8 +2342,8 @@ static int rcu_nocb_kthread(void *arg)
89954 list = next;
89955 }
89956 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
89957 - ACCESS_ONCE(rdp->nocb_p_count) -= c;
89958 - ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
89959 + ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
89960 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
89961 rdp->n_nocbs_invoked += c;
89962 }
89963 return 0;
89964 @@ -2360,7 +2360,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
89965 {
89966 if (!rcu_nocb_need_deferred_wakeup(rdp))
89967 return;
89968 - ACCESS_ONCE(rdp->nocb_defer_wakeup) = false;
89969 + ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = false;
89970 wake_up(&rdp->nocb_wq);
89971 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWakeEmpty"));
89972 }
89973 @@ -2386,7 +2386,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
89974 t = kthread_run(rcu_nocb_kthread, rdp,
89975 "rcuo%c/%d", rsp->abbr, cpu);
89976 BUG_ON(IS_ERR(t));
89977 - ACCESS_ONCE(rdp->nocb_kthread) = t;
89978 + ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
89979 }
89980 }
89981
89982 @@ -2522,11 +2522,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
89983
89984 /* Record start of fully idle period. */
89985 j = jiffies;
89986 - ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
89987 + ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
89988 smp_mb__before_atomic_inc();
89989 - atomic_inc(&rdtp->dynticks_idle);
89990 + atomic_inc_unchecked(&rdtp->dynticks_idle);
89991 smp_mb__after_atomic_inc();
89992 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
89993 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
89994 }
89995
89996 /*
89997 @@ -2591,9 +2591,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
89998
89999 /* Record end of idle period. */
90000 smp_mb__before_atomic_inc();
90001 - atomic_inc(&rdtp->dynticks_idle);
90002 + atomic_inc_unchecked(&rdtp->dynticks_idle);
90003 smp_mb__after_atomic_inc();
90004 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
90005 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
90006
90007 /*
90008 * If we are the timekeeping CPU, we are permitted to be non-idle
90009 @@ -2634,7 +2634,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
90010 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
90011
90012 /* Pick up current idle and NMI-nesting counter and check. */
90013 - cur = atomic_read(&rdtp->dynticks_idle);
90014 + cur = atomic_read_unchecked(&rdtp->dynticks_idle);
90015 if (cur & 0x1) {
90016 *isidle = false; /* We are not idle! */
90017 return;
90018 @@ -2697,7 +2697,7 @@ static void rcu_sysidle(unsigned long j)
90019 case RCU_SYSIDLE_NOT:
90020
90021 /* First time all are idle, so note a short idle period. */
90022 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
90023 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
90024 break;
90025
90026 case RCU_SYSIDLE_SHORT:
90027 @@ -2734,7 +2734,7 @@ static void rcu_sysidle(unsigned long j)
90028 static void rcu_sysidle_cancel(void)
90029 {
90030 smp_mb();
90031 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
90032 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
90033 }
90034
90035 /*
90036 @@ -2782,7 +2782,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
90037 smp_mb(); /* grace period precedes setting inuse. */
90038
90039 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
90040 - ACCESS_ONCE(rshp->inuse) = 0;
90041 + ACCESS_ONCE_RW(rshp->inuse) = 0;
90042 }
90043
90044 /*
90045 diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
90046 index 5cdc62e..cc52e88 100644
90047 --- a/kernel/rcu/tree_trace.c
90048 +++ b/kernel/rcu/tree_trace.c
90049 @@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
90050 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
90051 rdp->passed_quiesce, rdp->qs_pending);
90052 seq_printf(m, " dt=%d/%llx/%d df=%lu",
90053 - atomic_read(&rdp->dynticks->dynticks),
90054 + atomic_read_unchecked(&rdp->dynticks->dynticks),
90055 rdp->dynticks->dynticks_nesting,
90056 rdp->dynticks->dynticks_nmi_nesting,
90057 rdp->dynticks_fqs);
90058 @@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
90059 struct rcu_state *rsp = (struct rcu_state *)m->private;
90060
90061 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",
90062 - atomic_long_read(&rsp->expedited_start),
90063 + atomic_long_read_unchecked(&rsp->expedited_start),
90064 atomic_long_read(&rsp->expedited_done),
90065 - atomic_long_read(&rsp->expedited_wrap),
90066 - atomic_long_read(&rsp->expedited_tryfail),
90067 - atomic_long_read(&rsp->expedited_workdone1),
90068 - atomic_long_read(&rsp->expedited_workdone2),
90069 - atomic_long_read(&rsp->expedited_normal),
90070 - atomic_long_read(&rsp->expedited_stoppedcpus),
90071 - atomic_long_read(&rsp->expedited_done_tries),
90072 - atomic_long_read(&rsp->expedited_done_lost),
90073 - atomic_long_read(&rsp->expedited_done_exit));
90074 + atomic_long_read_unchecked(&rsp->expedited_wrap),
90075 + atomic_long_read_unchecked(&rsp->expedited_tryfail),
90076 + atomic_long_read_unchecked(&rsp->expedited_workdone1),
90077 + atomic_long_read_unchecked(&rsp->expedited_workdone2),
90078 + atomic_long_read_unchecked(&rsp->expedited_normal),
90079 + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
90080 + atomic_long_read_unchecked(&rsp->expedited_done_tries),
90081 + atomic_long_read_unchecked(&rsp->expedited_done_lost),
90082 + atomic_long_read_unchecked(&rsp->expedited_done_exit));
90083 return 0;
90084 }
90085
90086 diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
90087 index 4c0a9b0..7e81362 100644
90088 --- a/kernel/rcu/update.c
90089 +++ b/kernel/rcu/update.c
90090 @@ -311,10 +311,10 @@ int rcu_jiffies_till_stall_check(void)
90091 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
90092 */
90093 if (till_stall_check < 3) {
90094 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
90095 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
90096 till_stall_check = 3;
90097 } else if (till_stall_check > 300) {
90098 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
90099 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
90100 till_stall_check = 300;
90101 }
90102 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
90103 diff --git a/kernel/resource.c b/kernel/resource.c
90104 index 8957d68..770cbe4 100644
90105 --- a/kernel/resource.c
90106 +++ b/kernel/resource.c
90107 @@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
90108
90109 static int __init ioresources_init(void)
90110 {
90111 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
90112 +#ifdef CONFIG_GRKERNSEC_PROC_USER
90113 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
90114 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
90115 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
90116 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
90117 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
90118 +#endif
90119 +#else
90120 proc_create("ioports", 0, NULL, &proc_ioports_operations);
90121 proc_create("iomem", 0, NULL, &proc_iomem_operations);
90122 +#endif
90123 return 0;
90124 }
90125 __initcall(ioresources_init);
90126 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
90127 index e73efba..c9bfbd4 100644
90128 --- a/kernel/sched/auto_group.c
90129 +++ b/kernel/sched/auto_group.c
90130 @@ -11,7 +11,7 @@
90131
90132 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
90133 static struct autogroup autogroup_default;
90134 -static atomic_t autogroup_seq_nr;
90135 +static atomic_unchecked_t autogroup_seq_nr;
90136
90137 void __init autogroup_init(struct task_struct *init_task)
90138 {
90139 @@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
90140
90141 kref_init(&ag->kref);
90142 init_rwsem(&ag->lock);
90143 - ag->id = atomic_inc_return(&autogroup_seq_nr);
90144 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
90145 ag->tg = tg;
90146 #ifdef CONFIG_RT_GROUP_SCHED
90147 /*
90148 diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
90149 index a63f4dc..349bbb0 100644
90150 --- a/kernel/sched/completion.c
90151 +++ b/kernel/sched/completion.c
90152 @@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
90153 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
90154 * or number of jiffies left till timeout) if completed.
90155 */
90156 -long __sched
90157 +long __sched __intentional_overflow(-1)
90158 wait_for_completion_interruptible_timeout(struct completion *x,
90159 unsigned long timeout)
90160 {
90161 @@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
90162 *
90163 * Return: -ERESTARTSYS if interrupted, 0 if completed.
90164 */
90165 -int __sched wait_for_completion_killable(struct completion *x)
90166 +int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
90167 {
90168 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
90169 if (t == -ERESTARTSYS)
90170 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
90171 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
90172 * or number of jiffies left till timeout) if completed.
90173 */
90174 -long __sched
90175 +long __sched __intentional_overflow(-1)
90176 wait_for_completion_killable_timeout(struct completion *x,
90177 unsigned long timeout)
90178 {
90179 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
90180 index 8da7e49..ef10a02 100644
90181 --- a/kernel/sched/core.c
90182 +++ b/kernel/sched/core.c
90183 @@ -1775,7 +1775,7 @@ void set_numabalancing_state(bool enabled)
90184 int sysctl_numa_balancing(struct ctl_table *table, int write,
90185 void __user *buffer, size_t *lenp, loff_t *ppos)
90186 {
90187 - struct ctl_table t;
90188 + ctl_table_no_const t;
90189 int err;
90190 int state = numabalancing_enabled;
90191
90192 @@ -2238,8 +2238,10 @@ context_switch(struct rq *rq, struct task_struct *prev,
90193 next->active_mm = oldmm;
90194 atomic_inc(&oldmm->mm_count);
90195 enter_lazy_tlb(oldmm, next);
90196 - } else
90197 + } else {
90198 switch_mm(oldmm, mm, next);
90199 + populate_stack();
90200 + }
90201
90202 if (!prev->mm) {
90203 prev->active_mm = NULL;
90204 @@ -3004,6 +3006,8 @@ int can_nice(const struct task_struct *p, const int nice)
90205 /* convert nice value [19,-20] to rlimit style value [1,40] */
90206 int nice_rlim = 20 - nice;
90207
90208 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
90209 +
90210 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
90211 capable(CAP_SYS_NICE));
90212 }
90213 @@ -3037,7 +3041,8 @@ SYSCALL_DEFINE1(nice, int, increment)
90214 if (nice > MAX_NICE)
90215 nice = MAX_NICE;
90216
90217 - if (increment < 0 && !can_nice(current, nice))
90218 + if (increment < 0 && (!can_nice(current, nice) ||
90219 + gr_handle_chroot_nice()))
90220 return -EPERM;
90221
90222 retval = security_task_setnice(current, nice);
90223 @@ -3310,6 +3315,7 @@ recheck:
90224 if (policy != p->policy && !rlim_rtprio)
90225 return -EPERM;
90226
90227 + gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
90228 /* can't increase priority */
90229 if (attr->sched_priority > p->rt_priority &&
90230 attr->sched_priority > rlim_rtprio)
90231 @@ -4708,6 +4714,7 @@ void idle_task_exit(void)
90232
90233 if (mm != &init_mm) {
90234 switch_mm(mm, &init_mm, current);
90235 + populate_stack();
90236 finish_arch_post_lock_switch();
90237 }
90238 mmdrop(mm);
90239 @@ -4803,7 +4810,7 @@ static void migrate_tasks(unsigned int dead_cpu)
90240
90241 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
90242
90243 -static struct ctl_table sd_ctl_dir[] = {
90244 +static ctl_table_no_const sd_ctl_dir[] __read_only = {
90245 {
90246 .procname = "sched_domain",
90247 .mode = 0555,
90248 @@ -4820,17 +4827,17 @@ static struct ctl_table sd_ctl_root[] = {
90249 {}
90250 };
90251
90252 -static struct ctl_table *sd_alloc_ctl_entry(int n)
90253 +static ctl_table_no_const *sd_alloc_ctl_entry(int n)
90254 {
90255 - struct ctl_table *entry =
90256 + ctl_table_no_const *entry =
90257 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
90258
90259 return entry;
90260 }
90261
90262 -static void sd_free_ctl_entry(struct ctl_table **tablep)
90263 +static void sd_free_ctl_entry(ctl_table_no_const *tablep)
90264 {
90265 - struct ctl_table *entry;
90266 + ctl_table_no_const *entry;
90267
90268 /*
90269 * In the intermediate directories, both the child directory and
90270 @@ -4838,22 +4845,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
90271 * will always be set. In the lowest directory the names are
90272 * static strings and all have proc handlers.
90273 */
90274 - for (entry = *tablep; entry->mode; entry++) {
90275 - if (entry->child)
90276 - sd_free_ctl_entry(&entry->child);
90277 + for (entry = tablep; entry->mode; entry++) {
90278 + if (entry->child) {
90279 + sd_free_ctl_entry(entry->child);
90280 + pax_open_kernel();
90281 + entry->child = NULL;
90282 + pax_close_kernel();
90283 + }
90284 if (entry->proc_handler == NULL)
90285 kfree(entry->procname);
90286 }
90287
90288 - kfree(*tablep);
90289 - *tablep = NULL;
90290 + kfree(tablep);
90291 }
90292
90293 static int min_load_idx = 0;
90294 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
90295
90296 static void
90297 -set_table_entry(struct ctl_table *entry,
90298 +set_table_entry(ctl_table_no_const *entry,
90299 const char *procname, void *data, int maxlen,
90300 umode_t mode, proc_handler *proc_handler,
90301 bool load_idx)
90302 @@ -4873,7 +4883,7 @@ set_table_entry(struct ctl_table *entry,
90303 static struct ctl_table *
90304 sd_alloc_ctl_domain_table(struct sched_domain *sd)
90305 {
90306 - struct ctl_table *table = sd_alloc_ctl_entry(14);
90307 + ctl_table_no_const *table = sd_alloc_ctl_entry(14);
90308
90309 if (table == NULL)
90310 return NULL;
90311 @@ -4911,9 +4921,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
90312 return table;
90313 }
90314
90315 -static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
90316 +static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
90317 {
90318 - struct ctl_table *entry, *table;
90319 + ctl_table_no_const *entry, *table;
90320 struct sched_domain *sd;
90321 int domain_num = 0, i;
90322 char buf[32];
90323 @@ -4940,11 +4950,13 @@ static struct ctl_table_header *sd_sysctl_header;
90324 static void register_sched_domain_sysctl(void)
90325 {
90326 int i, cpu_num = num_possible_cpus();
90327 - struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
90328 + ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
90329 char buf[32];
90330
90331 WARN_ON(sd_ctl_dir[0].child);
90332 + pax_open_kernel();
90333 sd_ctl_dir[0].child = entry;
90334 + pax_close_kernel();
90335
90336 if (entry == NULL)
90337 return;
90338 @@ -4967,8 +4979,12 @@ static void unregister_sched_domain_sysctl(void)
90339 if (sd_sysctl_header)
90340 unregister_sysctl_table(sd_sysctl_header);
90341 sd_sysctl_header = NULL;
90342 - if (sd_ctl_dir[0].child)
90343 - sd_free_ctl_entry(&sd_ctl_dir[0].child);
90344 + if (sd_ctl_dir[0].child) {
90345 + sd_free_ctl_entry(sd_ctl_dir[0].child);
90346 + pax_open_kernel();
90347 + sd_ctl_dir[0].child = NULL;
90348 + pax_close_kernel();
90349 + }
90350 }
90351 #else
90352 static void register_sched_domain_sysctl(void)
90353 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
90354 index 8cbe2d2..61f20a1 100644
90355 --- a/kernel/sched/fair.c
90356 +++ b/kernel/sched/fair.c
90357 @@ -1806,7 +1806,7 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
90358
90359 static void reset_ptenuma_scan(struct task_struct *p)
90360 {
90361 - ACCESS_ONCE(p->mm->numa_scan_seq)++;
90362 + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
90363 p->mm->numa_scan_offset = 0;
90364 }
90365
90366 @@ -7181,7 +7181,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
90367 * run_rebalance_domains is triggered when needed from the scheduler tick.
90368 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
90369 */
90370 -static void run_rebalance_domains(struct softirq_action *h)
90371 +static __latent_entropy void run_rebalance_domains(void)
90372 {
90373 struct rq *this_rq = this_rq();
90374 enum cpu_idle_type idle = this_rq->idle_balance ?
90375 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
90376 index 369b4d6..fa4eb3b 100644
90377 --- a/kernel/sched/sched.h
90378 +++ b/kernel/sched/sched.h
90379 @@ -1157,7 +1157,7 @@ struct sched_class {
90380 #ifdef CONFIG_FAIR_GROUP_SCHED
90381 void (*task_move_group) (struct task_struct *p, int on_rq);
90382 #endif
90383 -};
90384 +} __do_const;
90385
90386 static inline void put_prev_task(struct rq *rq, struct task_struct *prev)
90387 {
90388 diff --git a/kernel/signal.c b/kernel/signal.c
90389 index 6ea13c0..31e3b25 100644
90390 --- a/kernel/signal.c
90391 +++ b/kernel/signal.c
90392 @@ -53,12 +53,12 @@ static struct kmem_cache *sigqueue_cachep;
90393
90394 int print_fatal_signals __read_mostly;
90395
90396 -static void __user *sig_handler(struct task_struct *t, int sig)
90397 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
90398 {
90399 return t->sighand->action[sig - 1].sa.sa_handler;
90400 }
90401
90402 -static int sig_handler_ignored(void __user *handler, int sig)
90403 +static int sig_handler_ignored(__sighandler_t handler, int sig)
90404 {
90405 /* Is it explicitly or implicitly ignored? */
90406 return handler == SIG_IGN ||
90407 @@ -67,7 +67,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
90408
90409 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
90410 {
90411 - void __user *handler;
90412 + __sighandler_t handler;
90413
90414 handler = sig_handler(t, sig);
90415
90416 @@ -371,6 +371,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
90417 atomic_inc(&user->sigpending);
90418 rcu_read_unlock();
90419
90420 + if (!override_rlimit)
90421 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
90422 +
90423 if (override_rlimit ||
90424 atomic_read(&user->sigpending) <=
90425 task_rlimit(t, RLIMIT_SIGPENDING)) {
90426 @@ -498,7 +501,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
90427
90428 int unhandled_signal(struct task_struct *tsk, int sig)
90429 {
90430 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
90431 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
90432 if (is_global_init(tsk))
90433 return 1;
90434 if (handler != SIG_IGN && handler != SIG_DFL)
90435 @@ -818,6 +821,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
90436 }
90437 }
90438
90439 + /* allow glibc communication via tgkill to other threads in our
90440 + thread group */
90441 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
90442 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
90443 + && gr_handle_signal(t, sig))
90444 + return -EPERM;
90445 +
90446 return security_task_kill(t, info, sig, 0);
90447 }
90448
90449 @@ -1201,7 +1211,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
90450 return send_signal(sig, info, p, 1);
90451 }
90452
90453 -static int
90454 +int
90455 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90456 {
90457 return send_signal(sig, info, t, 0);
90458 @@ -1238,6 +1248,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90459 unsigned long int flags;
90460 int ret, blocked, ignored;
90461 struct k_sigaction *action;
90462 + int is_unhandled = 0;
90463
90464 spin_lock_irqsave(&t->sighand->siglock, flags);
90465 action = &t->sighand->action[sig-1];
90466 @@ -1252,9 +1263,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90467 }
90468 if (action->sa.sa_handler == SIG_DFL)
90469 t->signal->flags &= ~SIGNAL_UNKILLABLE;
90470 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
90471 + is_unhandled = 1;
90472 ret = specific_send_sig_info(sig, info, t);
90473 spin_unlock_irqrestore(&t->sighand->siglock, flags);
90474
90475 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
90476 + normal operation */
90477 + if (is_unhandled) {
90478 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
90479 + gr_handle_crash(t, sig);
90480 + }
90481 +
90482 return ret;
90483 }
90484
90485 @@ -1321,8 +1341,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
90486 ret = check_kill_permission(sig, info, p);
90487 rcu_read_unlock();
90488
90489 - if (!ret && sig)
90490 + if (!ret && sig) {
90491 ret = do_send_sig_info(sig, info, p, true);
90492 + if (!ret)
90493 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
90494 + }
90495
90496 return ret;
90497 }
90498 @@ -2928,7 +2951,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
90499 int error = -ESRCH;
90500
90501 rcu_read_lock();
90502 - p = find_task_by_vpid(pid);
90503 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
90504 + /* allow glibc communication via tgkill to other threads in our
90505 + thread group */
90506 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
90507 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
90508 + p = find_task_by_vpid_unrestricted(pid);
90509 + else
90510 +#endif
90511 + p = find_task_by_vpid(pid);
90512 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
90513 error = check_kill_permission(sig, info, p);
90514 /*
90515 @@ -3241,8 +3272,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
90516 }
90517 seg = get_fs();
90518 set_fs(KERNEL_DS);
90519 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
90520 - (stack_t __force __user *) &uoss,
90521 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
90522 + (stack_t __force_user *) &uoss,
90523 compat_user_stack_pointer());
90524 set_fs(seg);
90525 if (ret >= 0 && uoss_ptr) {
90526 diff --git a/kernel/smpboot.c b/kernel/smpboot.c
90527 index eb89e18..a4e6792 100644
90528 --- a/kernel/smpboot.c
90529 +++ b/kernel/smpboot.c
90530 @@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
90531 }
90532 smpboot_unpark_thread(plug_thread, cpu);
90533 }
90534 - list_add(&plug_thread->list, &hotplug_threads);
90535 + pax_list_add(&plug_thread->list, &hotplug_threads);
90536 out:
90537 mutex_unlock(&smpboot_threads_lock);
90538 return ret;
90539 @@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
90540 {
90541 get_online_cpus();
90542 mutex_lock(&smpboot_threads_lock);
90543 - list_del(&plug_thread->list);
90544 + pax_list_del(&plug_thread->list);
90545 smpboot_destroy_threads(plug_thread);
90546 mutex_unlock(&smpboot_threads_lock);
90547 put_online_cpus();
90548 diff --git a/kernel/softirq.c b/kernel/softirq.c
90549 index 92f24f5..db41501 100644
90550 --- a/kernel/softirq.c
90551 +++ b/kernel/softirq.c
90552 @@ -53,7 +53,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
90553 EXPORT_SYMBOL(irq_stat);
90554 #endif
90555
90556 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
90557 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
90558
90559 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
90560
90561 @@ -268,7 +268,7 @@ restart:
90562 kstat_incr_softirqs_this_cpu(vec_nr);
90563
90564 trace_softirq_entry(vec_nr);
90565 - h->action(h);
90566 + h->action();
90567 trace_softirq_exit(vec_nr);
90568 if (unlikely(prev_count != preempt_count())) {
90569 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
90570 @@ -428,7 +428,7 @@ void __raise_softirq_irqoff(unsigned int nr)
90571 or_softirq_pending(1UL << nr);
90572 }
90573
90574 -void open_softirq(int nr, void (*action)(struct softirq_action *))
90575 +void __init open_softirq(int nr, void (*action)(void))
90576 {
90577 softirq_vec[nr].action = action;
90578 }
90579 @@ -480,7 +480,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
90580 }
90581 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
90582
90583 -static void tasklet_action(struct softirq_action *a)
90584 +static void tasklet_action(void)
90585 {
90586 struct tasklet_struct *list;
90587
90588 @@ -516,7 +516,7 @@ static void tasklet_action(struct softirq_action *a)
90589 }
90590 }
90591
90592 -static void tasklet_hi_action(struct softirq_action *a)
90593 +static __latent_entropy void tasklet_hi_action(void)
90594 {
90595 struct tasklet_struct *list;
90596
90597 @@ -743,7 +743,7 @@ static struct notifier_block cpu_nfb = {
90598 .notifier_call = cpu_callback
90599 };
90600
90601 -static struct smp_hotplug_thread softirq_threads = {
90602 +static struct smp_hotplug_thread softirq_threads __read_only = {
90603 .store = &ksoftirqd,
90604 .thread_should_run = ksoftirqd_should_run,
90605 .thread_fn = run_ksoftirqd,
90606 diff --git a/kernel/sys.c b/kernel/sys.c
90607 index fba0f29..84400e2 100644
90608 --- a/kernel/sys.c
90609 +++ b/kernel/sys.c
90610 @@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
90611 error = -EACCES;
90612 goto out;
90613 }
90614 +
90615 + if (gr_handle_chroot_setpriority(p, niceval)) {
90616 + error = -EACCES;
90617 + goto out;
90618 + }
90619 +
90620 no_nice = security_task_setnice(p, niceval);
90621 if (no_nice) {
90622 error = no_nice;
90623 @@ -351,6 +357,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
90624 goto error;
90625 }
90626
90627 + if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
90628 + goto error;
90629 +
90630 if (rgid != (gid_t) -1 ||
90631 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
90632 new->sgid = new->egid;
90633 @@ -386,6 +395,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
90634 old = current_cred();
90635
90636 retval = -EPERM;
90637 +
90638 + if (gr_check_group_change(kgid, kgid, kgid))
90639 + goto error;
90640 +
90641 if (ns_capable(old->user_ns, CAP_SETGID))
90642 new->gid = new->egid = new->sgid = new->fsgid = kgid;
90643 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
90644 @@ -403,7 +416,7 @@ error:
90645 /*
90646 * change the user struct in a credentials set to match the new UID
90647 */
90648 -static int set_user(struct cred *new)
90649 +int set_user(struct cred *new)
90650 {
90651 struct user_struct *new_user;
90652
90653 @@ -483,6 +496,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
90654 goto error;
90655 }
90656
90657 + if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
90658 + goto error;
90659 +
90660 if (!uid_eq(new->uid, old->uid)) {
90661 retval = set_user(new);
90662 if (retval < 0)
90663 @@ -533,6 +549,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
90664 old = current_cred();
90665
90666 retval = -EPERM;
90667 +
90668 + if (gr_check_crash_uid(kuid))
90669 + goto error;
90670 + if (gr_check_user_change(kuid, kuid, kuid))
90671 + goto error;
90672 +
90673 if (ns_capable(old->user_ns, CAP_SETUID)) {
90674 new->suid = new->uid = kuid;
90675 if (!uid_eq(kuid, old->uid)) {
90676 @@ -602,6 +624,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
90677 goto error;
90678 }
90679
90680 + if (gr_check_user_change(kruid, keuid, INVALID_UID))
90681 + goto error;
90682 +
90683 if (ruid != (uid_t) -1) {
90684 new->uid = kruid;
90685 if (!uid_eq(kruid, old->uid)) {
90686 @@ -684,6 +709,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
90687 goto error;
90688 }
90689
90690 + if (gr_check_group_change(krgid, kegid, INVALID_GID))
90691 + goto error;
90692 +
90693 if (rgid != (gid_t) -1)
90694 new->gid = krgid;
90695 if (egid != (gid_t) -1)
90696 @@ -745,12 +773,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
90697 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
90698 ns_capable(old->user_ns, CAP_SETUID)) {
90699 if (!uid_eq(kuid, old->fsuid)) {
90700 + if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
90701 + goto error;
90702 +
90703 new->fsuid = kuid;
90704 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
90705 goto change_okay;
90706 }
90707 }
90708
90709 +error:
90710 abort_creds(new);
90711 return old_fsuid;
90712
90713 @@ -783,12 +815,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
90714 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
90715 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
90716 ns_capable(old->user_ns, CAP_SETGID)) {
90717 + if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
90718 + goto error;
90719 +
90720 if (!gid_eq(kgid, old->fsgid)) {
90721 new->fsgid = kgid;
90722 goto change_okay;
90723 }
90724 }
90725
90726 +error:
90727 abort_creds(new);
90728 return old_fsgid;
90729
90730 @@ -1167,19 +1203,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
90731 return -EFAULT;
90732
90733 down_read(&uts_sem);
90734 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
90735 + error = __copy_to_user(name->sysname, &utsname()->sysname,
90736 __OLD_UTS_LEN);
90737 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
90738 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
90739 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
90740 __OLD_UTS_LEN);
90741 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
90742 - error |= __copy_to_user(&name->release, &utsname()->release,
90743 + error |= __copy_to_user(name->release, &utsname()->release,
90744 __OLD_UTS_LEN);
90745 error |= __put_user(0, name->release + __OLD_UTS_LEN);
90746 - error |= __copy_to_user(&name->version, &utsname()->version,
90747 + error |= __copy_to_user(name->version, &utsname()->version,
90748 __OLD_UTS_LEN);
90749 error |= __put_user(0, name->version + __OLD_UTS_LEN);
90750 - error |= __copy_to_user(&name->machine, &utsname()->machine,
90751 + error |= __copy_to_user(name->machine, &utsname()->machine,
90752 __OLD_UTS_LEN);
90753 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
90754 up_read(&uts_sem);
90755 @@ -1381,6 +1417,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
90756 */
90757 new_rlim->rlim_cur = 1;
90758 }
90759 + /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
90760 + is changed to a lower value. Since tasks can be created by the same
90761 + user in between this limit change and an execve by this task, force
90762 + a recheck only for this task by setting PF_NPROC_EXCEEDED
90763 + */
90764 + if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
90765 + tsk->flags |= PF_NPROC_EXCEEDED;
90766 }
90767 if (!retval) {
90768 if (old_rlim)
90769 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
90770 index 0e0373f..69f5181 100644
90771 --- a/kernel/sysctl.c
90772 +++ b/kernel/sysctl.c
90773 @@ -94,7 +94,6 @@
90774
90775
90776 #if defined(CONFIG_SYSCTL)
90777 -
90778 /* External variables not in a header file. */
90779 extern int max_threads;
90780 extern int suid_dumpable;
90781 @@ -115,19 +114,20 @@ extern int sysctl_nr_trim_pages;
90782
90783 /* Constants used for minimum and maximum */
90784 #ifdef CONFIG_LOCKUP_DETECTOR
90785 -static int sixty = 60;
90786 +static int sixty __read_only = 60;
90787 #endif
90788
90789 -static int __maybe_unused neg_one = -1;
90790 +static int __maybe_unused neg_one __read_only = -1;
90791
90792 -static int zero;
90793 -static int __maybe_unused one = 1;
90794 -static int __maybe_unused two = 2;
90795 -static int __maybe_unused four = 4;
90796 -static unsigned long one_ul = 1;
90797 -static int one_hundred = 100;
90798 +static int zero __read_only = 0;
90799 +static int __maybe_unused one __read_only = 1;
90800 +static int __maybe_unused two __read_only = 2;
90801 +static int __maybe_unused three __read_only = 3;
90802 +static int __maybe_unused four __read_only = 4;
90803 +static unsigned long one_ul __read_only = 1;
90804 +static int one_hundred __read_only = 100;
90805 #ifdef CONFIG_PRINTK
90806 -static int ten_thousand = 10000;
90807 +static int ten_thousand __read_only = 10000;
90808 #endif
90809
90810 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
90811 @@ -178,10 +178,8 @@ static int proc_taint(struct ctl_table *table, int write,
90812 void __user *buffer, size_t *lenp, loff_t *ppos);
90813 #endif
90814
90815 -#ifdef CONFIG_PRINTK
90816 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90817 void __user *buffer, size_t *lenp, loff_t *ppos);
90818 -#endif
90819
90820 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
90821 void __user *buffer, size_t *lenp, loff_t *ppos);
90822 @@ -212,6 +210,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
90823
90824 #endif
90825
90826 +extern struct ctl_table grsecurity_table[];
90827 +
90828 static struct ctl_table kern_table[];
90829 static struct ctl_table vm_table[];
90830 static struct ctl_table fs_table[];
90831 @@ -226,6 +226,20 @@ extern struct ctl_table epoll_table[];
90832 int sysctl_legacy_va_layout;
90833 #endif
90834
90835 +#ifdef CONFIG_PAX_SOFTMODE
90836 +static ctl_table pax_table[] = {
90837 + {
90838 + .procname = "softmode",
90839 + .data = &pax_softmode,
90840 + .maxlen = sizeof(unsigned int),
90841 + .mode = 0600,
90842 + .proc_handler = &proc_dointvec,
90843 + },
90844 +
90845 + { }
90846 +};
90847 +#endif
90848 +
90849 /* The default sysctl tables: */
90850
90851 static struct ctl_table sysctl_base_table[] = {
90852 @@ -274,6 +288,22 @@ static int max_extfrag_threshold = 1000;
90853 #endif
90854
90855 static struct ctl_table kern_table[] = {
90856 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
90857 + {
90858 + .procname = "grsecurity",
90859 + .mode = 0500,
90860 + .child = grsecurity_table,
90861 + },
90862 +#endif
90863 +
90864 +#ifdef CONFIG_PAX_SOFTMODE
90865 + {
90866 + .procname = "pax",
90867 + .mode = 0500,
90868 + .child = pax_table,
90869 + },
90870 +#endif
90871 +
90872 {
90873 .procname = "sched_child_runs_first",
90874 .data = &sysctl_sched_child_runs_first,
90875 @@ -629,7 +659,7 @@ static struct ctl_table kern_table[] = {
90876 .data = &modprobe_path,
90877 .maxlen = KMOD_PATH_LEN,
90878 .mode = 0644,
90879 - .proc_handler = proc_dostring,
90880 + .proc_handler = proc_dostring_modpriv,
90881 },
90882 {
90883 .procname = "modules_disabled",
90884 @@ -796,16 +826,20 @@ static struct ctl_table kern_table[] = {
90885 .extra1 = &zero,
90886 .extra2 = &one,
90887 },
90888 +#endif
90889 {
90890 .procname = "kptr_restrict",
90891 .data = &kptr_restrict,
90892 .maxlen = sizeof(int),
90893 .mode = 0644,
90894 .proc_handler = proc_dointvec_minmax_sysadmin,
90895 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90896 + .extra1 = &two,
90897 +#else
90898 .extra1 = &zero,
90899 +#endif
90900 .extra2 = &two,
90901 },
90902 -#endif
90903 {
90904 .procname = "ngroups_max",
90905 .data = &ngroups_max,
90906 @@ -1050,10 +1084,17 @@ static struct ctl_table kern_table[] = {
90907 */
90908 {
90909 .procname = "perf_event_paranoid",
90910 - .data = &sysctl_perf_event_paranoid,
90911 - .maxlen = sizeof(sysctl_perf_event_paranoid),
90912 + .data = &sysctl_perf_event_legitimately_concerned,
90913 + .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
90914 .mode = 0644,
90915 - .proc_handler = proc_dointvec,
90916 + /* go ahead, be a hero */
90917 + .proc_handler = proc_dointvec_minmax_sysadmin,
90918 + .extra1 = &neg_one,
90919 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
90920 + .extra2 = &three,
90921 +#else
90922 + .extra2 = &two,
90923 +#endif
90924 },
90925 {
90926 .procname = "perf_event_mlock_kb",
90927 @@ -1315,6 +1356,13 @@ static struct ctl_table vm_table[] = {
90928 .proc_handler = proc_dointvec_minmax,
90929 .extra1 = &zero,
90930 },
90931 + {
90932 + .procname = "heap_stack_gap",
90933 + .data = &sysctl_heap_stack_gap,
90934 + .maxlen = sizeof(sysctl_heap_stack_gap),
90935 + .mode = 0644,
90936 + .proc_handler = proc_doulongvec_minmax,
90937 + },
90938 #else
90939 {
90940 .procname = "nr_trim_pages",
90941 @@ -1779,6 +1827,16 @@ int proc_dostring(struct ctl_table *table, int write,
90942 buffer, lenp, ppos);
90943 }
90944
90945 +int proc_dostring_modpriv(struct ctl_table *table, int write,
90946 + void __user *buffer, size_t *lenp, loff_t *ppos)
90947 +{
90948 + if (write && !capable(CAP_SYS_MODULE))
90949 + return -EPERM;
90950 +
90951 + return _proc_do_string(table->data, table->maxlen, write,
90952 + buffer, lenp, ppos);
90953 +}
90954 +
90955 static size_t proc_skip_spaces(char **buf)
90956 {
90957 size_t ret;
90958 @@ -1884,6 +1942,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
90959 len = strlen(tmp);
90960 if (len > *size)
90961 len = *size;
90962 + if (len > sizeof(tmp))
90963 + len = sizeof(tmp);
90964 if (copy_to_user(*buf, tmp, len))
90965 return -EFAULT;
90966 *size -= len;
90967 @@ -2048,7 +2108,7 @@ int proc_dointvec(struct ctl_table *table, int write,
90968 static int proc_taint(struct ctl_table *table, int write,
90969 void __user *buffer, size_t *lenp, loff_t *ppos)
90970 {
90971 - struct ctl_table t;
90972 + ctl_table_no_const t;
90973 unsigned long tmptaint = get_taint();
90974 int err;
90975
90976 @@ -2076,7 +2136,6 @@ static int proc_taint(struct ctl_table *table, int write,
90977 return err;
90978 }
90979
90980 -#ifdef CONFIG_PRINTK
90981 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90982 void __user *buffer, size_t *lenp, loff_t *ppos)
90983 {
90984 @@ -2085,7 +2144,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90985
90986 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
90987 }
90988 -#endif
90989
90990 struct do_proc_dointvec_minmax_conv_param {
90991 int *min;
90992 @@ -2632,6 +2690,12 @@ int proc_dostring(struct ctl_table *table, int write,
90993 return -ENOSYS;
90994 }
90995
90996 +int proc_dostring_modpriv(struct ctl_table *table, int write,
90997 + void __user *buffer, size_t *lenp, loff_t *ppos)
90998 +{
90999 + return -ENOSYS;
91000 +}
91001 +
91002 int proc_dointvec(struct ctl_table *table, int write,
91003 void __user *buffer, size_t *lenp, loff_t *ppos)
91004 {
91005 @@ -2688,5 +2752,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
91006 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
91007 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
91008 EXPORT_SYMBOL(proc_dostring);
91009 +EXPORT_SYMBOL(proc_dostring_modpriv);
91010 EXPORT_SYMBOL(proc_doulongvec_minmax);
91011 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
91012 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
91013 index 13d2f7c..c93d0b0 100644
91014 --- a/kernel/taskstats.c
91015 +++ b/kernel/taskstats.c
91016 @@ -28,9 +28,12 @@
91017 #include <linux/fs.h>
91018 #include <linux/file.h>
91019 #include <linux/pid_namespace.h>
91020 +#include <linux/grsecurity.h>
91021 #include <net/genetlink.h>
91022 #include <linux/atomic.h>
91023
91024 +extern int gr_is_taskstats_denied(int pid);
91025 +
91026 /*
91027 * Maximum length of a cpumask that can be specified in
91028 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
91029 @@ -576,6 +579,9 @@ err:
91030
91031 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
91032 {
91033 + if (gr_is_taskstats_denied(current->pid))
91034 + return -EACCES;
91035 +
91036 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
91037 return cmd_attr_register_cpumask(info);
91038 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
91039 diff --git a/kernel/time.c b/kernel/time.c
91040 index 7c7964c..2a0d412 100644
91041 --- a/kernel/time.c
91042 +++ b/kernel/time.c
91043 @@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
91044 return error;
91045
91046 if (tz) {
91047 + /* we log in do_settimeofday called below, so don't log twice
91048 + */
91049 + if (!tv)
91050 + gr_log_timechange();
91051 +
91052 sys_tz = *tz;
91053 update_vsyscall_tz();
91054 if (firsttime) {
91055 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
91056 index fe75444..190c528 100644
91057 --- a/kernel/time/alarmtimer.c
91058 +++ b/kernel/time/alarmtimer.c
91059 @@ -811,7 +811,7 @@ static int __init alarmtimer_init(void)
91060 struct platform_device *pdev;
91061 int error = 0;
91062 int i;
91063 - struct k_clock alarm_clock = {
91064 + static struct k_clock alarm_clock = {
91065 .clock_getres = alarm_clock_getres,
91066 .clock_get = alarm_clock_get,
91067 .timer_create = alarm_timer_create,
91068 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
91069 index f7df8ea..0810193 100644
91070 --- a/kernel/time/timekeeping.c
91071 +++ b/kernel/time/timekeeping.c
91072 @@ -15,6 +15,7 @@
91073 #include <linux/init.h>
91074 #include <linux/mm.h>
91075 #include <linux/sched.h>
91076 +#include <linux/grsecurity.h>
91077 #include <linux/syscore_ops.h>
91078 #include <linux/clocksource.h>
91079 #include <linux/jiffies.h>
91080 @@ -502,6 +503,8 @@ int do_settimeofday(const struct timespec *tv)
91081 if (!timespec_valid_strict(tv))
91082 return -EINVAL;
91083
91084 + gr_log_timechange();
91085 +
91086 raw_spin_lock_irqsave(&timekeeper_lock, flags);
91087 write_seqcount_begin(&timekeeper_seq);
91088
91089 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
91090 index 61ed862..3b52c65 100644
91091 --- a/kernel/time/timer_list.c
91092 +++ b/kernel/time/timer_list.c
91093 @@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
91094
91095 static void print_name_offset(struct seq_file *m, void *sym)
91096 {
91097 +#ifdef CONFIG_GRKERNSEC_HIDESYM
91098 + SEQ_printf(m, "<%p>", NULL);
91099 +#else
91100 char symname[KSYM_NAME_LEN];
91101
91102 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
91103 SEQ_printf(m, "<%pK>", sym);
91104 else
91105 SEQ_printf(m, "%s", symname);
91106 +#endif
91107 }
91108
91109 static void
91110 @@ -119,7 +123,11 @@ next_one:
91111 static void
91112 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
91113 {
91114 +#ifdef CONFIG_GRKERNSEC_HIDESYM
91115 + SEQ_printf(m, " .base: %p\n", NULL);
91116 +#else
91117 SEQ_printf(m, " .base: %pK\n", base);
91118 +#endif
91119 SEQ_printf(m, " .index: %d\n",
91120 base->index);
91121 SEQ_printf(m, " .resolution: %Lu nsecs\n",
91122 @@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
91123 {
91124 struct proc_dir_entry *pe;
91125
91126 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
91127 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
91128 +#else
91129 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
91130 +#endif
91131 if (!pe)
91132 return -ENOMEM;
91133 return 0;
91134 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
91135 index 1fb08f2..ca4bb1e 100644
91136 --- a/kernel/time/timer_stats.c
91137 +++ b/kernel/time/timer_stats.c
91138 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
91139 static unsigned long nr_entries;
91140 static struct entry entries[MAX_ENTRIES];
91141
91142 -static atomic_t overflow_count;
91143 +static atomic_unchecked_t overflow_count;
91144
91145 /*
91146 * The entries are in a hash-table, for fast lookup:
91147 @@ -140,7 +140,7 @@ static void reset_entries(void)
91148 nr_entries = 0;
91149 memset(entries, 0, sizeof(entries));
91150 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
91151 - atomic_set(&overflow_count, 0);
91152 + atomic_set_unchecked(&overflow_count, 0);
91153 }
91154
91155 static struct entry *alloc_entry(void)
91156 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
91157 if (likely(entry))
91158 entry->count++;
91159 else
91160 - atomic_inc(&overflow_count);
91161 + atomic_inc_unchecked(&overflow_count);
91162
91163 out_unlock:
91164 raw_spin_unlock_irqrestore(lock, flags);
91165 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
91166
91167 static void print_name_offset(struct seq_file *m, unsigned long addr)
91168 {
91169 +#ifdef CONFIG_GRKERNSEC_HIDESYM
91170 + seq_printf(m, "<%p>", NULL);
91171 +#else
91172 char symname[KSYM_NAME_LEN];
91173
91174 if (lookup_symbol_name(addr, symname) < 0)
91175 - seq_printf(m, "<%p>", (void *)addr);
91176 + seq_printf(m, "<%pK>", (void *)addr);
91177 else
91178 seq_printf(m, "%s", symname);
91179 +#endif
91180 }
91181
91182 static int tstats_show(struct seq_file *m, void *v)
91183 @@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
91184
91185 seq_puts(m, "Timer Stats Version: v0.3\n");
91186 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
91187 - if (atomic_read(&overflow_count))
91188 - seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
91189 + if (atomic_read_unchecked(&overflow_count))
91190 + seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
91191 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
91192
91193 for (i = 0; i < nr_entries; i++) {
91194 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
91195 {
91196 struct proc_dir_entry *pe;
91197
91198 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
91199 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
91200 +#else
91201 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
91202 +#endif
91203 if (!pe)
91204 return -ENOMEM;
91205 return 0;
91206 diff --git a/kernel/timer.c b/kernel/timer.c
91207 index 3bb01a3..0e7760e 100644
91208 --- a/kernel/timer.c
91209 +++ b/kernel/timer.c
91210 @@ -1393,7 +1393,7 @@ void update_process_times(int user_tick)
91211 /*
91212 * This function runs timers and the timer-tq in bottom half context.
91213 */
91214 -static void run_timer_softirq(struct softirq_action *h)
91215 +static __latent_entropy void run_timer_softirq(void)
91216 {
91217 struct tvec_base *base = __this_cpu_read(tvec_bases);
91218
91219 @@ -1456,7 +1456,7 @@ static void process_timeout(unsigned long __data)
91220 *
91221 * In all cases the return value is guaranteed to be non-negative.
91222 */
91223 -signed long __sched schedule_timeout(signed long timeout)
91224 +signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
91225 {
91226 struct timer_list timer;
91227 unsigned long expire;
91228 diff --git a/kernel/torture.c b/kernel/torture.c
91229 index acc9afc..4f9eb49 100644
91230 --- a/kernel/torture.c
91231 +++ b/kernel/torture.c
91232 @@ -489,7 +489,7 @@ static int torture_shutdown_notify(struct notifier_block *unused1,
91233 mutex_lock(&fullstop_mutex);
91234 if (ACCESS_ONCE(fullstop) == FULLSTOP_DONTSTOP) {
91235 VERBOSE_TOROUT_STRING("Unscheduled system shutdown detected");
91236 - ACCESS_ONCE(fullstop) = FULLSTOP_SHUTDOWN;
91237 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_SHUTDOWN;
91238 } else {
91239 pr_warn("Concurrent rmmod and shutdown illegal!\n");
91240 }
91241 @@ -551,11 +551,11 @@ static int torture_stutter(void *arg)
91242 do {
91243 if (!torture_must_stop()) {
91244 schedule_timeout_interruptible(stutter);
91245 - ACCESS_ONCE(stutter_pause_test) = 1;
91246 + ACCESS_ONCE_RW(stutter_pause_test) = 1;
91247 }
91248 if (!torture_must_stop())
91249 schedule_timeout_interruptible(stutter);
91250 - ACCESS_ONCE(stutter_pause_test) = 0;
91251 + ACCESS_ONCE_RW(stutter_pause_test) = 0;
91252 torture_shutdown_absorb("torture_stutter");
91253 } while (!torture_must_stop());
91254 torture_kthread_stopping("torture_stutter");
91255 @@ -636,7 +636,7 @@ bool torture_cleanup(void)
91256 schedule_timeout_uninterruptible(10);
91257 return true;
91258 }
91259 - ACCESS_ONCE(fullstop) = FULLSTOP_RMMOD;
91260 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_RMMOD;
91261 mutex_unlock(&fullstop_mutex);
91262 torture_shutdown_cleanup();
91263 torture_shuffle_cleanup();
91264 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
91265 index c1bd4ad..4b861dc 100644
91266 --- a/kernel/trace/blktrace.c
91267 +++ b/kernel/trace/blktrace.c
91268 @@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
91269 struct blk_trace *bt = filp->private_data;
91270 char buf[16];
91271
91272 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
91273 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
91274
91275 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
91276 }
91277 @@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
91278 return 1;
91279
91280 bt = buf->chan->private_data;
91281 - atomic_inc(&bt->dropped);
91282 + atomic_inc_unchecked(&bt->dropped);
91283 return 0;
91284 }
91285
91286 @@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
91287
91288 bt->dir = dir;
91289 bt->dev = dev;
91290 - atomic_set(&bt->dropped, 0);
91291 + atomic_set_unchecked(&bt->dropped, 0);
91292 INIT_LIST_HEAD(&bt->running_list);
91293
91294 ret = -EIO;
91295 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
91296 index 5aeac53..863ed29 100644
91297 --- a/kernel/trace/ftrace.c
91298 +++ b/kernel/trace/ftrace.c
91299 @@ -1960,12 +1960,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
91300 if (unlikely(ftrace_disabled))
91301 return 0;
91302
91303 + ret = ftrace_arch_code_modify_prepare();
91304 + FTRACE_WARN_ON(ret);
91305 + if (ret)
91306 + return 0;
91307 +
91308 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
91309 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
91310 if (ret) {
91311 ftrace_bug(ret, ip);
91312 - return 0;
91313 }
91314 - return 1;
91315 + return ret ? 0 : 1;
91316 }
91317
91318 /*
91319 @@ -4195,8 +4200,10 @@ static int ftrace_process_locs(struct module *mod,
91320 if (!count)
91321 return 0;
91322
91323 + pax_open_kernel();
91324 sort(start, count, sizeof(*start),
91325 ftrace_cmp_ips, ftrace_swap_ips);
91326 + pax_close_kernel();
91327
91328 start_pg = ftrace_allocate_pages(count);
91329 if (!start_pg)
91330 @@ -4908,8 +4915,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
91331 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
91332
91333 static int ftrace_graph_active;
91334 -static struct notifier_block ftrace_suspend_notifier;
91335 -
91336 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
91337 {
91338 return 0;
91339 @@ -5085,6 +5090,10 @@ static void update_function_graph_func(void)
91340 ftrace_graph_entry = ftrace_graph_entry_test;
91341 }
91342
91343 +static struct notifier_block ftrace_suspend_notifier = {
91344 + .notifier_call = ftrace_suspend_notifier_call
91345 +};
91346 +
91347 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
91348 trace_func_graph_ent_t entryfunc)
91349 {
91350 @@ -5098,7 +5107,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
91351 goto out;
91352 }
91353
91354 - ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
91355 register_pm_notifier(&ftrace_suspend_notifier);
91356
91357 ftrace_graph_active++;
91358 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
91359 index ff70271..e1e8cf1 100644
91360 --- a/kernel/trace/ring_buffer.c
91361 +++ b/kernel/trace/ring_buffer.c
91362 @@ -352,9 +352,9 @@ struct buffer_data_page {
91363 */
91364 struct buffer_page {
91365 struct list_head list; /* list of buffer pages */
91366 - local_t write; /* index for next write */
91367 + local_unchecked_t write; /* index for next write */
91368 unsigned read; /* index for next read */
91369 - local_t entries; /* entries on this page */
91370 + local_unchecked_t entries; /* entries on this page */
91371 unsigned long real_end; /* real end of data */
91372 struct buffer_data_page *page; /* Actual data page */
91373 };
91374 @@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
91375 unsigned long last_overrun;
91376 local_t entries_bytes;
91377 local_t entries;
91378 - local_t overrun;
91379 - local_t commit_overrun;
91380 + local_unchecked_t overrun;
91381 + local_unchecked_t commit_overrun;
91382 local_t dropped_events;
91383 local_t committing;
91384 local_t commits;
91385 @@ -991,8 +991,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
91386 *
91387 * We add a counter to the write field to denote this.
91388 */
91389 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
91390 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
91391 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
91392 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
91393
91394 /*
91395 * Just make sure we have seen our old_write and synchronize
91396 @@ -1020,8 +1020,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
91397 * cmpxchg to only update if an interrupt did not already
91398 * do it for us. If the cmpxchg fails, we don't care.
91399 */
91400 - (void)local_cmpxchg(&next_page->write, old_write, val);
91401 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
91402 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
91403 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
91404
91405 /*
91406 * No need to worry about races with clearing out the commit.
91407 @@ -1388,12 +1388,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
91408
91409 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
91410 {
91411 - return local_read(&bpage->entries) & RB_WRITE_MASK;
91412 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
91413 }
91414
91415 static inline unsigned long rb_page_write(struct buffer_page *bpage)
91416 {
91417 - return local_read(&bpage->write) & RB_WRITE_MASK;
91418 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
91419 }
91420
91421 static int
91422 @@ -1488,7 +1488,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
91423 * bytes consumed in ring buffer from here.
91424 * Increment overrun to account for the lost events.
91425 */
91426 - local_add(page_entries, &cpu_buffer->overrun);
91427 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
91428 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
91429 }
91430
91431 @@ -2066,7 +2066,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
91432 * it is our responsibility to update
91433 * the counters.
91434 */
91435 - local_add(entries, &cpu_buffer->overrun);
91436 + local_add_unchecked(entries, &cpu_buffer->overrun);
91437 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
91438
91439 /*
91440 @@ -2216,7 +2216,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91441 if (tail == BUF_PAGE_SIZE)
91442 tail_page->real_end = 0;
91443
91444 - local_sub(length, &tail_page->write);
91445 + local_sub_unchecked(length, &tail_page->write);
91446 return;
91447 }
91448
91449 @@ -2251,7 +2251,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91450 rb_event_set_padding(event);
91451
91452 /* Set the write back to the previous setting */
91453 - local_sub(length, &tail_page->write);
91454 + local_sub_unchecked(length, &tail_page->write);
91455 return;
91456 }
91457
91458 @@ -2263,7 +2263,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91459
91460 /* Set write to end of buffer */
91461 length = (tail + length) - BUF_PAGE_SIZE;
91462 - local_sub(length, &tail_page->write);
91463 + local_sub_unchecked(length, &tail_page->write);
91464 }
91465
91466 /*
91467 @@ -2289,7 +2289,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
91468 * about it.
91469 */
91470 if (unlikely(next_page == commit_page)) {
91471 - local_inc(&cpu_buffer->commit_overrun);
91472 + local_inc_unchecked(&cpu_buffer->commit_overrun);
91473 goto out_reset;
91474 }
91475
91476 @@ -2345,7 +2345,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
91477 cpu_buffer->tail_page) &&
91478 (cpu_buffer->commit_page ==
91479 cpu_buffer->reader_page))) {
91480 - local_inc(&cpu_buffer->commit_overrun);
91481 + local_inc_unchecked(&cpu_buffer->commit_overrun);
91482 goto out_reset;
91483 }
91484 }
91485 @@ -2393,7 +2393,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
91486 length += RB_LEN_TIME_EXTEND;
91487
91488 tail_page = cpu_buffer->tail_page;
91489 - write = local_add_return(length, &tail_page->write);
91490 + write = local_add_return_unchecked(length, &tail_page->write);
91491
91492 /* set write to only the index of the write */
91493 write &= RB_WRITE_MASK;
91494 @@ -2417,7 +2417,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
91495 kmemcheck_annotate_bitfield(event, bitfield);
91496 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
91497
91498 - local_inc(&tail_page->entries);
91499 + local_inc_unchecked(&tail_page->entries);
91500
91501 /*
91502 * If this is the first commit on the page, then update
91503 @@ -2450,7 +2450,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
91504
91505 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
91506 unsigned long write_mask =
91507 - local_read(&bpage->write) & ~RB_WRITE_MASK;
91508 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
91509 unsigned long event_length = rb_event_length(event);
91510 /*
91511 * This is on the tail page. It is possible that
91512 @@ -2460,7 +2460,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
91513 */
91514 old_index += write_mask;
91515 new_index += write_mask;
91516 - index = local_cmpxchg(&bpage->write, old_index, new_index);
91517 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
91518 if (index == old_index) {
91519 /* update counters */
91520 local_sub(event_length, &cpu_buffer->entries_bytes);
91521 @@ -2852,7 +2852,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
91522
91523 /* Do the likely case first */
91524 if (likely(bpage->page == (void *)addr)) {
91525 - local_dec(&bpage->entries);
91526 + local_dec_unchecked(&bpage->entries);
91527 return;
91528 }
91529
91530 @@ -2864,7 +2864,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
91531 start = bpage;
91532 do {
91533 if (bpage->page == (void *)addr) {
91534 - local_dec(&bpage->entries);
91535 + local_dec_unchecked(&bpage->entries);
91536 return;
91537 }
91538 rb_inc_page(cpu_buffer, &bpage);
91539 @@ -3148,7 +3148,7 @@ static inline unsigned long
91540 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
91541 {
91542 return local_read(&cpu_buffer->entries) -
91543 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
91544 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
91545 }
91546
91547 /**
91548 @@ -3237,7 +3237,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
91549 return 0;
91550
91551 cpu_buffer = buffer->buffers[cpu];
91552 - ret = local_read(&cpu_buffer->overrun);
91553 + ret = local_read_unchecked(&cpu_buffer->overrun);
91554
91555 return ret;
91556 }
91557 @@ -3260,7 +3260,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
91558 return 0;
91559
91560 cpu_buffer = buffer->buffers[cpu];
91561 - ret = local_read(&cpu_buffer->commit_overrun);
91562 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
91563
91564 return ret;
91565 }
91566 @@ -3345,7 +3345,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
91567 /* if you care about this being correct, lock the buffer */
91568 for_each_buffer_cpu(buffer, cpu) {
91569 cpu_buffer = buffer->buffers[cpu];
91570 - overruns += local_read(&cpu_buffer->overrun);
91571 + overruns += local_read_unchecked(&cpu_buffer->overrun);
91572 }
91573
91574 return overruns;
91575 @@ -3521,8 +3521,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
91576 /*
91577 * Reset the reader page to size zero.
91578 */
91579 - local_set(&cpu_buffer->reader_page->write, 0);
91580 - local_set(&cpu_buffer->reader_page->entries, 0);
91581 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
91582 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
91583 local_set(&cpu_buffer->reader_page->page->commit, 0);
91584 cpu_buffer->reader_page->real_end = 0;
91585
91586 @@ -3556,7 +3556,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
91587 * want to compare with the last_overrun.
91588 */
91589 smp_mb();
91590 - overwrite = local_read(&(cpu_buffer->overrun));
91591 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
91592
91593 /*
91594 * Here's the tricky part.
91595 @@ -4126,8 +4126,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
91596
91597 cpu_buffer->head_page
91598 = list_entry(cpu_buffer->pages, struct buffer_page, list);
91599 - local_set(&cpu_buffer->head_page->write, 0);
91600 - local_set(&cpu_buffer->head_page->entries, 0);
91601 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
91602 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
91603 local_set(&cpu_buffer->head_page->page->commit, 0);
91604
91605 cpu_buffer->head_page->read = 0;
91606 @@ -4137,14 +4137,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
91607
91608 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
91609 INIT_LIST_HEAD(&cpu_buffer->new_pages);
91610 - local_set(&cpu_buffer->reader_page->write, 0);
91611 - local_set(&cpu_buffer->reader_page->entries, 0);
91612 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
91613 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
91614 local_set(&cpu_buffer->reader_page->page->commit, 0);
91615 cpu_buffer->reader_page->read = 0;
91616
91617 local_set(&cpu_buffer->entries_bytes, 0);
91618 - local_set(&cpu_buffer->overrun, 0);
91619 - local_set(&cpu_buffer->commit_overrun, 0);
91620 + local_set_unchecked(&cpu_buffer->overrun, 0);
91621 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
91622 local_set(&cpu_buffer->dropped_events, 0);
91623 local_set(&cpu_buffer->entries, 0);
91624 local_set(&cpu_buffer->committing, 0);
91625 @@ -4549,8 +4549,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
91626 rb_init_page(bpage);
91627 bpage = reader->page;
91628 reader->page = *data_page;
91629 - local_set(&reader->write, 0);
91630 - local_set(&reader->entries, 0);
91631 + local_set_unchecked(&reader->write, 0);
91632 + local_set_unchecked(&reader->entries, 0);
91633 reader->read = 0;
91634 *data_page = bpage;
91635
91636 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
91637 index e1baa92f..7b2e345 100644
91638 --- a/kernel/trace/trace.c
91639 +++ b/kernel/trace/trace.c
91640 @@ -3461,7 +3461,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
91641 return 0;
91642 }
91643
91644 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
91645 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
91646 {
91647 /* do nothing if flag is already set */
91648 if (!!(trace_flags & mask) == !!enabled)
91649 diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
91650 index 99676cd..670b9e8 100644
91651 --- a/kernel/trace/trace.h
91652 +++ b/kernel/trace/trace.h
91653 @@ -1264,7 +1264,7 @@ extern const char *__stop___tracepoint_str[];
91654 void trace_printk_init_buffers(void);
91655 void trace_printk_start_comm(void);
91656 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
91657 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
91658 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
91659
91660 /*
91661 * Normal trace_printk() and friends allocates special buffers
91662 diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
91663 index 57b67b1..66082a9 100644
91664 --- a/kernel/trace/trace_clock.c
91665 +++ b/kernel/trace/trace_clock.c
91666 @@ -124,7 +124,7 @@ u64 notrace trace_clock_global(void)
91667 return now;
91668 }
91669
91670 -static atomic64_t trace_counter;
91671 +static atomic64_unchecked_t trace_counter;
91672
91673 /*
91674 * trace_clock_counter(): simply an atomic counter.
91675 @@ -133,5 +133,5 @@ static atomic64_t trace_counter;
91676 */
91677 u64 notrace trace_clock_counter(void)
91678 {
91679 - return atomic64_add_return(1, &trace_counter);
91680 + return atomic64_inc_return_unchecked(&trace_counter);
91681 }
91682 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
91683 index aec1dac..6ca72ee 100644
91684 --- a/kernel/trace/trace_events.c
91685 +++ b/kernel/trace/trace_events.c
91686 @@ -1719,7 +1719,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
91687 return 0;
91688 }
91689
91690 -struct ftrace_module_file_ops;
91691 static void __add_event_to_tracers(struct ftrace_event_call *call);
91692
91693 /* Add an additional event_call dynamically */
91694 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
91695 index 0abd9b8..6a663a2 100644
91696 --- a/kernel/trace/trace_mmiotrace.c
91697 +++ b/kernel/trace/trace_mmiotrace.c
91698 @@ -24,7 +24,7 @@ struct header_iter {
91699 static struct trace_array *mmio_trace_array;
91700 static bool overrun_detected;
91701 static unsigned long prev_overruns;
91702 -static atomic_t dropped_count;
91703 +static atomic_unchecked_t dropped_count;
91704
91705 static void mmio_reset_data(struct trace_array *tr)
91706 {
91707 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
91708
91709 static unsigned long count_overruns(struct trace_iterator *iter)
91710 {
91711 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
91712 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
91713 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
91714
91715 if (over > prev_overruns)
91716 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
91717 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
91718 sizeof(*entry), 0, pc);
91719 if (!event) {
91720 - atomic_inc(&dropped_count);
91721 + atomic_inc_unchecked(&dropped_count);
91722 return;
91723 }
91724 entry = ring_buffer_event_data(event);
91725 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
91726 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
91727 sizeof(*entry), 0, pc);
91728 if (!event) {
91729 - atomic_inc(&dropped_count);
91730 + atomic_inc_unchecked(&dropped_count);
91731 return;
91732 }
91733 entry = ring_buffer_event_data(event);
91734 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
91735 index a436de1..f64dde2 100644
91736 --- a/kernel/trace/trace_output.c
91737 +++ b/kernel/trace/trace_output.c
91738 @@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
91739
91740 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
91741 if (!IS_ERR(p)) {
91742 - p = mangle_path(s->buffer + s->len, p, "\n");
91743 + p = mangle_path(s->buffer + s->len, p, "\n\\");
91744 if (p) {
91745 s->len = p - s->buffer;
91746 return 1;
91747 @@ -939,14 +939,16 @@ int register_ftrace_event(struct trace_event *event)
91748 goto out;
91749 }
91750
91751 + pax_open_kernel();
91752 if (event->funcs->trace == NULL)
91753 - event->funcs->trace = trace_nop_print;
91754 + *(void **)&event->funcs->trace = trace_nop_print;
91755 if (event->funcs->raw == NULL)
91756 - event->funcs->raw = trace_nop_print;
91757 + *(void **)&event->funcs->raw = trace_nop_print;
91758 if (event->funcs->hex == NULL)
91759 - event->funcs->hex = trace_nop_print;
91760 + *(void **)&event->funcs->hex = trace_nop_print;
91761 if (event->funcs->binary == NULL)
91762 - event->funcs->binary = trace_nop_print;
91763 + *(void **)&event->funcs->binary = trace_nop_print;
91764 + pax_close_kernel();
91765
91766 key = event->type & (EVENT_HASHSIZE - 1);
91767
91768 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
91769 index 21b320e..40607bc 100644
91770 --- a/kernel/trace/trace_stack.c
91771 +++ b/kernel/trace/trace_stack.c
91772 @@ -69,7 +69,7 @@ check_stack(unsigned long ip, unsigned long *stack)
91773 return;
91774
91775 /* we do not handle interrupt stacks yet */
91776 - if (!object_is_on_stack(stack))
91777 + if (!object_starts_on_stack(stack))
91778 return;
91779
91780 local_irq_save(flags);
91781 diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
91782 index bf71b4b..04dee68 100644
91783 --- a/kernel/user_namespace.c
91784 +++ b/kernel/user_namespace.c
91785 @@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
91786 !kgid_has_mapping(parent_ns, group))
91787 return -EPERM;
91788
91789 +#ifdef CONFIG_GRKERNSEC
91790 + /*
91791 + * This doesn't really inspire confidence:
91792 + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
91793 + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
91794 + * Increases kernel attack surface in areas developers
91795 + * previously cared little about ("low importance due
91796 + * to requiring "root" capability")
91797 + * To be removed when this code receives *proper* review
91798 + */
91799 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
91800 + !capable(CAP_SETGID))
91801 + return -EPERM;
91802 +#endif
91803 +
91804 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
91805 if (!ns)
91806 return -ENOMEM;
91807 @@ -865,7 +880,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
91808 if (atomic_read(&current->mm->mm_users) > 1)
91809 return -EINVAL;
91810
91811 - if (current->fs->users != 1)
91812 + if (atomic_read(&current->fs->users) != 1)
91813 return -EINVAL;
91814
91815 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
91816 diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
91817 index 4f69f9a..7c6f8f8 100644
91818 --- a/kernel/utsname_sysctl.c
91819 +++ b/kernel/utsname_sysctl.c
91820 @@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
91821 static int proc_do_uts_string(ctl_table *table, int write,
91822 void __user *buffer, size_t *lenp, loff_t *ppos)
91823 {
91824 - struct ctl_table uts_table;
91825 + ctl_table_no_const uts_table;
91826 int r;
91827 memcpy(&uts_table, table, sizeof(uts_table));
91828 uts_table.data = get_uts(table, write);
91829 diff --git a/kernel/watchdog.c b/kernel/watchdog.c
91830 index 30e4822..dd2b854 100644
91831 --- a/kernel/watchdog.c
91832 +++ b/kernel/watchdog.c
91833 @@ -479,7 +479,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
91834 static void watchdog_nmi_disable(unsigned int cpu) { return; }
91835 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
91836
91837 -static struct smp_hotplug_thread watchdog_threads = {
91838 +static struct smp_hotplug_thread watchdog_threads __read_only = {
91839 .store = &softlockup_watchdog,
91840 .thread_should_run = watchdog_should_run,
91841 .thread_fn = watchdog,
91842 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
91843 index 7ba5897..c8ed1f2 100644
91844 --- a/kernel/workqueue.c
91845 +++ b/kernel/workqueue.c
91846 @@ -4710,7 +4710,7 @@ static void rebind_workers(struct worker_pool *pool)
91847 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
91848 worker_flags |= WORKER_REBOUND;
91849 worker_flags &= ~WORKER_UNBOUND;
91850 - ACCESS_ONCE(worker->flags) = worker_flags;
91851 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
91852 }
91853
91854 spin_unlock_irq(&pool->lock);
91855 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
91856 index 819ac51..1c8a65e 100644
91857 --- a/lib/Kconfig.debug
91858 +++ b/lib/Kconfig.debug
91859 @@ -853,7 +853,7 @@ config DEBUG_MUTEXES
91860
91861 config DEBUG_WW_MUTEX_SLOWPATH
91862 bool "Wait/wound mutex debugging: Slowpath testing"
91863 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91864 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91865 select DEBUG_LOCK_ALLOC
91866 select DEBUG_SPINLOCK
91867 select DEBUG_MUTEXES
91868 @@ -866,7 +866,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
91869
91870 config DEBUG_LOCK_ALLOC
91871 bool "Lock debugging: detect incorrect freeing of live locks"
91872 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91873 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91874 select DEBUG_SPINLOCK
91875 select DEBUG_MUTEXES
91876 select LOCKDEP
91877 @@ -880,7 +880,7 @@ config DEBUG_LOCK_ALLOC
91878
91879 config PROVE_LOCKING
91880 bool "Lock debugging: prove locking correctness"
91881 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91882 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91883 select LOCKDEP
91884 select DEBUG_SPINLOCK
91885 select DEBUG_MUTEXES
91886 @@ -931,7 +931,7 @@ config LOCKDEP
91887
91888 config LOCK_STAT
91889 bool "Lock usage statistics"
91890 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91891 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91892 select LOCKDEP
91893 select DEBUG_SPINLOCK
91894 select DEBUG_MUTEXES
91895 @@ -1403,6 +1403,7 @@ config LATENCYTOP
91896 depends on DEBUG_KERNEL
91897 depends on STACKTRACE_SUPPORT
91898 depends on PROC_FS
91899 + depends on !GRKERNSEC_HIDESYM
91900 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
91901 select KALLSYMS
91902 select KALLSYMS_ALL
91903 @@ -1419,7 +1420,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
91904 config DEBUG_STRICT_USER_COPY_CHECKS
91905 bool "Strict user copy size checks"
91906 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
91907 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
91908 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
91909 help
91910 Enabling this option turns a certain set of sanity checks for user
91911 copy operations into compile time failures.
91912 @@ -1538,7 +1539,7 @@ endmenu # runtime tests
91913
91914 config PROVIDE_OHCI1394_DMA_INIT
91915 bool "Remote debugging over FireWire early on boot"
91916 - depends on PCI && X86
91917 + depends on PCI && X86 && !GRKERNSEC
91918 help
91919 If you want to debug problems which hang or crash the kernel early
91920 on boot and the crashing machine has a FireWire port, you can use
91921 diff --git a/lib/Makefile b/lib/Makefile
91922 index 0cd7b68..e149e37 100644
91923 --- a/lib/Makefile
91924 +++ b/lib/Makefile
91925 @@ -52,7 +52,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
91926 obj-$(CONFIG_BTREE) += btree.o
91927 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
91928 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
91929 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
91930 +obj-y += list_debug.o
91931 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
91932
91933 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
91934 diff --git a/lib/average.c b/lib/average.c
91935 index 114d1be..ab0350c 100644
91936 --- a/lib/average.c
91937 +++ b/lib/average.c
91938 @@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
91939 {
91940 unsigned long internal = ACCESS_ONCE(avg->internal);
91941
91942 - ACCESS_ONCE(avg->internal) = internal ?
91943 + ACCESS_ONCE_RW(avg->internal) = internal ?
91944 (((internal << avg->weight) - internal) +
91945 (val << avg->factor)) >> avg->weight :
91946 (val << avg->factor);
91947 diff --git a/lib/bitmap.c b/lib/bitmap.c
91948 index 06f7e4f..f3cf2b0 100644
91949 --- a/lib/bitmap.c
91950 +++ b/lib/bitmap.c
91951 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
91952 {
91953 int c, old_c, totaldigits, ndigits, nchunks, nbits;
91954 u32 chunk;
91955 - const char __user __force *ubuf = (const char __user __force *)buf;
91956 + const char __user *ubuf = (const char __force_user *)buf;
91957
91958 bitmap_zero(maskp, nmaskbits);
91959
91960 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
91961 {
91962 if (!access_ok(VERIFY_READ, ubuf, ulen))
91963 return -EFAULT;
91964 - return __bitmap_parse((const char __force *)ubuf,
91965 + return __bitmap_parse((const char __force_kernel *)ubuf,
91966 ulen, 1, maskp, nmaskbits);
91967
91968 }
91969 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
91970 {
91971 unsigned a, b;
91972 int c, old_c, totaldigits;
91973 - const char __user __force *ubuf = (const char __user __force *)buf;
91974 + const char __user *ubuf = (const char __force_user *)buf;
91975 int exp_digit, in_range;
91976
91977 totaldigits = c = 0;
91978 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
91979 {
91980 if (!access_ok(VERIFY_READ, ubuf, ulen))
91981 return -EFAULT;
91982 - return __bitmap_parselist((const char __force *)ubuf,
91983 + return __bitmap_parselist((const char __force_kernel *)ubuf,
91984 ulen, 1, maskp, nmaskbits);
91985 }
91986 EXPORT_SYMBOL(bitmap_parselist_user);
91987 diff --git a/lib/bug.c b/lib/bug.c
91988 index 1686034..a9c00c8 100644
91989 --- a/lib/bug.c
91990 +++ b/lib/bug.c
91991 @@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
91992 return BUG_TRAP_TYPE_NONE;
91993
91994 bug = find_bug(bugaddr);
91995 + if (!bug)
91996 + return BUG_TRAP_TYPE_NONE;
91997
91998 file = NULL;
91999 line = 0;
92000 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
92001 index e0731c3..ad66444 100644
92002 --- a/lib/debugobjects.c
92003 +++ b/lib/debugobjects.c
92004 @@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
92005 if (limit > 4)
92006 return;
92007
92008 - is_on_stack = object_is_on_stack(addr);
92009 + is_on_stack = object_starts_on_stack(addr);
92010 if (is_on_stack == onstack)
92011 return;
92012
92013 diff --git a/lib/div64.c b/lib/div64.c
92014 index 4382ad7..08aa558 100644
92015 --- a/lib/div64.c
92016 +++ b/lib/div64.c
92017 @@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
92018 EXPORT_SYMBOL(__div64_32);
92019
92020 #ifndef div_s64_rem
92021 -s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
92022 +s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
92023 {
92024 u64 quotient;
92025
92026 @@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
92027 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
92028 */
92029 #ifndef div64_u64
92030 -u64 div64_u64(u64 dividend, u64 divisor)
92031 +u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
92032 {
92033 u32 high = divisor >> 32;
92034 u64 quot;
92035 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
92036 index 98f2d7e..899da5c 100644
92037 --- a/lib/dma-debug.c
92038 +++ b/lib/dma-debug.c
92039 @@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
92040
92041 void dma_debug_add_bus(struct bus_type *bus)
92042 {
92043 - struct notifier_block *nb;
92044 + notifier_block_no_const *nb;
92045
92046 if (global_disable)
92047 return;
92048 @@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
92049
92050 static void check_for_stack(struct device *dev, void *addr)
92051 {
92052 - if (object_is_on_stack(addr))
92053 + if (object_starts_on_stack(addr))
92054 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
92055 "stack [addr=%p]\n", addr);
92056 }
92057 diff --git a/lib/hash.c b/lib/hash.c
92058 index fea973f..386626f 100644
92059 --- a/lib/hash.c
92060 +++ b/lib/hash.c
92061 @@ -14,7 +14,7 @@
92062 #include <linux/hash.h>
92063 #include <linux/cache.h>
92064
92065 -static struct fast_hash_ops arch_hash_ops __read_mostly = {
92066 +static struct fast_hash_ops arch_hash_ops __read_only = {
92067 .hash = jhash,
92068 .hash2 = jhash2,
92069 };
92070 diff --git a/lib/inflate.c b/lib/inflate.c
92071 index 013a761..c28f3fc 100644
92072 --- a/lib/inflate.c
92073 +++ b/lib/inflate.c
92074 @@ -269,7 +269,7 @@ static void free(void *where)
92075 malloc_ptr = free_mem_ptr;
92076 }
92077 #else
92078 -#define malloc(a) kmalloc(a, GFP_KERNEL)
92079 +#define malloc(a) kmalloc((a), GFP_KERNEL)
92080 #define free(a) kfree(a)
92081 #endif
92082
92083 diff --git a/lib/ioremap.c b/lib/ioremap.c
92084 index 0c9216c..863bd89 100644
92085 --- a/lib/ioremap.c
92086 +++ b/lib/ioremap.c
92087 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
92088 unsigned long next;
92089
92090 phys_addr -= addr;
92091 - pmd = pmd_alloc(&init_mm, pud, addr);
92092 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
92093 if (!pmd)
92094 return -ENOMEM;
92095 do {
92096 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
92097 unsigned long next;
92098
92099 phys_addr -= addr;
92100 - pud = pud_alloc(&init_mm, pgd, addr);
92101 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
92102 if (!pud)
92103 return -ENOMEM;
92104 do {
92105 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
92106 index bd2bea9..6b3c95e 100644
92107 --- a/lib/is_single_threaded.c
92108 +++ b/lib/is_single_threaded.c
92109 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
92110 struct task_struct *p, *t;
92111 bool ret;
92112
92113 + if (!mm)
92114 + return true;
92115 +
92116 if (atomic_read(&task->signal->live) != 1)
92117 return false;
92118
92119 diff --git a/lib/kobject.c b/lib/kobject.c
92120 index 58751bb..93a1853 100644
92121 --- a/lib/kobject.c
92122 +++ b/lib/kobject.c
92123 @@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
92124
92125
92126 static DEFINE_SPINLOCK(kobj_ns_type_lock);
92127 -static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
92128 +static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
92129
92130 -int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
92131 +int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
92132 {
92133 enum kobj_ns_type type = ops->type;
92134 int error;
92135 diff --git a/lib/list_debug.c b/lib/list_debug.c
92136 index c24c2f7..f0296f4 100644
92137 --- a/lib/list_debug.c
92138 +++ b/lib/list_debug.c
92139 @@ -11,7 +11,9 @@
92140 #include <linux/bug.h>
92141 #include <linux/kernel.h>
92142 #include <linux/rculist.h>
92143 +#include <linux/mm.h>
92144
92145 +#ifdef CONFIG_DEBUG_LIST
92146 /*
92147 * Insert a new entry between two known consecutive entries.
92148 *
92149 @@ -19,21 +21,40 @@
92150 * the prev/next entries already!
92151 */
92152
92153 +static bool __list_add_debug(struct list_head *new,
92154 + struct list_head *prev,
92155 + struct list_head *next)
92156 +{
92157 + if (unlikely(next->prev != prev)) {
92158 + printk(KERN_ERR "list_add corruption. next->prev should be "
92159 + "prev (%p), but was %p. (next=%p).\n",
92160 + prev, next->prev, next);
92161 + BUG();
92162 + return false;
92163 + }
92164 + if (unlikely(prev->next != next)) {
92165 + printk(KERN_ERR "list_add corruption. prev->next should be "
92166 + "next (%p), but was %p. (prev=%p).\n",
92167 + next, prev->next, prev);
92168 + BUG();
92169 + return false;
92170 + }
92171 + if (unlikely(new == prev || new == next)) {
92172 + printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
92173 + new, prev, next);
92174 + BUG();
92175 + return false;
92176 + }
92177 + return true;
92178 +}
92179 +
92180 void __list_add(struct list_head *new,
92181 - struct list_head *prev,
92182 - struct list_head *next)
92183 + struct list_head *prev,
92184 + struct list_head *next)
92185 {
92186 - WARN(next->prev != prev,
92187 - "list_add corruption. next->prev should be "
92188 - "prev (%p), but was %p. (next=%p).\n",
92189 - prev, next->prev, next);
92190 - WARN(prev->next != next,
92191 - "list_add corruption. prev->next should be "
92192 - "next (%p), but was %p. (prev=%p).\n",
92193 - next, prev->next, prev);
92194 - WARN(new == prev || new == next,
92195 - "list_add double add: new=%p, prev=%p, next=%p.\n",
92196 - new, prev, next);
92197 + if (!__list_add_debug(new, prev, next))
92198 + return;
92199 +
92200 next->prev = new;
92201 new->next = next;
92202 new->prev = prev;
92203 @@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
92204 }
92205 EXPORT_SYMBOL(__list_add);
92206
92207 -void __list_del_entry(struct list_head *entry)
92208 +static bool __list_del_entry_debug(struct list_head *entry)
92209 {
92210 struct list_head *prev, *next;
92211
92212 prev = entry->prev;
92213 next = entry->next;
92214
92215 - if (WARN(next == LIST_POISON1,
92216 - "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
92217 - entry, LIST_POISON1) ||
92218 - WARN(prev == LIST_POISON2,
92219 - "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
92220 - entry, LIST_POISON2) ||
92221 - WARN(prev->next != entry,
92222 - "list_del corruption. prev->next should be %p, "
92223 - "but was %p\n", entry, prev->next) ||
92224 - WARN(next->prev != entry,
92225 - "list_del corruption. next->prev should be %p, "
92226 - "but was %p\n", entry, next->prev))
92227 + if (unlikely(next == LIST_POISON1)) {
92228 + printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
92229 + entry, LIST_POISON1);
92230 + BUG();
92231 + return false;
92232 + }
92233 + if (unlikely(prev == LIST_POISON2)) {
92234 + printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
92235 + entry, LIST_POISON2);
92236 + BUG();
92237 + return false;
92238 + }
92239 + if (unlikely(entry->prev->next != entry)) {
92240 + printk(KERN_ERR "list_del corruption. prev->next should be %p, "
92241 + "but was %p\n", entry, prev->next);
92242 + BUG();
92243 + return false;
92244 + }
92245 + if (unlikely(entry->next->prev != entry)) {
92246 + printk(KERN_ERR "list_del corruption. next->prev should be %p, "
92247 + "but was %p\n", entry, next->prev);
92248 + BUG();
92249 + return false;
92250 + }
92251 + return true;
92252 +}
92253 +
92254 +void __list_del_entry(struct list_head *entry)
92255 +{
92256 + if (!__list_del_entry_debug(entry))
92257 return;
92258
92259 - __list_del(prev, next);
92260 + __list_del(entry->prev, entry->next);
92261 }
92262 EXPORT_SYMBOL(__list_del_entry);
92263
92264 @@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
92265 void __list_add_rcu(struct list_head *new,
92266 struct list_head *prev, struct list_head *next)
92267 {
92268 - WARN(next->prev != prev,
92269 - "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
92270 - prev, next->prev, next);
92271 - WARN(prev->next != next,
92272 - "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
92273 - next, prev->next, prev);
92274 + if (!__list_add_debug(new, prev, next))
92275 + return;
92276 +
92277 new->next = next;
92278 new->prev = prev;
92279 rcu_assign_pointer(list_next_rcu(prev), new);
92280 next->prev = new;
92281 }
92282 EXPORT_SYMBOL(__list_add_rcu);
92283 +#endif
92284 +
92285 +void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
92286 +{
92287 +#ifdef CONFIG_DEBUG_LIST
92288 + if (!__list_add_debug(new, prev, next))
92289 + return;
92290 +#endif
92291 +
92292 + pax_open_kernel();
92293 + next->prev = new;
92294 + new->next = next;
92295 + new->prev = prev;
92296 + prev->next = new;
92297 + pax_close_kernel();
92298 +}
92299 +EXPORT_SYMBOL(__pax_list_add);
92300 +
92301 +void pax_list_del(struct list_head *entry)
92302 +{
92303 +#ifdef CONFIG_DEBUG_LIST
92304 + if (!__list_del_entry_debug(entry))
92305 + return;
92306 +#endif
92307 +
92308 + pax_open_kernel();
92309 + __list_del(entry->prev, entry->next);
92310 + entry->next = LIST_POISON1;
92311 + entry->prev = LIST_POISON2;
92312 + pax_close_kernel();
92313 +}
92314 +EXPORT_SYMBOL(pax_list_del);
92315 +
92316 +void pax_list_del_init(struct list_head *entry)
92317 +{
92318 + pax_open_kernel();
92319 + __list_del(entry->prev, entry->next);
92320 + INIT_LIST_HEAD(entry);
92321 + pax_close_kernel();
92322 +}
92323 +EXPORT_SYMBOL(pax_list_del_init);
92324 +
92325 +void __pax_list_add_rcu(struct list_head *new,
92326 + struct list_head *prev, struct list_head *next)
92327 +{
92328 +#ifdef CONFIG_DEBUG_LIST
92329 + if (!__list_add_debug(new, prev, next))
92330 + return;
92331 +#endif
92332 +
92333 + pax_open_kernel();
92334 + new->next = next;
92335 + new->prev = prev;
92336 + rcu_assign_pointer(list_next_rcu(prev), new);
92337 + next->prev = new;
92338 + pax_close_kernel();
92339 +}
92340 +EXPORT_SYMBOL(__pax_list_add_rcu);
92341 +
92342 +void pax_list_del_rcu(struct list_head *entry)
92343 +{
92344 +#ifdef CONFIG_DEBUG_LIST
92345 + if (!__list_del_entry_debug(entry))
92346 + return;
92347 +#endif
92348 +
92349 + pax_open_kernel();
92350 + __list_del(entry->prev, entry->next);
92351 + entry->next = LIST_POISON1;
92352 + entry->prev = LIST_POISON2;
92353 + pax_close_kernel();
92354 +}
92355 +EXPORT_SYMBOL(pax_list_del_rcu);
92356 diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
92357 index 963b703..438bc51 100644
92358 --- a/lib/percpu-refcount.c
92359 +++ b/lib/percpu-refcount.c
92360 @@ -29,7 +29,7 @@
92361 * can't hit 0 before we've added up all the percpu refs.
92362 */
92363
92364 -#define PCPU_COUNT_BIAS (1U << 31)
92365 +#define PCPU_COUNT_BIAS (1U << 30)
92366
92367 /**
92368 * percpu_ref_init - initialize a percpu refcount
92369 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
92370 index 9599aa7..9cf6c72 100644
92371 --- a/lib/radix-tree.c
92372 +++ b/lib/radix-tree.c
92373 @@ -66,7 +66,7 @@ struct radix_tree_preload {
92374 int nr;
92375 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
92376 };
92377 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
92378 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
92379
92380 static inline void *ptr_to_indirect(void *ptr)
92381 {
92382 diff --git a/lib/random32.c b/lib/random32.c
92383 index fa5da61..35fe9af 100644
92384 --- a/lib/random32.c
92385 +++ b/lib/random32.c
92386 @@ -42,7 +42,7 @@
92387 static void __init prandom_state_selftest(void);
92388 #endif
92389
92390 -static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
92391 +static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
92392
92393 /**
92394 * prandom_u32_state - seeded pseudo-random number generator.
92395 diff --git a/lib/rbtree.c b/lib/rbtree.c
92396 index 65f4eff..2cfa167 100644
92397 --- a/lib/rbtree.c
92398 +++ b/lib/rbtree.c
92399 @@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
92400 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
92401
92402 static const struct rb_augment_callbacks dummy_callbacks = {
92403 - dummy_propagate, dummy_copy, dummy_rotate
92404 + .propagate = dummy_propagate,
92405 + .copy = dummy_copy,
92406 + .rotate = dummy_rotate
92407 };
92408
92409 void rb_insert_color(struct rb_node *node, struct rb_root *root)
92410 diff --git a/lib/show_mem.c b/lib/show_mem.c
92411 index 0922579..9d7adb9 100644
92412 --- a/lib/show_mem.c
92413 +++ b/lib/show_mem.c
92414 @@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
92415 quicklist_total_size());
92416 #endif
92417 #ifdef CONFIG_MEMORY_FAILURE
92418 - printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
92419 + printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
92420 #endif
92421 }
92422 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
92423 index bb2b201..46abaf9 100644
92424 --- a/lib/strncpy_from_user.c
92425 +++ b/lib/strncpy_from_user.c
92426 @@ -21,7 +21,7 @@
92427 */
92428 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
92429 {
92430 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92431 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92432 long res = 0;
92433
92434 /*
92435 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
92436 index a28df52..3d55877 100644
92437 --- a/lib/strnlen_user.c
92438 +++ b/lib/strnlen_user.c
92439 @@ -26,7 +26,7 @@
92440 */
92441 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
92442 {
92443 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92444 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92445 long align, res = 0;
92446 unsigned long c;
92447
92448 diff --git a/lib/swiotlb.c b/lib/swiotlb.c
92449 index b604b83..c0547f6 100644
92450 --- a/lib/swiotlb.c
92451 +++ b/lib/swiotlb.c
92452 @@ -674,7 +674,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
92453
92454 void
92455 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
92456 - dma_addr_t dev_addr)
92457 + dma_addr_t dev_addr, struct dma_attrs *attrs)
92458 {
92459 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
92460
92461 diff --git a/lib/usercopy.c b/lib/usercopy.c
92462 index 4f5b1dd..7cab418 100644
92463 --- a/lib/usercopy.c
92464 +++ b/lib/usercopy.c
92465 @@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
92466 WARN(1, "Buffer overflow detected!\n");
92467 }
92468 EXPORT_SYMBOL(copy_from_user_overflow);
92469 +
92470 +void copy_to_user_overflow(void)
92471 +{
92472 + WARN(1, "Buffer overflow detected!\n");
92473 +}
92474 +EXPORT_SYMBOL(copy_to_user_overflow);
92475 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
92476 index 0648291..42bf42b 100644
92477 --- a/lib/vsprintf.c
92478 +++ b/lib/vsprintf.c
92479 @@ -16,6 +16,9 @@
92480 * - scnprintf and vscnprintf
92481 */
92482
92483 +#ifdef CONFIG_GRKERNSEC_HIDESYM
92484 +#define __INCLUDED_BY_HIDESYM 1
92485 +#endif
92486 #include <stdarg.h>
92487 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
92488 #include <linux/types.h>
92489 @@ -1183,7 +1186,11 @@ char *address_val(char *buf, char *end, const void *addr,
92490 return number(buf, end, num, spec);
92491 }
92492
92493 +#ifdef CONFIG_GRKERNSEC_HIDESYM
92494 +int kptr_restrict __read_mostly = 2;
92495 +#else
92496 int kptr_restrict __read_mostly;
92497 +#endif
92498
92499 /*
92500 * Show a '%p' thing. A kernel extension is that the '%p' is followed
92501 @@ -1196,6 +1203,7 @@ int kptr_restrict __read_mostly;
92502 * - 'f' For simple symbolic function names without offset
92503 * - 'S' For symbolic direct pointers with offset
92504 * - 's' For symbolic direct pointers without offset
92505 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
92506 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
92507 * - 'B' For backtraced symbolic direct pointers with offset
92508 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
92509 @@ -1263,12 +1271,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92510
92511 if (!ptr && *fmt != 'K') {
92512 /*
92513 - * Print (null) with the same width as a pointer so it makes
92514 + * Print (nil) with the same width as a pointer so it makes
92515 * tabular output look nice.
92516 */
92517 if (spec.field_width == -1)
92518 spec.field_width = default_width;
92519 - return string(buf, end, "(null)", spec);
92520 + return string(buf, end, "(nil)", spec);
92521 }
92522
92523 switch (*fmt) {
92524 @@ -1278,6 +1286,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92525 /* Fallthrough */
92526 case 'S':
92527 case 's':
92528 +#ifdef CONFIG_GRKERNSEC_HIDESYM
92529 + break;
92530 +#else
92531 + return symbol_string(buf, end, ptr, spec, fmt);
92532 +#endif
92533 + case 'A':
92534 case 'B':
92535 return symbol_string(buf, end, ptr, spec, fmt);
92536 case 'R':
92537 @@ -1333,6 +1347,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92538 va_end(va);
92539 return buf;
92540 }
92541 + case 'P':
92542 + break;
92543 case 'K':
92544 /*
92545 * %pK cannot be used in IRQ context because its test
92546 @@ -1390,6 +1406,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92547 ((const struct file *)ptr)->f_path.dentry,
92548 spec, fmt);
92549 }
92550 +
92551 +#ifdef CONFIG_GRKERNSEC_HIDESYM
92552 + /* 'P' = approved pointers to copy to userland,
92553 + as in the /proc/kallsyms case, as we make it display nothing
92554 + for non-root users, and the real contents for root users
92555 + Also ignore 'K' pointers, since we force their NULLing for non-root users
92556 + above
92557 + */
92558 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
92559 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
92560 + dump_stack();
92561 + ptr = NULL;
92562 + }
92563 +#endif
92564 +
92565 spec.flags |= SMALL;
92566 if (spec.field_width == -1) {
92567 spec.field_width = default_width;
92568 @@ -2089,11 +2120,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
92569 typeof(type) value; \
92570 if (sizeof(type) == 8) { \
92571 args = PTR_ALIGN(args, sizeof(u32)); \
92572 - *(u32 *)&value = *(u32 *)args; \
92573 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
92574 + *(u32 *)&value = *(const u32 *)args; \
92575 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
92576 } else { \
92577 args = PTR_ALIGN(args, sizeof(type)); \
92578 - value = *(typeof(type) *)args; \
92579 + value = *(const typeof(type) *)args; \
92580 } \
92581 args += sizeof(type); \
92582 value; \
92583 @@ -2156,7 +2187,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
92584 case FORMAT_TYPE_STR: {
92585 const char *str_arg = args;
92586 args += strlen(str_arg) + 1;
92587 - str = string(str, end, (char *)str_arg, spec);
92588 + str = string(str, end, str_arg, spec);
92589 break;
92590 }
92591
92592 diff --git a/localversion-grsec b/localversion-grsec
92593 new file mode 100644
92594 index 0000000..7cd6065
92595 --- /dev/null
92596 +++ b/localversion-grsec
92597 @@ -0,0 +1 @@
92598 +-grsec
92599 diff --git a/mm/Kconfig b/mm/Kconfig
92600 index 2f42b9c..6095e14 100644
92601 --- a/mm/Kconfig
92602 +++ b/mm/Kconfig
92603 @@ -330,10 +330,11 @@ config KSM
92604 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
92605
92606 config DEFAULT_MMAP_MIN_ADDR
92607 - int "Low address space to protect from user allocation"
92608 + int "Low address space to protect from user allocation"
92609 depends on MMU
92610 - default 4096
92611 - help
92612 + default 32768 if ALPHA || ARM || PARISC || SPARC32
92613 + default 65536
92614 + help
92615 This is the portion of low virtual memory which should be protected
92616 from userspace allocation. Keeping a user from writing to low pages
92617 can help reduce the impact of kernel NULL pointer bugs.
92618 @@ -364,7 +365,7 @@ config MEMORY_FAILURE
92619
92620 config HWPOISON_INJECT
92621 tristate "HWPoison pages injector"
92622 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
92623 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
92624 select PROC_PAGE_MONITOR
92625
92626 config NOMMU_INITIAL_TRIM_EXCESS
92627 diff --git a/mm/backing-dev.c b/mm/backing-dev.c
92628 index 09d9591..165bb75 100644
92629 --- a/mm/backing-dev.c
92630 +++ b/mm/backing-dev.c
92631 @@ -12,7 +12,7 @@
92632 #include <linux/device.h>
92633 #include <trace/events/writeback.h>
92634
92635 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
92636 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
92637
92638 struct backing_dev_info default_backing_dev_info = {
92639 .name = "default",
92640 @@ -533,7 +533,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
92641 return err;
92642
92643 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
92644 - atomic_long_inc_return(&bdi_seq));
92645 + atomic_long_inc_return_unchecked(&bdi_seq));
92646 if (err) {
92647 bdi_destroy(bdi);
92648 return err;
92649 diff --git a/mm/filemap.c b/mm/filemap.c
92650 index 088358c..bb415bf 100644
92651 --- a/mm/filemap.c
92652 +++ b/mm/filemap.c
92653 @@ -2125,7 +2125,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
92654 struct address_space *mapping = file->f_mapping;
92655
92656 if (!mapping->a_ops->readpage)
92657 - return -ENOEXEC;
92658 + return -ENODEV;
92659 file_accessed(file);
92660 vma->vm_ops = &generic_file_vm_ops;
92661 return 0;
92662 @@ -2303,6 +2303,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
92663 *pos = i_size_read(inode);
92664
92665 if (limit != RLIM_INFINITY) {
92666 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
92667 if (*pos >= limit) {
92668 send_sig(SIGXFSZ, current, 0);
92669 return -EFBIG;
92670 diff --git a/mm/fremap.c b/mm/fremap.c
92671 index 34feba6..315fe78 100644
92672 --- a/mm/fremap.c
92673 +++ b/mm/fremap.c
92674 @@ -179,6 +179,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
92675 retry:
92676 vma = find_vma(mm, start);
92677
92678 +#ifdef CONFIG_PAX_SEGMEXEC
92679 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
92680 + goto out;
92681 +#endif
92682 +
92683 /*
92684 * Make sure the vma is shared, that it supports prefaulting,
92685 * and that the remapped range is valid and fully within
92686 diff --git a/mm/highmem.c b/mm/highmem.c
92687 index b32b70c..e512eb0 100644
92688 --- a/mm/highmem.c
92689 +++ b/mm/highmem.c
92690 @@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
92691 * So no dangers, even with speculative execution.
92692 */
92693 page = pte_page(pkmap_page_table[i]);
92694 + pax_open_kernel();
92695 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
92696 -
92697 + pax_close_kernel();
92698 set_page_address(page, NULL);
92699 need_flush = 1;
92700 }
92701 @@ -198,9 +199,11 @@ start:
92702 }
92703 }
92704 vaddr = PKMAP_ADDR(last_pkmap_nr);
92705 +
92706 + pax_open_kernel();
92707 set_pte_at(&init_mm, vaddr,
92708 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
92709 -
92710 + pax_close_kernel();
92711 pkmap_count[last_pkmap_nr] = 1;
92712 set_page_address(page, (void *)vaddr);
92713
92714 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
92715 index 002f08e..68f11e8 100644
92716 --- a/mm/hugetlb.c
92717 +++ b/mm/hugetlb.c
92718 @@ -2107,6 +2107,7 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
92719 struct hstate *h = &default_hstate;
92720 unsigned long tmp;
92721 int ret;
92722 + ctl_table_no_const hugetlb_table;
92723
92724 if (!hugepages_supported())
92725 return -ENOTSUPP;
92726 @@ -2116,9 +2117,10 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
92727 if (write && h->order >= MAX_ORDER)
92728 return -EINVAL;
92729
92730 - table->data = &tmp;
92731 - table->maxlen = sizeof(unsigned long);
92732 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
92733 + hugetlb_table = *table;
92734 + hugetlb_table.data = &tmp;
92735 + hugetlb_table.maxlen = sizeof(unsigned long);
92736 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
92737 if (ret)
92738 goto out;
92739
92740 @@ -2163,6 +2165,7 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
92741 struct hstate *h = &default_hstate;
92742 unsigned long tmp;
92743 int ret;
92744 + ctl_table_no_const hugetlb_table;
92745
92746 if (!hugepages_supported())
92747 return -ENOTSUPP;
92748 @@ -2172,9 +2175,10 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
92749 if (write && h->order >= MAX_ORDER)
92750 return -EINVAL;
92751
92752 - table->data = &tmp;
92753 - table->maxlen = sizeof(unsigned long);
92754 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
92755 + hugetlb_table = *table;
92756 + hugetlb_table.data = &tmp;
92757 + hugetlb_table.maxlen = sizeof(unsigned long);
92758 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
92759 if (ret)
92760 goto out;
92761
92762 @@ -2655,6 +2659,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
92763 return 1;
92764 }
92765
92766 +#ifdef CONFIG_PAX_SEGMEXEC
92767 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
92768 +{
92769 + struct mm_struct *mm = vma->vm_mm;
92770 + struct vm_area_struct *vma_m;
92771 + unsigned long address_m;
92772 + pte_t *ptep_m;
92773 +
92774 + vma_m = pax_find_mirror_vma(vma);
92775 + if (!vma_m)
92776 + return;
92777 +
92778 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92779 + address_m = address + SEGMEXEC_TASK_SIZE;
92780 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
92781 + get_page(page_m);
92782 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
92783 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
92784 +}
92785 +#endif
92786 +
92787 /*
92788 * Hugetlb_cow() should be called with page lock of the original hugepage held.
92789 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
92790 @@ -2772,6 +2797,11 @@ retry_avoidcopy:
92791 make_huge_pte(vma, new_page, 1));
92792 page_remove_rmap(old_page);
92793 hugepage_add_new_anon_rmap(new_page, vma, address);
92794 +
92795 +#ifdef CONFIG_PAX_SEGMEXEC
92796 + pax_mirror_huge_pte(vma, address, new_page);
92797 +#endif
92798 +
92799 /* Make the old page be freed below */
92800 new_page = old_page;
92801 }
92802 @@ -2931,6 +2961,10 @@ retry:
92803 && (vma->vm_flags & VM_SHARED)));
92804 set_huge_pte_at(mm, address, ptep, new_pte);
92805
92806 +#ifdef CONFIG_PAX_SEGMEXEC
92807 + pax_mirror_huge_pte(vma, address, page);
92808 +#endif
92809 +
92810 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
92811 /* Optimization, do the COW without a second fault */
92812 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
92813 @@ -2997,6 +3031,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92814 struct hstate *h = hstate_vma(vma);
92815 struct address_space *mapping;
92816
92817 +#ifdef CONFIG_PAX_SEGMEXEC
92818 + struct vm_area_struct *vma_m;
92819 +#endif
92820 +
92821 address &= huge_page_mask(h);
92822
92823 ptep = huge_pte_offset(mm, address);
92824 @@ -3010,6 +3048,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92825 VM_FAULT_SET_HINDEX(hstate_index(h));
92826 }
92827
92828 +#ifdef CONFIG_PAX_SEGMEXEC
92829 + vma_m = pax_find_mirror_vma(vma);
92830 + if (vma_m) {
92831 + unsigned long address_m;
92832 +
92833 + if (vma->vm_start > vma_m->vm_start) {
92834 + address_m = address;
92835 + address -= SEGMEXEC_TASK_SIZE;
92836 + vma = vma_m;
92837 + h = hstate_vma(vma);
92838 + } else
92839 + address_m = address + SEGMEXEC_TASK_SIZE;
92840 +
92841 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
92842 + return VM_FAULT_OOM;
92843 + address_m &= HPAGE_MASK;
92844 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
92845 + }
92846 +#endif
92847 +
92848 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
92849 if (!ptep)
92850 return VM_FAULT_OOM;
92851 diff --git a/mm/internal.h b/mm/internal.h
92852 index 07b6736..ae8da20 100644
92853 --- a/mm/internal.h
92854 +++ b/mm/internal.h
92855 @@ -109,6 +109,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
92856 * in mm/page_alloc.c
92857 */
92858 extern void __free_pages_bootmem(struct page *page, unsigned int order);
92859 +extern void free_compound_page(struct page *page);
92860 extern void prep_compound_page(struct page *page, unsigned long order);
92861 #ifdef CONFIG_MEMORY_FAILURE
92862 extern bool is_free_buddy_page(struct page *page);
92863 @@ -367,7 +368,7 @@ extern u32 hwpoison_filter_enable;
92864
92865 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
92866 unsigned long, unsigned long,
92867 - unsigned long, unsigned long);
92868 + unsigned long, unsigned long) __intentional_overflow(-1);
92869
92870 extern void set_pageblock_order(void);
92871 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
92872 diff --git a/mm/iov_iter.c b/mm/iov_iter.c
92873 index 10e46cd..e3052f6 100644
92874 --- a/mm/iov_iter.c
92875 +++ b/mm/iov_iter.c
92876 @@ -87,7 +87,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
92877
92878 while (bytes) {
92879 char __user *buf = iov->iov_base + base;
92880 - int copy = min(bytes, iov->iov_len - base);
92881 + size_t copy = min(bytes, iov->iov_len - base);
92882
92883 base = 0;
92884 left = __copy_from_user_inatomic(vaddr, buf, copy);
92885 @@ -115,7 +115,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
92886
92887 kaddr = kmap_atomic(page);
92888 if (likely(i->nr_segs == 1)) {
92889 - int left;
92890 + size_t left;
92891 char __user *buf = i->iov->iov_base + i->iov_offset;
92892 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
92893 copied = bytes - left;
92894 @@ -143,7 +143,7 @@ size_t iov_iter_copy_from_user(struct page *page,
92895
92896 kaddr = kmap(page);
92897 if (likely(i->nr_segs == 1)) {
92898 - int left;
92899 + size_t left;
92900 char __user *buf = i->iov->iov_base + i->iov_offset;
92901 left = __copy_from_user(kaddr + offset, buf, bytes);
92902 copied = bytes - left;
92903 @@ -173,7 +173,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
92904 * zero-length segments (without overruning the iovec).
92905 */
92906 while (bytes || unlikely(i->count && !iov->iov_len)) {
92907 - int copy;
92908 + size_t copy;
92909
92910 copy = min(bytes, iov->iov_len - base);
92911 BUG_ON(!i->count || i->count < copy);
92912 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
92913 index 8d2fcdf..6dd9f1a 100644
92914 --- a/mm/kmemleak.c
92915 +++ b/mm/kmemleak.c
92916 @@ -364,7 +364,7 @@ static void print_unreferenced(struct seq_file *seq,
92917
92918 for (i = 0; i < object->trace_len; i++) {
92919 void *ptr = (void *)object->trace[i];
92920 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
92921 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
92922 }
92923 }
92924
92925 @@ -1871,7 +1871,7 @@ static int __init kmemleak_late_init(void)
92926 return -ENOMEM;
92927 }
92928
92929 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
92930 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
92931 &kmemleak_fops);
92932 if (!dentry)
92933 pr_warning("Failed to create the debugfs kmemleak file\n");
92934 diff --git a/mm/maccess.c b/mm/maccess.c
92935 index d53adf9..03a24bf 100644
92936 --- a/mm/maccess.c
92937 +++ b/mm/maccess.c
92938 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
92939 set_fs(KERNEL_DS);
92940 pagefault_disable();
92941 ret = __copy_from_user_inatomic(dst,
92942 - (__force const void __user *)src, size);
92943 + (const void __force_user *)src, size);
92944 pagefault_enable();
92945 set_fs(old_fs);
92946
92947 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
92948
92949 set_fs(KERNEL_DS);
92950 pagefault_disable();
92951 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
92952 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
92953 pagefault_enable();
92954 set_fs(old_fs);
92955
92956 diff --git a/mm/madvise.c b/mm/madvise.c
92957 index a402f8f..f5e5daa 100644
92958 --- a/mm/madvise.c
92959 +++ b/mm/madvise.c
92960 @@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
92961 pgoff_t pgoff;
92962 unsigned long new_flags = vma->vm_flags;
92963
92964 +#ifdef CONFIG_PAX_SEGMEXEC
92965 + struct vm_area_struct *vma_m;
92966 +#endif
92967 +
92968 switch (behavior) {
92969 case MADV_NORMAL:
92970 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
92971 @@ -126,6 +130,13 @@ success:
92972 /*
92973 * vm_flags is protected by the mmap_sem held in write mode.
92974 */
92975 +
92976 +#ifdef CONFIG_PAX_SEGMEXEC
92977 + vma_m = pax_find_mirror_vma(vma);
92978 + if (vma_m)
92979 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
92980 +#endif
92981 +
92982 vma->vm_flags = new_flags;
92983
92984 out:
92985 @@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
92986 struct vm_area_struct **prev,
92987 unsigned long start, unsigned long end)
92988 {
92989 +
92990 +#ifdef CONFIG_PAX_SEGMEXEC
92991 + struct vm_area_struct *vma_m;
92992 +#endif
92993 +
92994 *prev = vma;
92995 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
92996 return -EINVAL;
92997 @@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
92998 zap_page_range(vma, start, end - start, &details);
92999 } else
93000 zap_page_range(vma, start, end - start, NULL);
93001 +
93002 +#ifdef CONFIG_PAX_SEGMEXEC
93003 + vma_m = pax_find_mirror_vma(vma);
93004 + if (vma_m) {
93005 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
93006 + struct zap_details details = {
93007 + .nonlinear_vma = vma_m,
93008 + .last_index = ULONG_MAX,
93009 + };
93010 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
93011 + } else
93012 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
93013 + }
93014 +#endif
93015 +
93016 return 0;
93017 }
93018
93019 @@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
93020 if (end < start)
93021 return error;
93022
93023 +#ifdef CONFIG_PAX_SEGMEXEC
93024 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
93025 + if (end > SEGMEXEC_TASK_SIZE)
93026 + return error;
93027 + } else
93028 +#endif
93029 +
93030 + if (end > TASK_SIZE)
93031 + return error;
93032 +
93033 error = 0;
93034 if (end == start)
93035 return error;
93036 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
93037 index eb8fb72..ae36cf3 100644
93038 --- a/mm/memory-failure.c
93039 +++ b/mm/memory-failure.c
93040 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
93041
93042 int sysctl_memory_failure_recovery __read_mostly = 1;
93043
93044 -atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
93045 +atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
93046
93047 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
93048
93049 @@ -198,7 +198,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
93050 pfn, t->comm, t->pid);
93051 si.si_signo = SIGBUS;
93052 si.si_errno = 0;
93053 - si.si_addr = (void *)addr;
93054 + si.si_addr = (void __user *)addr;
93055 #ifdef __ARCH_SI_TRAPNO
93056 si.si_trapno = trapno;
93057 #endif
93058 @@ -791,7 +791,7 @@ static struct page_state {
93059 unsigned long res;
93060 char *msg;
93061 int (*action)(struct page *p, unsigned long pfn);
93062 -} error_states[] = {
93063 +} __do_const error_states[] = {
93064 { reserved, reserved, "reserved kernel", me_kernel },
93065 /*
93066 * free pages are specially detected outside this table:
93067 @@ -1091,7 +1091,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
93068 nr_pages = 1 << compound_order(hpage);
93069 else /* normal page or thp */
93070 nr_pages = 1;
93071 - atomic_long_add(nr_pages, &num_poisoned_pages);
93072 + atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
93073
93074 /*
93075 * We need/can do nothing about count=0 pages.
93076 @@ -1120,7 +1120,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
93077 if (PageHWPoison(hpage)) {
93078 if ((hwpoison_filter(p) && TestClearPageHWPoison(p))
93079 || (p != hpage && TestSetPageHWPoison(hpage))) {
93080 - atomic_long_sub(nr_pages, &num_poisoned_pages);
93081 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
93082 unlock_page(hpage);
93083 return 0;
93084 }
93085 @@ -1186,14 +1186,14 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
93086 */
93087 if (!PageHWPoison(p)) {
93088 printk(KERN_ERR "MCE %#lx: just unpoisoned\n", pfn);
93089 - atomic_long_sub(nr_pages, &num_poisoned_pages);
93090 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
93091 put_page(hpage);
93092 res = 0;
93093 goto out;
93094 }
93095 if (hwpoison_filter(p)) {
93096 if (TestClearPageHWPoison(p))
93097 - atomic_long_sub(nr_pages, &num_poisoned_pages);
93098 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
93099 unlock_page(hpage);
93100 put_page(hpage);
93101 return 0;
93102 @@ -1415,7 +1415,7 @@ int unpoison_memory(unsigned long pfn)
93103 return 0;
93104 }
93105 if (TestClearPageHWPoison(p))
93106 - atomic_long_dec(&num_poisoned_pages);
93107 + atomic_long_dec_unchecked(&num_poisoned_pages);
93108 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
93109 return 0;
93110 }
93111 @@ -1429,7 +1429,7 @@ int unpoison_memory(unsigned long pfn)
93112 */
93113 if (TestClearPageHWPoison(page)) {
93114 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
93115 - atomic_long_sub(nr_pages, &num_poisoned_pages);
93116 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
93117 freeit = 1;
93118 if (PageHuge(page))
93119 clear_page_hwpoison_huge_page(page);
93120 @@ -1554,11 +1554,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
93121 if (PageHuge(page)) {
93122 set_page_hwpoison_huge_page(hpage);
93123 dequeue_hwpoisoned_huge_page(hpage);
93124 - atomic_long_add(1 << compound_order(hpage),
93125 + atomic_long_add_unchecked(1 << compound_order(hpage),
93126 &num_poisoned_pages);
93127 } else {
93128 SetPageHWPoison(page);
93129 - atomic_long_inc(&num_poisoned_pages);
93130 + atomic_long_inc_unchecked(&num_poisoned_pages);
93131 }
93132 }
93133 return ret;
93134 @@ -1597,7 +1597,7 @@ static int __soft_offline_page(struct page *page, int flags)
93135 put_page(page);
93136 pr_info("soft_offline: %#lx: invalidated\n", pfn);
93137 SetPageHWPoison(page);
93138 - atomic_long_inc(&num_poisoned_pages);
93139 + atomic_long_inc_unchecked(&num_poisoned_pages);
93140 return 0;
93141 }
93142
93143 @@ -1648,7 +1648,7 @@ static int __soft_offline_page(struct page *page, int flags)
93144 if (!is_free_buddy_page(page))
93145 pr_info("soft offline: %#lx: page leaked\n",
93146 pfn);
93147 - atomic_long_inc(&num_poisoned_pages);
93148 + atomic_long_inc_unchecked(&num_poisoned_pages);
93149 }
93150 } else {
93151 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
93152 @@ -1722,11 +1722,11 @@ int soft_offline_page(struct page *page, int flags)
93153 if (PageHuge(page)) {
93154 set_page_hwpoison_huge_page(hpage);
93155 dequeue_hwpoisoned_huge_page(hpage);
93156 - atomic_long_add(1 << compound_order(hpage),
93157 + atomic_long_add_unchecked(1 << compound_order(hpage),
93158 &num_poisoned_pages);
93159 } else {
93160 SetPageHWPoison(page);
93161 - atomic_long_inc(&num_poisoned_pages);
93162 + atomic_long_inc_unchecked(&num_poisoned_pages);
93163 }
93164 }
93165 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
93166 diff --git a/mm/memory.c b/mm/memory.c
93167 index 4f9e530..779c7ce 100644
93168 --- a/mm/memory.c
93169 +++ b/mm/memory.c
93170 @@ -413,6 +413,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
93171 free_pte_range(tlb, pmd, addr);
93172 } while (pmd++, addr = next, addr != end);
93173
93174 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
93175 start &= PUD_MASK;
93176 if (start < floor)
93177 return;
93178 @@ -427,6 +428,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
93179 pmd = pmd_offset(pud, start);
93180 pud_clear(pud);
93181 pmd_free_tlb(tlb, pmd, start);
93182 +#endif
93183 +
93184 }
93185
93186 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
93187 @@ -446,6 +449,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
93188 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
93189 } while (pud++, addr = next, addr != end);
93190
93191 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
93192 start &= PGDIR_MASK;
93193 if (start < floor)
93194 return;
93195 @@ -460,6 +464,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
93196 pud = pud_offset(pgd, start);
93197 pgd_clear(pgd);
93198 pud_free_tlb(tlb, pud, start);
93199 +#endif
93200 +
93201 }
93202
93203 /*
93204 @@ -1652,12 +1658,6 @@ no_page_table:
93205 return page;
93206 }
93207
93208 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
93209 -{
93210 - return stack_guard_page_start(vma, addr) ||
93211 - stack_guard_page_end(vma, addr+PAGE_SIZE);
93212 -}
93213 -
93214 /**
93215 * __get_user_pages() - pin user pages in memory
93216 * @tsk: task_struct of target task
93217 @@ -1735,10 +1735,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
93218
93219 i = 0;
93220
93221 - do {
93222 + while (nr_pages) {
93223 struct vm_area_struct *vma;
93224
93225 - vma = find_extend_vma(mm, start);
93226 + vma = find_vma(mm, start);
93227 if (!vma && in_gate_area(mm, start)) {
93228 unsigned long pg = start & PAGE_MASK;
93229 pgd_t *pgd;
93230 @@ -1787,7 +1787,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
93231 goto next_page;
93232 }
93233
93234 - if (!vma)
93235 + if (!vma || start < vma->vm_start)
93236 goto efault;
93237 vm_flags = vma->vm_flags;
93238 if (vm_flags & (VM_IO | VM_PFNMAP))
93239 @@ -1848,11 +1848,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
93240 int ret;
93241 unsigned int fault_flags = 0;
93242
93243 - /* For mlock, just skip the stack guard page. */
93244 - if (foll_flags & FOLL_MLOCK) {
93245 - if (stack_guard_page(vma, start))
93246 - goto next_page;
93247 - }
93248 if (foll_flags & FOLL_WRITE)
93249 fault_flags |= FAULT_FLAG_WRITE;
93250 if (nonblocking)
93251 @@ -1932,7 +1927,7 @@ next_page:
93252 start += page_increm * PAGE_SIZE;
93253 nr_pages -= page_increm;
93254 } while (nr_pages && start < vma->vm_end);
93255 - } while (nr_pages);
93256 + }
93257 return i;
93258 efault:
93259 return i ? : -EFAULT;
93260 @@ -2145,6 +2140,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
93261 page_add_file_rmap(page);
93262 set_pte_at(mm, addr, pte, mk_pte(page, prot));
93263
93264 +#ifdef CONFIG_PAX_SEGMEXEC
93265 + pax_mirror_file_pte(vma, addr, page, ptl);
93266 +#endif
93267 +
93268 retval = 0;
93269 pte_unmap_unlock(pte, ptl);
93270 return retval;
93271 @@ -2189,9 +2188,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
93272 if (!page_count(page))
93273 return -EINVAL;
93274 if (!(vma->vm_flags & VM_MIXEDMAP)) {
93275 +
93276 +#ifdef CONFIG_PAX_SEGMEXEC
93277 + struct vm_area_struct *vma_m;
93278 +#endif
93279 +
93280 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
93281 BUG_ON(vma->vm_flags & VM_PFNMAP);
93282 vma->vm_flags |= VM_MIXEDMAP;
93283 +
93284 +#ifdef CONFIG_PAX_SEGMEXEC
93285 + vma_m = pax_find_mirror_vma(vma);
93286 + if (vma_m)
93287 + vma_m->vm_flags |= VM_MIXEDMAP;
93288 +#endif
93289 +
93290 }
93291 return insert_page(vma, addr, page, vma->vm_page_prot);
93292 }
93293 @@ -2274,6 +2285,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
93294 unsigned long pfn)
93295 {
93296 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
93297 + BUG_ON(vma->vm_mirror);
93298
93299 if (addr < vma->vm_start || addr >= vma->vm_end)
93300 return -EFAULT;
93301 @@ -2521,7 +2533,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
93302
93303 BUG_ON(pud_huge(*pud));
93304
93305 - pmd = pmd_alloc(mm, pud, addr);
93306 + pmd = (mm == &init_mm) ?
93307 + pmd_alloc_kernel(mm, pud, addr) :
93308 + pmd_alloc(mm, pud, addr);
93309 if (!pmd)
93310 return -ENOMEM;
93311 do {
93312 @@ -2541,7 +2555,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
93313 unsigned long next;
93314 int err;
93315
93316 - pud = pud_alloc(mm, pgd, addr);
93317 + pud = (mm == &init_mm) ?
93318 + pud_alloc_kernel(mm, pgd, addr) :
93319 + pud_alloc(mm, pgd, addr);
93320 if (!pud)
93321 return -ENOMEM;
93322 do {
93323 @@ -2663,6 +2679,186 @@ static int do_page_mkwrite(struct vm_area_struct *vma, struct page *page,
93324 return ret;
93325 }
93326
93327 +#ifdef CONFIG_PAX_SEGMEXEC
93328 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
93329 +{
93330 + struct mm_struct *mm = vma->vm_mm;
93331 + spinlock_t *ptl;
93332 + pte_t *pte, entry;
93333 +
93334 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
93335 + entry = *pte;
93336 + if (!pte_present(entry)) {
93337 + if (!pte_none(entry)) {
93338 + BUG_ON(pte_file(entry));
93339 + free_swap_and_cache(pte_to_swp_entry(entry));
93340 + pte_clear_not_present_full(mm, address, pte, 0);
93341 + }
93342 + } else {
93343 + struct page *page;
93344 +
93345 + flush_cache_page(vma, address, pte_pfn(entry));
93346 + entry = ptep_clear_flush(vma, address, pte);
93347 + BUG_ON(pte_dirty(entry));
93348 + page = vm_normal_page(vma, address, entry);
93349 + if (page) {
93350 + update_hiwater_rss(mm);
93351 + if (PageAnon(page))
93352 + dec_mm_counter_fast(mm, MM_ANONPAGES);
93353 + else
93354 + dec_mm_counter_fast(mm, MM_FILEPAGES);
93355 + page_remove_rmap(page);
93356 + page_cache_release(page);
93357 + }
93358 + }
93359 + pte_unmap_unlock(pte, ptl);
93360 +}
93361 +
93362 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
93363 + *
93364 + * the ptl of the lower mapped page is held on entry and is not released on exit
93365 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
93366 + */
93367 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
93368 +{
93369 + struct mm_struct *mm = vma->vm_mm;
93370 + unsigned long address_m;
93371 + spinlock_t *ptl_m;
93372 + struct vm_area_struct *vma_m;
93373 + pmd_t *pmd_m;
93374 + pte_t *pte_m, entry_m;
93375 +
93376 + BUG_ON(!page_m || !PageAnon(page_m));
93377 +
93378 + vma_m = pax_find_mirror_vma(vma);
93379 + if (!vma_m)
93380 + return;
93381 +
93382 + BUG_ON(!PageLocked(page_m));
93383 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
93384 + address_m = address + SEGMEXEC_TASK_SIZE;
93385 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
93386 + pte_m = pte_offset_map(pmd_m, address_m);
93387 + ptl_m = pte_lockptr(mm, pmd_m);
93388 + if (ptl != ptl_m) {
93389 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
93390 + if (!pte_none(*pte_m))
93391 + goto out;
93392 + }
93393 +
93394 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
93395 + page_cache_get(page_m);
93396 + page_add_anon_rmap(page_m, vma_m, address_m);
93397 + inc_mm_counter_fast(mm, MM_ANONPAGES);
93398 + set_pte_at(mm, address_m, pte_m, entry_m);
93399 + update_mmu_cache(vma_m, address_m, pte_m);
93400 +out:
93401 + if (ptl != ptl_m)
93402 + spin_unlock(ptl_m);
93403 + pte_unmap(pte_m);
93404 + unlock_page(page_m);
93405 +}
93406 +
93407 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
93408 +{
93409 + struct mm_struct *mm = vma->vm_mm;
93410 + unsigned long address_m;
93411 + spinlock_t *ptl_m;
93412 + struct vm_area_struct *vma_m;
93413 + pmd_t *pmd_m;
93414 + pte_t *pte_m, entry_m;
93415 +
93416 + BUG_ON(!page_m || PageAnon(page_m));
93417 +
93418 + vma_m = pax_find_mirror_vma(vma);
93419 + if (!vma_m)
93420 + return;
93421 +
93422 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
93423 + address_m = address + SEGMEXEC_TASK_SIZE;
93424 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
93425 + pte_m = pte_offset_map(pmd_m, address_m);
93426 + ptl_m = pte_lockptr(mm, pmd_m);
93427 + if (ptl != ptl_m) {
93428 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
93429 + if (!pte_none(*pte_m))
93430 + goto out;
93431 + }
93432 +
93433 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
93434 + page_cache_get(page_m);
93435 + page_add_file_rmap(page_m);
93436 + inc_mm_counter_fast(mm, MM_FILEPAGES);
93437 + set_pte_at(mm, address_m, pte_m, entry_m);
93438 + update_mmu_cache(vma_m, address_m, pte_m);
93439 +out:
93440 + if (ptl != ptl_m)
93441 + spin_unlock(ptl_m);
93442 + pte_unmap(pte_m);
93443 +}
93444 +
93445 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
93446 +{
93447 + struct mm_struct *mm = vma->vm_mm;
93448 + unsigned long address_m;
93449 + spinlock_t *ptl_m;
93450 + struct vm_area_struct *vma_m;
93451 + pmd_t *pmd_m;
93452 + pte_t *pte_m, entry_m;
93453 +
93454 + vma_m = pax_find_mirror_vma(vma);
93455 + if (!vma_m)
93456 + return;
93457 +
93458 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
93459 + address_m = address + SEGMEXEC_TASK_SIZE;
93460 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
93461 + pte_m = pte_offset_map(pmd_m, address_m);
93462 + ptl_m = pte_lockptr(mm, pmd_m);
93463 + if (ptl != ptl_m) {
93464 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
93465 + if (!pte_none(*pte_m))
93466 + goto out;
93467 + }
93468 +
93469 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
93470 + set_pte_at(mm, address_m, pte_m, entry_m);
93471 +out:
93472 + if (ptl != ptl_m)
93473 + spin_unlock(ptl_m);
93474 + pte_unmap(pte_m);
93475 +}
93476 +
93477 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
93478 +{
93479 + struct page *page_m;
93480 + pte_t entry;
93481 +
93482 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
93483 + goto out;
93484 +
93485 + entry = *pte;
93486 + page_m = vm_normal_page(vma, address, entry);
93487 + if (!page_m)
93488 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
93489 + else if (PageAnon(page_m)) {
93490 + if (pax_find_mirror_vma(vma)) {
93491 + pte_unmap_unlock(pte, ptl);
93492 + lock_page(page_m);
93493 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
93494 + if (pte_same(entry, *pte))
93495 + pax_mirror_anon_pte(vma, address, page_m, ptl);
93496 + else
93497 + unlock_page(page_m);
93498 + }
93499 + } else
93500 + pax_mirror_file_pte(vma, address, page_m, ptl);
93501 +
93502 +out:
93503 + pte_unmap_unlock(pte, ptl);
93504 +}
93505 +#endif
93506 +
93507 /*
93508 * This routine handles present pages, when users try to write
93509 * to a shared page. It is done by copying the page to a new address
93510 @@ -2860,6 +3056,12 @@ gotten:
93511 */
93512 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
93513 if (likely(pte_same(*page_table, orig_pte))) {
93514 +
93515 +#ifdef CONFIG_PAX_SEGMEXEC
93516 + if (pax_find_mirror_vma(vma))
93517 + BUG_ON(!trylock_page(new_page));
93518 +#endif
93519 +
93520 if (old_page) {
93521 if (!PageAnon(old_page)) {
93522 dec_mm_counter_fast(mm, MM_FILEPAGES);
93523 @@ -2911,6 +3113,10 @@ gotten:
93524 page_remove_rmap(old_page);
93525 }
93526
93527 +#ifdef CONFIG_PAX_SEGMEXEC
93528 + pax_mirror_anon_pte(vma, address, new_page, ptl);
93529 +#endif
93530 +
93531 /* Free the old page.. */
93532 new_page = old_page;
93533 ret |= VM_FAULT_WRITE;
93534 @@ -3184,6 +3390,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
93535 swap_free(entry);
93536 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
93537 try_to_free_swap(page);
93538 +
93539 +#ifdef CONFIG_PAX_SEGMEXEC
93540 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
93541 +#endif
93542 +
93543 unlock_page(page);
93544 if (page != swapcache) {
93545 /*
93546 @@ -3207,6 +3418,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
93547
93548 /* No need to invalidate - it was non-present before */
93549 update_mmu_cache(vma, address, page_table);
93550 +
93551 +#ifdef CONFIG_PAX_SEGMEXEC
93552 + pax_mirror_anon_pte(vma, address, page, ptl);
93553 +#endif
93554 +
93555 unlock:
93556 pte_unmap_unlock(page_table, ptl);
93557 out:
93558 @@ -3226,40 +3442,6 @@ out_release:
93559 }
93560
93561 /*
93562 - * This is like a special single-page "expand_{down|up}wards()",
93563 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
93564 - * doesn't hit another vma.
93565 - */
93566 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
93567 -{
93568 - address &= PAGE_MASK;
93569 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
93570 - struct vm_area_struct *prev = vma->vm_prev;
93571 -
93572 - /*
93573 - * Is there a mapping abutting this one below?
93574 - *
93575 - * That's only ok if it's the same stack mapping
93576 - * that has gotten split..
93577 - */
93578 - if (prev && prev->vm_end == address)
93579 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
93580 -
93581 - expand_downwards(vma, address - PAGE_SIZE);
93582 - }
93583 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
93584 - struct vm_area_struct *next = vma->vm_next;
93585 -
93586 - /* As VM_GROWSDOWN but s/below/above/ */
93587 - if (next && next->vm_start == address + PAGE_SIZE)
93588 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
93589 -
93590 - expand_upwards(vma, address + PAGE_SIZE);
93591 - }
93592 - return 0;
93593 -}
93594 -
93595 -/*
93596 * We enter with non-exclusive mmap_sem (to exclude vma changes,
93597 * but allow concurrent faults), and pte mapped but not yet locked.
93598 * We return with mmap_sem still held, but pte unmapped and unlocked.
93599 @@ -3268,27 +3450,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
93600 unsigned long address, pte_t *page_table, pmd_t *pmd,
93601 unsigned int flags)
93602 {
93603 - struct page *page;
93604 + struct page *page = NULL;
93605 spinlock_t *ptl;
93606 pte_t entry;
93607
93608 - pte_unmap(page_table);
93609 -
93610 - /* Check if we need to add a guard page to the stack */
93611 - if (check_stack_guard_page(vma, address) < 0)
93612 - return VM_FAULT_SIGBUS;
93613 -
93614 - /* Use the zero-page for reads */
93615 if (!(flags & FAULT_FLAG_WRITE)) {
93616 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
93617 vma->vm_page_prot));
93618 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
93619 + ptl = pte_lockptr(mm, pmd);
93620 + spin_lock(ptl);
93621 if (!pte_none(*page_table))
93622 goto unlock;
93623 goto setpte;
93624 }
93625
93626 /* Allocate our own private page. */
93627 + pte_unmap(page_table);
93628 +
93629 if (unlikely(anon_vma_prepare(vma)))
93630 goto oom;
93631 page = alloc_zeroed_user_highpage_movable(vma, address);
93632 @@ -3312,6 +3490,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
93633 if (!pte_none(*page_table))
93634 goto release;
93635
93636 +#ifdef CONFIG_PAX_SEGMEXEC
93637 + if (pax_find_mirror_vma(vma))
93638 + BUG_ON(!trylock_page(page));
93639 +#endif
93640 +
93641 inc_mm_counter_fast(mm, MM_ANONPAGES);
93642 page_add_new_anon_rmap(page, vma, address);
93643 setpte:
93644 @@ -3319,6 +3502,12 @@ setpte:
93645
93646 /* No need to invalidate - it was non-present before */
93647 update_mmu_cache(vma, address, page_table);
93648 +
93649 +#ifdef CONFIG_PAX_SEGMEXEC
93650 + if (page)
93651 + pax_mirror_anon_pte(vma, address, page, ptl);
93652 +#endif
93653 +
93654 unlock:
93655 pte_unmap_unlock(page_table, ptl);
93656 return 0;
93657 @@ -3515,7 +3704,8 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93658 * if page by the offset is not ready to be mapped (cold cache or
93659 * something).
93660 */
93661 - if (vma->vm_ops->map_pages && !(flags & FAULT_FLAG_NONLINEAR)) {
93662 + if (vma->vm_ops->map_pages && !(flags & FAULT_FLAG_NONLINEAR) &&
93663 + fault_around_pages() > 1) {
93664 pte = pte_offset_map_lock(mm, pmd, address, &ptl);
93665 do_fault_around(vma, address, pte, pgoff, flags);
93666 if (!pte_same(*pte, orig_pte))
93667 @@ -3535,6 +3725,11 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93668 return ret;
93669 }
93670 do_set_pte(vma, address, fault_page, pte, false, false);
93671 +
93672 +#ifdef CONFIG_PAX_SEGMEXEC
93673 + pax_mirror_file_pte(vma, address, fault_page, ptl);
93674 +#endif
93675 +
93676 unlock_page(fault_page);
93677 unlock_out:
93678 pte_unmap_unlock(pte, ptl);
93679 @@ -3576,7 +3771,18 @@ static int do_cow_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93680 page_cache_release(fault_page);
93681 goto uncharge_out;
93682 }
93683 +
93684 +#ifdef CONFIG_PAX_SEGMEXEC
93685 + if (pax_find_mirror_vma(vma))
93686 + BUG_ON(!trylock_page(new_page));
93687 +#endif
93688 +
93689 do_set_pte(vma, address, new_page, pte, true, true);
93690 +
93691 +#ifdef CONFIG_PAX_SEGMEXEC
93692 + pax_mirror_anon_pte(vma, address, new_page, ptl);
93693 +#endif
93694 +
93695 pte_unmap_unlock(pte, ptl);
93696 unlock_page(fault_page);
93697 page_cache_release(fault_page);
93698 @@ -3624,6 +3830,11 @@ static int do_shared_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93699 return ret;
93700 }
93701 do_set_pte(vma, address, fault_page, pte, true, false);
93702 +
93703 +#ifdef CONFIG_PAX_SEGMEXEC
93704 + pax_mirror_file_pte(vma, address, fault_page, ptl);
93705 +#endif
93706 +
93707 pte_unmap_unlock(pte, ptl);
93708
93709 if (set_page_dirty(fault_page))
93710 @@ -3854,6 +4065,12 @@ static int handle_pte_fault(struct mm_struct *mm,
93711 if (flags & FAULT_FLAG_WRITE)
93712 flush_tlb_fix_spurious_fault(vma, address);
93713 }
93714 +
93715 +#ifdef CONFIG_PAX_SEGMEXEC
93716 + pax_mirror_pte(vma, address, pte, pmd, ptl);
93717 + return 0;
93718 +#endif
93719 +
93720 unlock:
93721 pte_unmap_unlock(pte, ptl);
93722 return 0;
93723 @@ -3870,9 +4087,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93724 pmd_t *pmd;
93725 pte_t *pte;
93726
93727 +#ifdef CONFIG_PAX_SEGMEXEC
93728 + struct vm_area_struct *vma_m;
93729 +#endif
93730 +
93731 if (unlikely(is_vm_hugetlb_page(vma)))
93732 return hugetlb_fault(mm, vma, address, flags);
93733
93734 +#ifdef CONFIG_PAX_SEGMEXEC
93735 + vma_m = pax_find_mirror_vma(vma);
93736 + if (vma_m) {
93737 + unsigned long address_m;
93738 + pgd_t *pgd_m;
93739 + pud_t *pud_m;
93740 + pmd_t *pmd_m;
93741 +
93742 + if (vma->vm_start > vma_m->vm_start) {
93743 + address_m = address;
93744 + address -= SEGMEXEC_TASK_SIZE;
93745 + vma = vma_m;
93746 + } else
93747 + address_m = address + SEGMEXEC_TASK_SIZE;
93748 +
93749 + pgd_m = pgd_offset(mm, address_m);
93750 + pud_m = pud_alloc(mm, pgd_m, address_m);
93751 + if (!pud_m)
93752 + return VM_FAULT_OOM;
93753 + pmd_m = pmd_alloc(mm, pud_m, address_m);
93754 + if (!pmd_m)
93755 + return VM_FAULT_OOM;
93756 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
93757 + return VM_FAULT_OOM;
93758 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
93759 + }
93760 +#endif
93761 +
93762 pgd = pgd_offset(mm, address);
93763 pud = pud_alloc(mm, pgd, address);
93764 if (!pud)
93765 @@ -4000,6 +4249,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
93766 spin_unlock(&mm->page_table_lock);
93767 return 0;
93768 }
93769 +
93770 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
93771 +{
93772 + pud_t *new = pud_alloc_one(mm, address);
93773 + if (!new)
93774 + return -ENOMEM;
93775 +
93776 + smp_wmb(); /* See comment in __pte_alloc */
93777 +
93778 + spin_lock(&mm->page_table_lock);
93779 + if (pgd_present(*pgd)) /* Another has populated it */
93780 + pud_free(mm, new);
93781 + else
93782 + pgd_populate_kernel(mm, pgd, new);
93783 + spin_unlock(&mm->page_table_lock);
93784 + return 0;
93785 +}
93786 #endif /* __PAGETABLE_PUD_FOLDED */
93787
93788 #ifndef __PAGETABLE_PMD_FOLDED
93789 @@ -4030,6 +4296,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
93790 spin_unlock(&mm->page_table_lock);
93791 return 0;
93792 }
93793 +
93794 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
93795 +{
93796 + pmd_t *new = pmd_alloc_one(mm, address);
93797 + if (!new)
93798 + return -ENOMEM;
93799 +
93800 + smp_wmb(); /* See comment in __pte_alloc */
93801 +
93802 + spin_lock(&mm->page_table_lock);
93803 +#ifndef __ARCH_HAS_4LEVEL_HACK
93804 + if (pud_present(*pud)) /* Another has populated it */
93805 + pmd_free(mm, new);
93806 + else
93807 + pud_populate_kernel(mm, pud, new);
93808 +#else
93809 + if (pgd_present(*pud)) /* Another has populated it */
93810 + pmd_free(mm, new);
93811 + else
93812 + pgd_populate_kernel(mm, pud, new);
93813 +#endif /* __ARCH_HAS_4LEVEL_HACK */
93814 + spin_unlock(&mm->page_table_lock);
93815 + return 0;
93816 +}
93817 #endif /* __PAGETABLE_PMD_FOLDED */
93818
93819 #if !defined(__HAVE_ARCH_GATE_AREA)
93820 @@ -4043,7 +4333,7 @@ static int __init gate_vma_init(void)
93821 gate_vma.vm_start = FIXADDR_USER_START;
93822 gate_vma.vm_end = FIXADDR_USER_END;
93823 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
93824 - gate_vma.vm_page_prot = __P101;
93825 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
93826
93827 return 0;
93828 }
93829 @@ -4177,8 +4467,8 @@ out:
93830 return ret;
93831 }
93832
93833 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
93834 - void *buf, int len, int write)
93835 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
93836 + void *buf, size_t len, int write)
93837 {
93838 resource_size_t phys_addr;
93839 unsigned long prot = 0;
93840 @@ -4204,8 +4494,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
93841 * Access another process' address space as given in mm. If non-NULL, use the
93842 * given task for page fault accounting.
93843 */
93844 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93845 - unsigned long addr, void *buf, int len, int write)
93846 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93847 + unsigned long addr, void *buf, size_t len, int write)
93848 {
93849 struct vm_area_struct *vma;
93850 void *old_buf = buf;
93851 @@ -4213,7 +4503,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93852 down_read(&mm->mmap_sem);
93853 /* ignore errors, just check how much was successfully transferred */
93854 while (len) {
93855 - int bytes, ret, offset;
93856 + ssize_t bytes, ret, offset;
93857 void *maddr;
93858 struct page *page = NULL;
93859
93860 @@ -4272,8 +4562,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93861 *
93862 * The caller must hold a reference on @mm.
93863 */
93864 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93865 - void *buf, int len, int write)
93866 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
93867 + void *buf, size_t len, int write)
93868 {
93869 return __access_remote_vm(NULL, mm, addr, buf, len, write);
93870 }
93871 @@ -4283,11 +4573,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93872 * Source/target buffer must be kernel space,
93873 * Do not walk the page table directly, use get_user_pages
93874 */
93875 -int access_process_vm(struct task_struct *tsk, unsigned long addr,
93876 - void *buf, int len, int write)
93877 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
93878 + void *buf, size_t len, int write)
93879 {
93880 struct mm_struct *mm;
93881 - int ret;
93882 + ssize_t ret;
93883
93884 mm = get_task_mm(tsk);
93885 if (!mm)
93886 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
93887 index 6b65d10..e6f415a 100644
93888 --- a/mm/mempolicy.c
93889 +++ b/mm/mempolicy.c
93890 @@ -747,6 +747,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
93891 unsigned long vmstart;
93892 unsigned long vmend;
93893
93894 +#ifdef CONFIG_PAX_SEGMEXEC
93895 + struct vm_area_struct *vma_m;
93896 +#endif
93897 +
93898 vma = find_vma(mm, start);
93899 if (!vma || vma->vm_start > start)
93900 return -EFAULT;
93901 @@ -790,6 +794,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
93902 err = vma_replace_policy(vma, new_pol);
93903 if (err)
93904 goto out;
93905 +
93906 +#ifdef CONFIG_PAX_SEGMEXEC
93907 + vma_m = pax_find_mirror_vma(vma);
93908 + if (vma_m) {
93909 + err = vma_replace_policy(vma_m, new_pol);
93910 + if (err)
93911 + goto out;
93912 + }
93913 +#endif
93914 +
93915 }
93916
93917 out:
93918 @@ -1222,6 +1236,17 @@ static long do_mbind(unsigned long start, unsigned long len,
93919
93920 if (end < start)
93921 return -EINVAL;
93922 +
93923 +#ifdef CONFIG_PAX_SEGMEXEC
93924 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
93925 + if (end > SEGMEXEC_TASK_SIZE)
93926 + return -EINVAL;
93927 + } else
93928 +#endif
93929 +
93930 + if (end > TASK_SIZE)
93931 + return -EINVAL;
93932 +
93933 if (end == start)
93934 return 0;
93935
93936 @@ -1447,8 +1472,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
93937 */
93938 tcred = __task_cred(task);
93939 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
93940 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
93941 - !capable(CAP_SYS_NICE)) {
93942 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
93943 rcu_read_unlock();
93944 err = -EPERM;
93945 goto out_put;
93946 @@ -1479,6 +1503,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
93947 goto out;
93948 }
93949
93950 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
93951 + if (mm != current->mm &&
93952 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
93953 + mmput(mm);
93954 + err = -EPERM;
93955 + goto out;
93956 + }
93957 +#endif
93958 +
93959 err = do_migrate_pages(mm, old, new,
93960 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
93961
93962 diff --git a/mm/migrate.c b/mm/migrate.c
93963 index bed4880..a493f67 100644
93964 --- a/mm/migrate.c
93965 +++ b/mm/migrate.c
93966 @@ -1485,8 +1485,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
93967 */
93968 tcred = __task_cred(task);
93969 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
93970 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
93971 - !capable(CAP_SYS_NICE)) {
93972 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
93973 rcu_read_unlock();
93974 err = -EPERM;
93975 goto out;
93976 diff --git a/mm/mlock.c b/mm/mlock.c
93977 index b1eb536..091d154 100644
93978 --- a/mm/mlock.c
93979 +++ b/mm/mlock.c
93980 @@ -14,6 +14,7 @@
93981 #include <linux/pagevec.h>
93982 #include <linux/mempolicy.h>
93983 #include <linux/syscalls.h>
93984 +#include <linux/security.h>
93985 #include <linux/sched.h>
93986 #include <linux/export.h>
93987 #include <linux/rmap.h>
93988 @@ -606,7 +607,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
93989 {
93990 unsigned long nstart, end, tmp;
93991 struct vm_area_struct * vma, * prev;
93992 - int error;
93993 + int error = 0;
93994
93995 VM_BUG_ON(start & ~PAGE_MASK);
93996 VM_BUG_ON(len != PAGE_ALIGN(len));
93997 @@ -615,6 +616,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
93998 return -EINVAL;
93999 if (end == start)
94000 return 0;
94001 + if (end > TASK_SIZE)
94002 + return -EINVAL;
94003 +
94004 vma = find_vma(current->mm, start);
94005 if (!vma || vma->vm_start > start)
94006 return -ENOMEM;
94007 @@ -626,6 +630,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
94008 for (nstart = start ; ; ) {
94009 vm_flags_t newflags;
94010
94011 +#ifdef CONFIG_PAX_SEGMEXEC
94012 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
94013 + break;
94014 +#endif
94015 +
94016 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
94017
94018 newflags = vma->vm_flags & ~VM_LOCKED;
94019 @@ -739,6 +748,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
94020 locked += current->mm->locked_vm;
94021
94022 /* check against resource limits */
94023 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
94024 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
94025 error = do_mlock(start, len, 1);
94026
94027 @@ -776,6 +786,11 @@ static int do_mlockall(int flags)
94028 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
94029 vm_flags_t newflags;
94030
94031 +#ifdef CONFIG_PAX_SEGMEXEC
94032 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
94033 + break;
94034 +#endif
94035 +
94036 newflags = vma->vm_flags & ~VM_LOCKED;
94037 if (flags & MCL_CURRENT)
94038 newflags |= VM_LOCKED;
94039 @@ -807,8 +822,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
94040 lock_limit >>= PAGE_SHIFT;
94041
94042 ret = -ENOMEM;
94043 +
94044 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
94045 +
94046 down_write(&current->mm->mmap_sem);
94047 -
94048 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
94049 capable(CAP_IPC_LOCK))
94050 ret = do_mlockall(flags);
94051 diff --git a/mm/mmap.c b/mm/mmap.c
94052 index b1202cf..ee487f8 100644
94053 --- a/mm/mmap.c
94054 +++ b/mm/mmap.c
94055 @@ -37,6 +37,7 @@
94056 #include <linux/sched/sysctl.h>
94057 #include <linux/notifier.h>
94058 #include <linux/memory.h>
94059 +#include <linux/random.h>
94060
94061 #include <asm/uaccess.h>
94062 #include <asm/cacheflush.h>
94063 @@ -53,6 +54,16 @@
94064 #define arch_rebalance_pgtables(addr, len) (addr)
94065 #endif
94066
94067 +static inline void verify_mm_writelocked(struct mm_struct *mm)
94068 +{
94069 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
94070 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
94071 + up_read(&mm->mmap_sem);
94072 + BUG();
94073 + }
94074 +#endif
94075 +}
94076 +
94077 static void unmap_region(struct mm_struct *mm,
94078 struct vm_area_struct *vma, struct vm_area_struct *prev,
94079 unsigned long start, unsigned long end);
94080 @@ -72,16 +83,25 @@ static void unmap_region(struct mm_struct *mm,
94081 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
94082 *
94083 */
94084 -pgprot_t protection_map[16] = {
94085 +pgprot_t protection_map[16] __read_only = {
94086 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
94087 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
94088 };
94089
94090 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
94091 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
94092 {
94093 - return __pgprot(pgprot_val(protection_map[vm_flags &
94094 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
94095 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
94096 pgprot_val(arch_vm_get_page_prot(vm_flags)));
94097 +
94098 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
94099 + if (!(__supported_pte_mask & _PAGE_NX) &&
94100 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
94101 + (vm_flags & (VM_READ | VM_WRITE)))
94102 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
94103 +#endif
94104 +
94105 + return prot;
94106 }
94107 EXPORT_SYMBOL(vm_get_page_prot);
94108
94109 @@ -91,6 +111,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
94110 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
94111 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
94112 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
94113 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
94114 /*
94115 * Make sure vm_committed_as in one cacheline and not cacheline shared with
94116 * other variables. It can be updated by several CPUs frequently.
94117 @@ -247,6 +268,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
94118 struct vm_area_struct *next = vma->vm_next;
94119
94120 might_sleep();
94121 + BUG_ON(vma->vm_mirror);
94122 if (vma->vm_ops && vma->vm_ops->close)
94123 vma->vm_ops->close(vma);
94124 if (vma->vm_file)
94125 @@ -291,6 +313,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
94126 * not page aligned -Ram Gupta
94127 */
94128 rlim = rlimit(RLIMIT_DATA);
94129 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
94130 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
94131 (mm->end_data - mm->start_data) > rlim)
94132 goto out;
94133 @@ -942,6 +965,12 @@ static int
94134 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
94135 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
94136 {
94137 +
94138 +#ifdef CONFIG_PAX_SEGMEXEC
94139 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
94140 + return 0;
94141 +#endif
94142 +
94143 if (is_mergeable_vma(vma, file, vm_flags) &&
94144 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
94145 if (vma->vm_pgoff == vm_pgoff)
94146 @@ -961,6 +990,12 @@ static int
94147 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
94148 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
94149 {
94150 +
94151 +#ifdef CONFIG_PAX_SEGMEXEC
94152 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
94153 + return 0;
94154 +#endif
94155 +
94156 if (is_mergeable_vma(vma, file, vm_flags) &&
94157 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
94158 pgoff_t vm_pglen;
94159 @@ -1003,13 +1038,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
94160 struct vm_area_struct *vma_merge(struct mm_struct *mm,
94161 struct vm_area_struct *prev, unsigned long addr,
94162 unsigned long end, unsigned long vm_flags,
94163 - struct anon_vma *anon_vma, struct file *file,
94164 + struct anon_vma *anon_vma, struct file *file,
94165 pgoff_t pgoff, struct mempolicy *policy)
94166 {
94167 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
94168 struct vm_area_struct *area, *next;
94169 int err;
94170
94171 +#ifdef CONFIG_PAX_SEGMEXEC
94172 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
94173 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
94174 +
94175 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
94176 +#endif
94177 +
94178 /*
94179 * We later require that vma->vm_flags == vm_flags,
94180 * so this tests vma->vm_flags & VM_SPECIAL, too.
94181 @@ -1025,6 +1067,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
94182 if (next && next->vm_end == end) /* cases 6, 7, 8 */
94183 next = next->vm_next;
94184
94185 +#ifdef CONFIG_PAX_SEGMEXEC
94186 + if (prev)
94187 + prev_m = pax_find_mirror_vma(prev);
94188 + if (area)
94189 + area_m = pax_find_mirror_vma(area);
94190 + if (next)
94191 + next_m = pax_find_mirror_vma(next);
94192 +#endif
94193 +
94194 /*
94195 * Can it merge with the predecessor?
94196 */
94197 @@ -1044,9 +1095,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
94198 /* cases 1, 6 */
94199 err = vma_adjust(prev, prev->vm_start,
94200 next->vm_end, prev->vm_pgoff, NULL);
94201 - } else /* cases 2, 5, 7 */
94202 +
94203 +#ifdef CONFIG_PAX_SEGMEXEC
94204 + if (!err && prev_m)
94205 + err = vma_adjust(prev_m, prev_m->vm_start,
94206 + next_m->vm_end, prev_m->vm_pgoff, NULL);
94207 +#endif
94208 +
94209 + } else { /* cases 2, 5, 7 */
94210 err = vma_adjust(prev, prev->vm_start,
94211 end, prev->vm_pgoff, NULL);
94212 +
94213 +#ifdef CONFIG_PAX_SEGMEXEC
94214 + if (!err && prev_m)
94215 + err = vma_adjust(prev_m, prev_m->vm_start,
94216 + end_m, prev_m->vm_pgoff, NULL);
94217 +#endif
94218 +
94219 + }
94220 if (err)
94221 return NULL;
94222 khugepaged_enter_vma_merge(prev);
94223 @@ -1060,12 +1126,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
94224 mpol_equal(policy, vma_policy(next)) &&
94225 can_vma_merge_before(next, vm_flags,
94226 anon_vma, file, pgoff+pglen)) {
94227 - if (prev && addr < prev->vm_end) /* case 4 */
94228 + if (prev && addr < prev->vm_end) { /* case 4 */
94229 err = vma_adjust(prev, prev->vm_start,
94230 addr, prev->vm_pgoff, NULL);
94231 - else /* cases 3, 8 */
94232 +
94233 +#ifdef CONFIG_PAX_SEGMEXEC
94234 + if (!err && prev_m)
94235 + err = vma_adjust(prev_m, prev_m->vm_start,
94236 + addr_m, prev_m->vm_pgoff, NULL);
94237 +#endif
94238 +
94239 + } else { /* cases 3, 8 */
94240 err = vma_adjust(area, addr, next->vm_end,
94241 next->vm_pgoff - pglen, NULL);
94242 +
94243 +#ifdef CONFIG_PAX_SEGMEXEC
94244 + if (!err && area_m)
94245 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
94246 + next_m->vm_pgoff - pglen, NULL);
94247 +#endif
94248 +
94249 + }
94250 if (err)
94251 return NULL;
94252 khugepaged_enter_vma_merge(area);
94253 @@ -1174,8 +1255,10 @@ none:
94254 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
94255 struct file *file, long pages)
94256 {
94257 - const unsigned long stack_flags
94258 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
94259 +
94260 +#ifdef CONFIG_PAX_RANDMMAP
94261 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
94262 +#endif
94263
94264 mm->total_vm += pages;
94265
94266 @@ -1183,7 +1266,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
94267 mm->shared_vm += pages;
94268 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
94269 mm->exec_vm += pages;
94270 - } else if (flags & stack_flags)
94271 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
94272 mm->stack_vm += pages;
94273 }
94274 #endif /* CONFIG_PROC_FS */
94275 @@ -1213,6 +1296,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
94276 locked += mm->locked_vm;
94277 lock_limit = rlimit(RLIMIT_MEMLOCK);
94278 lock_limit >>= PAGE_SHIFT;
94279 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
94280 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
94281 return -EAGAIN;
94282 }
94283 @@ -1239,7 +1323,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
94284 * (the exception is when the underlying filesystem is noexec
94285 * mounted, in which case we dont add PROT_EXEC.)
94286 */
94287 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
94288 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
94289 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
94290 prot |= PROT_EXEC;
94291
94292 @@ -1265,7 +1349,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
94293 /* Obtain the address to map to. we verify (or select) it and ensure
94294 * that it represents a valid section of the address space.
94295 */
94296 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
94297 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
94298 if (addr & ~PAGE_MASK)
94299 return addr;
94300
94301 @@ -1276,6 +1360,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
94302 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
94303 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
94304
94305 +#ifdef CONFIG_PAX_MPROTECT
94306 + if (mm->pax_flags & MF_PAX_MPROTECT) {
94307 +
94308 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
94309 + if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
94310 + mm->binfmt->handle_mmap)
94311 + mm->binfmt->handle_mmap(file);
94312 +#endif
94313 +
94314 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
94315 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
94316 + gr_log_rwxmmap(file);
94317 +
94318 +#ifdef CONFIG_PAX_EMUPLT
94319 + vm_flags &= ~VM_EXEC;
94320 +#else
94321 + return -EPERM;
94322 +#endif
94323 +
94324 + }
94325 +
94326 + if (!(vm_flags & VM_EXEC))
94327 + vm_flags &= ~VM_MAYEXEC;
94328 +#else
94329 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
94330 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
94331 +#endif
94332 + else
94333 + vm_flags &= ~VM_MAYWRITE;
94334 + }
94335 +#endif
94336 +
94337 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
94338 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
94339 + vm_flags &= ~VM_PAGEEXEC;
94340 +#endif
94341 +
94342 if (flags & MAP_LOCKED)
94343 if (!can_do_mlock())
94344 return -EPERM;
94345 @@ -1363,6 +1484,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
94346 vm_flags |= VM_NORESERVE;
94347 }
94348
94349 + if (!gr_acl_handle_mmap(file, prot))
94350 + return -EACCES;
94351 +
94352 addr = mmap_region(file, addr, len, vm_flags, pgoff);
94353 if (!IS_ERR_VALUE(addr) &&
94354 ((vm_flags & VM_LOCKED) ||
94355 @@ -1456,7 +1580,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
94356 vm_flags_t vm_flags = vma->vm_flags;
94357
94358 /* If it was private or non-writable, the write bit is already clear */
94359 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
94360 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
94361 return 0;
94362
94363 /* The backer wishes to know when pages are first written to? */
94364 @@ -1502,7 +1626,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
94365 struct rb_node **rb_link, *rb_parent;
94366 unsigned long charged = 0;
94367
94368 +#ifdef CONFIG_PAX_SEGMEXEC
94369 + struct vm_area_struct *vma_m = NULL;
94370 +#endif
94371 +
94372 + /*
94373 + * mm->mmap_sem is required to protect against another thread
94374 + * changing the mappings in case we sleep.
94375 + */
94376 + verify_mm_writelocked(mm);
94377 +
94378 /* Check against address space limit. */
94379 +
94380 +#ifdef CONFIG_PAX_RANDMMAP
94381 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
94382 +#endif
94383 +
94384 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
94385 unsigned long nr_pages;
94386
94387 @@ -1521,11 +1660,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
94388
94389 /* Clear old maps */
94390 error = -ENOMEM;
94391 -munmap_back:
94392 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
94393 if (do_munmap(mm, addr, len))
94394 return -ENOMEM;
94395 - goto munmap_back;
94396 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
94397 }
94398
94399 /*
94400 @@ -1556,6 +1694,16 @@ munmap_back:
94401 goto unacct_error;
94402 }
94403
94404 +#ifdef CONFIG_PAX_SEGMEXEC
94405 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
94406 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94407 + if (!vma_m) {
94408 + error = -ENOMEM;
94409 + goto free_vma;
94410 + }
94411 + }
94412 +#endif
94413 +
94414 vma->vm_mm = mm;
94415 vma->vm_start = addr;
94416 vma->vm_end = addr + len;
94417 @@ -1575,6 +1723,13 @@ munmap_back:
94418 if (error)
94419 goto unmap_and_free_vma;
94420
94421 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
94422 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
94423 + vma->vm_flags |= VM_PAGEEXEC;
94424 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
94425 + }
94426 +#endif
94427 +
94428 /* Can addr have changed??
94429 *
94430 * Answer: Yes, several device drivers can do it in their
94431 @@ -1608,6 +1763,12 @@ munmap_back:
94432 }
94433
94434 vma_link(mm, vma, prev, rb_link, rb_parent);
94435 +
94436 +#ifdef CONFIG_PAX_SEGMEXEC
94437 + if (vma_m)
94438 + BUG_ON(pax_mirror_vma(vma_m, vma));
94439 +#endif
94440 +
94441 /* Once vma denies write, undo our temporary denial count */
94442 if (vm_flags & VM_DENYWRITE)
94443 allow_write_access(file);
94444 @@ -1616,6 +1777,7 @@ out:
94445 perf_event_mmap(vma);
94446
94447 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
94448 + track_exec_limit(mm, addr, addr + len, vm_flags);
94449 if (vm_flags & VM_LOCKED) {
94450 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
94451 vma == get_gate_vma(current->mm)))
94452 @@ -1648,6 +1810,12 @@ unmap_and_free_vma:
94453 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
94454 charged = 0;
94455 free_vma:
94456 +
94457 +#ifdef CONFIG_PAX_SEGMEXEC
94458 + if (vma_m)
94459 + kmem_cache_free(vm_area_cachep, vma_m);
94460 +#endif
94461 +
94462 kmem_cache_free(vm_area_cachep, vma);
94463 unacct_error:
94464 if (charged)
94465 @@ -1655,7 +1823,63 @@ unacct_error:
94466 return error;
94467 }
94468
94469 -unsigned long unmapped_area(struct vm_unmapped_area_info *info)
94470 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
94471 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
94472 +{
94473 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
94474 + return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
94475 +
94476 + return 0;
94477 +}
94478 +#endif
94479 +
94480 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
94481 +{
94482 + if (!vma) {
94483 +#ifdef CONFIG_STACK_GROWSUP
94484 + if (addr > sysctl_heap_stack_gap)
94485 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
94486 + else
94487 + vma = find_vma(current->mm, 0);
94488 + if (vma && (vma->vm_flags & VM_GROWSUP))
94489 + return false;
94490 +#endif
94491 + return true;
94492 + }
94493 +
94494 + if (addr + len > vma->vm_start)
94495 + return false;
94496 +
94497 + if (vma->vm_flags & VM_GROWSDOWN)
94498 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
94499 +#ifdef CONFIG_STACK_GROWSUP
94500 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
94501 + return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
94502 +#endif
94503 + else if (offset)
94504 + return offset <= vma->vm_start - addr - len;
94505 +
94506 + return true;
94507 +}
94508 +
94509 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
94510 +{
94511 + if (vma->vm_start < len)
94512 + return -ENOMEM;
94513 +
94514 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
94515 + if (offset <= vma->vm_start - len)
94516 + return vma->vm_start - len - offset;
94517 + else
94518 + return -ENOMEM;
94519 + }
94520 +
94521 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
94522 + return vma->vm_start - len - sysctl_heap_stack_gap;
94523 + return -ENOMEM;
94524 +}
94525 +
94526 +unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
94527 {
94528 /*
94529 * We implement the search by looking for an rbtree node that
94530 @@ -1703,11 +1927,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
94531 }
94532 }
94533
94534 - gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
94535 + gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
94536 check_current:
94537 /* Check if current node has a suitable gap */
94538 if (gap_start > high_limit)
94539 return -ENOMEM;
94540 +
94541 + if (gap_end - gap_start > info->threadstack_offset)
94542 + gap_start += info->threadstack_offset;
94543 + else
94544 + gap_start = gap_end;
94545 +
94546 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
94547 + if (gap_end - gap_start > sysctl_heap_stack_gap)
94548 + gap_start += sysctl_heap_stack_gap;
94549 + else
94550 + gap_start = gap_end;
94551 + }
94552 + if (vma->vm_flags & VM_GROWSDOWN) {
94553 + if (gap_end - gap_start > sysctl_heap_stack_gap)
94554 + gap_end -= sysctl_heap_stack_gap;
94555 + else
94556 + gap_end = gap_start;
94557 + }
94558 if (gap_end >= low_limit && gap_end - gap_start >= length)
94559 goto found;
94560
94561 @@ -1757,7 +1999,7 @@ found:
94562 return gap_start;
94563 }
94564
94565 -unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
94566 +unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
94567 {
94568 struct mm_struct *mm = current->mm;
94569 struct vm_area_struct *vma;
94570 @@ -1811,6 +2053,24 @@ check_current:
94571 gap_end = vma->vm_start;
94572 if (gap_end < low_limit)
94573 return -ENOMEM;
94574 +
94575 + if (gap_end - gap_start > info->threadstack_offset)
94576 + gap_end -= info->threadstack_offset;
94577 + else
94578 + gap_end = gap_start;
94579 +
94580 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
94581 + if (gap_end - gap_start > sysctl_heap_stack_gap)
94582 + gap_start += sysctl_heap_stack_gap;
94583 + else
94584 + gap_start = gap_end;
94585 + }
94586 + if (vma->vm_flags & VM_GROWSDOWN) {
94587 + if (gap_end - gap_start > sysctl_heap_stack_gap)
94588 + gap_end -= sysctl_heap_stack_gap;
94589 + else
94590 + gap_end = gap_start;
94591 + }
94592 if (gap_start <= high_limit && gap_end - gap_start >= length)
94593 goto found;
94594
94595 @@ -1874,6 +2134,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94596 struct mm_struct *mm = current->mm;
94597 struct vm_area_struct *vma;
94598 struct vm_unmapped_area_info info;
94599 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
94600
94601 if (len > TASK_SIZE - mmap_min_addr)
94602 return -ENOMEM;
94603 @@ -1881,11 +2142,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94604 if (flags & MAP_FIXED)
94605 return addr;
94606
94607 +#ifdef CONFIG_PAX_RANDMMAP
94608 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
94609 +#endif
94610 +
94611 if (addr) {
94612 addr = PAGE_ALIGN(addr);
94613 vma = find_vma(mm, addr);
94614 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
94615 - (!vma || addr + len <= vma->vm_start))
94616 + check_heap_stack_gap(vma, addr, len, offset))
94617 return addr;
94618 }
94619
94620 @@ -1894,6 +2159,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94621 info.low_limit = mm->mmap_base;
94622 info.high_limit = TASK_SIZE;
94623 info.align_mask = 0;
94624 + info.threadstack_offset = offset;
94625 return vm_unmapped_area(&info);
94626 }
94627 #endif
94628 @@ -1912,6 +2178,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94629 struct mm_struct *mm = current->mm;
94630 unsigned long addr = addr0;
94631 struct vm_unmapped_area_info info;
94632 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
94633
94634 /* requested length too big for entire address space */
94635 if (len > TASK_SIZE - mmap_min_addr)
94636 @@ -1920,12 +2187,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94637 if (flags & MAP_FIXED)
94638 return addr;
94639
94640 +#ifdef CONFIG_PAX_RANDMMAP
94641 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
94642 +#endif
94643 +
94644 /* requesting a specific address */
94645 if (addr) {
94646 addr = PAGE_ALIGN(addr);
94647 vma = find_vma(mm, addr);
94648 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
94649 - (!vma || addr + len <= vma->vm_start))
94650 + check_heap_stack_gap(vma, addr, len, offset))
94651 return addr;
94652 }
94653
94654 @@ -1934,6 +2205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94655 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
94656 info.high_limit = mm->mmap_base;
94657 info.align_mask = 0;
94658 + info.threadstack_offset = offset;
94659 addr = vm_unmapped_area(&info);
94660
94661 /*
94662 @@ -1946,6 +2218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94663 VM_BUG_ON(addr != -ENOMEM);
94664 info.flags = 0;
94665 info.low_limit = TASK_UNMAPPED_BASE;
94666 +
94667 +#ifdef CONFIG_PAX_RANDMMAP
94668 + if (mm->pax_flags & MF_PAX_RANDMMAP)
94669 + info.low_limit += mm->delta_mmap;
94670 +#endif
94671 +
94672 info.high_limit = TASK_SIZE;
94673 addr = vm_unmapped_area(&info);
94674 }
94675 @@ -2046,6 +2324,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
94676 return vma;
94677 }
94678
94679 +#ifdef CONFIG_PAX_SEGMEXEC
94680 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
94681 +{
94682 + struct vm_area_struct *vma_m;
94683 +
94684 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
94685 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
94686 + BUG_ON(vma->vm_mirror);
94687 + return NULL;
94688 + }
94689 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
94690 + vma_m = vma->vm_mirror;
94691 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
94692 + BUG_ON(vma->vm_file != vma_m->vm_file);
94693 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
94694 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
94695 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
94696 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
94697 + return vma_m;
94698 +}
94699 +#endif
94700 +
94701 /*
94702 * Verify that the stack growth is acceptable and
94703 * update accounting. This is shared with both the
94704 @@ -2062,6 +2362,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94705 return -ENOMEM;
94706
94707 /* Stack limit test */
94708 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
94709 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
94710 return -ENOMEM;
94711
94712 @@ -2072,6 +2373,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94713 locked = mm->locked_vm + grow;
94714 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
94715 limit >>= PAGE_SHIFT;
94716 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
94717 if (locked > limit && !capable(CAP_IPC_LOCK))
94718 return -ENOMEM;
94719 }
94720 @@ -2101,37 +2403,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94721 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
94722 * vma is the last one with address > vma->vm_end. Have to extend vma.
94723 */
94724 +#ifndef CONFIG_IA64
94725 +static
94726 +#endif
94727 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
94728 {
94729 int error;
94730 + bool locknext;
94731
94732 if (!(vma->vm_flags & VM_GROWSUP))
94733 return -EFAULT;
94734
94735 + /* Also guard against wrapping around to address 0. */
94736 + if (address < PAGE_ALIGN(address+1))
94737 + address = PAGE_ALIGN(address+1);
94738 + else
94739 + return -ENOMEM;
94740 +
94741 /*
94742 * We must make sure the anon_vma is allocated
94743 * so that the anon_vma locking is not a noop.
94744 */
94745 if (unlikely(anon_vma_prepare(vma)))
94746 return -ENOMEM;
94747 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
94748 + if (locknext && anon_vma_prepare(vma->vm_next))
94749 + return -ENOMEM;
94750 vma_lock_anon_vma(vma);
94751 + if (locknext)
94752 + vma_lock_anon_vma(vma->vm_next);
94753
94754 /*
94755 * vma->vm_start/vm_end cannot change under us because the caller
94756 * is required to hold the mmap_sem in read mode. We need the
94757 - * anon_vma lock to serialize against concurrent expand_stacks.
94758 - * Also guard against wrapping around to address 0.
94759 + * anon_vma locks to serialize against concurrent expand_stacks
94760 + * and expand_upwards.
94761 */
94762 - if (address < PAGE_ALIGN(address+4))
94763 - address = PAGE_ALIGN(address+4);
94764 - else {
94765 - vma_unlock_anon_vma(vma);
94766 - return -ENOMEM;
94767 - }
94768 error = 0;
94769
94770 /* Somebody else might have raced and expanded it already */
94771 - if (address > vma->vm_end) {
94772 + 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)
94773 + error = -ENOMEM;
94774 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
94775 unsigned long size, grow;
94776
94777 size = address - vma->vm_start;
94778 @@ -2166,6 +2479,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
94779 }
94780 }
94781 }
94782 + if (locknext)
94783 + vma_unlock_anon_vma(vma->vm_next);
94784 vma_unlock_anon_vma(vma);
94785 khugepaged_enter_vma_merge(vma);
94786 validate_mm(vma->vm_mm);
94787 @@ -2180,6 +2495,8 @@ int expand_downwards(struct vm_area_struct *vma,
94788 unsigned long address)
94789 {
94790 int error;
94791 + bool lockprev = false;
94792 + struct vm_area_struct *prev;
94793
94794 /*
94795 * We must make sure the anon_vma is allocated
94796 @@ -2193,6 +2510,15 @@ int expand_downwards(struct vm_area_struct *vma,
94797 if (error)
94798 return error;
94799
94800 + prev = vma->vm_prev;
94801 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
94802 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
94803 +#endif
94804 + if (lockprev && anon_vma_prepare(prev))
94805 + return -ENOMEM;
94806 + if (lockprev)
94807 + vma_lock_anon_vma(prev);
94808 +
94809 vma_lock_anon_vma(vma);
94810
94811 /*
94812 @@ -2202,9 +2528,17 @@ int expand_downwards(struct vm_area_struct *vma,
94813 */
94814
94815 /* Somebody else might have raced and expanded it already */
94816 - if (address < vma->vm_start) {
94817 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
94818 + error = -ENOMEM;
94819 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
94820 unsigned long size, grow;
94821
94822 +#ifdef CONFIG_PAX_SEGMEXEC
94823 + struct vm_area_struct *vma_m;
94824 +
94825 + vma_m = pax_find_mirror_vma(vma);
94826 +#endif
94827 +
94828 size = vma->vm_end - address;
94829 grow = (vma->vm_start - address) >> PAGE_SHIFT;
94830
94831 @@ -2229,13 +2563,27 @@ int expand_downwards(struct vm_area_struct *vma,
94832 vma->vm_pgoff -= grow;
94833 anon_vma_interval_tree_post_update_vma(vma);
94834 vma_gap_update(vma);
94835 +
94836 +#ifdef CONFIG_PAX_SEGMEXEC
94837 + if (vma_m) {
94838 + anon_vma_interval_tree_pre_update_vma(vma_m);
94839 + vma_m->vm_start -= grow << PAGE_SHIFT;
94840 + vma_m->vm_pgoff -= grow;
94841 + anon_vma_interval_tree_post_update_vma(vma_m);
94842 + vma_gap_update(vma_m);
94843 + }
94844 +#endif
94845 +
94846 spin_unlock(&vma->vm_mm->page_table_lock);
94847
94848 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
94849 perf_event_mmap(vma);
94850 }
94851 }
94852 }
94853 vma_unlock_anon_vma(vma);
94854 + if (lockprev)
94855 + vma_unlock_anon_vma(prev);
94856 khugepaged_enter_vma_merge(vma);
94857 validate_mm(vma->vm_mm);
94858 return error;
94859 @@ -2333,6 +2681,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
94860 do {
94861 long nrpages = vma_pages(vma);
94862
94863 +#ifdef CONFIG_PAX_SEGMEXEC
94864 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
94865 + vma = remove_vma(vma);
94866 + continue;
94867 + }
94868 +#endif
94869 +
94870 if (vma->vm_flags & VM_ACCOUNT)
94871 nr_accounted += nrpages;
94872 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
94873 @@ -2377,6 +2732,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
94874 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
94875 vma->vm_prev = NULL;
94876 do {
94877 +
94878 +#ifdef CONFIG_PAX_SEGMEXEC
94879 + if (vma->vm_mirror) {
94880 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
94881 + vma->vm_mirror->vm_mirror = NULL;
94882 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
94883 + vma->vm_mirror = NULL;
94884 + }
94885 +#endif
94886 +
94887 vma_rb_erase(vma, &mm->mm_rb);
94888 mm->map_count--;
94889 tail_vma = vma;
94890 @@ -2404,14 +2769,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94891 struct vm_area_struct *new;
94892 int err = -ENOMEM;
94893
94894 +#ifdef CONFIG_PAX_SEGMEXEC
94895 + struct vm_area_struct *vma_m, *new_m = NULL;
94896 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
94897 +#endif
94898 +
94899 if (is_vm_hugetlb_page(vma) && (addr &
94900 ~(huge_page_mask(hstate_vma(vma)))))
94901 return -EINVAL;
94902
94903 +#ifdef CONFIG_PAX_SEGMEXEC
94904 + vma_m = pax_find_mirror_vma(vma);
94905 +#endif
94906 +
94907 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
94908 if (!new)
94909 goto out_err;
94910
94911 +#ifdef CONFIG_PAX_SEGMEXEC
94912 + if (vma_m) {
94913 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
94914 + if (!new_m) {
94915 + kmem_cache_free(vm_area_cachep, new);
94916 + goto out_err;
94917 + }
94918 + }
94919 +#endif
94920 +
94921 /* most fields are the same, copy all, and then fixup */
94922 *new = *vma;
94923
94924 @@ -2424,6 +2808,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94925 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
94926 }
94927
94928 +#ifdef CONFIG_PAX_SEGMEXEC
94929 + if (vma_m) {
94930 + *new_m = *vma_m;
94931 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
94932 + new_m->vm_mirror = new;
94933 + new->vm_mirror = new_m;
94934 +
94935 + if (new_below)
94936 + new_m->vm_end = addr_m;
94937 + else {
94938 + new_m->vm_start = addr_m;
94939 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
94940 + }
94941 + }
94942 +#endif
94943 +
94944 err = vma_dup_policy(vma, new);
94945 if (err)
94946 goto out_free_vma;
94947 @@ -2443,6 +2843,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94948 else
94949 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
94950
94951 +#ifdef CONFIG_PAX_SEGMEXEC
94952 + if (!err && vma_m) {
94953 + struct mempolicy *pol = vma_policy(new);
94954 +
94955 + if (anon_vma_clone(new_m, vma_m))
94956 + goto out_free_mpol;
94957 +
94958 + mpol_get(pol);
94959 + set_vma_policy(new_m, pol);
94960 +
94961 + if (new_m->vm_file)
94962 + get_file(new_m->vm_file);
94963 +
94964 + if (new_m->vm_ops && new_m->vm_ops->open)
94965 + new_m->vm_ops->open(new_m);
94966 +
94967 + if (new_below)
94968 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
94969 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
94970 + else
94971 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
94972 +
94973 + if (err) {
94974 + if (new_m->vm_ops && new_m->vm_ops->close)
94975 + new_m->vm_ops->close(new_m);
94976 + if (new_m->vm_file)
94977 + fput(new_m->vm_file);
94978 + mpol_put(pol);
94979 + }
94980 + }
94981 +#endif
94982 +
94983 /* Success. */
94984 if (!err)
94985 return 0;
94986 @@ -2452,10 +2884,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94987 new->vm_ops->close(new);
94988 if (new->vm_file)
94989 fput(new->vm_file);
94990 - unlink_anon_vmas(new);
94991 out_free_mpol:
94992 mpol_put(vma_policy(new));
94993 out_free_vma:
94994 +
94995 +#ifdef CONFIG_PAX_SEGMEXEC
94996 + if (new_m) {
94997 + unlink_anon_vmas(new_m);
94998 + kmem_cache_free(vm_area_cachep, new_m);
94999 + }
95000 +#endif
95001 +
95002 + unlink_anon_vmas(new);
95003 kmem_cache_free(vm_area_cachep, new);
95004 out_err:
95005 return err;
95006 @@ -2468,6 +2908,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
95007 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
95008 unsigned long addr, int new_below)
95009 {
95010 +
95011 +#ifdef CONFIG_PAX_SEGMEXEC
95012 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
95013 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
95014 + if (mm->map_count >= sysctl_max_map_count-1)
95015 + return -ENOMEM;
95016 + } else
95017 +#endif
95018 +
95019 if (mm->map_count >= sysctl_max_map_count)
95020 return -ENOMEM;
95021
95022 @@ -2479,11 +2928,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
95023 * work. This now handles partial unmappings.
95024 * Jeremy Fitzhardinge <jeremy@goop.org>
95025 */
95026 +#ifdef CONFIG_PAX_SEGMEXEC
95027 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
95028 {
95029 + int ret = __do_munmap(mm, start, len);
95030 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
95031 + return ret;
95032 +
95033 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
95034 +}
95035 +
95036 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
95037 +#else
95038 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
95039 +#endif
95040 +{
95041 unsigned long end;
95042 struct vm_area_struct *vma, *prev, *last;
95043
95044 + /*
95045 + * mm->mmap_sem is required to protect against another thread
95046 + * changing the mappings in case we sleep.
95047 + */
95048 + verify_mm_writelocked(mm);
95049 +
95050 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
95051 return -EINVAL;
95052
95053 @@ -2558,6 +3026,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
95054 /* Fix up all other VM information */
95055 remove_vma_list(mm, vma);
95056
95057 + track_exec_limit(mm, start, end, 0UL);
95058 +
95059 return 0;
95060 }
95061
95062 @@ -2566,6 +3036,13 @@ int vm_munmap(unsigned long start, size_t len)
95063 int ret;
95064 struct mm_struct *mm = current->mm;
95065
95066 +
95067 +#ifdef CONFIG_PAX_SEGMEXEC
95068 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
95069 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
95070 + return -EINVAL;
95071 +#endif
95072 +
95073 down_write(&mm->mmap_sem);
95074 ret = do_munmap(mm, start, len);
95075 up_write(&mm->mmap_sem);
95076 @@ -2579,16 +3056,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
95077 return vm_munmap(addr, len);
95078 }
95079
95080 -static inline void verify_mm_writelocked(struct mm_struct *mm)
95081 -{
95082 -#ifdef CONFIG_DEBUG_VM
95083 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
95084 - WARN_ON(1);
95085 - up_read(&mm->mmap_sem);
95086 - }
95087 -#endif
95088 -}
95089 -
95090 /*
95091 * this is really a simplified "do_mmap". it only handles
95092 * anonymous maps. eventually we may be able to do some
95093 @@ -2602,6 +3069,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
95094 struct rb_node ** rb_link, * rb_parent;
95095 pgoff_t pgoff = addr >> PAGE_SHIFT;
95096 int error;
95097 + unsigned long charged;
95098
95099 len = PAGE_ALIGN(len);
95100 if (!len)
95101 @@ -2609,10 +3077,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
95102
95103 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
95104
95105 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
95106 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
95107 + flags &= ~VM_EXEC;
95108 +
95109 +#ifdef CONFIG_PAX_MPROTECT
95110 + if (mm->pax_flags & MF_PAX_MPROTECT)
95111 + flags &= ~VM_MAYEXEC;
95112 +#endif
95113 +
95114 + }
95115 +#endif
95116 +
95117 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
95118 if (error & ~PAGE_MASK)
95119 return error;
95120
95121 + charged = len >> PAGE_SHIFT;
95122 +
95123 error = mlock_future_check(mm, mm->def_flags, len);
95124 if (error)
95125 return error;
95126 @@ -2626,21 +3108,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
95127 /*
95128 * Clear old maps. this also does some error checking for us
95129 */
95130 - munmap_back:
95131 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
95132 if (do_munmap(mm, addr, len))
95133 return -ENOMEM;
95134 - goto munmap_back;
95135 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
95136 }
95137
95138 /* Check against address space limits *after* clearing old maps... */
95139 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
95140 + if (!may_expand_vm(mm, charged))
95141 return -ENOMEM;
95142
95143 if (mm->map_count > sysctl_max_map_count)
95144 return -ENOMEM;
95145
95146 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
95147 + if (security_vm_enough_memory_mm(mm, charged))
95148 return -ENOMEM;
95149
95150 /* Can we just expand an old private anonymous mapping? */
95151 @@ -2654,7 +3135,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
95152 */
95153 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
95154 if (!vma) {
95155 - vm_unacct_memory(len >> PAGE_SHIFT);
95156 + vm_unacct_memory(charged);
95157 return -ENOMEM;
95158 }
95159
95160 @@ -2668,10 +3149,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
95161 vma_link(mm, vma, prev, rb_link, rb_parent);
95162 out:
95163 perf_event_mmap(vma);
95164 - mm->total_vm += len >> PAGE_SHIFT;
95165 + mm->total_vm += charged;
95166 if (flags & VM_LOCKED)
95167 - mm->locked_vm += (len >> PAGE_SHIFT);
95168 + mm->locked_vm += charged;
95169 vma->vm_flags |= VM_SOFTDIRTY;
95170 + track_exec_limit(mm, addr, addr + len, flags);
95171 return addr;
95172 }
95173
95174 @@ -2733,6 +3215,7 @@ void exit_mmap(struct mm_struct *mm)
95175 while (vma) {
95176 if (vma->vm_flags & VM_ACCOUNT)
95177 nr_accounted += vma_pages(vma);
95178 + vma->vm_mirror = NULL;
95179 vma = remove_vma(vma);
95180 }
95181 vm_unacct_memory(nr_accounted);
95182 @@ -2750,6 +3233,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
95183 struct vm_area_struct *prev;
95184 struct rb_node **rb_link, *rb_parent;
95185
95186 +#ifdef CONFIG_PAX_SEGMEXEC
95187 + struct vm_area_struct *vma_m = NULL;
95188 +#endif
95189 +
95190 + if (security_mmap_addr(vma->vm_start))
95191 + return -EPERM;
95192 +
95193 /*
95194 * The vm_pgoff of a purely anonymous vma should be irrelevant
95195 * until its first write fault, when page's anon_vma and index
95196 @@ -2773,7 +3263,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
95197 security_vm_enough_memory_mm(mm, vma_pages(vma)))
95198 return -ENOMEM;
95199
95200 +#ifdef CONFIG_PAX_SEGMEXEC
95201 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
95202 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
95203 + if (!vma_m)
95204 + return -ENOMEM;
95205 + }
95206 +#endif
95207 +
95208 vma_link(mm, vma, prev, rb_link, rb_parent);
95209 +
95210 +#ifdef CONFIG_PAX_SEGMEXEC
95211 + if (vma_m)
95212 + BUG_ON(pax_mirror_vma(vma_m, vma));
95213 +#endif
95214 +
95215 return 0;
95216 }
95217
95218 @@ -2792,6 +3296,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
95219 struct rb_node **rb_link, *rb_parent;
95220 bool faulted_in_anon_vma = true;
95221
95222 + BUG_ON(vma->vm_mirror);
95223 +
95224 /*
95225 * If anonymous vma has not yet been faulted, update new pgoff
95226 * to match new location, to increase its chance of merging.
95227 @@ -2856,6 +3362,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
95228 return NULL;
95229 }
95230
95231 +#ifdef CONFIG_PAX_SEGMEXEC
95232 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
95233 +{
95234 + struct vm_area_struct *prev_m;
95235 + struct rb_node **rb_link_m, *rb_parent_m;
95236 + struct mempolicy *pol_m;
95237 +
95238 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
95239 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
95240 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
95241 + *vma_m = *vma;
95242 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
95243 + if (anon_vma_clone(vma_m, vma))
95244 + return -ENOMEM;
95245 + pol_m = vma_policy(vma_m);
95246 + mpol_get(pol_m);
95247 + set_vma_policy(vma_m, pol_m);
95248 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
95249 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
95250 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
95251 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
95252 + if (vma_m->vm_file)
95253 + get_file(vma_m->vm_file);
95254 + if (vma_m->vm_ops && vma_m->vm_ops->open)
95255 + vma_m->vm_ops->open(vma_m);
95256 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
95257 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
95258 + vma_m->vm_mirror = vma;
95259 + vma->vm_mirror = vma_m;
95260 + return 0;
95261 +}
95262 +#endif
95263 +
95264 /*
95265 * Return true if the calling process may expand its vm space by the passed
95266 * number of pages
95267 @@ -2867,6 +3406,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
95268
95269 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
95270
95271 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
95272 if (cur + npages > lim)
95273 return 0;
95274 return 1;
95275 @@ -2937,6 +3477,22 @@ struct vm_area_struct *_install_special_mapping(struct mm_struct *mm,
95276 vma->vm_start = addr;
95277 vma->vm_end = addr + len;
95278
95279 +#ifdef CONFIG_PAX_MPROTECT
95280 + if (mm->pax_flags & MF_PAX_MPROTECT) {
95281 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
95282 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
95283 + return ERR_PTR(-EPERM);
95284 + if (!(vm_flags & VM_EXEC))
95285 + vm_flags &= ~VM_MAYEXEC;
95286 +#else
95287 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
95288 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
95289 +#endif
95290 + else
95291 + vm_flags &= ~VM_MAYWRITE;
95292 + }
95293 +#endif
95294 +
95295 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
95296 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
95297
95298 diff --git a/mm/mprotect.c b/mm/mprotect.c
95299 index c43d557..0b7ccd2 100644
95300 --- a/mm/mprotect.c
95301 +++ b/mm/mprotect.c
95302 @@ -24,10 +24,18 @@
95303 #include <linux/migrate.h>
95304 #include <linux/perf_event.h>
95305 #include <linux/ksm.h>
95306 +#include <linux/sched/sysctl.h>
95307 +
95308 +#ifdef CONFIG_PAX_MPROTECT
95309 +#include <linux/elf.h>
95310 +#include <linux/binfmts.h>
95311 +#endif
95312 +
95313 #include <asm/uaccess.h>
95314 #include <asm/pgtable.h>
95315 #include <asm/cacheflush.h>
95316 #include <asm/tlbflush.h>
95317 +#include <asm/mmu_context.h>
95318
95319 #ifndef pgprot_modify
95320 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
95321 @@ -256,6 +264,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
95322 return pages;
95323 }
95324
95325 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
95326 +/* called while holding the mmap semaphor for writing except stack expansion */
95327 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
95328 +{
95329 + unsigned long oldlimit, newlimit = 0UL;
95330 +
95331 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
95332 + return;
95333 +
95334 + spin_lock(&mm->page_table_lock);
95335 + oldlimit = mm->context.user_cs_limit;
95336 + if ((prot & VM_EXEC) && oldlimit < end)
95337 + /* USER_CS limit moved up */
95338 + newlimit = end;
95339 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
95340 + /* USER_CS limit moved down */
95341 + newlimit = start;
95342 +
95343 + if (newlimit) {
95344 + mm->context.user_cs_limit = newlimit;
95345 +
95346 +#ifdef CONFIG_SMP
95347 + wmb();
95348 + cpus_clear(mm->context.cpu_user_cs_mask);
95349 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
95350 +#endif
95351 +
95352 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
95353 + }
95354 + spin_unlock(&mm->page_table_lock);
95355 + if (newlimit == end) {
95356 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
95357 +
95358 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
95359 + if (is_vm_hugetlb_page(vma))
95360 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
95361 + else
95362 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
95363 + }
95364 +}
95365 +#endif
95366 +
95367 int
95368 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
95369 unsigned long start, unsigned long end, unsigned long newflags)
95370 @@ -268,11 +318,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
95371 int error;
95372 int dirty_accountable = 0;
95373
95374 +#ifdef CONFIG_PAX_SEGMEXEC
95375 + struct vm_area_struct *vma_m = NULL;
95376 + unsigned long start_m, end_m;
95377 +
95378 + start_m = start + SEGMEXEC_TASK_SIZE;
95379 + end_m = end + SEGMEXEC_TASK_SIZE;
95380 +#endif
95381 +
95382 if (newflags == oldflags) {
95383 *pprev = vma;
95384 return 0;
95385 }
95386
95387 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
95388 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
95389 +
95390 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
95391 + return -ENOMEM;
95392 +
95393 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
95394 + return -ENOMEM;
95395 + }
95396 +
95397 /*
95398 * If we make a private mapping writable we increase our commit;
95399 * but (without finer accounting) cannot reduce our commit if we
95400 @@ -289,6 +357,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
95401 }
95402 }
95403
95404 +#ifdef CONFIG_PAX_SEGMEXEC
95405 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
95406 + if (start != vma->vm_start) {
95407 + error = split_vma(mm, vma, start, 1);
95408 + if (error)
95409 + goto fail;
95410 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
95411 + *pprev = (*pprev)->vm_next;
95412 + }
95413 +
95414 + if (end != vma->vm_end) {
95415 + error = split_vma(mm, vma, end, 0);
95416 + if (error)
95417 + goto fail;
95418 + }
95419 +
95420 + if (pax_find_mirror_vma(vma)) {
95421 + error = __do_munmap(mm, start_m, end_m - start_m);
95422 + if (error)
95423 + goto fail;
95424 + } else {
95425 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
95426 + if (!vma_m) {
95427 + error = -ENOMEM;
95428 + goto fail;
95429 + }
95430 + vma->vm_flags = newflags;
95431 + error = pax_mirror_vma(vma_m, vma);
95432 + if (error) {
95433 + vma->vm_flags = oldflags;
95434 + goto fail;
95435 + }
95436 + }
95437 + }
95438 +#endif
95439 +
95440 /*
95441 * First try to merge with previous and/or next vma.
95442 */
95443 @@ -319,9 +423,21 @@ success:
95444 * vm_flags and vm_page_prot are protected by the mmap_sem
95445 * held in write mode.
95446 */
95447 +
95448 +#ifdef CONFIG_PAX_SEGMEXEC
95449 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
95450 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
95451 +#endif
95452 +
95453 vma->vm_flags = newflags;
95454 +
95455 +#ifdef CONFIG_PAX_MPROTECT
95456 + if (mm->binfmt && mm->binfmt->handle_mprotect)
95457 + mm->binfmt->handle_mprotect(vma, newflags);
95458 +#endif
95459 +
95460 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
95461 - vm_get_page_prot(newflags));
95462 + vm_get_page_prot(vma->vm_flags));
95463
95464 if (vma_wants_writenotify(vma)) {
95465 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
95466 @@ -360,6 +476,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95467 end = start + len;
95468 if (end <= start)
95469 return -ENOMEM;
95470 +
95471 +#ifdef CONFIG_PAX_SEGMEXEC
95472 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
95473 + if (end > SEGMEXEC_TASK_SIZE)
95474 + return -EINVAL;
95475 + } else
95476 +#endif
95477 +
95478 + if (end > TASK_SIZE)
95479 + return -EINVAL;
95480 +
95481 if (!arch_validate_prot(prot))
95482 return -EINVAL;
95483
95484 @@ -367,7 +494,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95485 /*
95486 * Does the application expect PROT_READ to imply PROT_EXEC:
95487 */
95488 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
95489 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
95490 prot |= PROT_EXEC;
95491
95492 vm_flags = calc_vm_prot_bits(prot);
95493 @@ -399,6 +526,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95494 if (start > vma->vm_start)
95495 prev = vma;
95496
95497 +#ifdef CONFIG_PAX_MPROTECT
95498 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
95499 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
95500 +#endif
95501 +
95502 for (nstart = start ; ; ) {
95503 unsigned long newflags;
95504
95505 @@ -409,6 +541,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95506
95507 /* newflags >> 4 shift VM_MAY% in place of VM_% */
95508 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
95509 + if (prot & (PROT_WRITE | PROT_EXEC))
95510 + gr_log_rwxmprotect(vma);
95511 +
95512 + error = -EACCES;
95513 + goto out;
95514 + }
95515 +
95516 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
95517 error = -EACCES;
95518 goto out;
95519 }
95520 @@ -423,6 +563,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95521 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
95522 if (error)
95523 goto out;
95524 +
95525 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
95526 +
95527 nstart = tmp;
95528
95529 if (nstart < prev->vm_end)
95530 diff --git a/mm/mremap.c b/mm/mremap.c
95531 index 05f1180..c3cde48 100644
95532 --- a/mm/mremap.c
95533 +++ b/mm/mremap.c
95534 @@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
95535 continue;
95536 pte = ptep_get_and_clear(mm, old_addr, old_pte);
95537 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
95538 +
95539 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
95540 + if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
95541 + pte = pte_exprotect(pte);
95542 +#endif
95543 +
95544 pte = move_soft_dirty_pte(pte);
95545 set_pte_at(mm, new_addr, new_pte, pte);
95546 }
95547 @@ -344,6 +350,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
95548 if (is_vm_hugetlb_page(vma))
95549 goto Einval;
95550
95551 +#ifdef CONFIG_PAX_SEGMEXEC
95552 + if (pax_find_mirror_vma(vma))
95553 + goto Einval;
95554 +#endif
95555 +
95556 /* We can't remap across vm area boundaries */
95557 if (old_len > vma->vm_end - addr)
95558 goto Efault;
95559 @@ -399,20 +410,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
95560 unsigned long ret = -EINVAL;
95561 unsigned long charged = 0;
95562 unsigned long map_flags;
95563 + unsigned long pax_task_size = TASK_SIZE;
95564
95565 if (new_addr & ~PAGE_MASK)
95566 goto out;
95567
95568 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
95569 +#ifdef CONFIG_PAX_SEGMEXEC
95570 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
95571 + pax_task_size = SEGMEXEC_TASK_SIZE;
95572 +#endif
95573 +
95574 + pax_task_size -= PAGE_SIZE;
95575 +
95576 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
95577 goto out;
95578
95579 /* Check if the location we're moving into overlaps the
95580 * old location at all, and fail if it does.
95581 */
95582 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
95583 - goto out;
95584 -
95585 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
95586 + if (addr + old_len > new_addr && new_addr + new_len > addr)
95587 goto out;
95588
95589 ret = do_munmap(mm, new_addr, new_len);
95590 @@ -481,6 +497,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95591 unsigned long ret = -EINVAL;
95592 unsigned long charged = 0;
95593 bool locked = false;
95594 + unsigned long pax_task_size = TASK_SIZE;
95595
95596 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
95597 return ret;
95598 @@ -502,6 +519,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95599 if (!new_len)
95600 return ret;
95601
95602 +#ifdef CONFIG_PAX_SEGMEXEC
95603 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
95604 + pax_task_size = SEGMEXEC_TASK_SIZE;
95605 +#endif
95606 +
95607 + pax_task_size -= PAGE_SIZE;
95608 +
95609 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
95610 + old_len > pax_task_size || addr > pax_task_size-old_len)
95611 + return ret;
95612 +
95613 down_write(&current->mm->mmap_sem);
95614
95615 if (flags & MREMAP_FIXED) {
95616 @@ -552,6 +580,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95617 new_addr = addr;
95618 }
95619 ret = addr;
95620 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
95621 goto out;
95622 }
95623 }
95624 @@ -575,7 +604,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95625 goto out;
95626 }
95627
95628 + map_flags = vma->vm_flags;
95629 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
95630 + if (!(ret & ~PAGE_MASK)) {
95631 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
95632 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
95633 + }
95634 }
95635 out:
95636 if (ret & ~PAGE_MASK)
95637 diff --git a/mm/nommu.c b/mm/nommu.c
95638 index 431fd7c..8674512 100644
95639 --- a/mm/nommu.c
95640 +++ b/mm/nommu.c
95641 @@ -67,7 +67,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
95642 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
95643 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
95644 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
95645 -int heap_stack_gap = 0;
95646
95647 atomic_long_t mmap_pages_allocated;
95648
95649 @@ -854,15 +853,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
95650 EXPORT_SYMBOL(find_vma);
95651
95652 /*
95653 - * find a VMA
95654 - * - we don't extend stack VMAs under NOMMU conditions
95655 - */
95656 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
95657 -{
95658 - return find_vma(mm, addr);
95659 -}
95660 -
95661 -/*
95662 * expand a stack to a given address
95663 * - not supported under NOMMU conditions
95664 */
95665 @@ -1569,6 +1559,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
95666
95667 /* most fields are the same, copy all, and then fixup */
95668 *new = *vma;
95669 + INIT_LIST_HEAD(&new->anon_vma_chain);
95670 *region = *vma->vm_region;
95671 new->vm_region = region;
95672
95673 @@ -2004,8 +1995,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
95674 }
95675 EXPORT_SYMBOL(generic_file_remap_pages);
95676
95677 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95678 - unsigned long addr, void *buf, int len, int write)
95679 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95680 + unsigned long addr, void *buf, size_t len, int write)
95681 {
95682 struct vm_area_struct *vma;
95683
95684 @@ -2046,8 +2037,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95685 *
95686 * The caller must hold a reference on @mm.
95687 */
95688 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
95689 - void *buf, int len, int write)
95690 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
95691 + void *buf, size_t len, int write)
95692 {
95693 return __access_remote_vm(NULL, mm, addr, buf, len, write);
95694 }
95695 @@ -2056,7 +2047,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
95696 * Access another process' address space.
95697 * - source/target buffer must be kernel space
95698 */
95699 -int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
95700 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
95701 {
95702 struct mm_struct *mm;
95703
95704 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
95705 index f972182..e7f7c07 100644
95706 --- a/mm/page-writeback.c
95707 +++ b/mm/page-writeback.c
95708 @@ -685,7 +685,7 @@ static long long pos_ratio_polynom(unsigned long setpoint,
95709 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
95710 * - the bdi dirty thresh drops quickly due to change of JBOD workload
95711 */
95712 -static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
95713 +static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
95714 unsigned long thresh,
95715 unsigned long bg_thresh,
95716 unsigned long dirty,
95717 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
95718 index e98306f..3311d5e 100644
95719 --- a/mm/page_alloc.c
95720 +++ b/mm/page_alloc.c
95721 @@ -61,6 +61,7 @@
95722 #include <linux/page-debug-flags.h>
95723 #include <linux/hugetlb.h>
95724 #include <linux/sched/rt.h>
95725 +#include <linux/random.h>
95726
95727 #include <asm/sections.h>
95728 #include <asm/tlbflush.h>
95729 @@ -356,7 +357,7 @@ out:
95730 * This usage means that zero-order pages may not be compound.
95731 */
95732
95733 -static void free_compound_page(struct page *page)
95734 +void free_compound_page(struct page *page)
95735 {
95736 __free_pages_ok(page, compound_order(page));
95737 }
95738 @@ -730,6 +731,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
95739 int i;
95740 int bad = 0;
95741
95742 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95743 + unsigned long index = 1UL << order;
95744 +#endif
95745 +
95746 trace_mm_page_free(page, order);
95747 kmemcheck_free_shadow(page, order);
95748
95749 @@ -746,6 +751,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
95750 debug_check_no_obj_freed(page_address(page),
95751 PAGE_SIZE << order);
95752 }
95753 +
95754 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95755 + for (; index; --index)
95756 + sanitize_highpage(page + index - 1);
95757 +#endif
95758 +
95759 arch_free_page(page, order);
95760 kernel_map_pages(page, 1 << order, 0);
95761
95762 @@ -768,6 +779,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
95763 local_irq_restore(flags);
95764 }
95765
95766 +#ifdef CONFIG_PAX_LATENT_ENTROPY
95767 +bool __meminitdata extra_latent_entropy;
95768 +
95769 +static int __init setup_pax_extra_latent_entropy(char *str)
95770 +{
95771 + extra_latent_entropy = true;
95772 + return 0;
95773 +}
95774 +early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
95775 +
95776 +volatile u64 latent_entropy __latent_entropy;
95777 +EXPORT_SYMBOL(latent_entropy);
95778 +#endif
95779 +
95780 void __init __free_pages_bootmem(struct page *page, unsigned int order)
95781 {
95782 unsigned int nr_pages = 1 << order;
95783 @@ -783,6 +808,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
95784 __ClearPageReserved(p);
95785 set_page_count(p, 0);
95786
95787 +#ifdef CONFIG_PAX_LATENT_ENTROPY
95788 + if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
95789 + u64 hash = 0;
95790 + size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
95791 + const u64 *data = lowmem_page_address(page);
95792 +
95793 + for (index = 0; index < end; index++)
95794 + hash ^= hash + data[index];
95795 + latent_entropy ^= hash;
95796 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
95797 + }
95798 +#endif
95799 +
95800 page_zone(page)->managed_pages += nr_pages;
95801 set_page_refcounted(page);
95802 __free_pages(page, order);
95803 @@ -911,8 +949,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
95804 arch_alloc_page(page, order);
95805 kernel_map_pages(page, 1 << order, 1);
95806
95807 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
95808 if (gfp_flags & __GFP_ZERO)
95809 prep_zero_page(page, order, gfp_flags);
95810 +#endif
95811
95812 if (order && (gfp_flags & __GFP_COMP))
95813 prep_compound_page(page, order);
95814 @@ -2415,7 +2455,7 @@ static void reset_alloc_batches(struct zonelist *zonelist,
95815 continue;
95816 mod_zone_page_state(zone, NR_ALLOC_BATCH,
95817 high_wmark_pages(zone) - low_wmark_pages(zone) -
95818 - atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
95819 + atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
95820 }
95821 }
95822
95823 diff --git a/mm/page_io.c b/mm/page_io.c
95824 index 7c59ef6..1358905 100644
95825 --- a/mm/page_io.c
95826 +++ b/mm/page_io.c
95827 @@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
95828 struct file *swap_file = sis->swap_file;
95829 struct address_space *mapping = swap_file->f_mapping;
95830 struct iovec iov = {
95831 - .iov_base = kmap(page),
95832 + .iov_base = (void __force_user *)kmap(page),
95833 .iov_len = PAGE_SIZE,
95834 };
95835
95836 diff --git a/mm/percpu.c b/mm/percpu.c
95837 index 2ddf9a9..f8fc075 100644
95838 --- a/mm/percpu.c
95839 +++ b/mm/percpu.c
95840 @@ -123,7 +123,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
95841 static unsigned int pcpu_high_unit_cpu __read_mostly;
95842
95843 /* the address of the first chunk which starts with the kernel static area */
95844 -void *pcpu_base_addr __read_mostly;
95845 +void *pcpu_base_addr __read_only;
95846 EXPORT_SYMBOL_GPL(pcpu_base_addr);
95847
95848 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
95849 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
95850 index 8505c92..946bfc9 100644
95851 --- a/mm/process_vm_access.c
95852 +++ b/mm/process_vm_access.c
95853 @@ -13,6 +13,7 @@
95854 #include <linux/uio.h>
95855 #include <linux/sched.h>
95856 #include <linux/highmem.h>
95857 +#include <linux/security.h>
95858 #include <linux/ptrace.h>
95859 #include <linux/slab.h>
95860 #include <linux/syscalls.h>
95861 @@ -161,19 +162,19 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
95862 ssize_t iov_len;
95863 size_t total_len = iov_iter_count(iter);
95864
95865 + return -ENOSYS; // PaX: until properly audited
95866 +
95867 /*
95868 * Work out how many pages of struct pages we're going to need
95869 * when eventually calling get_user_pages
95870 */
95871 for (i = 0; i < riovcnt; i++) {
95872 iov_len = rvec[i].iov_len;
95873 - if (iov_len > 0) {
95874 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
95875 - + iov_len)
95876 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
95877 - / PAGE_SIZE + 1;
95878 - nr_pages = max(nr_pages, nr_pages_iov);
95879 - }
95880 + if (iov_len <= 0)
95881 + continue;
95882 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
95883 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
95884 + nr_pages = max(nr_pages, nr_pages_iov);
95885 }
95886
95887 if (nr_pages == 0)
95888 @@ -201,6 +202,11 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
95889 goto free_proc_pages;
95890 }
95891
95892 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
95893 + rc = -EPERM;
95894 + goto put_task_struct;
95895 + }
95896 +
95897 mm = mm_access(task, PTRACE_MODE_ATTACH);
95898 if (!mm || IS_ERR(mm)) {
95899 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
95900 diff --git a/mm/rmap.c b/mm/rmap.c
95901 index 14d1e28..3777962 100644
95902 --- a/mm/rmap.c
95903 +++ b/mm/rmap.c
95904 @@ -164,6 +164,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95905 struct anon_vma *anon_vma = vma->anon_vma;
95906 struct anon_vma_chain *avc;
95907
95908 +#ifdef CONFIG_PAX_SEGMEXEC
95909 + struct anon_vma_chain *avc_m = NULL;
95910 +#endif
95911 +
95912 might_sleep();
95913 if (unlikely(!anon_vma)) {
95914 struct mm_struct *mm = vma->vm_mm;
95915 @@ -173,6 +177,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95916 if (!avc)
95917 goto out_enomem;
95918
95919 +#ifdef CONFIG_PAX_SEGMEXEC
95920 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
95921 + if (!avc_m)
95922 + goto out_enomem_free_avc;
95923 +#endif
95924 +
95925 anon_vma = find_mergeable_anon_vma(vma);
95926 allocated = NULL;
95927 if (!anon_vma) {
95928 @@ -186,6 +196,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95929 /* page_table_lock to protect against threads */
95930 spin_lock(&mm->page_table_lock);
95931 if (likely(!vma->anon_vma)) {
95932 +
95933 +#ifdef CONFIG_PAX_SEGMEXEC
95934 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
95935 +
95936 + if (vma_m) {
95937 + BUG_ON(vma_m->anon_vma);
95938 + vma_m->anon_vma = anon_vma;
95939 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
95940 + avc_m = NULL;
95941 + }
95942 +#endif
95943 +
95944 vma->anon_vma = anon_vma;
95945 anon_vma_chain_link(vma, avc, anon_vma);
95946 allocated = NULL;
95947 @@ -196,12 +218,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95948
95949 if (unlikely(allocated))
95950 put_anon_vma(allocated);
95951 +
95952 +#ifdef CONFIG_PAX_SEGMEXEC
95953 + if (unlikely(avc_m))
95954 + anon_vma_chain_free(avc_m);
95955 +#endif
95956 +
95957 if (unlikely(avc))
95958 anon_vma_chain_free(avc);
95959 }
95960 return 0;
95961
95962 out_enomem_free_avc:
95963 +
95964 +#ifdef CONFIG_PAX_SEGMEXEC
95965 + if (avc_m)
95966 + anon_vma_chain_free(avc_m);
95967 +#endif
95968 +
95969 anon_vma_chain_free(avc);
95970 out_enomem:
95971 return -ENOMEM;
95972 @@ -237,7 +271,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
95973 * Attach the anon_vmas from src to dst.
95974 * Returns 0 on success, -ENOMEM on failure.
95975 */
95976 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
95977 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
95978 {
95979 struct anon_vma_chain *avc, *pavc;
95980 struct anon_vma *root = NULL;
95981 @@ -270,7 +304,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
95982 * the corresponding VMA in the parent process is attached to.
95983 * Returns 0 on success, non-zero on failure.
95984 */
95985 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
95986 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
95987 {
95988 struct anon_vma_chain *avc;
95989 struct anon_vma *anon_vma;
95990 @@ -374,8 +408,10 @@ static void anon_vma_ctor(void *data)
95991 void __init anon_vma_init(void)
95992 {
95993 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
95994 - 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
95995 - anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
95996 + 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
95997 + anon_vma_ctor);
95998 + anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
95999 + SLAB_PANIC|SLAB_NO_SANITIZE);
96000 }
96001
96002 /*
96003 diff --git a/mm/shmem.c b/mm/shmem.c
96004 index a731cef..1e82984 100644
96005 --- a/mm/shmem.c
96006 +++ b/mm/shmem.c
96007 @@ -33,7 +33,7 @@
96008 #include <linux/swap.h>
96009 #include <linux/aio.h>
96010
96011 -static struct vfsmount *shm_mnt;
96012 +struct vfsmount *shm_mnt;
96013
96014 #ifdef CONFIG_SHMEM
96015 /*
96016 @@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
96017 #define BOGO_DIRENT_SIZE 20
96018
96019 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
96020 -#define SHORT_SYMLINK_LEN 128
96021 +#define SHORT_SYMLINK_LEN 64
96022
96023 /*
96024 * shmem_fallocate communicates with shmem_fault or shmem_writepage via
96025 @@ -2218,6 +2218,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
96026 static int shmem_xattr_validate(const char *name)
96027 {
96028 struct { const char *prefix; size_t len; } arr[] = {
96029 +
96030 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
96031 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
96032 +#endif
96033 +
96034 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
96035 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
96036 };
96037 @@ -2273,6 +2278,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
96038 if (err)
96039 return err;
96040
96041 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
96042 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
96043 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
96044 + return -EOPNOTSUPP;
96045 + if (size > 8)
96046 + return -EINVAL;
96047 + }
96048 +#endif
96049 +
96050 return simple_xattr_set(&info->xattrs, name, value, size, flags);
96051 }
96052
96053 @@ -2585,8 +2599,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
96054 int err = -ENOMEM;
96055
96056 /* Round up to L1_CACHE_BYTES to resist false sharing */
96057 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
96058 - L1_CACHE_BYTES), GFP_KERNEL);
96059 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
96060 if (!sbinfo)
96061 return -ENOMEM;
96062
96063 diff --git a/mm/slab.c b/mm/slab.c
96064 index 9432556..e0dc685 100644
96065 --- a/mm/slab.c
96066 +++ b/mm/slab.c
96067 @@ -311,10 +311,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
96068 if ((x)->max_freeable < i) \
96069 (x)->max_freeable = i; \
96070 } while (0)
96071 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
96072 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
96073 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
96074 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
96075 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
96076 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
96077 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
96078 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
96079 +#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
96080 +#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
96081 #else
96082 #define STATS_INC_ACTIVE(x) do { } while (0)
96083 #define STATS_DEC_ACTIVE(x) do { } while (0)
96084 @@ -331,6 +333,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
96085 #define STATS_INC_ALLOCMISS(x) do { } while (0)
96086 #define STATS_INC_FREEHIT(x) do { } while (0)
96087 #define STATS_INC_FREEMISS(x) do { } while (0)
96088 +#define STATS_INC_SANITIZED(x) do { } while (0)
96089 +#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
96090 #endif
96091
96092 #if DEBUG
96093 @@ -447,7 +451,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
96094 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
96095 */
96096 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
96097 - const struct page *page, void *obj)
96098 + const struct page *page, const void *obj)
96099 {
96100 u32 offset = (obj - page->s_mem);
96101 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
96102 @@ -1558,12 +1562,12 @@ void __init kmem_cache_init(void)
96103 */
96104
96105 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
96106 - kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
96107 + kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
96108
96109 if (INDEX_AC != INDEX_NODE)
96110 kmalloc_caches[INDEX_NODE] =
96111 create_kmalloc_cache("kmalloc-node",
96112 - kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
96113 + kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
96114
96115 slab_early_init = 0;
96116
96117 @@ -3525,6 +3529,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
96118 struct array_cache *ac = cpu_cache_get(cachep);
96119
96120 check_irq_off();
96121 +
96122 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96123 + if (pax_sanitize_slab) {
96124 + if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
96125 + memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
96126 +
96127 + if (cachep->ctor)
96128 + cachep->ctor(objp);
96129 +
96130 + STATS_INC_SANITIZED(cachep);
96131 + } else
96132 + STATS_INC_NOT_SANITIZED(cachep);
96133 + }
96134 +#endif
96135 +
96136 kmemleak_free_recursive(objp, cachep->flags);
96137 objp = cache_free_debugcheck(cachep, objp, caller);
96138
96139 @@ -3748,6 +3767,7 @@ void kfree(const void *objp)
96140
96141 if (unlikely(ZERO_OR_NULL_PTR(objp)))
96142 return;
96143 + VM_BUG_ON(!virt_addr_valid(objp));
96144 local_irq_save(flags);
96145 kfree_debugcheck(objp);
96146 c = virt_to_cache(objp);
96147 @@ -4189,14 +4209,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
96148 }
96149 /* cpu stats */
96150 {
96151 - unsigned long allochit = atomic_read(&cachep->allochit);
96152 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
96153 - unsigned long freehit = atomic_read(&cachep->freehit);
96154 - unsigned long freemiss = atomic_read(&cachep->freemiss);
96155 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
96156 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
96157 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
96158 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
96159
96160 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
96161 allochit, allocmiss, freehit, freemiss);
96162 }
96163 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96164 + {
96165 + unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
96166 + unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
96167 +
96168 + seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
96169 + }
96170 +#endif
96171 #endif
96172 }
96173
96174 @@ -4417,13 +4445,69 @@ static const struct file_operations proc_slabstats_operations = {
96175 static int __init slab_proc_init(void)
96176 {
96177 #ifdef CONFIG_DEBUG_SLAB_LEAK
96178 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
96179 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
96180 #endif
96181 return 0;
96182 }
96183 module_init(slab_proc_init);
96184 #endif
96185
96186 +bool is_usercopy_object(const void *ptr)
96187 +{
96188 + struct page *page;
96189 + struct kmem_cache *cachep;
96190 +
96191 + if (ZERO_OR_NULL_PTR(ptr))
96192 + return false;
96193 +
96194 + if (!slab_is_available())
96195 + return false;
96196 +
96197 + if (!virt_addr_valid(ptr))
96198 + return false;
96199 +
96200 + page = virt_to_head_page(ptr);
96201 +
96202 + if (!PageSlab(page))
96203 + return false;
96204 +
96205 + cachep = page->slab_cache;
96206 + return cachep->flags & SLAB_USERCOPY;
96207 +}
96208 +
96209 +#ifdef CONFIG_PAX_USERCOPY
96210 +const char *check_heap_object(const void *ptr, unsigned long n)
96211 +{
96212 + struct page *page;
96213 + struct kmem_cache *cachep;
96214 + unsigned int objnr;
96215 + unsigned long offset;
96216 +
96217 + if (ZERO_OR_NULL_PTR(ptr))
96218 + return "<null>";
96219 +
96220 + if (!virt_addr_valid(ptr))
96221 + return NULL;
96222 +
96223 + page = virt_to_head_page(ptr);
96224 +
96225 + if (!PageSlab(page))
96226 + return NULL;
96227 +
96228 + cachep = page->slab_cache;
96229 + if (!(cachep->flags & SLAB_USERCOPY))
96230 + return cachep->name;
96231 +
96232 + objnr = obj_to_index(cachep, page, ptr);
96233 + BUG_ON(objnr >= cachep->num);
96234 + offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
96235 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
96236 + return NULL;
96237 +
96238 + return cachep->name;
96239 +}
96240 +#endif
96241 +
96242 /**
96243 * ksize - get the actual amount of memory allocated for a given object
96244 * @objp: Pointer to the object
96245 diff --git a/mm/slab.h b/mm/slab.h
96246 index 6bd4c35..97565a1 100644
96247 --- a/mm/slab.h
96248 +++ b/mm/slab.h
96249 @@ -32,6 +32,15 @@ extern struct list_head slab_caches;
96250 /* The slab cache that manages slab cache information */
96251 extern struct kmem_cache *kmem_cache;
96252
96253 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96254 +#ifdef CONFIG_X86_64
96255 +#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
96256 +#else
96257 +#define PAX_MEMORY_SANITIZE_VALUE '\xff'
96258 +#endif
96259 +extern bool pax_sanitize_slab;
96260 +#endif
96261 +
96262 unsigned long calculate_alignment(unsigned long flags,
96263 unsigned long align, unsigned long size);
96264
96265 @@ -67,7 +76,8 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
96266
96267 /* Legal flag mask for kmem_cache_create(), for various configurations */
96268 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
96269 - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
96270 + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
96271 + SLAB_USERCOPY | SLAB_NO_SANITIZE)
96272
96273 #if defined(CONFIG_DEBUG_SLAB)
96274 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
96275 @@ -245,6 +255,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
96276 return s;
96277
96278 page = virt_to_head_page(x);
96279 +
96280 + BUG_ON(!PageSlab(page));
96281 +
96282 cachep = page->slab_cache;
96283 if (slab_equal_or_root(cachep, s))
96284 return cachep;
96285 diff --git a/mm/slab_common.c b/mm/slab_common.c
96286 index b810fba..ae882bf 100644
96287 --- a/mm/slab_common.c
96288 +++ b/mm/slab_common.c
96289 @@ -23,11 +23,22 @@
96290
96291 #include "slab.h"
96292
96293 -enum slab_state slab_state;
96294 +enum slab_state slab_state __read_only;
96295 LIST_HEAD(slab_caches);
96296 DEFINE_MUTEX(slab_mutex);
96297 struct kmem_cache *kmem_cache;
96298
96299 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96300 +bool pax_sanitize_slab __read_only = true;
96301 +static int __init pax_sanitize_slab_setup(char *str)
96302 +{
96303 + pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
96304 + printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
96305 + return 1;
96306 +}
96307 +__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
96308 +#endif
96309 +
96310 #ifdef CONFIG_DEBUG_VM
96311 static int kmem_cache_sanity_check(const char *name, size_t size)
96312 {
96313 @@ -158,7 +169,7 @@ do_kmem_cache_create(char *name, size_t object_size, size_t size, size_t align,
96314 if (err)
96315 goto out_free_cache;
96316
96317 - s->refcount = 1;
96318 + atomic_set(&s->refcount, 1);
96319 list_add(&s->list, &slab_caches);
96320 memcg_register_cache(s);
96321 out:
96322 @@ -334,8 +345,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
96323 get_online_cpus();
96324 mutex_lock(&slab_mutex);
96325
96326 - s->refcount--;
96327 - if (s->refcount)
96328 + if (!atomic_dec_and_test(&s->refcount))
96329 goto out_unlock;
96330
96331 if (kmem_cache_destroy_memcg_children(s) != 0)
96332 @@ -358,7 +368,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
96333 rcu_barrier();
96334
96335 memcg_free_cache_params(s);
96336 -#ifdef SLAB_SUPPORTS_SYSFS
96337 +#if defined(SLAB_SUPPORTS_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96338 sysfs_slab_remove(s);
96339 #else
96340 slab_kmem_cache_release(s);
96341 @@ -393,7 +403,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
96342 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
96343 name, size, err);
96344
96345 - s->refcount = -1; /* Exempt from merging for now */
96346 + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
96347 }
96348
96349 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
96350 @@ -406,7 +416,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
96351
96352 create_boot_cache(s, name, size, flags);
96353 list_add(&s->list, &slab_caches);
96354 - s->refcount = 1;
96355 + atomic_set(&s->refcount, 1);
96356 return s;
96357 }
96358
96359 @@ -418,6 +428,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
96360 EXPORT_SYMBOL(kmalloc_dma_caches);
96361 #endif
96362
96363 +#ifdef CONFIG_PAX_USERCOPY_SLABS
96364 +struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
96365 +EXPORT_SYMBOL(kmalloc_usercopy_caches);
96366 +#endif
96367 +
96368 /*
96369 * Conversion table for small slabs sizes / 8 to the index in the
96370 * kmalloc array. This is necessary for slabs < 192 since we have non power
96371 @@ -482,6 +497,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
96372 return kmalloc_dma_caches[index];
96373
96374 #endif
96375 +
96376 +#ifdef CONFIG_PAX_USERCOPY_SLABS
96377 + if (unlikely((flags & GFP_USERCOPY)))
96378 + return kmalloc_usercopy_caches[index];
96379 +
96380 +#endif
96381 +
96382 return kmalloc_caches[index];
96383 }
96384
96385 @@ -538,7 +560,7 @@ void __init create_kmalloc_caches(unsigned long flags)
96386 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
96387 if (!kmalloc_caches[i]) {
96388 kmalloc_caches[i] = create_kmalloc_cache(NULL,
96389 - 1 << i, flags);
96390 + 1 << i, SLAB_USERCOPY | flags);
96391 }
96392
96393 /*
96394 @@ -547,10 +569,10 @@ void __init create_kmalloc_caches(unsigned long flags)
96395 * earlier power of two caches
96396 */
96397 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
96398 - kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
96399 + kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
96400
96401 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
96402 - kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
96403 + kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
96404 }
96405
96406 /* Kmalloc array is now usable */
96407 @@ -583,6 +605,23 @@ void __init create_kmalloc_caches(unsigned long flags)
96408 }
96409 }
96410 #endif
96411 +
96412 +#ifdef CONFIG_PAX_USERCOPY_SLABS
96413 + for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
96414 + struct kmem_cache *s = kmalloc_caches[i];
96415 +
96416 + if (s) {
96417 + int size = kmalloc_size(i);
96418 + char *n = kasprintf(GFP_NOWAIT,
96419 + "usercopy-kmalloc-%d", size);
96420 +
96421 + BUG_ON(!n);
96422 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
96423 + size, SLAB_USERCOPY | flags);
96424 + }
96425 + }
96426 +#endif
96427 +
96428 }
96429 #endif /* !CONFIG_SLOB */
96430
96431 @@ -623,6 +662,9 @@ void print_slabinfo_header(struct seq_file *m)
96432 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
96433 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
96434 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
96435 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96436 + seq_puts(m, " : pax <sanitized> <not_sanitized>");
96437 +#endif
96438 #endif
96439 seq_putc(m, '\n');
96440 }
96441 diff --git a/mm/slob.c b/mm/slob.c
96442 index 730cad4..8cfd442 100644
96443 --- a/mm/slob.c
96444 +++ b/mm/slob.c
96445 @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
96446 /*
96447 * Return the size of a slob block.
96448 */
96449 -static slobidx_t slob_units(slob_t *s)
96450 +static slobidx_t slob_units(const slob_t *s)
96451 {
96452 if (s->units > 0)
96453 return s->units;
96454 @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
96455 /*
96456 * Return the next free slob block pointer after this one.
96457 */
96458 -static slob_t *slob_next(slob_t *s)
96459 +static slob_t *slob_next(const slob_t *s)
96460 {
96461 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
96462 slobidx_t next;
96463 @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
96464 /*
96465 * Returns true if s is the last free block in its page.
96466 */
96467 -static int slob_last(slob_t *s)
96468 +static int slob_last(const slob_t *s)
96469 {
96470 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
96471 }
96472
96473 -static void *slob_new_pages(gfp_t gfp, int order, int node)
96474 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
96475 {
96476 - void *page;
96477 + struct page *page;
96478
96479 #ifdef CONFIG_NUMA
96480 if (node != NUMA_NO_NODE)
96481 @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
96482 if (!page)
96483 return NULL;
96484
96485 - return page_address(page);
96486 + __SetPageSlab(page);
96487 + return page;
96488 }
96489
96490 -static void slob_free_pages(void *b, int order)
96491 +static void slob_free_pages(struct page *sp, int order)
96492 {
96493 if (current->reclaim_state)
96494 current->reclaim_state->reclaimed_slab += 1 << order;
96495 - free_pages((unsigned long)b, order);
96496 + __ClearPageSlab(sp);
96497 + page_mapcount_reset(sp);
96498 + sp->private = 0;
96499 + __free_pages(sp, order);
96500 }
96501
96502 /*
96503 @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
96504
96505 /* Not enough space: must allocate a new page */
96506 if (!b) {
96507 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
96508 - if (!b)
96509 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
96510 + if (!sp)
96511 return NULL;
96512 - sp = virt_to_page(b);
96513 - __SetPageSlab(sp);
96514 + b = page_address(sp);
96515
96516 spin_lock_irqsave(&slob_lock, flags);
96517 sp->units = SLOB_UNITS(PAGE_SIZE);
96518 sp->freelist = b;
96519 + sp->private = 0;
96520 INIT_LIST_HEAD(&sp->lru);
96521 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
96522 set_slob_page_free(sp, slob_list);
96523 @@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
96524 if (slob_page_free(sp))
96525 clear_slob_page_free(sp);
96526 spin_unlock_irqrestore(&slob_lock, flags);
96527 - __ClearPageSlab(sp);
96528 - page_mapcount_reset(sp);
96529 - slob_free_pages(b, 0);
96530 + slob_free_pages(sp, 0);
96531 return;
96532 }
96533
96534 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96535 + if (pax_sanitize_slab)
96536 + memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
96537 +#endif
96538 +
96539 if (!slob_page_free(sp)) {
96540 /* This slob page is about to become partially free. Easy! */
96541 sp->units = units;
96542 @@ -424,11 +431,10 @@ out:
96543 */
96544
96545 static __always_inline void *
96546 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96547 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
96548 {
96549 - unsigned int *m;
96550 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96551 - void *ret;
96552 + slob_t *m;
96553 + void *ret = NULL;
96554
96555 gfp &= gfp_allowed_mask;
96556
96557 @@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96558
96559 if (!m)
96560 return NULL;
96561 - *m = size;
96562 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
96563 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
96564 + m[0].units = size;
96565 + m[1].units = align;
96566 ret = (void *)m + align;
96567
96568 trace_kmalloc_node(caller, ret,
96569 size, size + align, gfp, node);
96570 } else {
96571 unsigned int order = get_order(size);
96572 + struct page *page;
96573
96574 if (likely(order))
96575 gfp |= __GFP_COMP;
96576 - ret = slob_new_pages(gfp, order, node);
96577 + page = slob_new_pages(gfp, order, node);
96578 + if (page) {
96579 + ret = page_address(page);
96580 + page->private = size;
96581 + }
96582
96583 trace_kmalloc_node(caller, ret,
96584 size, PAGE_SIZE << order, gfp, node);
96585 }
96586
96587 - kmemleak_alloc(ret, size, 1, gfp);
96588 + return ret;
96589 +}
96590 +
96591 +static __always_inline void *
96592 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96593 +{
96594 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96595 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
96596 +
96597 + if (!ZERO_OR_NULL_PTR(ret))
96598 + kmemleak_alloc(ret, size, 1, gfp);
96599 return ret;
96600 }
96601
96602 @@ -493,34 +517,112 @@ void kfree(const void *block)
96603 return;
96604 kmemleak_free(block);
96605
96606 + VM_BUG_ON(!virt_addr_valid(block));
96607 sp = virt_to_page(block);
96608 - if (PageSlab(sp)) {
96609 + VM_BUG_ON(!PageSlab(sp));
96610 + if (!sp->private) {
96611 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96612 - unsigned int *m = (unsigned int *)(block - align);
96613 - slob_free(m, *m + align);
96614 - } else
96615 + slob_t *m = (slob_t *)(block - align);
96616 + slob_free(m, m[0].units + align);
96617 + } else {
96618 + __ClearPageSlab(sp);
96619 + page_mapcount_reset(sp);
96620 + sp->private = 0;
96621 __free_pages(sp, compound_order(sp));
96622 + }
96623 }
96624 EXPORT_SYMBOL(kfree);
96625
96626 +bool is_usercopy_object(const void *ptr)
96627 +{
96628 + if (!slab_is_available())
96629 + return false;
96630 +
96631 + // PAX: TODO
96632 +
96633 + return false;
96634 +}
96635 +
96636 +#ifdef CONFIG_PAX_USERCOPY
96637 +const char *check_heap_object(const void *ptr, unsigned long n)
96638 +{
96639 + struct page *page;
96640 + const slob_t *free;
96641 + const void *base;
96642 + unsigned long flags;
96643 +
96644 + if (ZERO_OR_NULL_PTR(ptr))
96645 + return "<null>";
96646 +
96647 + if (!virt_addr_valid(ptr))
96648 + return NULL;
96649 +
96650 + page = virt_to_head_page(ptr);
96651 + if (!PageSlab(page))
96652 + return NULL;
96653 +
96654 + if (page->private) {
96655 + base = page;
96656 + if (base <= ptr && n <= page->private - (ptr - base))
96657 + return NULL;
96658 + return "<slob>";
96659 + }
96660 +
96661 + /* some tricky double walking to find the chunk */
96662 + spin_lock_irqsave(&slob_lock, flags);
96663 + base = (void *)((unsigned long)ptr & PAGE_MASK);
96664 + free = page->freelist;
96665 +
96666 + while (!slob_last(free) && (void *)free <= ptr) {
96667 + base = free + slob_units(free);
96668 + free = slob_next(free);
96669 + }
96670 +
96671 + while (base < (void *)free) {
96672 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
96673 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
96674 + int offset;
96675 +
96676 + if (ptr < base + align)
96677 + break;
96678 +
96679 + offset = ptr - base - align;
96680 + if (offset >= m) {
96681 + base += size;
96682 + continue;
96683 + }
96684 +
96685 + if (n > m - offset)
96686 + break;
96687 +
96688 + spin_unlock_irqrestore(&slob_lock, flags);
96689 + return NULL;
96690 + }
96691 +
96692 + spin_unlock_irqrestore(&slob_lock, flags);
96693 + return "<slob>";
96694 +}
96695 +#endif
96696 +
96697 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
96698 size_t ksize(const void *block)
96699 {
96700 struct page *sp;
96701 int align;
96702 - unsigned int *m;
96703 + slob_t *m;
96704
96705 BUG_ON(!block);
96706 if (unlikely(block == ZERO_SIZE_PTR))
96707 return 0;
96708
96709 sp = virt_to_page(block);
96710 - if (unlikely(!PageSlab(sp)))
96711 - return PAGE_SIZE << compound_order(sp);
96712 + VM_BUG_ON(!PageSlab(sp));
96713 + if (sp->private)
96714 + return sp->private;
96715
96716 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96717 - m = (unsigned int *)(block - align);
96718 - return SLOB_UNITS(*m) * SLOB_UNIT;
96719 + m = (slob_t *)(block - align);
96720 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
96721 }
96722 EXPORT_SYMBOL(ksize);
96723
96724 @@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
96725
96726 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
96727 {
96728 - void *b;
96729 + void *b = NULL;
96730
96731 flags &= gfp_allowed_mask;
96732
96733 lockdep_trace_alloc(flags);
96734
96735 +#ifdef CONFIG_PAX_USERCOPY_SLABS
96736 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
96737 +#else
96738 if (c->size < PAGE_SIZE) {
96739 b = slob_alloc(c->size, flags, c->align, node);
96740 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
96741 SLOB_UNITS(c->size) * SLOB_UNIT,
96742 flags, node);
96743 } else {
96744 - b = slob_new_pages(flags, get_order(c->size), node);
96745 + struct page *sp;
96746 +
96747 + sp = slob_new_pages(flags, get_order(c->size), node);
96748 + if (sp) {
96749 + b = page_address(sp);
96750 + sp->private = c->size;
96751 + }
96752 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
96753 PAGE_SIZE << get_order(c->size),
96754 flags, node);
96755 }
96756 +#endif
96757
96758 if (b && c->ctor)
96759 c->ctor(b);
96760 @@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
96761
96762 static void __kmem_cache_free(void *b, int size)
96763 {
96764 - if (size < PAGE_SIZE)
96765 + struct page *sp;
96766 +
96767 + sp = virt_to_page(b);
96768 + BUG_ON(!PageSlab(sp));
96769 + if (!sp->private)
96770 slob_free(b, size);
96771 else
96772 - slob_free_pages(b, get_order(size));
96773 + slob_free_pages(sp, get_order(size));
96774 }
96775
96776 static void kmem_rcu_free(struct rcu_head *head)
96777 @@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
96778
96779 void kmem_cache_free(struct kmem_cache *c, void *b)
96780 {
96781 + int size = c->size;
96782 +
96783 +#ifdef CONFIG_PAX_USERCOPY_SLABS
96784 + if (size + c->align < PAGE_SIZE) {
96785 + size += c->align;
96786 + b -= c->align;
96787 + }
96788 +#endif
96789 +
96790 kmemleak_free_recursive(b, c->flags);
96791 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
96792 struct slob_rcu *slob_rcu;
96793 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
96794 - slob_rcu->size = c->size;
96795 + slob_rcu = b + (size - sizeof(struct slob_rcu));
96796 + slob_rcu->size = size;
96797 call_rcu(&slob_rcu->head, kmem_rcu_free);
96798 } else {
96799 - __kmem_cache_free(b, c->size);
96800 + __kmem_cache_free(b, size);
96801 }
96802
96803 +#ifdef CONFIG_PAX_USERCOPY_SLABS
96804 + trace_kfree(_RET_IP_, b);
96805 +#else
96806 trace_kmem_cache_free(_RET_IP_, b);
96807 +#endif
96808 +
96809 }
96810 EXPORT_SYMBOL(kmem_cache_free);
96811
96812 diff --git a/mm/slub.c b/mm/slub.c
96813 index 2b1ce69..4a2193f 100644
96814 --- a/mm/slub.c
96815 +++ b/mm/slub.c
96816 @@ -207,7 +207,7 @@ struct track {
96817
96818 enum track_item { TRACK_ALLOC, TRACK_FREE };
96819
96820 -#ifdef CONFIG_SYSFS
96821 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96822 static int sysfs_slab_add(struct kmem_cache *);
96823 static int sysfs_slab_alias(struct kmem_cache *, const char *);
96824 static void memcg_propagate_slab_attrs(struct kmem_cache *s);
96825 @@ -546,7 +546,7 @@ static void print_track(const char *s, struct track *t)
96826 if (!t->addr)
96827 return;
96828
96829 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
96830 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
96831 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
96832 #ifdef CONFIG_STACKTRACE
96833 {
96834 @@ -2666,6 +2666,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
96835
96836 slab_free_hook(s, x);
96837
96838 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96839 + if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
96840 + memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
96841 + if (s->ctor)
96842 + s->ctor(x);
96843 + }
96844 +#endif
96845 +
96846 redo:
96847 /*
96848 * Determine the currently cpus per cpu slab.
96849 @@ -2733,7 +2741,7 @@ static int slub_min_objects;
96850 * Merge control. If this is set then no merging of slab caches will occur.
96851 * (Could be removed. This was introduced to pacify the merge skeptics.)
96852 */
96853 -static int slub_nomerge;
96854 +static int slub_nomerge = 1;
96855
96856 /*
96857 * Calculate the order of allocation given an slab object size.
96858 @@ -3014,6 +3022,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
96859 s->inuse = size;
96860
96861 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
96862 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96863 + (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
96864 +#endif
96865 s->ctor)) {
96866 /*
96867 * Relocate free pointer after the object if it is not
96868 @@ -3343,6 +3354,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
96869 EXPORT_SYMBOL(__kmalloc_node);
96870 #endif
96871
96872 +bool is_usercopy_object(const void *ptr)
96873 +{
96874 + struct page *page;
96875 + struct kmem_cache *s;
96876 +
96877 + if (ZERO_OR_NULL_PTR(ptr))
96878 + return false;
96879 +
96880 + if (!slab_is_available())
96881 + return false;
96882 +
96883 + if (!virt_addr_valid(ptr))
96884 + return false;
96885 +
96886 + page = virt_to_head_page(ptr);
96887 +
96888 + if (!PageSlab(page))
96889 + return false;
96890 +
96891 + s = page->slab_cache;
96892 + return s->flags & SLAB_USERCOPY;
96893 +}
96894 +
96895 +#ifdef CONFIG_PAX_USERCOPY
96896 +const char *check_heap_object(const void *ptr, unsigned long n)
96897 +{
96898 + struct page *page;
96899 + struct kmem_cache *s;
96900 + unsigned long offset;
96901 +
96902 + if (ZERO_OR_NULL_PTR(ptr))
96903 + return "<null>";
96904 +
96905 + if (!virt_addr_valid(ptr))
96906 + return NULL;
96907 +
96908 + page = virt_to_head_page(ptr);
96909 +
96910 + if (!PageSlab(page))
96911 + return NULL;
96912 +
96913 + s = page->slab_cache;
96914 + if (!(s->flags & SLAB_USERCOPY))
96915 + return s->name;
96916 +
96917 + offset = (ptr - page_address(page)) % s->size;
96918 + if (offset <= s->object_size && n <= s->object_size - offset)
96919 + return NULL;
96920 +
96921 + return s->name;
96922 +}
96923 +#endif
96924 +
96925 size_t ksize(const void *object)
96926 {
96927 struct page *page;
96928 @@ -3371,6 +3435,7 @@ void kfree(const void *x)
96929 if (unlikely(ZERO_OR_NULL_PTR(x)))
96930 return;
96931
96932 + VM_BUG_ON(!virt_addr_valid(x));
96933 page = virt_to_head_page(x);
96934 if (unlikely(!PageSlab(page))) {
96935 BUG_ON(!PageCompound(page));
96936 @@ -3679,7 +3744,7 @@ static int slab_unmergeable(struct kmem_cache *s)
96937 /*
96938 * We may have set a slab to be unmergeable during bootstrap.
96939 */
96940 - if (s->refcount < 0)
96941 + if (atomic_read(&s->refcount) < 0)
96942 return 1;
96943
96944 return 0;
96945 @@ -3736,7 +3801,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
96946 int i;
96947 struct kmem_cache *c;
96948
96949 - s->refcount++;
96950 + atomic_inc(&s->refcount);
96951
96952 /*
96953 * Adjust the object sizes so that we clear
96954 @@ -3755,7 +3820,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
96955 }
96956
96957 if (sysfs_slab_alias(s, name)) {
96958 - s->refcount--;
96959 + atomic_dec(&s->refcount);
96960 s = NULL;
96961 }
96962 }
96963 @@ -3872,7 +3937,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
96964 }
96965 #endif
96966
96967 -#ifdef CONFIG_SYSFS
96968 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96969 static int count_inuse(struct page *page)
96970 {
96971 return page->inuse;
96972 @@ -4156,7 +4221,11 @@ static int list_locations(struct kmem_cache *s, char *buf,
96973 len += sprintf(buf + len, "%7ld ", l->count);
96974
96975 if (l->addr)
96976 +#ifdef CONFIG_GRKERNSEC_HIDESYM
96977 + len += sprintf(buf + len, "%pS", NULL);
96978 +#else
96979 len += sprintf(buf + len, "%pS", (void *)l->addr);
96980 +#endif
96981 else
96982 len += sprintf(buf + len, "<not-available>");
96983
96984 @@ -4261,12 +4330,12 @@ static void resiliency_test(void)
96985 validate_slab_cache(kmalloc_caches[9]);
96986 }
96987 #else
96988 -#ifdef CONFIG_SYSFS
96989 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96990 static void resiliency_test(void) {};
96991 #endif
96992 #endif
96993
96994 -#ifdef CONFIG_SYSFS
96995 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96996 enum slab_stat_type {
96997 SL_ALL, /* All slabs */
96998 SL_PARTIAL, /* Only partially allocated slabs */
96999 @@ -4506,13 +4575,17 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
97000 {
97001 if (!s->ctor)
97002 return 0;
97003 +#ifdef CONFIG_GRKERNSEC_HIDESYM
97004 + return sprintf(buf, "%pS\n", NULL);
97005 +#else
97006 return sprintf(buf, "%pS\n", s->ctor);
97007 +#endif
97008 }
97009 SLAB_ATTR_RO(ctor);
97010
97011 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
97012 {
97013 - return sprintf(buf, "%d\n", s->refcount - 1);
97014 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
97015 }
97016 SLAB_ATTR_RO(aliases);
97017
97018 @@ -4600,6 +4673,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
97019 SLAB_ATTR_RO(cache_dma);
97020 #endif
97021
97022 +#ifdef CONFIG_PAX_USERCOPY_SLABS
97023 +static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
97024 +{
97025 + return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
97026 +}
97027 +SLAB_ATTR_RO(usercopy);
97028 +#endif
97029 +
97030 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
97031 {
97032 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
97033 @@ -4934,6 +5015,9 @@ static struct attribute *slab_attrs[] = {
97034 #ifdef CONFIG_ZONE_DMA
97035 &cache_dma_attr.attr,
97036 #endif
97037 +#ifdef CONFIG_PAX_USERCOPY_SLABS
97038 + &usercopy_attr.attr,
97039 +#endif
97040 #ifdef CONFIG_NUMA
97041 &remote_node_defrag_ratio_attr.attr,
97042 #endif
97043 @@ -5184,6 +5268,7 @@ static char *create_unique_id(struct kmem_cache *s)
97044 return name;
97045 }
97046
97047 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
97048 static int sysfs_slab_add(struct kmem_cache *s)
97049 {
97050 int err;
97051 @@ -5257,6 +5342,7 @@ void sysfs_slab_remove(struct kmem_cache *s)
97052 kobject_del(&s->kobj);
97053 kobject_put(&s->kobj);
97054 }
97055 +#endif
97056
97057 /*
97058 * Need to buffer aliases during bootup until sysfs becomes
97059 @@ -5270,6 +5356,7 @@ struct saved_alias {
97060
97061 static struct saved_alias *alias_list;
97062
97063 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
97064 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
97065 {
97066 struct saved_alias *al;
97067 @@ -5292,6 +5379,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
97068 alias_list = al;
97069 return 0;
97070 }
97071 +#endif
97072
97073 static int __init slab_sysfs_init(void)
97074 {
97075 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
97076 index 4cba9c2..b4f9fcc 100644
97077 --- a/mm/sparse-vmemmap.c
97078 +++ b/mm/sparse-vmemmap.c
97079 @@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
97080 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
97081 if (!p)
97082 return NULL;
97083 - pud_populate(&init_mm, pud, p);
97084 + pud_populate_kernel(&init_mm, pud, p);
97085 }
97086 return pud;
97087 }
97088 @@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
97089 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
97090 if (!p)
97091 return NULL;
97092 - pgd_populate(&init_mm, pgd, p);
97093 + pgd_populate_kernel(&init_mm, pgd, p);
97094 }
97095 return pgd;
97096 }
97097 diff --git a/mm/sparse.c b/mm/sparse.c
97098 index d1b48b6..6e8590e 100644
97099 --- a/mm/sparse.c
97100 +++ b/mm/sparse.c
97101 @@ -750,7 +750,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
97102
97103 for (i = 0; i < PAGES_PER_SECTION; i++) {
97104 if (PageHWPoison(&memmap[i])) {
97105 - atomic_long_sub(1, &num_poisoned_pages);
97106 + atomic_long_sub_unchecked(1, &num_poisoned_pages);
97107 ClearPageHWPoison(&memmap[i]);
97108 }
97109 }
97110 diff --git a/mm/swap.c b/mm/swap.c
97111 index 9ce43ba..43bdc4c 100644
97112 --- a/mm/swap.c
97113 +++ b/mm/swap.c
97114 @@ -31,6 +31,7 @@
97115 #include <linux/memcontrol.h>
97116 #include <linux/gfp.h>
97117 #include <linux/uio.h>
97118 +#include <linux/hugetlb.h>
97119
97120 #include "internal.h"
97121
97122 @@ -76,6 +77,8 @@ static void __put_compound_page(struct page *page)
97123
97124 __page_cache_release(page);
97125 dtor = get_compound_page_dtor(page);
97126 + if (!PageHuge(page))
97127 + BUG_ON(dtor != free_compound_page);
97128 (*dtor)(page);
97129 }
97130
97131 diff --git a/mm/swapfile.c b/mm/swapfile.c
97132 index 4a7f7e6..22cddf5 100644
97133 --- a/mm/swapfile.c
97134 +++ b/mm/swapfile.c
97135 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
97136
97137 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
97138 /* Activity counter to indicate that a swapon or swapoff has occurred */
97139 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
97140 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
97141
97142 static inline unsigned char swap_count(unsigned char ent)
97143 {
97144 @@ -1959,7 +1959,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
97145 spin_unlock(&swap_lock);
97146
97147 err = 0;
97148 - atomic_inc(&proc_poll_event);
97149 + atomic_inc_unchecked(&proc_poll_event);
97150 wake_up_interruptible(&proc_poll_wait);
97151
97152 out_dput:
97153 @@ -1976,8 +1976,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
97154
97155 poll_wait(file, &proc_poll_wait, wait);
97156
97157 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
97158 - seq->poll_event = atomic_read(&proc_poll_event);
97159 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
97160 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
97161 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
97162 }
97163
97164 @@ -2075,7 +2075,7 @@ static int swaps_open(struct inode *inode, struct file *file)
97165 return ret;
97166
97167 seq = file->private_data;
97168 - seq->poll_event = atomic_read(&proc_poll_event);
97169 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
97170 return 0;
97171 }
97172
97173 @@ -2534,7 +2534,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
97174 (frontswap_map) ? "FS" : "");
97175
97176 mutex_unlock(&swapon_mutex);
97177 - atomic_inc(&proc_poll_event);
97178 + atomic_inc_unchecked(&proc_poll_event);
97179 wake_up_interruptible(&proc_poll_wait);
97180
97181 if (S_ISREG(inode->i_mode))
97182 diff --git a/mm/util.c b/mm/util.c
97183 index d5ea733..e8953f9 100644
97184 --- a/mm/util.c
97185 +++ b/mm/util.c
97186 @@ -299,6 +299,12 @@ done:
97187 void arch_pick_mmap_layout(struct mm_struct *mm)
97188 {
97189 mm->mmap_base = TASK_UNMAPPED_BASE;
97190 +
97191 +#ifdef CONFIG_PAX_RANDMMAP
97192 + if (mm->pax_flags & MF_PAX_RANDMMAP)
97193 + mm->mmap_base += mm->delta_mmap;
97194 +#endif
97195 +
97196 mm->get_unmapped_area = arch_get_unmapped_area;
97197 }
97198 #endif
97199 @@ -475,6 +481,9 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
97200 if (!mm->arg_end)
97201 goto out_mm; /* Shh! No looking before we're done */
97202
97203 + if (gr_acl_handle_procpidmem(task))
97204 + goto out_mm;
97205 +
97206 len = mm->arg_end - mm->arg_start;
97207
97208 if (len > buflen)
97209 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
97210 index bf233b2..1dfa1bc 100644
97211 --- a/mm/vmalloc.c
97212 +++ b/mm/vmalloc.c
97213 @@ -40,6 +40,21 @@ struct vfree_deferred {
97214 };
97215 static DEFINE_PER_CPU(struct vfree_deferred, vfree_deferred);
97216
97217 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97218 +struct stack_deferred_llist {
97219 + struct llist_head list;
97220 + void *stack;
97221 + void *lowmem_stack;
97222 +};
97223 +
97224 +struct stack_deferred {
97225 + struct stack_deferred_llist list;
97226 + struct work_struct wq;
97227 +};
97228 +
97229 +static DEFINE_PER_CPU(struct stack_deferred, stack_deferred);
97230 +#endif
97231 +
97232 static void __vunmap(const void *, int);
97233
97234 static void free_work(struct work_struct *w)
97235 @@ -47,12 +62,30 @@ static void free_work(struct work_struct *w)
97236 struct vfree_deferred *p = container_of(w, struct vfree_deferred, wq);
97237 struct llist_node *llnode = llist_del_all(&p->list);
97238 while (llnode) {
97239 - void *p = llnode;
97240 + void *x = llnode;
97241 llnode = llist_next(llnode);
97242 - __vunmap(p, 1);
97243 + __vunmap(x, 1);
97244 }
97245 }
97246
97247 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97248 +static void unmap_work(struct work_struct *w)
97249 +{
97250 + struct stack_deferred *p = container_of(w, struct stack_deferred, wq);
97251 + struct llist_node *llnode = llist_del_all(&p->list.list);
97252 + while (llnode) {
97253 + struct stack_deferred_llist *x =
97254 + llist_entry((struct llist_head *)llnode,
97255 + struct stack_deferred_llist, list);
97256 + void *stack = ACCESS_ONCE(x->stack);
97257 + void *lowmem_stack = ACCESS_ONCE(x->lowmem_stack);
97258 + llnode = llist_next(llnode);
97259 + __vunmap(stack, 0);
97260 + free_memcg_kmem_pages((unsigned long)lowmem_stack, THREAD_SIZE_ORDER);
97261 + }
97262 +}
97263 +#endif
97264 +
97265 /*** Page table manipulation functions ***/
97266
97267 static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
97268 @@ -61,8 +94,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
97269
97270 pte = pte_offset_kernel(pmd, addr);
97271 do {
97272 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
97273 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
97274 +
97275 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
97276 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
97277 + BUG_ON(!pte_exec(*pte));
97278 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
97279 + continue;
97280 + }
97281 +#endif
97282 +
97283 + {
97284 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
97285 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
97286 + }
97287 } while (pte++, addr += PAGE_SIZE, addr != end);
97288 }
97289
97290 @@ -122,16 +166,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
97291 pte = pte_alloc_kernel(pmd, addr);
97292 if (!pte)
97293 return -ENOMEM;
97294 +
97295 + pax_open_kernel();
97296 do {
97297 struct page *page = pages[*nr];
97298
97299 - if (WARN_ON(!pte_none(*pte)))
97300 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
97301 + if (pgprot_val(prot) & _PAGE_NX)
97302 +#endif
97303 +
97304 + if (!pte_none(*pte)) {
97305 + pax_close_kernel();
97306 + WARN_ON(1);
97307 return -EBUSY;
97308 - if (WARN_ON(!page))
97309 + }
97310 + if (!page) {
97311 + pax_close_kernel();
97312 + WARN_ON(1);
97313 return -ENOMEM;
97314 + }
97315 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
97316 (*nr)++;
97317 } while (pte++, addr += PAGE_SIZE, addr != end);
97318 + pax_close_kernel();
97319 return 0;
97320 }
97321
97322 @@ -141,7 +198,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
97323 pmd_t *pmd;
97324 unsigned long next;
97325
97326 - pmd = pmd_alloc(&init_mm, pud, addr);
97327 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
97328 if (!pmd)
97329 return -ENOMEM;
97330 do {
97331 @@ -158,7 +215,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
97332 pud_t *pud;
97333 unsigned long next;
97334
97335 - pud = pud_alloc(&init_mm, pgd, addr);
97336 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
97337 if (!pud)
97338 return -ENOMEM;
97339 do {
97340 @@ -218,6 +275,12 @@ int is_vmalloc_or_module_addr(const void *x)
97341 if (addr >= MODULES_VADDR && addr < MODULES_END)
97342 return 1;
97343 #endif
97344 +
97345 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
97346 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
97347 + return 1;
97348 +#endif
97349 +
97350 return is_vmalloc_addr(x);
97351 }
97352
97353 @@ -238,8 +301,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
97354
97355 if (!pgd_none(*pgd)) {
97356 pud_t *pud = pud_offset(pgd, addr);
97357 +#ifdef CONFIG_X86
97358 + if (!pud_large(*pud))
97359 +#endif
97360 if (!pud_none(*pud)) {
97361 pmd_t *pmd = pmd_offset(pud, addr);
97362 +#ifdef CONFIG_X86
97363 + if (!pmd_large(*pmd))
97364 +#endif
97365 if (!pmd_none(*pmd)) {
97366 pte_t *ptep, pte;
97367
97368 @@ -1183,13 +1252,23 @@ void __init vmalloc_init(void)
97369 for_each_possible_cpu(i) {
97370 struct vmap_block_queue *vbq;
97371 struct vfree_deferred *p;
97372 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97373 + struct stack_deferred *p2;
97374 +#endif
97375
97376 vbq = &per_cpu(vmap_block_queue, i);
97377 spin_lock_init(&vbq->lock);
97378 INIT_LIST_HEAD(&vbq->free);
97379 +
97380 p = &per_cpu(vfree_deferred, i);
97381 init_llist_head(&p->list);
97382 INIT_WORK(&p->wq, free_work);
97383 +
97384 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97385 + p2 = &per_cpu(stack_deferred, i);
97386 + init_llist_head(&p2->list.list);
97387 + INIT_WORK(&p2->wq, unmap_work);
97388 +#endif
97389 }
97390
97391 /* Import existing vmlist entries. */
97392 @@ -1317,6 +1396,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
97393 struct vm_struct *area;
97394
97395 BUG_ON(in_interrupt());
97396 +
97397 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
97398 + if (flags & VM_KERNEXEC) {
97399 + if (start != VMALLOC_START || end != VMALLOC_END)
97400 + return NULL;
97401 + start = (unsigned long)MODULES_EXEC_VADDR;
97402 + end = (unsigned long)MODULES_EXEC_END;
97403 + }
97404 +#endif
97405 +
97406 if (flags & VM_IOREMAP)
97407 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
97408
97409 @@ -1522,6 +1611,23 @@ void vunmap(const void *addr)
97410 }
97411 EXPORT_SYMBOL(vunmap);
97412
97413 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97414 +void unmap_process_stacks(struct task_struct *task)
97415 +{
97416 + if (unlikely(in_interrupt())) {
97417 + struct stack_deferred *p = &__get_cpu_var(stack_deferred);
97418 + struct stack_deferred_llist *list = task->stack;
97419 + list->stack = task->stack;
97420 + list->lowmem_stack = task->lowmem_stack;
97421 + if (llist_add((struct llist_node *)&list->list, &p->list.list))
97422 + schedule_work(&p->wq);
97423 + } else {
97424 + __vunmap(task->stack, 0);
97425 + free_memcg_kmem_pages((unsigned long)task->lowmem_stack, THREAD_SIZE_ORDER);
97426 + }
97427 +}
97428 +#endif
97429 +
97430 /**
97431 * vmap - map an array of pages into virtually contiguous space
97432 * @pages: array of page pointers
97433 @@ -1542,6 +1648,11 @@ void *vmap(struct page **pages, unsigned int count,
97434 if (count > totalram_pages)
97435 return NULL;
97436
97437 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
97438 + if (!(pgprot_val(prot) & _PAGE_NX))
97439 + flags |= VM_KERNEXEC;
97440 +#endif
97441 +
97442 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
97443 __builtin_return_address(0));
97444 if (!area)
97445 @@ -1642,6 +1753,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
97446 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
97447 goto fail;
97448
97449 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
97450 + if (!(pgprot_val(prot) & _PAGE_NX))
97451 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
97452 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
97453 + else
97454 +#endif
97455 +
97456 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
97457 start, end, node, gfp_mask, caller);
97458 if (!area)
97459 @@ -1818,10 +1936,9 @@ EXPORT_SYMBOL(vzalloc_node);
97460 * For tight control over page level allocator and protection flags
97461 * use __vmalloc() instead.
97462 */
97463 -
97464 void *vmalloc_exec(unsigned long size)
97465 {
97466 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
97467 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
97468 NUMA_NO_NODE, __builtin_return_address(0));
97469 }
97470
97471 @@ -2128,6 +2245,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
97472 {
97473 struct vm_struct *area;
97474
97475 + BUG_ON(vma->vm_mirror);
97476 +
97477 size = PAGE_ALIGN(size);
97478
97479 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
97480 @@ -2610,7 +2729,11 @@ static int s_show(struct seq_file *m, void *p)
97481 v->addr, v->addr + v->size, v->size);
97482
97483 if (v->caller)
97484 +#ifdef CONFIG_GRKERNSEC_HIDESYM
97485 + seq_printf(m, " %pK", v->caller);
97486 +#else
97487 seq_printf(m, " %pS", v->caller);
97488 +#endif
97489
97490 if (v->nr_pages)
97491 seq_printf(m, " pages=%d", v->nr_pages);
97492 diff --git a/mm/vmstat.c b/mm/vmstat.c
97493 index 302dd07..3841f1c 100644
97494 --- a/mm/vmstat.c
97495 +++ b/mm/vmstat.c
97496 @@ -20,6 +20,7 @@
97497 #include <linux/writeback.h>
97498 #include <linux/compaction.h>
97499 #include <linux/mm_inline.h>
97500 +#include <linux/grsecurity.h>
97501
97502 #include "internal.h"
97503
97504 @@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
97505 *
97506 * vm_stat contains the global counters
97507 */
97508 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
97509 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
97510 EXPORT_SYMBOL(vm_stat);
97511
97512 #ifdef CONFIG_SMP
97513 @@ -423,7 +424,7 @@ static inline void fold_diff(int *diff)
97514
97515 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
97516 if (diff[i])
97517 - atomic_long_add(diff[i], &vm_stat[i]);
97518 + atomic_long_add_unchecked(diff[i], &vm_stat[i]);
97519 }
97520
97521 /*
97522 @@ -455,7 +456,7 @@ static void refresh_cpu_vm_stats(void)
97523 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
97524 if (v) {
97525
97526 - atomic_long_add(v, &zone->vm_stat[i]);
97527 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97528 global_diff[i] += v;
97529 #ifdef CONFIG_NUMA
97530 /* 3 seconds idle till flush */
97531 @@ -517,7 +518,7 @@ void cpu_vm_stats_fold(int cpu)
97532
97533 v = p->vm_stat_diff[i];
97534 p->vm_stat_diff[i] = 0;
97535 - atomic_long_add(v, &zone->vm_stat[i]);
97536 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97537 global_diff[i] += v;
97538 }
97539 }
97540 @@ -537,8 +538,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
97541 if (pset->vm_stat_diff[i]) {
97542 int v = pset->vm_stat_diff[i];
97543 pset->vm_stat_diff[i] = 0;
97544 - atomic_long_add(v, &zone->vm_stat[i]);
97545 - atomic_long_add(v, &vm_stat[i]);
97546 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97547 + atomic_long_add_unchecked(v, &vm_stat[i]);
97548 }
97549 }
97550 #endif
97551 @@ -1156,10 +1157,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
97552 stat_items_size += sizeof(struct vm_event_state);
97553 #endif
97554
97555 - v = kmalloc(stat_items_size, GFP_KERNEL);
97556 + v = kzalloc(stat_items_size, GFP_KERNEL);
97557 m->private = v;
97558 if (!v)
97559 return ERR_PTR(-ENOMEM);
97560 +
97561 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
97562 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
97563 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
97564 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
97565 + && !in_group_p(grsec_proc_gid)
97566 +#endif
97567 + )
97568 + return (unsigned long *)m->private + *pos;
97569 +#endif
97570 +#endif
97571 +
97572 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
97573 v[i] = global_page_state(i);
97574 v += NR_VM_ZONE_STAT_ITEMS;
97575 @@ -1308,10 +1321,16 @@ static int __init setup_vmstat(void)
97576 cpu_notifier_register_done();
97577 #endif
97578 #ifdef CONFIG_PROC_FS
97579 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
97580 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
97581 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
97582 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
97583 + {
97584 + mode_t gr_mode = S_IRUGO;
97585 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
97586 + gr_mode = S_IRUSR;
97587 +#endif
97588 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
97589 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
97590 + proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
97591 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
97592 + }
97593 #endif
97594 return 0;
97595 }
97596 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
97597 index 44ebd5c..1f732bae 100644
97598 --- a/net/8021q/vlan.c
97599 +++ b/net/8021q/vlan.c
97600 @@ -475,7 +475,7 @@ out:
97601 return NOTIFY_DONE;
97602 }
97603
97604 -static struct notifier_block vlan_notifier_block __read_mostly = {
97605 +static struct notifier_block vlan_notifier_block = {
97606 .notifier_call = vlan_device_event,
97607 };
97608
97609 @@ -550,8 +550,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
97610 err = -EPERM;
97611 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
97612 break;
97613 - if ((args.u.name_type >= 0) &&
97614 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
97615 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
97616 struct vlan_net *vn;
97617
97618 vn = net_generic(net, vlan_net_id);
97619 diff --git a/net/9p/client.c b/net/9p/client.c
97620 index 0004cba..feba240 100644
97621 --- a/net/9p/client.c
97622 +++ b/net/9p/client.c
97623 @@ -596,7 +596,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
97624 len - inline_len);
97625 } else {
97626 err = copy_from_user(ename + inline_len,
97627 - uidata, len - inline_len);
97628 + (char __force_user *)uidata, len - inline_len);
97629 if (err) {
97630 err = -EFAULT;
97631 goto out_err;
97632 @@ -1571,7 +1571,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
97633 kernel_buf = 1;
97634 indata = data;
97635 } else
97636 - indata = (__force char *)udata;
97637 + indata = (__force_kernel char *)udata;
97638 /*
97639 * response header len is 11
97640 * PDU Header(7) + IO Size (4)
97641 @@ -1646,7 +1646,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
97642 kernel_buf = 1;
97643 odata = data;
97644 } else
97645 - odata = (char *)udata;
97646 + odata = (char __force_kernel *)udata;
97647 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
97648 P9_ZC_HDR_SZ, kernel_buf, "dqd",
97649 fid->fid, offset, rsize);
97650 diff --git a/net/9p/mod.c b/net/9p/mod.c
97651 index 6ab36ae..6f1841b 100644
97652 --- a/net/9p/mod.c
97653 +++ b/net/9p/mod.c
97654 @@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
97655 void v9fs_register_trans(struct p9_trans_module *m)
97656 {
97657 spin_lock(&v9fs_trans_lock);
97658 - list_add_tail(&m->list, &v9fs_trans_list);
97659 + pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
97660 spin_unlock(&v9fs_trans_lock);
97661 }
97662 EXPORT_SYMBOL(v9fs_register_trans);
97663 @@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
97664 void v9fs_unregister_trans(struct p9_trans_module *m)
97665 {
97666 spin_lock(&v9fs_trans_lock);
97667 - list_del_init(&m->list);
97668 + pax_list_del_init((struct list_head *)&m->list);
97669 spin_unlock(&v9fs_trans_lock);
97670 }
97671 EXPORT_SYMBOL(v9fs_unregister_trans);
97672 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
97673 index 80d08f6..de63fd1 100644
97674 --- a/net/9p/trans_fd.c
97675 +++ b/net/9p/trans_fd.c
97676 @@ -428,7 +428,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
97677 oldfs = get_fs();
97678 set_fs(get_ds());
97679 /* The cast to a user pointer is valid due to the set_fs() */
97680 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
97681 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
97682 set_fs(oldfs);
97683
97684 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
97685 diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
97686 index af46bc4..f9adfcd 100644
97687 --- a/net/appletalk/atalk_proc.c
97688 +++ b/net/appletalk/atalk_proc.c
97689 @@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
97690 struct proc_dir_entry *p;
97691 int rc = -ENOMEM;
97692
97693 - atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
97694 + atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
97695 if (!atalk_proc_dir)
97696 goto out;
97697
97698 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
97699 index 876fbe8..8bbea9f 100644
97700 --- a/net/atm/atm_misc.c
97701 +++ b/net/atm/atm_misc.c
97702 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
97703 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
97704 return 1;
97705 atm_return(vcc, truesize);
97706 - atomic_inc(&vcc->stats->rx_drop);
97707 + atomic_inc_unchecked(&vcc->stats->rx_drop);
97708 return 0;
97709 }
97710 EXPORT_SYMBOL(atm_charge);
97711 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
97712 }
97713 }
97714 atm_return(vcc, guess);
97715 - atomic_inc(&vcc->stats->rx_drop);
97716 + atomic_inc_unchecked(&vcc->stats->rx_drop);
97717 return NULL;
97718 }
97719 EXPORT_SYMBOL(atm_alloc_charge);
97720 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
97721
97722 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
97723 {
97724 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
97725 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
97726 __SONET_ITEMS
97727 #undef __HANDLE_ITEM
97728 }
97729 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
97730
97731 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
97732 {
97733 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
97734 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
97735 __SONET_ITEMS
97736 #undef __HANDLE_ITEM
97737 }
97738 diff --git a/net/atm/lec.c b/net/atm/lec.c
97739 index 4c5b8ba..95f7005 100644
97740 --- a/net/atm/lec.c
97741 +++ b/net/atm/lec.c
97742 @@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
97743 }
97744
97745 static struct lane2_ops lane2_ops = {
97746 - lane2_resolve, /* resolve, spec 3.1.3 */
97747 - lane2_associate_req, /* associate_req, spec 3.1.4 */
97748 - NULL /* associate indicator, spec 3.1.5 */
97749 + .resolve = lane2_resolve,
97750 + .associate_req = lane2_associate_req,
97751 + .associate_indicator = NULL
97752 };
97753
97754 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
97755 diff --git a/net/atm/lec.h b/net/atm/lec.h
97756 index 4149db1..f2ab682 100644
97757 --- a/net/atm/lec.h
97758 +++ b/net/atm/lec.h
97759 @@ -48,7 +48,7 @@ struct lane2_ops {
97760 const u8 *tlvs, u32 sizeoftlvs);
97761 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
97762 const u8 *tlvs, u32 sizeoftlvs);
97763 -};
97764 +} __no_const;
97765
97766 /*
97767 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
97768 diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
97769 index d1b2d9a..d549f7f 100644
97770 --- a/net/atm/mpoa_caches.c
97771 +++ b/net/atm/mpoa_caches.c
97772 @@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
97773
97774
97775 static struct in_cache_ops ingress_ops = {
97776 - in_cache_add_entry, /* add_entry */
97777 - in_cache_get, /* get */
97778 - in_cache_get_with_mask, /* get_with_mask */
97779 - in_cache_get_by_vcc, /* get_by_vcc */
97780 - in_cache_put, /* put */
97781 - in_cache_remove_entry, /* remove_entry */
97782 - cache_hit, /* cache_hit */
97783 - clear_count_and_expired, /* clear_count */
97784 - check_resolving_entries, /* check_resolving */
97785 - refresh_entries, /* refresh */
97786 - in_destroy_cache /* destroy_cache */
97787 + .add_entry = in_cache_add_entry,
97788 + .get = in_cache_get,
97789 + .get_with_mask = in_cache_get_with_mask,
97790 + .get_by_vcc = in_cache_get_by_vcc,
97791 + .put = in_cache_put,
97792 + .remove_entry = in_cache_remove_entry,
97793 + .cache_hit = cache_hit,
97794 + .clear_count = clear_count_and_expired,
97795 + .check_resolving = check_resolving_entries,
97796 + .refresh = refresh_entries,
97797 + .destroy_cache = in_destroy_cache
97798 };
97799
97800 static struct eg_cache_ops egress_ops = {
97801 - eg_cache_add_entry, /* add_entry */
97802 - eg_cache_get_by_cache_id, /* get_by_cache_id */
97803 - eg_cache_get_by_tag, /* get_by_tag */
97804 - eg_cache_get_by_vcc, /* get_by_vcc */
97805 - eg_cache_get_by_src_ip, /* get_by_src_ip */
97806 - eg_cache_put, /* put */
97807 - eg_cache_remove_entry, /* remove_entry */
97808 - update_eg_cache_entry, /* update */
97809 - clear_expired, /* clear_expired */
97810 - eg_destroy_cache /* destroy_cache */
97811 + .add_entry = eg_cache_add_entry,
97812 + .get_by_cache_id = eg_cache_get_by_cache_id,
97813 + .get_by_tag = eg_cache_get_by_tag,
97814 + .get_by_vcc = eg_cache_get_by_vcc,
97815 + .get_by_src_ip = eg_cache_get_by_src_ip,
97816 + .put = eg_cache_put,
97817 + .remove_entry = eg_cache_remove_entry,
97818 + .update = update_eg_cache_entry,
97819 + .clear_expired = clear_expired,
97820 + .destroy_cache = eg_destroy_cache
97821 };
97822
97823
97824 diff --git a/net/atm/proc.c b/net/atm/proc.c
97825 index bbb6461..cf04016 100644
97826 --- a/net/atm/proc.c
97827 +++ b/net/atm/proc.c
97828 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
97829 const struct k_atm_aal_stats *stats)
97830 {
97831 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
97832 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
97833 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
97834 - atomic_read(&stats->rx_drop));
97835 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
97836 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
97837 + atomic_read_unchecked(&stats->rx_drop));
97838 }
97839
97840 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
97841 diff --git a/net/atm/resources.c b/net/atm/resources.c
97842 index 0447d5d..3cf4728 100644
97843 --- a/net/atm/resources.c
97844 +++ b/net/atm/resources.c
97845 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
97846 static void copy_aal_stats(struct k_atm_aal_stats *from,
97847 struct atm_aal_stats *to)
97848 {
97849 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
97850 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
97851 __AAL_STAT_ITEMS
97852 #undef __HANDLE_ITEM
97853 }
97854 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
97855 static void subtract_aal_stats(struct k_atm_aal_stats *from,
97856 struct atm_aal_stats *to)
97857 {
97858 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
97859 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
97860 __AAL_STAT_ITEMS
97861 #undef __HANDLE_ITEM
97862 }
97863 diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
97864 index 919a5ce..cc6b444 100644
97865 --- a/net/ax25/sysctl_net_ax25.c
97866 +++ b/net/ax25/sysctl_net_ax25.c
97867 @@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
97868 {
97869 char path[sizeof("net/ax25/") + IFNAMSIZ];
97870 int k;
97871 - struct ctl_table *table;
97872 + ctl_table_no_const *table;
97873
97874 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
97875 if (!table)
97876 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
97877 index f04224c..f326579 100644
97878 --- a/net/batman-adv/bat_iv_ogm.c
97879 +++ b/net/batman-adv/bat_iv_ogm.c
97880 @@ -312,7 +312,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
97881
97882 /* randomize initial seqno to avoid collision */
97883 get_random_bytes(&random_seqno, sizeof(random_seqno));
97884 - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
97885 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
97886
97887 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
97888 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
97889 @@ -917,9 +917,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
97890 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
97891
97892 /* change sequence number to network order */
97893 - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
97894 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
97895 batadv_ogm_packet->seqno = htonl(seqno);
97896 - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
97897 + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
97898
97899 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
97900
97901 @@ -1596,7 +1596,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
97902 return;
97903
97904 /* could be changed by schedule_own_packet() */
97905 - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
97906 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
97907
97908 if (ogm_packet->flags & BATADV_DIRECTLINK)
97909 has_directlink_flag = true;
97910 diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
97911 index 022d18a..919daff 100644
97912 --- a/net/batman-adv/fragmentation.c
97913 +++ b/net/batman-adv/fragmentation.c
97914 @@ -450,7 +450,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
97915 frag_header.packet_type = BATADV_UNICAST_FRAG;
97916 frag_header.version = BATADV_COMPAT_VERSION;
97917 frag_header.ttl = BATADV_TTL;
97918 - frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
97919 + frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
97920 frag_header.reserved = 0;
97921 frag_header.no = 0;
97922 frag_header.total_size = htons(skb->len);
97923 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
97924 index 744a59b..8fd037c 100644
97925 --- a/net/batman-adv/soft-interface.c
97926 +++ b/net/batman-adv/soft-interface.c
97927 @@ -296,7 +296,7 @@ send:
97928 primary_if->net_dev->dev_addr);
97929
97930 /* set broadcast sequence number */
97931 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
97932 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
97933 bcast_packet->seqno = htonl(seqno);
97934
97935 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
97936 @@ -729,7 +729,7 @@ static int batadv_softif_init_late(struct net_device *dev)
97937 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
97938
97939 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
97940 - atomic_set(&bat_priv->bcast_seqno, 1);
97941 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
97942 atomic_set(&bat_priv->tt.vn, 0);
97943 atomic_set(&bat_priv->tt.local_changes, 0);
97944 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
97945 @@ -743,7 +743,7 @@ static int batadv_softif_init_late(struct net_device *dev)
97946
97947 /* randomize initial seqno to avoid collision */
97948 get_random_bytes(&random_seqno, sizeof(random_seqno));
97949 - atomic_set(&bat_priv->frag_seqno, random_seqno);
97950 + atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
97951
97952 bat_priv->primary_if = NULL;
97953 bat_priv->num_ifaces = 0;
97954 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
97955 index 34891a5..3cfece0 100644
97956 --- a/net/batman-adv/types.h
97957 +++ b/net/batman-adv/types.h
97958 @@ -67,7 +67,7 @@ enum batadv_dhcp_recipient {
97959 struct batadv_hard_iface_bat_iv {
97960 unsigned char *ogm_buff;
97961 int ogm_buff_len;
97962 - atomic_t ogm_seqno;
97963 + atomic_unchecked_t ogm_seqno;
97964 };
97965
97966 /**
97967 @@ -766,7 +766,7 @@ struct batadv_priv {
97968 atomic_t bonding;
97969 atomic_t fragmentation;
97970 atomic_t packet_size_max;
97971 - atomic_t frag_seqno;
97972 + atomic_unchecked_t frag_seqno;
97973 #ifdef CONFIG_BATMAN_ADV_BLA
97974 atomic_t bridge_loop_avoidance;
97975 #endif
97976 @@ -785,7 +785,7 @@ struct batadv_priv {
97977 #endif
97978 uint32_t isolation_mark;
97979 uint32_t isolation_mark_mask;
97980 - atomic_t bcast_seqno;
97981 + atomic_unchecked_t bcast_seqno;
97982 atomic_t bcast_queue_left;
97983 atomic_t batman_queue_left;
97984 char num_ifaces;
97985 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
97986 index b9a418e..2af862a 100644
97987 --- a/net/bluetooth/hci_sock.c
97988 +++ b/net/bluetooth/hci_sock.c
97989 @@ -1053,7 +1053,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
97990 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
97991 }
97992
97993 - len = min_t(unsigned int, len, sizeof(uf));
97994 + len = min((size_t)len, sizeof(uf));
97995 if (copy_from_user(&uf, optval, len)) {
97996 err = -EFAULT;
97997 break;
97998 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
97999 index 1c97b7a..9171d69 100644
98000 --- a/net/bluetooth/l2cap_core.c
98001 +++ b/net/bluetooth/l2cap_core.c
98002 @@ -3542,8 +3542,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
98003 break;
98004
98005 case L2CAP_CONF_RFC:
98006 - if (olen == sizeof(rfc))
98007 - memcpy(&rfc, (void *)val, olen);
98008 + if (olen != sizeof(rfc))
98009 + break;
98010 +
98011 + memcpy(&rfc, (void *)val, olen);
98012
98013 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
98014 rfc.mode != chan->mode)
98015 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
98016 index e137869..33f3ebd 100644
98017 --- a/net/bluetooth/l2cap_sock.c
98018 +++ b/net/bluetooth/l2cap_sock.c
98019 @@ -628,7 +628,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
98020 struct sock *sk = sock->sk;
98021 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
98022 struct l2cap_options opts;
98023 - int len, err = 0;
98024 + int err = 0;
98025 + size_t len = optlen;
98026 u32 opt;
98027
98028 BT_DBG("sk %p", sk);
98029 @@ -655,7 +656,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
98030 opts.max_tx = chan->max_tx;
98031 opts.txwin_size = chan->tx_win;
98032
98033 - len = min_t(unsigned int, sizeof(opts), optlen);
98034 + len = min(sizeof(opts), len);
98035 if (copy_from_user((char *) &opts, optval, len)) {
98036 err = -EFAULT;
98037 break;
98038 @@ -742,7 +743,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
98039 struct bt_security sec;
98040 struct bt_power pwr;
98041 struct l2cap_conn *conn;
98042 - int len, err = 0;
98043 + int err = 0;
98044 + size_t len = optlen;
98045 u32 opt;
98046
98047 BT_DBG("sk %p", sk);
98048 @@ -766,7 +768,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
98049
98050 sec.level = BT_SECURITY_LOW;
98051
98052 - len = min_t(unsigned int, sizeof(sec), optlen);
98053 + len = min(sizeof(sec), len);
98054 if (copy_from_user((char *) &sec, optval, len)) {
98055 err = -EFAULT;
98056 break;
98057 @@ -861,7 +863,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
98058
98059 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
98060
98061 - len = min_t(unsigned int, sizeof(pwr), optlen);
98062 + len = min(sizeof(pwr), len);
98063 if (copy_from_user((char *) &pwr, optval, len)) {
98064 err = -EFAULT;
98065 break;
98066 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
98067 index c603a5e..7f08991 100644
98068 --- a/net/bluetooth/rfcomm/sock.c
98069 +++ b/net/bluetooth/rfcomm/sock.c
98070 @@ -687,7 +687,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
98071 struct sock *sk = sock->sk;
98072 struct bt_security sec;
98073 int err = 0;
98074 - size_t len;
98075 + size_t len = optlen;
98076 u32 opt;
98077
98078 BT_DBG("sk %p", sk);
98079 @@ -709,7 +709,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
98080
98081 sec.level = BT_SECURITY_LOW;
98082
98083 - len = min_t(unsigned int, sizeof(sec), optlen);
98084 + len = min(sizeof(sec), len);
98085 if (copy_from_user((char *) &sec, optval, len)) {
98086 err = -EFAULT;
98087 break;
98088 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
98089 index 403ec09..a21a003 100644
98090 --- a/net/bluetooth/rfcomm/tty.c
98091 +++ b/net/bluetooth/rfcomm/tty.c
98092 @@ -752,7 +752,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
98093 BT_DBG("tty %p id %d", tty, tty->index);
98094
98095 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
98096 - dev->channel, dev->port.count);
98097 + dev->channel, atomic_read(&dev->port.count));
98098
98099 err = tty_port_open(&dev->port, tty, filp);
98100 if (err)
98101 @@ -775,7 +775,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
98102 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
98103
98104 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
98105 - dev->port.count);
98106 + atomic_read(&dev->port.count));
98107
98108 tty_port_close(&dev->port, tty, filp);
98109 }
98110 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
98111 index 1059ed3..d70846a 100644
98112 --- a/net/bridge/netfilter/ebtables.c
98113 +++ b/net/bridge/netfilter/ebtables.c
98114 @@ -1524,7 +1524,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
98115 tmp.valid_hooks = t->table->valid_hooks;
98116 }
98117 mutex_unlock(&ebt_mutex);
98118 - if (copy_to_user(user, &tmp, *len) != 0) {
98119 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
98120 BUGPRINT("c2u Didn't work\n");
98121 ret = -EFAULT;
98122 break;
98123 @@ -2330,7 +2330,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
98124 goto out;
98125 tmp.valid_hooks = t->valid_hooks;
98126
98127 - if (copy_to_user(user, &tmp, *len) != 0) {
98128 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
98129 ret = -EFAULT;
98130 break;
98131 }
98132 @@ -2341,7 +2341,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
98133 tmp.entries_size = t->table->entries_size;
98134 tmp.valid_hooks = t->table->valid_hooks;
98135
98136 - if (copy_to_user(user, &tmp, *len) != 0) {
98137 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
98138 ret = -EFAULT;
98139 break;
98140 }
98141 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
98142 index 0f45522..dab651f 100644
98143 --- a/net/caif/cfctrl.c
98144 +++ b/net/caif/cfctrl.c
98145 @@ -10,6 +10,7 @@
98146 #include <linux/spinlock.h>
98147 #include <linux/slab.h>
98148 #include <linux/pkt_sched.h>
98149 +#include <linux/sched.h>
98150 #include <net/caif/caif_layer.h>
98151 #include <net/caif/cfpkt.h>
98152 #include <net/caif/cfctrl.h>
98153 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
98154 memset(&dev_info, 0, sizeof(dev_info));
98155 dev_info.id = 0xff;
98156 cfsrvl_init(&this->serv, 0, &dev_info, false);
98157 - atomic_set(&this->req_seq_no, 1);
98158 - atomic_set(&this->rsp_seq_no, 1);
98159 + atomic_set_unchecked(&this->req_seq_no, 1);
98160 + atomic_set_unchecked(&this->rsp_seq_no, 1);
98161 this->serv.layer.receive = cfctrl_recv;
98162 sprintf(this->serv.layer.name, "ctrl");
98163 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
98164 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
98165 struct cfctrl_request_info *req)
98166 {
98167 spin_lock_bh(&ctrl->info_list_lock);
98168 - atomic_inc(&ctrl->req_seq_no);
98169 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
98170 + atomic_inc_unchecked(&ctrl->req_seq_no);
98171 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
98172 list_add_tail(&req->list, &ctrl->list);
98173 spin_unlock_bh(&ctrl->info_list_lock);
98174 }
98175 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
98176 if (p != first)
98177 pr_warn("Requests are not received in order\n");
98178
98179 - atomic_set(&ctrl->rsp_seq_no,
98180 + atomic_set_unchecked(&ctrl->rsp_seq_no,
98181 p->sequence_no);
98182 list_del(&p->list);
98183 goto out;
98184 diff --git a/net/can/af_can.c b/net/can/af_can.c
98185 index a27f8aa..67174a3 100644
98186 --- a/net/can/af_can.c
98187 +++ b/net/can/af_can.c
98188 @@ -863,7 +863,7 @@ static const struct net_proto_family can_family_ops = {
98189 };
98190
98191 /* notifier block for netdevice event */
98192 -static struct notifier_block can_netdev_notifier __read_mostly = {
98193 +static struct notifier_block can_netdev_notifier = {
98194 .notifier_call = can_notifier,
98195 };
98196
98197 diff --git a/net/can/bcm.c b/net/can/bcm.c
98198 index dcb75c0..24b1b43 100644
98199 --- a/net/can/bcm.c
98200 +++ b/net/can/bcm.c
98201 @@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
98202 }
98203
98204 /* create /proc/net/can-bcm directory */
98205 - proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
98206 + proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
98207 return 0;
98208 }
98209
98210 diff --git a/net/can/gw.c b/net/can/gw.c
98211 index 050a211..bb9fe33 100644
98212 --- a/net/can/gw.c
98213 +++ b/net/can/gw.c
98214 @@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
98215 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
98216
98217 static HLIST_HEAD(cgw_list);
98218 -static struct notifier_block notifier;
98219
98220 static struct kmem_cache *cgw_cache __read_mostly;
98221
98222 @@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
98223 return err;
98224 }
98225
98226 +static struct notifier_block notifier = {
98227 + .notifier_call = cgw_notifier
98228 +};
98229 +
98230 static __init int cgw_module_init(void)
98231 {
98232 /* sanitize given module parameter */
98233 @@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
98234 return -ENOMEM;
98235
98236 /* set notifier */
98237 - notifier.notifier_call = cgw_notifier;
98238 register_netdevice_notifier(&notifier);
98239
98240 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
98241 diff --git a/net/can/proc.c b/net/can/proc.c
98242 index b543470..d2ddae2 100644
98243 --- a/net/can/proc.c
98244 +++ b/net/can/proc.c
98245 @@ -468,7 +468,7 @@ static void can_remove_proc_readentry(const char *name)
98246 void can_init_proc(void)
98247 {
98248 /* create /proc/net/can directory */
98249 - can_dir = proc_mkdir("can", init_net.proc_net);
98250 + can_dir = proc_mkdir_restrict("can", init_net.proc_net);
98251
98252 if (!can_dir) {
98253 printk(KERN_INFO "can: failed to create /proc/net/can . "
98254 diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
98255 index 1948d59..9e854d5 100644
98256 --- a/net/ceph/messenger.c
98257 +++ b/net/ceph/messenger.c
98258 @@ -187,7 +187,7 @@ static void con_fault(struct ceph_connection *con);
98259 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
98260
98261 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
98262 -static atomic_t addr_str_seq = ATOMIC_INIT(0);
98263 +static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
98264
98265 static struct page *zero_page; /* used in certain error cases */
98266
98267 @@ -198,7 +198,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
98268 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
98269 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
98270
98271 - i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
98272 + i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
98273 s = addr_str[i];
98274
98275 switch (ss->ss_family) {
98276 diff --git a/net/compat.c b/net/compat.c
98277 index bc8aeef..f9c070c 100644
98278 --- a/net/compat.c
98279 +++ b/net/compat.c
98280 @@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
98281 return -EFAULT;
98282 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
98283 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
98284 - kmsg->msg_name = compat_ptr(tmp1);
98285 - kmsg->msg_iov = compat_ptr(tmp2);
98286 - kmsg->msg_control = compat_ptr(tmp3);
98287 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
98288 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
98289 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
98290 return 0;
98291 }
98292
98293 @@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
98294
98295 if (kern_msg->msg_name && kern_msg->msg_namelen) {
98296 if (mode == VERIFY_READ) {
98297 - int err = move_addr_to_kernel(kern_msg->msg_name,
98298 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
98299 kern_msg->msg_namelen,
98300 kern_address);
98301 if (err < 0)
98302 @@ -100,7 +100,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
98303 }
98304
98305 tot_len = iov_from_user_compat_to_kern(kern_iov,
98306 - (struct compat_iovec __user *)kern_msg->msg_iov,
98307 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
98308 kern_msg->msg_iovlen);
98309 if (tot_len >= 0)
98310 kern_msg->msg_iov = kern_iov;
98311 @@ -120,20 +120,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
98312
98313 #define CMSG_COMPAT_FIRSTHDR(msg) \
98314 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
98315 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
98316 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
98317 (struct compat_cmsghdr __user *)NULL)
98318
98319 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
98320 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
98321 (ucmlen) <= (unsigned long) \
98322 ((mhdr)->msg_controllen - \
98323 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
98324 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
98325
98326 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
98327 struct compat_cmsghdr __user *cmsg, int cmsg_len)
98328 {
98329 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
98330 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
98331 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
98332 msg->msg_controllen)
98333 return NULL;
98334 return (struct compat_cmsghdr __user *)ptr;
98335 @@ -223,7 +223,7 @@ Efault:
98336
98337 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
98338 {
98339 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
98340 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
98341 struct compat_cmsghdr cmhdr;
98342 struct compat_timeval ctv;
98343 struct compat_timespec cts[3];
98344 @@ -279,7 +279,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
98345
98346 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
98347 {
98348 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
98349 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
98350 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
98351 int fdnum = scm->fp->count;
98352 struct file **fp = scm->fp->fp;
98353 @@ -367,7 +367,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
98354 return -EFAULT;
98355 old_fs = get_fs();
98356 set_fs(KERNEL_DS);
98357 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
98358 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
98359 set_fs(old_fs);
98360
98361 return err;
98362 @@ -428,7 +428,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
98363 len = sizeof(ktime);
98364 old_fs = get_fs();
98365 set_fs(KERNEL_DS);
98366 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
98367 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
98368 set_fs(old_fs);
98369
98370 if (!err) {
98371 @@ -571,7 +571,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
98372 case MCAST_JOIN_GROUP:
98373 case MCAST_LEAVE_GROUP:
98374 {
98375 - struct compat_group_req __user *gr32 = (void *)optval;
98376 + struct compat_group_req __user *gr32 = (void __user *)optval;
98377 struct group_req __user *kgr =
98378 compat_alloc_user_space(sizeof(struct group_req));
98379 u32 interface;
98380 @@ -592,7 +592,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
98381 case MCAST_BLOCK_SOURCE:
98382 case MCAST_UNBLOCK_SOURCE:
98383 {
98384 - struct compat_group_source_req __user *gsr32 = (void *)optval;
98385 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
98386 struct group_source_req __user *kgsr = compat_alloc_user_space(
98387 sizeof(struct group_source_req));
98388 u32 interface;
98389 @@ -613,7 +613,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
98390 }
98391 case MCAST_MSFILTER:
98392 {
98393 - struct compat_group_filter __user *gf32 = (void *)optval;
98394 + struct compat_group_filter __user *gf32 = (void __user *)optval;
98395 struct group_filter __user *kgf;
98396 u32 interface, fmode, numsrc;
98397
98398 @@ -651,7 +651,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
98399 char __user *optval, int __user *optlen,
98400 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
98401 {
98402 - struct compat_group_filter __user *gf32 = (void *)optval;
98403 + struct compat_group_filter __user *gf32 = (void __user *)optval;
98404 struct group_filter __user *kgf;
98405 int __user *koptlen;
98406 u32 interface, fmode, numsrc;
98407 @@ -804,7 +804,7 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
98408
98409 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
98410 return -EINVAL;
98411 - if (copy_from_user(a, args, nas[call]))
98412 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
98413 return -EFAULT;
98414 a0 = a[0];
98415 a1 = a[1];
98416 diff --git a/net/core/datagram.c b/net/core/datagram.c
98417 index a16ed7b..eb44d17 100644
98418 --- a/net/core/datagram.c
98419 +++ b/net/core/datagram.c
98420 @@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
98421 }
98422
98423 kfree_skb(skb);
98424 - atomic_inc(&sk->sk_drops);
98425 + atomic_inc_unchecked(&sk->sk_drops);
98426 sk_mem_reclaim_partial(sk);
98427
98428 return err;
98429 diff --git a/net/core/dev.c b/net/core/dev.c
98430 index a7621f3..ca7dac3 100644
98431 --- a/net/core/dev.c
98432 +++ b/net/core/dev.c
98433 @@ -1690,14 +1690,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
98434 {
98435 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
98436 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
98437 - atomic_long_inc(&dev->rx_dropped);
98438 + atomic_long_inc_unchecked(&dev->rx_dropped);
98439 kfree_skb(skb);
98440 return NET_RX_DROP;
98441 }
98442 }
98443
98444 if (unlikely(!is_skb_forwardable(dev, skb))) {
98445 - atomic_long_inc(&dev->rx_dropped);
98446 + atomic_long_inc_unchecked(&dev->rx_dropped);
98447 kfree_skb(skb);
98448 return NET_RX_DROP;
98449 }
98450 @@ -2470,7 +2470,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
98451
98452 struct dev_gso_cb {
98453 void (*destructor)(struct sk_buff *skb);
98454 -};
98455 +} __no_const;
98456
98457 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
98458
98459 @@ -2900,7 +2900,7 @@ recursion_alert:
98460 rc = -ENETDOWN;
98461 rcu_read_unlock_bh();
98462
98463 - atomic_long_inc(&dev->tx_dropped);
98464 + atomic_long_inc_unchecked(&dev->tx_dropped);
98465 kfree_skb(skb);
98466 return rc;
98467 out:
98468 @@ -3244,7 +3244,7 @@ enqueue:
98469
98470 local_irq_restore(flags);
98471
98472 - atomic_long_inc(&skb->dev->rx_dropped);
98473 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
98474 kfree_skb(skb);
98475 return NET_RX_DROP;
98476 }
98477 @@ -3321,7 +3321,7 @@ int netif_rx_ni(struct sk_buff *skb)
98478 }
98479 EXPORT_SYMBOL(netif_rx_ni);
98480
98481 -static void net_tx_action(struct softirq_action *h)
98482 +static __latent_entropy void net_tx_action(void)
98483 {
98484 struct softnet_data *sd = &__get_cpu_var(softnet_data);
98485
98486 @@ -3654,7 +3654,7 @@ ncls:
98487 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
98488 } else {
98489 drop:
98490 - atomic_long_inc(&skb->dev->rx_dropped);
98491 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
98492 kfree_skb(skb);
98493 /* Jamal, now you will not able to escape explaining
98494 * me how you were going to use this. :-)
98495 @@ -4375,7 +4375,7 @@ void netif_napi_del(struct napi_struct *napi)
98496 }
98497 EXPORT_SYMBOL(netif_napi_del);
98498
98499 -static void net_rx_action(struct softirq_action *h)
98500 +static __latent_entropy void net_rx_action(void)
98501 {
98502 struct softnet_data *sd = &__get_cpu_var(softnet_data);
98503 unsigned long time_limit = jiffies + 2;
98504 @@ -6375,8 +6375,8 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
98505 } else {
98506 netdev_stats_to_stats64(storage, &dev->stats);
98507 }
98508 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
98509 - storage->tx_dropped += atomic_long_read(&dev->tx_dropped);
98510 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
98511 + storage->tx_dropped += atomic_long_read_unchecked(&dev->tx_dropped);
98512 return storage;
98513 }
98514 EXPORT_SYMBOL(dev_get_stats);
98515 diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
98516 index cf999e0..c59a975 100644
98517 --- a/net/core/dev_ioctl.c
98518 +++ b/net/core/dev_ioctl.c
98519 @@ -366,9 +366,13 @@ void dev_load(struct net *net, const char *name)
98520 if (no_module && capable(CAP_NET_ADMIN))
98521 no_module = request_module("netdev-%s", name);
98522 if (no_module && capable(CAP_SYS_MODULE)) {
98523 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
98524 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
98525 +#else
98526 if (!request_module("%s", name))
98527 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
98528 name);
98529 +#endif
98530 }
98531 }
98532 EXPORT_SYMBOL(dev_load);
98533 diff --git a/net/core/filter.c b/net/core/filter.c
98534 index 5310d5e..01f885e 100644
98535 --- a/net/core/filter.c
98536 +++ b/net/core/filter.c
98537 @@ -1121,7 +1121,11 @@ do_pass:
98538 break;
98539
98540 default:
98541 - goto err;
98542 + WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
98543 + fp->code, fp->jt, fp->jf, fp->k);
98544 + kfree(addrs);
98545 + BUG();
98546 + return -EINVAL;
98547 }
98548
98549 insn++;
98550 @@ -1170,7 +1174,7 @@ static int check_load_and_stores(struct sock_filter *filter, int flen)
98551 u16 *masks, memvalid = 0; /* one bit per cell, 16 cells */
98552 int pc, ret = 0;
98553
98554 - BUILD_BUG_ON(BPF_MEMWORDS > 16);
98555 + BUILD_BUG_ON(BPF_MEMWORDS != 16);
98556 masks = kmalloc(flen * sizeof(*masks), GFP_KERNEL);
98557 if (!masks)
98558 return -ENOMEM;
98559 @@ -1605,7 +1609,7 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
98560 if (!fp)
98561 return -ENOMEM;
98562
98563 - memcpy(fp->insns, fprog->filter, fsize);
98564 + memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
98565
98566 atomic_set(&fp->refcnt, 1);
98567 fp->len = fprog->len;
98568 diff --git a/net/core/flow.c b/net/core/flow.c
98569 index a0348fd..6951c76 100644
98570 --- a/net/core/flow.c
98571 +++ b/net/core/flow.c
98572 @@ -65,7 +65,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
98573 static int flow_entry_valid(struct flow_cache_entry *fle,
98574 struct netns_xfrm *xfrm)
98575 {
98576 - if (atomic_read(&xfrm->flow_cache_genid) != fle->genid)
98577 + if (atomic_read_unchecked(&xfrm->flow_cache_genid) != fle->genid)
98578 return 0;
98579 if (fle->object && !fle->object->ops->check(fle->object))
98580 return 0;
98581 @@ -242,7 +242,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
98582 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
98583 fcp->hash_count++;
98584 }
98585 - } else if (likely(fle->genid == atomic_read(&net->xfrm.flow_cache_genid))) {
98586 + } else if (likely(fle->genid == atomic_read_unchecked(&net->xfrm.flow_cache_genid))) {
98587 flo = fle->object;
98588 if (!flo)
98589 goto ret_object;
98590 @@ -263,7 +263,7 @@ nocache:
98591 }
98592 flo = resolver(net, key, family, dir, flo, ctx);
98593 if (fle) {
98594 - fle->genid = atomic_read(&net->xfrm.flow_cache_genid);
98595 + fle->genid = atomic_read_unchecked(&net->xfrm.flow_cache_genid);
98596 if (!IS_ERR(flo))
98597 fle->object = flo;
98598 else
98599 diff --git a/net/core/iovec.c b/net/core/iovec.c
98600 index 26dc006..89e838e 100644
98601 --- a/net/core/iovec.c
98602 +++ b/net/core/iovec.c
98603 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
98604 if (m->msg_name && m->msg_namelen) {
98605 if (mode == VERIFY_READ) {
98606 void __user *namep;
98607 - namep = (void __user __force *) m->msg_name;
98608 + namep = (void __force_user *) m->msg_name;
98609 err = move_addr_to_kernel(namep, m->msg_namelen,
98610 address);
98611 if (err < 0)
98612 @@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
98613 }
98614
98615 size = m->msg_iovlen * sizeof(struct iovec);
98616 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
98617 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
98618 return -EFAULT;
98619
98620 m->msg_iov = iov;
98621 diff --git a/net/core/neighbour.c b/net/core/neighbour.c
98622 index 32d872e..487e769 100644
98623 --- a/net/core/neighbour.c
98624 +++ b/net/core/neighbour.c
98625 @@ -2825,7 +2825,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
98626 void __user *buffer, size_t *lenp, loff_t *ppos)
98627 {
98628 int size, ret;
98629 - struct ctl_table tmp = *ctl;
98630 + ctl_table_no_const tmp = *ctl;
98631
98632 tmp.extra1 = &zero;
98633 tmp.extra2 = &unres_qlen_max;
98634 @@ -2887,7 +2887,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
98635 void __user *buffer,
98636 size_t *lenp, loff_t *ppos)
98637 {
98638 - struct ctl_table tmp = *ctl;
98639 + ctl_table_no_const tmp = *ctl;
98640 int ret;
98641
98642 tmp.extra1 = &zero;
98643 @@ -3059,11 +3059,12 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
98644 memset(&t->neigh_vars[NEIGH_VAR_GC_INTERVAL], 0,
98645 sizeof(t->neigh_vars[NEIGH_VAR_GC_INTERVAL]));
98646 } else {
98647 + struct neigh_table *ntable = container_of(p, struct neigh_table, parms);
98648 dev_name_source = "default";
98649 - t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = (int *)(p + 1);
98650 - t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = (int *)(p + 1) + 1;
98651 - t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = (int *)(p + 1) + 2;
98652 - t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = (int *)(p + 1) + 3;
98653 + t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = &ntable->gc_interval;
98654 + t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = &ntable->gc_thresh1;
98655 + t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = &ntable->gc_thresh2;
98656 + t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = &ntable->gc_thresh3;
98657 }
98658
98659 if (handler) {
98660 diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
98661 index 2bf8329..2eb1423 100644
98662 --- a/net/core/net-procfs.c
98663 +++ b/net/core/net-procfs.c
98664 @@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
98665 struct rtnl_link_stats64 temp;
98666 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
98667
98668 - seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98669 + if (gr_proc_is_restricted())
98670 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98671 + "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
98672 + dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
98673 + 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
98674 + else
98675 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98676 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
98677 dev->name, stats->rx_bytes, stats->rx_packets,
98678 stats->rx_errors,
98679 @@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
98680 return 0;
98681 }
98682
98683 -static const struct seq_operations dev_seq_ops = {
98684 +const struct seq_operations dev_seq_ops = {
98685 .start = dev_seq_start,
98686 .next = dev_seq_next,
98687 .stop = dev_seq_stop,
98688 @@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
98689
98690 static int softnet_seq_open(struct inode *inode, struct file *file)
98691 {
98692 - return seq_open(file, &softnet_seq_ops);
98693 + return seq_open_restrict(file, &softnet_seq_ops);
98694 }
98695
98696 static const struct file_operations softnet_seq_fops = {
98697 @@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
98698 else
98699 seq_printf(seq, "%04x", ntohs(pt->type));
98700
98701 +#ifdef CONFIG_GRKERNSEC_HIDESYM
98702 + seq_printf(seq, " %-8s %pf\n",
98703 + pt->dev ? pt->dev->name : "", NULL);
98704 +#else
98705 seq_printf(seq, " %-8s %pf\n",
98706 pt->dev ? pt->dev->name : "", pt->func);
98707 +#endif
98708 }
98709
98710 return 0;
98711 diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
98712 index 1cac29e..fb482f3 100644
98713 --- a/net/core/net-sysfs.c
98714 +++ b/net/core/net-sysfs.c
98715 @@ -259,7 +259,7 @@ static ssize_t carrier_changes_show(struct device *dev,
98716 {
98717 struct net_device *netdev = to_net_dev(dev);
98718 return sprintf(buf, fmt_dec,
98719 - atomic_read(&netdev->carrier_changes));
98720 + atomic_read_unchecked(&netdev->carrier_changes));
98721 }
98722 static DEVICE_ATTR_RO(carrier_changes);
98723
98724 diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
98725 index 7c8ffd9..0cb3687 100644
98726 --- a/net/core/net_namespace.c
98727 +++ b/net/core/net_namespace.c
98728 @@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
98729 int error;
98730 LIST_HEAD(net_exit_list);
98731
98732 - list_add_tail(&ops->list, list);
98733 + pax_list_add_tail((struct list_head *)&ops->list, list);
98734 if (ops->init || (ops->id && ops->size)) {
98735 for_each_net(net) {
98736 error = ops_init(ops, net);
98737 @@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
98738
98739 out_undo:
98740 /* If I have an error cleanup all namespaces I initialized */
98741 - list_del(&ops->list);
98742 + pax_list_del((struct list_head *)&ops->list);
98743 ops_exit_list(ops, &net_exit_list);
98744 ops_free_list(ops, &net_exit_list);
98745 return error;
98746 @@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
98747 struct net *net;
98748 LIST_HEAD(net_exit_list);
98749
98750 - list_del(&ops->list);
98751 + pax_list_del((struct list_head *)&ops->list);
98752 for_each_net(net)
98753 list_add_tail(&net->exit_list, &net_exit_list);
98754 ops_exit_list(ops, &net_exit_list);
98755 @@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
98756 mutex_lock(&net_mutex);
98757 error = register_pernet_operations(&pernet_list, ops);
98758 if (!error && (first_device == &pernet_list))
98759 - first_device = &ops->list;
98760 + first_device = (struct list_head *)&ops->list;
98761 mutex_unlock(&net_mutex);
98762 return error;
98763 }
98764 diff --git a/net/core/netpoll.c b/net/core/netpoll.c
98765 index e33937f..b2b4981 100644
98766 --- a/net/core/netpoll.c
98767 +++ b/net/core/netpoll.c
98768 @@ -382,7 +382,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
98769 struct udphdr *udph;
98770 struct iphdr *iph;
98771 struct ethhdr *eth;
98772 - static atomic_t ip_ident;
98773 + static atomic_unchecked_t ip_ident;
98774 struct ipv6hdr *ip6h;
98775
98776 udp_len = len + sizeof(*udph);
98777 @@ -453,7 +453,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
98778 put_unaligned(0x45, (unsigned char *)iph);
98779 iph->tos = 0;
98780 put_unaligned(htons(ip_len), &(iph->tot_len));
98781 - iph->id = htons(atomic_inc_return(&ip_ident));
98782 + iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
98783 iph->frag_off = 0;
98784 iph->ttl = 64;
98785 iph->protocol = IPPROTO_UDP;
98786 diff --git a/net/core/pktgen.c b/net/core/pktgen.c
98787 index 0304f98..ddfead6 100644
98788 --- a/net/core/pktgen.c
98789 +++ b/net/core/pktgen.c
98790 @@ -3725,7 +3725,7 @@ static int __net_init pg_net_init(struct net *net)
98791 pn->net = net;
98792 INIT_LIST_HEAD(&pn->pktgen_threads);
98793 pn->pktgen_exiting = false;
98794 - pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
98795 + pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
98796 if (!pn->proc_dir) {
98797 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
98798 return -ENODEV;
98799 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
98800 index 1999ed8..1e6e58a 100644
98801 --- a/net/core/rtnetlink.c
98802 +++ b/net/core/rtnetlink.c
98803 @@ -58,7 +58,7 @@ struct rtnl_link {
98804 rtnl_doit_func doit;
98805 rtnl_dumpit_func dumpit;
98806 rtnl_calcit_func calcit;
98807 -};
98808 +} __no_const;
98809
98810 static DEFINE_MUTEX(rtnl_mutex);
98811
98812 @@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
98813 if (rtnl_link_ops_get(ops->kind))
98814 return -EEXIST;
98815
98816 - if (!ops->dellink)
98817 - ops->dellink = unregister_netdevice_queue;
98818 + if (!ops->dellink) {
98819 + pax_open_kernel();
98820 + *(void **)&ops->dellink = unregister_netdevice_queue;
98821 + pax_close_kernel();
98822 + }
98823
98824 - list_add_tail(&ops->list, &link_ops);
98825 + pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
98826 return 0;
98827 }
98828 EXPORT_SYMBOL_GPL(__rtnl_link_register);
98829 @@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
98830 for_each_net(net) {
98831 __rtnl_kill_links(net, ops);
98832 }
98833 - list_del(&ops->list);
98834 + pax_list_del((struct list_head *)&ops->list);
98835 }
98836 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
98837
98838 @@ -1008,7 +1011,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
98839 (dev->ifalias &&
98840 nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)) ||
98841 nla_put_u32(skb, IFLA_CARRIER_CHANGES,
98842 - atomic_read(&dev->carrier_changes)))
98843 + atomic_read_unchecked(&dev->carrier_changes)))
98844 goto nla_put_failure;
98845
98846 if (1) {
98847 diff --git a/net/core/scm.c b/net/core/scm.c
98848 index b442e7e..6f5b5a2 100644
98849 --- a/net/core/scm.c
98850 +++ b/net/core/scm.c
98851 @@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
98852 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
98853 {
98854 struct cmsghdr __user *cm
98855 - = (__force struct cmsghdr __user *)msg->msg_control;
98856 + = (struct cmsghdr __force_user *)msg->msg_control;
98857 struct cmsghdr cmhdr;
98858 int cmlen = CMSG_LEN(len);
98859 int err;
98860 @@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
98861 err = -EFAULT;
98862 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
98863 goto out;
98864 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
98865 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
98866 goto out;
98867 cmlen = CMSG_SPACE(len);
98868 if (msg->msg_controllen < cmlen)
98869 @@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
98870 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
98871 {
98872 struct cmsghdr __user *cm
98873 - = (__force struct cmsghdr __user*)msg->msg_control;
98874 + = (struct cmsghdr __force_user *)msg->msg_control;
98875
98876 int fdmax = 0;
98877 int fdnum = scm->fp->count;
98878 @@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
98879 if (fdnum < fdmax)
98880 fdmax = fdnum;
98881
98882 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
98883 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
98884 i++, cmfptr++)
98885 {
98886 struct socket *sock;
98887 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
98888 index 6ab5f77..6fd2a81 100644
98889 --- a/net/core/skbuff.c
98890 +++ b/net/core/skbuff.c
98891 @@ -2003,7 +2003,7 @@ EXPORT_SYMBOL(__skb_checksum);
98892 __wsum skb_checksum(const struct sk_buff *skb, int offset,
98893 int len, __wsum csum)
98894 {
98895 - const struct skb_checksum_ops ops = {
98896 + static const struct skb_checksum_ops ops = {
98897 .update = csum_partial_ext,
98898 .combine = csum_block_add_ext,
98899 };
98900 @@ -3221,13 +3221,15 @@ void __init skb_init(void)
98901 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
98902 sizeof(struct sk_buff),
98903 0,
98904 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
98905 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
98906 + SLAB_NO_SANITIZE,
98907 NULL);
98908 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
98909 (2*sizeof(struct sk_buff)) +
98910 sizeof(atomic_t),
98911 0,
98912 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
98913 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
98914 + SLAB_NO_SANITIZE,
98915 NULL);
98916 }
98917
98918 diff --git a/net/core/sock.c b/net/core/sock.c
98919 index 664ee42..aaf9e6e 100644
98920 --- a/net/core/sock.c
98921 +++ b/net/core/sock.c
98922 @@ -442,7 +442,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98923 struct sk_buff_head *list = &sk->sk_receive_queue;
98924
98925 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
98926 - atomic_inc(&sk->sk_drops);
98927 + atomic_inc_unchecked(&sk->sk_drops);
98928 trace_sock_rcvqueue_full(sk, skb);
98929 return -ENOMEM;
98930 }
98931 @@ -452,7 +452,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98932 return err;
98933
98934 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
98935 - atomic_inc(&sk->sk_drops);
98936 + atomic_inc_unchecked(&sk->sk_drops);
98937 return -ENOBUFS;
98938 }
98939
98940 @@ -472,7 +472,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98941 skb_dst_force(skb);
98942
98943 spin_lock_irqsave(&list->lock, flags);
98944 - skb->dropcount = atomic_read(&sk->sk_drops);
98945 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
98946 __skb_queue_tail(list, skb);
98947 spin_unlock_irqrestore(&list->lock, flags);
98948
98949 @@ -492,7 +492,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
98950 skb->dev = NULL;
98951
98952 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
98953 - atomic_inc(&sk->sk_drops);
98954 + atomic_inc_unchecked(&sk->sk_drops);
98955 goto discard_and_relse;
98956 }
98957 if (nested)
98958 @@ -510,7 +510,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
98959 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
98960 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
98961 bh_unlock_sock(sk);
98962 - atomic_inc(&sk->sk_drops);
98963 + atomic_inc_unchecked(&sk->sk_drops);
98964 goto discard_and_relse;
98965 }
98966
98967 @@ -998,12 +998,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98968 struct timeval tm;
98969 } v;
98970
98971 - int lv = sizeof(int);
98972 - int len;
98973 + unsigned int lv = sizeof(int);
98974 + unsigned int len;
98975
98976 if (get_user(len, optlen))
98977 return -EFAULT;
98978 - if (len < 0)
98979 + if (len > INT_MAX)
98980 return -EINVAL;
98981
98982 memset(&v, 0, sizeof(v));
98983 @@ -1155,11 +1155,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98984
98985 case SO_PEERNAME:
98986 {
98987 - char address[128];
98988 + char address[_K_SS_MAXSIZE];
98989
98990 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
98991 return -ENOTCONN;
98992 - if (lv < len)
98993 + if (lv < len || sizeof address < len)
98994 return -EINVAL;
98995 if (copy_to_user(optval, address, len))
98996 return -EFAULT;
98997 @@ -1240,7 +1240,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98998
98999 if (len > lv)
99000 len = lv;
99001 - if (copy_to_user(optval, &v, len))
99002 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
99003 return -EFAULT;
99004 lenout:
99005 if (put_user(len, optlen))
99006 @@ -2375,7 +2375,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
99007 */
99008 smp_wmb();
99009 atomic_set(&sk->sk_refcnt, 1);
99010 - atomic_set(&sk->sk_drops, 0);
99011 + atomic_set_unchecked(&sk->sk_drops, 0);
99012 }
99013 EXPORT_SYMBOL(sock_init_data);
99014
99015 @@ -2503,6 +2503,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
99016 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
99017 int level, int type)
99018 {
99019 + struct sock_extended_err ee;
99020 struct sock_exterr_skb *serr;
99021 struct sk_buff *skb, *skb2;
99022 int copied, err;
99023 @@ -2524,7 +2525,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
99024 sock_recv_timestamp(msg, sk, skb);
99025
99026 serr = SKB_EXT_ERR(skb);
99027 - put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
99028 + ee = serr->ee;
99029 + put_cmsg(msg, level, type, sizeof ee, &ee);
99030
99031 msg->msg_flags |= MSG_ERRQUEUE;
99032 err = copied;
99033 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
99034 index a4216a4..1c07687 100644
99035 --- a/net/core/sock_diag.c
99036 +++ b/net/core/sock_diag.c
99037 @@ -9,26 +9,33 @@
99038 #include <linux/inet_diag.h>
99039 #include <linux/sock_diag.h>
99040
99041 -static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
99042 +static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
99043 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
99044 static DEFINE_MUTEX(sock_diag_table_mutex);
99045
99046 int sock_diag_check_cookie(void *sk, __u32 *cookie)
99047 {
99048 +#ifndef CONFIG_GRKERNSEC_HIDESYM
99049 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
99050 cookie[1] != INET_DIAG_NOCOOKIE) &&
99051 ((u32)(unsigned long)sk != cookie[0] ||
99052 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
99053 return -ESTALE;
99054 else
99055 +#endif
99056 return 0;
99057 }
99058 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
99059
99060 void sock_diag_save_cookie(void *sk, __u32 *cookie)
99061 {
99062 +#ifdef CONFIG_GRKERNSEC_HIDESYM
99063 + cookie[0] = 0;
99064 + cookie[1] = 0;
99065 +#else
99066 cookie[0] = (u32)(unsigned long)sk;
99067 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
99068 +#endif
99069 }
99070 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
99071
99072 @@ -110,8 +117,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
99073 mutex_lock(&sock_diag_table_mutex);
99074 if (sock_diag_handlers[hndl->family])
99075 err = -EBUSY;
99076 - else
99077 + else {
99078 + pax_open_kernel();
99079 sock_diag_handlers[hndl->family] = hndl;
99080 + pax_close_kernel();
99081 + }
99082 mutex_unlock(&sock_diag_table_mutex);
99083
99084 return err;
99085 @@ -127,7 +137,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
99086
99087 mutex_lock(&sock_diag_table_mutex);
99088 BUG_ON(sock_diag_handlers[family] != hnld);
99089 + pax_open_kernel();
99090 sock_diag_handlers[family] = NULL;
99091 + pax_close_kernel();
99092 mutex_unlock(&sock_diag_table_mutex);
99093 }
99094 EXPORT_SYMBOL_GPL(sock_diag_unregister);
99095 diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
99096 index cf9cd13..8b56af3 100644
99097 --- a/net/core/sysctl_net_core.c
99098 +++ b/net/core/sysctl_net_core.c
99099 @@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
99100 {
99101 unsigned int orig_size, size;
99102 int ret, i;
99103 - struct ctl_table tmp = {
99104 + ctl_table_no_const tmp = {
99105 .data = &size,
99106 .maxlen = sizeof(size),
99107 .mode = table->mode
99108 @@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
99109 void __user *buffer, size_t *lenp, loff_t *ppos)
99110 {
99111 char id[IFNAMSIZ];
99112 - struct ctl_table tbl = {
99113 + ctl_table_no_const tbl = {
99114 .data = id,
99115 .maxlen = IFNAMSIZ,
99116 };
99117 @@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
99118
99119 static __net_init int sysctl_core_net_init(struct net *net)
99120 {
99121 - struct ctl_table *tbl;
99122 + ctl_table_no_const *tbl = NULL;
99123
99124 net->core.sysctl_somaxconn = SOMAXCONN;
99125
99126 - tbl = netns_core_table;
99127 if (!net_eq(net, &init_net)) {
99128 - tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
99129 + tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
99130 if (tbl == NULL)
99131 goto err_dup;
99132
99133 @@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
99134 if (net->user_ns != &init_user_ns) {
99135 tbl[0].procname = NULL;
99136 }
99137 - }
99138 -
99139 - net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
99140 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
99141 + } else
99142 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
99143 if (net->core.sysctl_hdr == NULL)
99144 goto err_reg;
99145
99146 return 0;
99147
99148 err_reg:
99149 - if (tbl != netns_core_table)
99150 - kfree(tbl);
99151 + kfree(tbl);
99152 err_dup:
99153 return -ENOMEM;
99154 }
99155 @@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
99156 kfree(tbl);
99157 }
99158
99159 -static __net_initdata struct pernet_operations sysctl_core_ops = {
99160 +static __net_initconst struct pernet_operations sysctl_core_ops = {
99161 .init = sysctl_core_net_init,
99162 .exit = sysctl_core_net_exit,
99163 };
99164 diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
99165 index 4c04848..f575934 100644
99166 --- a/net/decnet/af_decnet.c
99167 +++ b/net/decnet/af_decnet.c
99168 @@ -465,6 +465,7 @@ static struct proto dn_proto = {
99169 .sysctl_rmem = sysctl_decnet_rmem,
99170 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
99171 .obj_size = sizeof(struct dn_sock),
99172 + .slab_flags = SLAB_USERCOPY,
99173 };
99174
99175 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
99176 diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
99177 index 3b726f3..1af6368 100644
99178 --- a/net/decnet/dn_dev.c
99179 +++ b/net/decnet/dn_dev.c
99180 @@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
99181 .extra1 = &min_t3,
99182 .extra2 = &max_t3
99183 },
99184 - {0}
99185 + { }
99186 },
99187 };
99188
99189 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
99190 index 5325b54..a0d4d69 100644
99191 --- a/net/decnet/sysctl_net_decnet.c
99192 +++ b/net/decnet/sysctl_net_decnet.c
99193 @@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
99194
99195 if (len > *lenp) len = *lenp;
99196
99197 - if (copy_to_user(buffer, addr, len))
99198 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
99199 return -EFAULT;
99200
99201 *lenp = len;
99202 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
99203
99204 if (len > *lenp) len = *lenp;
99205
99206 - if (copy_to_user(buffer, devname, len))
99207 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
99208 return -EFAULT;
99209
99210 *lenp = len;
99211 diff --git a/net/ieee802154/reassembly.c b/net/ieee802154/reassembly.c
99212 index ef2d543..5b9b73f 100644
99213 --- a/net/ieee802154/reassembly.c
99214 +++ b/net/ieee802154/reassembly.c
99215 @@ -434,12 +434,11 @@ static struct ctl_table lowpan_frags_ctl_table[] = {
99216
99217 static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
99218 {
99219 - struct ctl_table *table;
99220 + ctl_table_no_const *table = NULL;
99221 struct ctl_table_header *hdr;
99222
99223 - table = lowpan_frags_ns_ctl_table;
99224 if (!net_eq(net, &init_net)) {
99225 - table = kmemdup(table, sizeof(lowpan_frags_ns_ctl_table),
99226 + table = kmemdup(lowpan_frags_ns_ctl_table, sizeof(lowpan_frags_ns_ctl_table),
99227 GFP_KERNEL);
99228 if (table == NULL)
99229 goto err_alloc;
99230 @@ -452,9 +451,9 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
99231 /* Don't export sysctls to unprivileged users */
99232 if (net->user_ns != &init_user_ns)
99233 table[0].procname = NULL;
99234 - }
99235 -
99236 - hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
99237 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
99238 + } else
99239 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", lowpan_frags_ns_ctl_table);
99240 if (hdr == NULL)
99241 goto err_reg;
99242
99243 @@ -462,8 +461,7 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
99244 return 0;
99245
99246 err_reg:
99247 - if (!net_eq(net, &init_net))
99248 - kfree(table);
99249 + kfree(table);
99250 err_alloc:
99251 return -ENOMEM;
99252 }
99253 diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
99254 index 6af8ab6..3831cb8 100644
99255 --- a/net/ipv4/af_inet.c
99256 +++ b/net/ipv4/af_inet.c
99257 @@ -1739,13 +1739,9 @@ static int __init inet_init(void)
99258
99259 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
99260
99261 - sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
99262 - if (!sysctl_local_reserved_ports)
99263 - goto out;
99264 -
99265 rc = proto_register(&tcp_prot, 1);
99266 if (rc)
99267 - goto out_free_reserved_ports;
99268 + goto out;
99269
99270 rc = proto_register(&udp_prot, 1);
99271 if (rc)
99272 @@ -1855,8 +1851,6 @@ out_unregister_udp_proto:
99273 proto_unregister(&udp_prot);
99274 out_unregister_tcp_proto:
99275 proto_unregister(&tcp_prot);
99276 -out_free_reserved_ports:
99277 - kfree(sysctl_local_reserved_ports);
99278 goto out;
99279 }
99280
99281 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
99282 index bdbf68b..deb4759 100644
99283 --- a/net/ipv4/devinet.c
99284 +++ b/net/ipv4/devinet.c
99285 @@ -1543,7 +1543,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
99286 idx = 0;
99287 head = &net->dev_index_head[h];
99288 rcu_read_lock();
99289 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
99290 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
99291 net->dev_base_seq;
99292 hlist_for_each_entry_rcu(dev, head, index_hlist) {
99293 if (idx < s_idx)
99294 @@ -1861,7 +1861,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
99295 idx = 0;
99296 head = &net->dev_index_head[h];
99297 rcu_read_lock();
99298 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
99299 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
99300 net->dev_base_seq;
99301 hlist_for_each_entry_rcu(dev, head, index_hlist) {
99302 if (idx < s_idx)
99303 @@ -2096,7 +2096,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
99304 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
99305 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
99306
99307 -static struct devinet_sysctl_table {
99308 +static const struct devinet_sysctl_table {
99309 struct ctl_table_header *sysctl_header;
99310 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
99311 } devinet_sysctl = {
99312 @@ -2218,7 +2218,7 @@ static __net_init int devinet_init_net(struct net *net)
99313 int err;
99314 struct ipv4_devconf *all, *dflt;
99315 #ifdef CONFIG_SYSCTL
99316 - struct ctl_table *tbl = ctl_forward_entry;
99317 + ctl_table_no_const *tbl = NULL;
99318 struct ctl_table_header *forw_hdr;
99319 #endif
99320
99321 @@ -2236,7 +2236,7 @@ static __net_init int devinet_init_net(struct net *net)
99322 goto err_alloc_dflt;
99323
99324 #ifdef CONFIG_SYSCTL
99325 - tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
99326 + tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
99327 if (tbl == NULL)
99328 goto err_alloc_ctl;
99329
99330 @@ -2256,7 +2256,10 @@ static __net_init int devinet_init_net(struct net *net)
99331 goto err_reg_dflt;
99332
99333 err = -ENOMEM;
99334 - forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
99335 + if (!net_eq(net, &init_net))
99336 + forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
99337 + else
99338 + forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
99339 if (forw_hdr == NULL)
99340 goto err_reg_ctl;
99341 net->ipv4.forw_hdr = forw_hdr;
99342 @@ -2272,8 +2275,7 @@ err_reg_ctl:
99343 err_reg_dflt:
99344 __devinet_sysctl_unregister(all);
99345 err_reg_all:
99346 - if (tbl != ctl_forward_entry)
99347 - kfree(tbl);
99348 + kfree(tbl);
99349 err_alloc_ctl:
99350 #endif
99351 if (dflt != &ipv4_devconf_dflt)
99352 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
99353 index 255aa99..45c78f8 100644
99354 --- a/net/ipv4/fib_frontend.c
99355 +++ b/net/ipv4/fib_frontend.c
99356 @@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
99357 #ifdef CONFIG_IP_ROUTE_MULTIPATH
99358 fib_sync_up(dev);
99359 #endif
99360 - atomic_inc(&net->ipv4.dev_addr_genid);
99361 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
99362 rt_cache_flush(dev_net(dev));
99363 break;
99364 case NETDEV_DOWN:
99365 fib_del_ifaddr(ifa, NULL);
99366 - atomic_inc(&net->ipv4.dev_addr_genid);
99367 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
99368 if (ifa->ifa_dev->ifa_list == NULL) {
99369 /* Last address was deleted from this interface.
99370 * Disable IP.
99371 @@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
99372 #ifdef CONFIG_IP_ROUTE_MULTIPATH
99373 fib_sync_up(dev);
99374 #endif
99375 - atomic_inc(&net->ipv4.dev_addr_genid);
99376 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
99377 rt_cache_flush(net);
99378 break;
99379 case NETDEV_DOWN:
99380 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
99381 index b10cd43a..22327f9 100644
99382 --- a/net/ipv4/fib_semantics.c
99383 +++ b/net/ipv4/fib_semantics.c
99384 @@ -768,7 +768,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
99385 nh->nh_saddr = inet_select_addr(nh->nh_dev,
99386 nh->nh_gw,
99387 nh->nh_parent->fib_scope);
99388 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
99389 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
99390
99391 return nh->nh_saddr;
99392 }
99393 diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
99394 index a56b8e6..5be2a30 100644
99395 --- a/net/ipv4/inet_connection_sock.c
99396 +++ b/net/ipv4/inet_connection_sock.c
99397 @@ -29,7 +29,7 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
99398 EXPORT_SYMBOL(inet_csk_timer_bug_msg);
99399 #endif
99400
99401 -unsigned long *sysctl_local_reserved_ports;
99402 +unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
99403 EXPORT_SYMBOL(sysctl_local_reserved_ports);
99404
99405 void inet_get_local_port_range(struct net *net, int *low, int *high)
99406 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
99407 index 8b9cf27..0d8d592 100644
99408 --- a/net/ipv4/inet_hashtables.c
99409 +++ b/net/ipv4/inet_hashtables.c
99410 @@ -18,6 +18,7 @@
99411 #include <linux/sched.h>
99412 #include <linux/slab.h>
99413 #include <linux/wait.h>
99414 +#include <linux/security.h>
99415
99416 #include <net/inet_connection_sock.h>
99417 #include <net/inet_hashtables.h>
99418 @@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
99419 return inet_ehashfn(net, laddr, lport, faddr, fport);
99420 }
99421
99422 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
99423 +
99424 /*
99425 * Allocate and initialize a new local port bind bucket.
99426 * The bindhash mutex for snum's hash chain must be held here.
99427 @@ -554,6 +557,8 @@ ok:
99428 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
99429 spin_unlock(&head->lock);
99430
99431 + gr_update_task_in_ip_table(current, inet_sk(sk));
99432 +
99433 if (tw) {
99434 inet_twsk_deschedule(tw, death_row);
99435 while (twrefcnt) {
99436 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
99437 index bf2cb4a..d83ba8a 100644
99438 --- a/net/ipv4/inetpeer.c
99439 +++ b/net/ipv4/inetpeer.c
99440 @@ -482,7 +482,7 @@ relookup:
99441 if (p) {
99442 p->daddr = *daddr;
99443 atomic_set(&p->refcnt, 1);
99444 - atomic_set(&p->rid, 0);
99445 + atomic_set_unchecked(&p->rid, 0);
99446 p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
99447 p->rate_tokens = 0;
99448 /* 60*HZ is arbitrary, but chosen enough high so that the first
99449 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
99450 index ed32313..3762abe 100644
99451 --- a/net/ipv4/ip_fragment.c
99452 +++ b/net/ipv4/ip_fragment.c
99453 @@ -284,7 +284,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
99454 return 0;
99455
99456 start = qp->rid;
99457 - end = atomic_inc_return(&peer->rid);
99458 + end = atomic_inc_return_unchecked(&peer->rid);
99459 qp->rid = end;
99460
99461 rc = qp->q.fragments && (end - start) > max;
99462 @@ -761,12 +761,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
99463
99464 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
99465 {
99466 - struct ctl_table *table;
99467 + ctl_table_no_const *table = NULL;
99468 struct ctl_table_header *hdr;
99469
99470 - table = ip4_frags_ns_ctl_table;
99471 if (!net_eq(net, &init_net)) {
99472 - table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
99473 + table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
99474 if (table == NULL)
99475 goto err_alloc;
99476
99477 @@ -777,9 +776,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
99478 /* Don't export sysctls to unprivileged users */
99479 if (net->user_ns != &init_user_ns)
99480 table[0].procname = NULL;
99481 - }
99482 + hdr = register_net_sysctl(net, "net/ipv4", table);
99483 + } else
99484 + hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
99485
99486 - hdr = register_net_sysctl(net, "net/ipv4", table);
99487 if (hdr == NULL)
99488 goto err_reg;
99489
99490 @@ -787,8 +787,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
99491 return 0;
99492
99493 err_reg:
99494 - if (!net_eq(net, &init_net))
99495 - kfree(table);
99496 + kfree(table);
99497 err_alloc:
99498 return -ENOMEM;
99499 }
99500 diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
99501 index 94213c8..8bdb342 100644
99502 --- a/net/ipv4/ip_gre.c
99503 +++ b/net/ipv4/ip_gre.c
99504 @@ -115,7 +115,7 @@ static bool log_ecn_error = true;
99505 module_param(log_ecn_error, bool, 0644);
99506 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
99507
99508 -static struct rtnl_link_ops ipgre_link_ops __read_mostly;
99509 +static struct rtnl_link_ops ipgre_link_ops;
99510 static int ipgre_tunnel_init(struct net_device *dev);
99511
99512 static int ipgre_net_id __read_mostly;
99513 @@ -732,7 +732,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
99514 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
99515 };
99516
99517 -static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
99518 +static struct rtnl_link_ops ipgre_link_ops = {
99519 .kind = "gre",
99520 .maxtype = IFLA_GRE_MAX,
99521 .policy = ipgre_policy,
99522 @@ -746,7 +746,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
99523 .fill_info = ipgre_fill_info,
99524 };
99525
99526 -static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
99527 +static struct rtnl_link_ops ipgre_tap_ops = {
99528 .kind = "gretap",
99529 .maxtype = IFLA_GRE_MAX,
99530 .policy = ipgre_policy,
99531 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
99532 index 64741b9..6f334a2 100644
99533 --- a/net/ipv4/ip_sockglue.c
99534 +++ b/net/ipv4/ip_sockglue.c
99535 @@ -1188,7 +1188,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
99536 len = min_t(unsigned int, len, opt->optlen);
99537 if (put_user(len, optlen))
99538 return -EFAULT;
99539 - if (copy_to_user(optval, opt->__data, len))
99540 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
99541 + copy_to_user(optval, opt->__data, len))
99542 return -EFAULT;
99543 return 0;
99544 }
99545 @@ -1319,7 +1320,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
99546 if (sk->sk_type != SOCK_STREAM)
99547 return -ENOPROTOOPT;
99548
99549 - msg.msg_control = optval;
99550 + msg.msg_control = (void __force_kernel *)optval;
99551 msg.msg_controllen = len;
99552 msg.msg_flags = flags;
99553
99554 diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
99555 index 13ef00f..8ffca25 100644
99556 --- a/net/ipv4/ip_vti.c
99557 +++ b/net/ipv4/ip_vti.c
99558 @@ -45,7 +45,7 @@
99559 #include <net/net_namespace.h>
99560 #include <net/netns/generic.h>
99561
99562 -static struct rtnl_link_ops vti_link_ops __read_mostly;
99563 +static struct rtnl_link_ops vti_link_ops;
99564
99565 static int vti_net_id __read_mostly;
99566 static int vti_tunnel_init(struct net_device *dev);
99567 @@ -513,7 +513,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
99568 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
99569 };
99570
99571 -static struct rtnl_link_ops vti_link_ops __read_mostly = {
99572 +static struct rtnl_link_ops vti_link_ops = {
99573 .kind = "vti",
99574 .maxtype = IFLA_VTI_MAX,
99575 .policy = vti_policy,
99576 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
99577 index b3e86ea..18ce98c 100644
99578 --- a/net/ipv4/ipconfig.c
99579 +++ b/net/ipv4/ipconfig.c
99580 @@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
99581
99582 mm_segment_t oldfs = get_fs();
99583 set_fs(get_ds());
99584 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
99585 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
99586 set_fs(oldfs);
99587 return res;
99588 }
99589 @@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
99590
99591 mm_segment_t oldfs = get_fs();
99592 set_fs(get_ds());
99593 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
99594 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
99595 set_fs(oldfs);
99596 return res;
99597 }
99598 @@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
99599
99600 mm_segment_t oldfs = get_fs();
99601 set_fs(get_ds());
99602 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
99603 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
99604 set_fs(oldfs);
99605 return res;
99606 }
99607 diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
99608 index 62eaa00..29b2dc2 100644
99609 --- a/net/ipv4/ipip.c
99610 +++ b/net/ipv4/ipip.c
99611 @@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
99612 static int ipip_net_id __read_mostly;
99613
99614 static int ipip_tunnel_init(struct net_device *dev);
99615 -static struct rtnl_link_ops ipip_link_ops __read_mostly;
99616 +static struct rtnl_link_ops ipip_link_ops;
99617
99618 static int ipip_err(struct sk_buff *skb, u32 info)
99619 {
99620 @@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
99621 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
99622 };
99623
99624 -static struct rtnl_link_ops ipip_link_ops __read_mostly = {
99625 +static struct rtnl_link_ops ipip_link_ops = {
99626 .kind = "ipip",
99627 .maxtype = IFLA_IPTUN_MAX,
99628 .policy = ipip_policy,
99629 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
99630 index f95b6f9..2ee2097 100644
99631 --- a/net/ipv4/netfilter/arp_tables.c
99632 +++ b/net/ipv4/netfilter/arp_tables.c
99633 @@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
99634 #endif
99635
99636 static int get_info(struct net *net, void __user *user,
99637 - const int *len, int compat)
99638 + int len, int compat)
99639 {
99640 char name[XT_TABLE_MAXNAMELEN];
99641 struct xt_table *t;
99642 int ret;
99643
99644 - if (*len != sizeof(struct arpt_getinfo)) {
99645 - duprintf("length %u != %Zu\n", *len,
99646 + if (len != sizeof(struct arpt_getinfo)) {
99647 + duprintf("length %u != %Zu\n", len,
99648 sizeof(struct arpt_getinfo));
99649 return -EINVAL;
99650 }
99651 @@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
99652 info.size = private->size;
99653 strcpy(info.name, name);
99654
99655 - if (copy_to_user(user, &info, *len) != 0)
99656 + if (copy_to_user(user, &info, len) != 0)
99657 ret = -EFAULT;
99658 else
99659 ret = 0;
99660 @@ -1690,7 +1690,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
99661
99662 switch (cmd) {
99663 case ARPT_SO_GET_INFO:
99664 - ret = get_info(sock_net(sk), user, len, 1);
99665 + ret = get_info(sock_net(sk), user, *len, 1);
99666 break;
99667 case ARPT_SO_GET_ENTRIES:
99668 ret = compat_get_entries(sock_net(sk), user, len);
99669 @@ -1735,7 +1735,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
99670
99671 switch (cmd) {
99672 case ARPT_SO_GET_INFO:
99673 - ret = get_info(sock_net(sk), user, len, 0);
99674 + ret = get_info(sock_net(sk), user, *len, 0);
99675 break;
99676
99677 case ARPT_SO_GET_ENTRIES:
99678 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
99679 index 99e810f..3711b81 100644
99680 --- a/net/ipv4/netfilter/ip_tables.c
99681 +++ b/net/ipv4/netfilter/ip_tables.c
99682 @@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
99683 #endif
99684
99685 static int get_info(struct net *net, void __user *user,
99686 - const int *len, int compat)
99687 + int len, int compat)
99688 {
99689 char name[XT_TABLE_MAXNAMELEN];
99690 struct xt_table *t;
99691 int ret;
99692
99693 - if (*len != sizeof(struct ipt_getinfo)) {
99694 - duprintf("length %u != %zu\n", *len,
99695 + if (len != sizeof(struct ipt_getinfo)) {
99696 + duprintf("length %u != %zu\n", len,
99697 sizeof(struct ipt_getinfo));
99698 return -EINVAL;
99699 }
99700 @@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
99701 info.size = private->size;
99702 strcpy(info.name, name);
99703
99704 - if (copy_to_user(user, &info, *len) != 0)
99705 + if (copy_to_user(user, &info, len) != 0)
99706 ret = -EFAULT;
99707 else
99708 ret = 0;
99709 @@ -1973,7 +1973,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99710
99711 switch (cmd) {
99712 case IPT_SO_GET_INFO:
99713 - ret = get_info(sock_net(sk), user, len, 1);
99714 + ret = get_info(sock_net(sk), user, *len, 1);
99715 break;
99716 case IPT_SO_GET_ENTRIES:
99717 ret = compat_get_entries(sock_net(sk), user, len);
99718 @@ -2020,7 +2020,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99719
99720 switch (cmd) {
99721 case IPT_SO_GET_INFO:
99722 - ret = get_info(sock_net(sk), user, len, 0);
99723 + ret = get_info(sock_net(sk), user, *len, 0);
99724 break;
99725
99726 case IPT_SO_GET_ENTRIES:
99727 diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
99728 index 2510c02..cfb34fa 100644
99729 --- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
99730 +++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
99731 @@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
99732 spin_lock_init(&cn->lock);
99733
99734 #ifdef CONFIG_PROC_FS
99735 - cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
99736 + cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
99737 if (!cn->procdir) {
99738 pr_err("Unable to proc dir entry\n");
99739 return -ENOMEM;
99740 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
99741 index 044a0dd..e0c1971 100644
99742 --- a/net/ipv4/ping.c
99743 +++ b/net/ipv4/ping.c
99744 @@ -59,7 +59,7 @@ struct ping_table {
99745 };
99746
99747 static struct ping_table ping_table;
99748 -struct pingv6_ops pingv6_ops;
99749 +struct pingv6_ops *pingv6_ops;
99750 EXPORT_SYMBOL_GPL(pingv6_ops);
99751
99752 static u16 ping_port_rover;
99753 @@ -348,7 +348,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
99754 return -ENODEV;
99755 }
99756 }
99757 - has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
99758 + has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
99759 scoped);
99760 rcu_read_unlock();
99761
99762 @@ -556,7 +556,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
99763 }
99764 #if IS_ENABLED(CONFIG_IPV6)
99765 } else if (skb->protocol == htons(ETH_P_IPV6)) {
99766 - harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
99767 + harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
99768 #endif
99769 }
99770
99771 @@ -574,7 +574,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
99772 info, (u8 *)icmph);
99773 #if IS_ENABLED(CONFIG_IPV6)
99774 } else if (family == AF_INET6) {
99775 - pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
99776 + pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
99777 info, (u8 *)icmph);
99778 #endif
99779 }
99780 @@ -844,6 +844,8 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99781 {
99782 struct inet_sock *isk = inet_sk(sk);
99783 int family = sk->sk_family;
99784 + struct sockaddr_in *sin;
99785 + struct sockaddr_in6 *sin6;
99786 struct sk_buff *skb;
99787 int copied, err;
99788
99789 @@ -853,12 +855,19 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99790 if (flags & MSG_OOB)
99791 goto out;
99792
99793 + if (addr_len) {
99794 + if (family == AF_INET)
99795 + *addr_len = sizeof(*sin);
99796 + else if (family == AF_INET6 && addr_len)
99797 + *addr_len = sizeof(*sin6);
99798 + }
99799 +
99800 if (flags & MSG_ERRQUEUE) {
99801 if (family == AF_INET) {
99802 return ip_recv_error(sk, msg, len, addr_len);
99803 #if IS_ENABLED(CONFIG_IPV6)
99804 } else if (family == AF_INET6) {
99805 - return pingv6_ops.ipv6_recv_error(sk, msg, len,
99806 + return pingv6_ops->ipv6_recv_error(sk, msg, len,
99807 addr_len);
99808 #endif
99809 }
99810 @@ -890,7 +899,6 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99811 sin->sin_port = 0 /* skb->h.uh->source */;
99812 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99813 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
99814 - *addr_len = sizeof(*sin);
99815 }
99816
99817 if (isk->cmsg_flags)
99818 @@ -912,14 +920,13 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99819 sin6->sin6_scope_id =
99820 ipv6_iface_scope_id(&sin6->sin6_addr,
99821 IP6CB(skb)->iif);
99822 - *addr_len = sizeof(*sin6);
99823 }
99824
99825 if (inet6_sk(sk)->rxopt.all)
99826 - pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
99827 + pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
99828 if (skb->protocol == htons(ETH_P_IPV6) &&
99829 inet6_sk(sk)->rxopt.all)
99830 - pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
99831 + pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
99832 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
99833 ip_cmsg_recv(msg, skb);
99834 #endif
99835 @@ -1111,7 +1118,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
99836 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
99837 0, sock_i_ino(sp),
99838 atomic_read(&sp->sk_refcnt), sp,
99839 - atomic_read(&sp->sk_drops));
99840 + atomic_read_unchecked(&sp->sk_drops));
99841 }
99842
99843 static int ping_v4_seq_show(struct seq_file *seq, void *v)
99844 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
99845 index 2c65160..b54c00e 100644
99846 --- a/net/ipv4/raw.c
99847 +++ b/net/ipv4/raw.c
99848 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
99849 int raw_rcv(struct sock *sk, struct sk_buff *skb)
99850 {
99851 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
99852 - atomic_inc(&sk->sk_drops);
99853 + atomic_inc_unchecked(&sk->sk_drops);
99854 kfree_skb(skb);
99855 return NET_RX_DROP;
99856 }
99857 @@ -696,6 +696,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99858 if (flags & MSG_OOB)
99859 goto out;
99860
99861 + if (addr_len)
99862 + *addr_len = sizeof(*sin);
99863 +
99864 if (flags & MSG_ERRQUEUE) {
99865 err = ip_recv_error(sk, msg, len, addr_len);
99866 goto out;
99867 @@ -723,7 +726,6 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99868 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99869 sin->sin_port = 0;
99870 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
99871 - *addr_len = sizeof(*sin);
99872 }
99873 if (inet->cmsg_flags)
99874 ip_cmsg_recv(msg, skb);
99875 @@ -748,16 +750,20 @@ static int raw_init(struct sock *sk)
99876
99877 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
99878 {
99879 + struct icmp_filter filter;
99880 +
99881 if (optlen > sizeof(struct icmp_filter))
99882 optlen = sizeof(struct icmp_filter);
99883 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
99884 + if (copy_from_user(&filter, optval, optlen))
99885 return -EFAULT;
99886 + raw_sk(sk)->filter = filter;
99887 return 0;
99888 }
99889
99890 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
99891 {
99892 int len, ret = -EFAULT;
99893 + struct icmp_filter filter;
99894
99895 if (get_user(len, optlen))
99896 goto out;
99897 @@ -767,8 +773,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
99898 if (len > sizeof(struct icmp_filter))
99899 len = sizeof(struct icmp_filter);
99900 ret = -EFAULT;
99901 - if (put_user(len, optlen) ||
99902 - copy_to_user(optval, &raw_sk(sk)->filter, len))
99903 + filter = raw_sk(sk)->filter;
99904 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
99905 goto out;
99906 ret = 0;
99907 out: return ret;
99908 @@ -997,7 +1003,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
99909 0, 0L, 0,
99910 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
99911 0, sock_i_ino(sp),
99912 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
99913 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
99914 }
99915
99916 static int raw_seq_show(struct seq_file *seq, void *v)
99917 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
99918 index fd618d4..aae0ac9 100644
99919 --- a/net/ipv4/route.c
99920 +++ b/net/ipv4/route.c
99921 @@ -228,7 +228,7 @@ static const struct seq_operations rt_cache_seq_ops = {
99922
99923 static int rt_cache_seq_open(struct inode *inode, struct file *file)
99924 {
99925 - return seq_open(file, &rt_cache_seq_ops);
99926 + return seq_open_restrict(file, &rt_cache_seq_ops);
99927 }
99928
99929 static const struct file_operations rt_cache_seq_fops = {
99930 @@ -319,7 +319,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
99931
99932 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
99933 {
99934 - return seq_open(file, &rt_cpu_seq_ops);
99935 + return seq_open_restrict(file, &rt_cpu_seq_ops);
99936 }
99937
99938 static const struct file_operations rt_cpu_seq_fops = {
99939 @@ -357,7 +357,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
99940
99941 static int rt_acct_proc_open(struct inode *inode, struct file *file)
99942 {
99943 - return single_open(file, rt_acct_proc_show, NULL);
99944 + return single_open_restrict(file, rt_acct_proc_show, NULL);
99945 }
99946
99947 static const struct file_operations rt_acct_proc_fops = {
99948 @@ -459,7 +459,7 @@ static struct neighbour *ipv4_neigh_lookup(const struct dst_entry *dst,
99949
99950 #define IP_IDENTS_SZ 2048u
99951 struct ip_ident_bucket {
99952 - atomic_t id;
99953 + atomic_unchecked_t id;
99954 u32 stamp32;
99955 };
99956
99957 @@ -479,7 +479,7 @@ u32 ip_idents_reserve(u32 hash, int segs)
99958 if (old != now && cmpxchg(&bucket->stamp32, old, now) == old)
99959 delta = prandom_u32_max(now - old);
99960
99961 - return atomic_add_return(segs + delta, &bucket->id) - segs;
99962 + return atomic_add_return_unchecked(segs + delta, &bucket->id) - segs;
99963 }
99964 EXPORT_SYMBOL(ip_idents_reserve);
99965
99966 @@ -2618,34 +2618,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
99967 .maxlen = sizeof(int),
99968 .mode = 0200,
99969 .proc_handler = ipv4_sysctl_rtcache_flush,
99970 + .extra1 = &init_net,
99971 },
99972 { },
99973 };
99974
99975 static __net_init int sysctl_route_net_init(struct net *net)
99976 {
99977 - struct ctl_table *tbl;
99978 + ctl_table_no_const *tbl = NULL;
99979
99980 - tbl = ipv4_route_flush_table;
99981 if (!net_eq(net, &init_net)) {
99982 - tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
99983 + tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
99984 if (tbl == NULL)
99985 goto err_dup;
99986
99987 /* Don't export sysctls to unprivileged users */
99988 if (net->user_ns != &init_user_ns)
99989 tbl[0].procname = NULL;
99990 - }
99991 - tbl[0].extra1 = net;
99992 + tbl[0].extra1 = net;
99993 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
99994 + } else
99995 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
99996
99997 - net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
99998 if (net->ipv4.route_hdr == NULL)
99999 goto err_reg;
100000 return 0;
100001
100002 err_reg:
100003 - if (tbl != ipv4_route_flush_table)
100004 - kfree(tbl);
100005 + kfree(tbl);
100006 err_dup:
100007 return -ENOMEM;
100008 }
100009 @@ -2668,8 +2668,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
100010
100011 static __net_init int rt_genid_init(struct net *net)
100012 {
100013 - atomic_set(&net->ipv4.rt_genid, 0);
100014 - atomic_set(&net->fnhe_genid, 0);
100015 + atomic_set_unchecked(&net->ipv4.rt_genid, 0);
100016 + atomic_set_unchecked(&net->fnhe_genid, 0);
100017 get_random_bytes(&net->ipv4.dev_addr_genid,
100018 sizeof(net->ipv4.dev_addr_genid));
100019 return 0;
100020 diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
100021 index 5cde8f2..5f5684e 100644
100022 --- a/net/ipv4/sysctl_net_ipv4.c
100023 +++ b/net/ipv4/sysctl_net_ipv4.c
100024 @@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
100025 container_of(table->data, struct net, ipv4.ip_local_ports.range);
100026 int ret;
100027 int range[2];
100028 - struct ctl_table tmp = {
100029 + ctl_table_no_const tmp = {
100030 .data = &range,
100031 .maxlen = sizeof(range),
100032 .mode = table->mode,
100033 @@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
100034 int ret;
100035 gid_t urange[2];
100036 kgid_t low, high;
100037 - struct ctl_table tmp = {
100038 + ctl_table_no_const tmp = {
100039 .data = &urange,
100040 .maxlen = sizeof(urange),
100041 .mode = table->mode,
100042 @@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
100043 void __user *buffer, size_t *lenp, loff_t *ppos)
100044 {
100045 char val[TCP_CA_NAME_MAX];
100046 - struct ctl_table tbl = {
100047 + ctl_table_no_const tbl = {
100048 .data = val,
100049 .maxlen = TCP_CA_NAME_MAX,
100050 };
100051 @@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
100052 void __user *buffer, size_t *lenp,
100053 loff_t *ppos)
100054 {
100055 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
100056 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
100057 int ret;
100058
100059 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
100060 @@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
100061 void __user *buffer, size_t *lenp,
100062 loff_t *ppos)
100063 {
100064 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
100065 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
100066 int ret;
100067
100068 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
100069 @@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
100070 void __user *buffer, size_t *lenp,
100071 loff_t *ppos)
100072 {
100073 - struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
100074 + ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
100075 struct tcp_fastopen_context *ctxt;
100076 int ret;
100077 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
100078 @@ -438,7 +438,7 @@ static struct ctl_table ipv4_table[] = {
100079 },
100080 {
100081 .procname = "ip_local_reserved_ports",
100082 - .data = NULL, /* initialized in sysctl_ipv4_init */
100083 + .data = sysctl_local_reserved_ports,
100084 .maxlen = 65536,
100085 .mode = 0644,
100086 .proc_handler = proc_do_large_bitmap,
100087 @@ -843,13 +843,12 @@ static struct ctl_table ipv4_net_table[] = {
100088
100089 static __net_init int ipv4_sysctl_init_net(struct net *net)
100090 {
100091 - struct ctl_table *table;
100092 + ctl_table_no_const *table = NULL;
100093
100094 - table = ipv4_net_table;
100095 if (!net_eq(net, &init_net)) {
100096 int i;
100097
100098 - table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
100099 + table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
100100 if (table == NULL)
100101 goto err_alloc;
100102
100103 @@ -858,15 +857,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
100104 table[i].data += (void *)net - (void *)&init_net;
100105 }
100106
100107 - net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
100108 + if (!net_eq(net, &init_net))
100109 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
100110 + else
100111 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
100112 if (net->ipv4.ipv4_hdr == NULL)
100113 goto err_reg;
100114
100115 return 0;
100116
100117 err_reg:
100118 - if (!net_eq(net, &init_net))
100119 - kfree(table);
100120 + kfree(table);
100121 err_alloc:
100122 return -ENOMEM;
100123 }
100124 @@ -888,16 +889,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
100125 static __init int sysctl_ipv4_init(void)
100126 {
100127 struct ctl_table_header *hdr;
100128 - struct ctl_table *i;
100129 -
100130 - for (i = ipv4_table; i->procname; i++) {
100131 - if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
100132 - i->data = sysctl_local_reserved_ports;
100133 - break;
100134 - }
100135 - }
100136 - if (!i->procname)
100137 - return -EINVAL;
100138
100139 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
100140 if (hdr == NULL)
100141 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
100142 index 09b85cd..df9c266 100644
100143 --- a/net/ipv4/tcp_input.c
100144 +++ b/net/ipv4/tcp_input.c
100145 @@ -754,7 +754,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
100146 * without any lock. We want to make sure compiler wont store
100147 * intermediate values in this location.
100148 */
100149 - ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
100150 + ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
100151 sk->sk_max_pacing_rate);
100152 }
100153
100154 @@ -4478,7 +4478,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
100155 * simplifies code)
100156 */
100157 static void
100158 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
100159 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
100160 struct sk_buff *head, struct sk_buff *tail,
100161 u32 start, u32 end)
100162 {
100163 @@ -5558,6 +5558,7 @@ discard:
100164 tcp_paws_reject(&tp->rx_opt, 0))
100165 goto discard_and_undo;
100166
100167 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
100168 if (th->syn) {
100169 /* We see SYN without ACK. It is attempt of
100170 * simultaneous connect with crossed SYNs.
100171 @@ -5608,6 +5609,7 @@ discard:
100172 goto discard;
100173 #endif
100174 }
100175 +#endif
100176 /* "fifth, if neither of the SYN or RST bits is set then
100177 * drop the segment and return."
100178 */
100179 @@ -5654,7 +5656,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
100180 goto discard;
100181
100182 if (th->syn) {
100183 - if (th->fin)
100184 + if (th->fin || th->urg || th->psh)
100185 goto discard;
100186 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
100187 return 1;
100188 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
100189 index 438f3b9..bc9e1ad 100644
100190 --- a/net/ipv4/tcp_ipv4.c
100191 +++ b/net/ipv4/tcp_ipv4.c
100192 @@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
100193 EXPORT_SYMBOL(sysctl_tcp_low_latency);
100194
100195
100196 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100197 +extern int grsec_enable_blackhole;
100198 +#endif
100199 +
100200 #ifdef CONFIG_TCP_MD5SIG
100201 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
100202 __be32 daddr, __be32 saddr, const struct tcphdr *th);
100203 @@ -1829,6 +1833,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
100204 return 0;
100205
100206 reset:
100207 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100208 + if (!grsec_enable_blackhole)
100209 +#endif
100210 tcp_v4_send_reset(rsk, skb);
100211 discard:
100212 kfree_skb(skb);
100213 @@ -1974,12 +1981,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
100214 TCP_SKB_CB(skb)->sacked = 0;
100215
100216 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
100217 - if (!sk)
100218 + if (!sk) {
100219 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100220 + ret = 1;
100221 +#endif
100222 goto no_tcp_socket;
100223 -
100224 + }
100225 process:
100226 - if (sk->sk_state == TCP_TIME_WAIT)
100227 + if (sk->sk_state == TCP_TIME_WAIT) {
100228 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100229 + ret = 2;
100230 +#endif
100231 goto do_time_wait;
100232 + }
100233
100234 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
100235 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
100236 @@ -2033,6 +2047,10 @@ csum_error:
100237 bad_packet:
100238 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
100239 } else {
100240 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100241 + if (!grsec_enable_blackhole || (ret == 1 &&
100242 + (skb->dev->flags & IFF_LOOPBACK)))
100243 +#endif
100244 tcp_v4_send_reset(NULL, skb);
100245 }
100246
100247 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
100248 index 05c1b15..3e9344b 100644
100249 --- a/net/ipv4/tcp_minisocks.c
100250 +++ b/net/ipv4/tcp_minisocks.c
100251 @@ -27,6 +27,10 @@
100252 #include <net/inet_common.h>
100253 #include <net/xfrm.h>
100254
100255 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100256 +extern int grsec_enable_blackhole;
100257 +#endif
100258 +
100259 int sysctl_tcp_syncookies __read_mostly = 1;
100260 EXPORT_SYMBOL(sysctl_tcp_syncookies);
100261
100262 @@ -709,7 +713,10 @@ embryonic_reset:
100263 * avoid becoming vulnerable to outside attack aiming at
100264 * resetting legit local connections.
100265 */
100266 - req->rsk_ops->send_reset(sk, skb);
100267 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100268 + if (!grsec_enable_blackhole)
100269 +#endif
100270 + req->rsk_ops->send_reset(sk, skb);
100271 } else if (fastopen) { /* received a valid RST pkt */
100272 reqsk_fastopen_remove(sk, req, true);
100273 tcp_reset(sk);
100274 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
100275 index 3b66610..bfbe23a 100644
100276 --- a/net/ipv4/tcp_probe.c
100277 +++ b/net/ipv4/tcp_probe.c
100278 @@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
100279 if (cnt + width >= len)
100280 break;
100281
100282 - if (copy_to_user(buf + cnt, tbuf, width))
100283 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
100284 return -EFAULT;
100285 cnt += width;
100286 }
100287 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
100288 index 286227a..c495a76 100644
100289 --- a/net/ipv4/tcp_timer.c
100290 +++ b/net/ipv4/tcp_timer.c
100291 @@ -22,6 +22,10 @@
100292 #include <linux/gfp.h>
100293 #include <net/tcp.h>
100294
100295 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100296 +extern int grsec_lastack_retries;
100297 +#endif
100298 +
100299 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
100300 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
100301 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
100302 @@ -192,6 +196,13 @@ static int tcp_write_timeout(struct sock *sk)
100303 }
100304 }
100305
100306 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100307 + if ((sk->sk_state == TCP_LAST_ACK) &&
100308 + (grsec_lastack_retries > 0) &&
100309 + (grsec_lastack_retries < retry_until))
100310 + retry_until = grsec_lastack_retries;
100311 +#endif
100312 +
100313 if (retransmits_timed_out(sk, retry_until,
100314 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
100315 /* Has it gone just too far? */
100316 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
100317 index 54a5fe9..78fea00 100644
100318 --- a/net/ipv4/udp.c
100319 +++ b/net/ipv4/udp.c
100320 @@ -87,6 +87,7 @@
100321 #include <linux/types.h>
100322 #include <linux/fcntl.h>
100323 #include <linux/module.h>
100324 +#include <linux/security.h>
100325 #include <linux/socket.h>
100326 #include <linux/sockios.h>
100327 #include <linux/igmp.h>
100328 @@ -113,6 +114,10 @@
100329 #include <net/busy_poll.h>
100330 #include "udp_impl.h"
100331
100332 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100333 +extern int grsec_enable_blackhole;
100334 +#endif
100335 +
100336 struct udp_table udp_table __read_mostly;
100337 EXPORT_SYMBOL(udp_table);
100338
100339 @@ -615,6 +620,9 @@ found:
100340 return s;
100341 }
100342
100343 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
100344 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
100345 +
100346 /*
100347 * This routine is called by the ICMP module when it gets some
100348 * sort of error condition. If err < 0 then the socket should
100349 @@ -914,9 +922,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100350 dport = usin->sin_port;
100351 if (dport == 0)
100352 return -EINVAL;
100353 +
100354 + err = gr_search_udp_sendmsg(sk, usin);
100355 + if (err)
100356 + return err;
100357 } else {
100358 if (sk->sk_state != TCP_ESTABLISHED)
100359 return -EDESTADDRREQ;
100360 +
100361 + err = gr_search_udp_sendmsg(sk, NULL);
100362 + if (err)
100363 + return err;
100364 +
100365 daddr = inet->inet_daddr;
100366 dport = inet->inet_dport;
100367 /* Open fast path for connected socket.
100368 @@ -1164,7 +1181,7 @@ static unsigned int first_packet_length(struct sock *sk)
100369 IS_UDPLITE(sk));
100370 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
100371 IS_UDPLITE(sk));
100372 - atomic_inc(&sk->sk_drops);
100373 + atomic_inc_unchecked(&sk->sk_drops);
100374 __skb_unlink(skb, rcvq);
100375 __skb_queue_tail(&list_kill, skb);
100376 }
100377 @@ -1235,6 +1252,12 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100378 int is_udplite = IS_UDPLITE(sk);
100379 bool slow;
100380
100381 + /*
100382 + * Check any passed addresses
100383 + */
100384 + if (addr_len)
100385 + *addr_len = sizeof(*sin);
100386 +
100387 if (flags & MSG_ERRQUEUE)
100388 return ip_recv_error(sk, msg, len, addr_len);
100389
100390 @@ -1244,6 +1267,10 @@ try_again:
100391 if (!skb)
100392 goto out;
100393
100394 + err = gr_search_udp_recvmsg(sk, skb);
100395 + if (err)
100396 + goto out_free;
100397 +
100398 ulen = skb->len - sizeof(struct udphdr);
100399 copied = len;
100400 if (copied > ulen)
100401 @@ -1277,7 +1304,7 @@ try_again:
100402 if (unlikely(err)) {
100403 trace_kfree_skb(skb, udp_recvmsg);
100404 if (!peeked) {
100405 - atomic_inc(&sk->sk_drops);
100406 + atomic_inc_unchecked(&sk->sk_drops);
100407 UDP_INC_STATS_USER(sock_net(sk),
100408 UDP_MIB_INERRORS, is_udplite);
100409 }
100410 @@ -1296,7 +1323,6 @@ try_again:
100411 sin->sin_port = udp_hdr(skb)->source;
100412 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
100413 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
100414 - *addr_len = sizeof(*sin);
100415 }
100416 if (inet->cmsg_flags)
100417 ip_cmsg_recv(msg, skb);
100418 @@ -1567,7 +1593,7 @@ csum_error:
100419 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
100420 drop:
100421 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
100422 - atomic_inc(&sk->sk_drops);
100423 + atomic_inc_unchecked(&sk->sk_drops);
100424 kfree_skb(skb);
100425 return -1;
100426 }
100427 @@ -1586,7 +1612,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
100428 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
100429
100430 if (!skb1) {
100431 - atomic_inc(&sk->sk_drops);
100432 + atomic_inc_unchecked(&sk->sk_drops);
100433 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
100434 IS_UDPLITE(sk));
100435 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
100436 @@ -1787,6 +1813,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
100437 goto csum_error;
100438
100439 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
100440 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100441 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
100442 +#endif
100443 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
100444
100445 /*
100446 @@ -2355,7 +2384,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
100447 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
100448 0, sock_i_ino(sp),
100449 atomic_read(&sp->sk_refcnt), sp,
100450 - atomic_read(&sp->sk_drops));
100451 + atomic_read_unchecked(&sp->sk_drops));
100452 }
100453
100454 int udp4_seq_show(struct seq_file *seq, void *v)
100455 diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
100456 index 6156f68..d6ab46d 100644
100457 --- a/net/ipv4/xfrm4_policy.c
100458 +++ b/net/ipv4/xfrm4_policy.c
100459 @@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
100460 fl4->flowi4_tos = iph->tos;
100461 }
100462
100463 -static inline int xfrm4_garbage_collect(struct dst_ops *ops)
100464 +static int xfrm4_garbage_collect(struct dst_ops *ops)
100465 {
100466 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
100467
100468 - xfrm4_policy_afinfo.garbage_collect(net);
100469 + xfrm_garbage_collect_deferred(net);
100470 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
100471 }
100472
100473 @@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
100474
100475 static int __net_init xfrm4_net_init(struct net *net)
100476 {
100477 - struct ctl_table *table;
100478 + ctl_table_no_const *table = NULL;
100479 struct ctl_table_header *hdr;
100480
100481 - table = xfrm4_policy_table;
100482 if (!net_eq(net, &init_net)) {
100483 - table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
100484 + table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
100485 if (!table)
100486 goto err_alloc;
100487
100488 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
100489 - }
100490 -
100491 - hdr = register_net_sysctl(net, "net/ipv4", table);
100492 + hdr = register_net_sysctl(net, "net/ipv4", table);
100493 + } else
100494 + hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
100495 if (!hdr)
100496 goto err_reg;
100497
100498 @@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
100499 return 0;
100500
100501 err_reg:
100502 - if (!net_eq(net, &init_net))
100503 - kfree(table);
100504 + kfree(table);
100505 err_alloc:
100506 return -ENOMEM;
100507 }
100508 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
100509 index 6c7fa08..8a31430 100644
100510 --- a/net/ipv6/addrconf.c
100511 +++ b/net/ipv6/addrconf.c
100512 @@ -598,7 +598,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
100513 idx = 0;
100514 head = &net->dev_index_head[h];
100515 rcu_read_lock();
100516 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
100517 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
100518 net->dev_base_seq;
100519 hlist_for_each_entry_rcu(dev, head, index_hlist) {
100520 if (idx < s_idx)
100521 @@ -2395,7 +2395,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
100522 p.iph.ihl = 5;
100523 p.iph.protocol = IPPROTO_IPV6;
100524 p.iph.ttl = 64;
100525 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
100526 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
100527
100528 if (ops->ndo_do_ioctl) {
100529 mm_segment_t oldfs = get_fs();
100530 @@ -3528,16 +3528,23 @@ static const struct file_operations if6_fops = {
100531 .release = seq_release_net,
100532 };
100533
100534 +extern void register_ipv6_seq_ops_addr(struct seq_operations *addr);
100535 +extern void unregister_ipv6_seq_ops_addr(void);
100536 +
100537 static int __net_init if6_proc_net_init(struct net *net)
100538 {
100539 - if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops))
100540 + register_ipv6_seq_ops_addr(&if6_seq_ops);
100541 + if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops)) {
100542 + unregister_ipv6_seq_ops_addr();
100543 return -ENOMEM;
100544 + }
100545 return 0;
100546 }
100547
100548 static void __net_exit if6_proc_net_exit(struct net *net)
100549 {
100550 remove_proc_entry("if_inet6", net->proc_net);
100551 + unregister_ipv6_seq_ops_addr();
100552 }
100553
100554 static struct pernet_operations if6_proc_net_ops = {
100555 @@ -4146,7 +4153,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
100556 s_ip_idx = ip_idx = cb->args[2];
100557
100558 rcu_read_lock();
100559 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
100560 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
100561 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
100562 idx = 0;
100563 head = &net->dev_index_head[h];
100564 @@ -4758,7 +4765,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
100565 dst_free(&ifp->rt->dst);
100566 break;
100567 }
100568 - atomic_inc(&net->ipv6.dev_addr_genid);
100569 + atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
100570 rt_genid_bump_ipv6(net);
100571 }
100572
100573 @@ -4779,7 +4786,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
100574 int *valp = ctl->data;
100575 int val = *valp;
100576 loff_t pos = *ppos;
100577 - struct ctl_table lctl;
100578 + ctl_table_no_const lctl;
100579 int ret;
100580
100581 /*
100582 @@ -4864,7 +4871,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
100583 int *valp = ctl->data;
100584 int val = *valp;
100585 loff_t pos = *ppos;
100586 - struct ctl_table lctl;
100587 + ctl_table_no_const lctl;
100588 int ret;
100589
100590 /*
100591 diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
100592 index d935889..2f64330 100644
100593 --- a/net/ipv6/af_inet6.c
100594 +++ b/net/ipv6/af_inet6.c
100595 @@ -776,7 +776,7 @@ static int __net_init inet6_net_init(struct net *net)
100596 net->ipv6.sysctl.bindv6only = 0;
100597 net->ipv6.sysctl.icmpv6_time = 1*HZ;
100598 net->ipv6.sysctl.flowlabel_consistency = 1;
100599 - atomic_set(&net->ipv6.rt_genid, 0);
100600 + atomic_set_unchecked(&net->ipv6.rt_genid, 0);
100601
100602 err = ipv6_init_mibs(net);
100603 if (err)
100604 diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
100605 index c3bf2d2..1f00573 100644
100606 --- a/net/ipv6/datagram.c
100607 +++ b/net/ipv6/datagram.c
100608 @@ -938,5 +938,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
100609 0,
100610 sock_i_ino(sp),
100611 atomic_read(&sp->sk_refcnt), sp,
100612 - atomic_read(&sp->sk_drops));
100613 + atomic_read_unchecked(&sp->sk_drops));
100614 }
100615 diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
100616 index 7b32652..0bc348b 100644
100617 --- a/net/ipv6/icmp.c
100618 +++ b/net/ipv6/icmp.c
100619 @@ -1005,7 +1005,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
100620
100621 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
100622 {
100623 - struct ctl_table *table;
100624 + ctl_table_no_const *table;
100625
100626 table = kmemdup(ipv6_icmp_table_template,
100627 sizeof(ipv6_icmp_table_template),
100628 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
100629 index 9d92146..d986c6a 100644
100630 --- a/net/ipv6/ip6_gre.c
100631 +++ b/net/ipv6/ip6_gre.c
100632 @@ -71,7 +71,7 @@ struct ip6gre_net {
100633 struct net_device *fb_tunnel_dev;
100634 };
100635
100636 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
100637 +static struct rtnl_link_ops ip6gre_link_ops;
100638 static int ip6gre_tunnel_init(struct net_device *dev);
100639 static void ip6gre_tunnel_setup(struct net_device *dev);
100640 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
100641 @@ -1291,7 +1291,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
100642 }
100643
100644
100645 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
100646 +static struct inet6_protocol ip6gre_protocol = {
100647 .handler = ip6gre_rcv,
100648 .err_handler = ip6gre_err,
100649 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
100650 @@ -1636,7 +1636,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
100651 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
100652 };
100653
100654 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
100655 +static struct rtnl_link_ops ip6gre_link_ops = {
100656 .kind = "ip6gre",
100657 .maxtype = IFLA_GRE_MAX,
100658 .policy = ip6gre_policy,
100659 @@ -1650,7 +1650,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
100660 .fill_info = ip6gre_fill_info,
100661 };
100662
100663 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
100664 +static struct rtnl_link_ops ip6gre_tap_ops = {
100665 .kind = "ip6gretap",
100666 .maxtype = IFLA_GRE_MAX,
100667 .policy = ip6gre_policy,
100668 diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
100669 index afa0824..04ba530 100644
100670 --- a/net/ipv6/ip6_tunnel.c
100671 +++ b/net/ipv6/ip6_tunnel.c
100672 @@ -86,7 +86,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
100673
100674 static int ip6_tnl_dev_init(struct net_device *dev);
100675 static void ip6_tnl_dev_setup(struct net_device *dev);
100676 -static struct rtnl_link_ops ip6_link_ops __read_mostly;
100677 +static struct rtnl_link_ops ip6_link_ops;
100678
100679 static int ip6_tnl_net_id __read_mostly;
100680 struct ip6_tnl_net {
100681 @@ -1708,7 +1708,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
100682 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
100683 };
100684
100685 -static struct rtnl_link_ops ip6_link_ops __read_mostly = {
100686 +static struct rtnl_link_ops ip6_link_ops = {
100687 .kind = "ip6tnl",
100688 .maxtype = IFLA_IPTUN_MAX,
100689 .policy = ip6_tnl_policy,
100690 diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
100691 index 6cc9f93..6e5bb7c 100644
100692 --- a/net/ipv6/ip6_vti.c
100693 +++ b/net/ipv6/ip6_vti.c
100694 @@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
100695
100696 static int vti6_dev_init(struct net_device *dev);
100697 static void vti6_dev_setup(struct net_device *dev);
100698 -static struct rtnl_link_ops vti6_link_ops __read_mostly;
100699 +static struct rtnl_link_ops vti6_link_ops;
100700
100701 static int vti6_net_id __read_mostly;
100702 struct vti6_net {
100703 @@ -980,7 +980,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
100704 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
100705 };
100706
100707 -static struct rtnl_link_ops vti6_link_ops __read_mostly = {
100708 +static struct rtnl_link_ops vti6_link_ops = {
100709 .kind = "vti6",
100710 .maxtype = IFLA_VTI_MAX,
100711 .policy = vti6_policy,
100712 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
100713 index edb58af..78de133 100644
100714 --- a/net/ipv6/ipv6_sockglue.c
100715 +++ b/net/ipv6/ipv6_sockglue.c
100716 @@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
100717 if (sk->sk_type != SOCK_STREAM)
100718 return -ENOPROTOOPT;
100719
100720 - msg.msg_control = optval;
100721 + msg.msg_control = (void __force_kernel *)optval;
100722 msg.msg_controllen = len;
100723 msg.msg_flags = flags;
100724
100725 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
100726 index e080fbb..412b3cf 100644
100727 --- a/net/ipv6/netfilter/ip6_tables.c
100728 +++ b/net/ipv6/netfilter/ip6_tables.c
100729 @@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
100730 #endif
100731
100732 static int get_info(struct net *net, void __user *user,
100733 - const int *len, int compat)
100734 + int len, int compat)
100735 {
100736 char name[XT_TABLE_MAXNAMELEN];
100737 struct xt_table *t;
100738 int ret;
100739
100740 - if (*len != sizeof(struct ip6t_getinfo)) {
100741 - duprintf("length %u != %zu\n", *len,
100742 + if (len != sizeof(struct ip6t_getinfo)) {
100743 + duprintf("length %u != %zu\n", len,
100744 sizeof(struct ip6t_getinfo));
100745 return -EINVAL;
100746 }
100747 @@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
100748 info.size = private->size;
100749 strcpy(info.name, name);
100750
100751 - if (copy_to_user(user, &info, *len) != 0)
100752 + if (copy_to_user(user, &info, len) != 0)
100753 ret = -EFAULT;
100754 else
100755 ret = 0;
100756 @@ -1983,7 +1983,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
100757
100758 switch (cmd) {
100759 case IP6T_SO_GET_INFO:
100760 - ret = get_info(sock_net(sk), user, len, 1);
100761 + ret = get_info(sock_net(sk), user, *len, 1);
100762 break;
100763 case IP6T_SO_GET_ENTRIES:
100764 ret = compat_get_entries(sock_net(sk), user, len);
100765 @@ -2030,7 +2030,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
100766
100767 switch (cmd) {
100768 case IP6T_SO_GET_INFO:
100769 - ret = get_info(sock_net(sk), user, len, 0);
100770 + ret = get_info(sock_net(sk), user, *len, 0);
100771 break;
100772
100773 case IP6T_SO_GET_ENTRIES:
100774 diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
100775 index 767ab8d..c5ec70a 100644
100776 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c
100777 +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
100778 @@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
100779
100780 static int nf_ct_frag6_sysctl_register(struct net *net)
100781 {
100782 - struct ctl_table *table;
100783 + ctl_table_no_const *table = NULL;
100784 struct ctl_table_header *hdr;
100785
100786 - table = nf_ct_frag6_sysctl_table;
100787 if (!net_eq(net, &init_net)) {
100788 - table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
100789 + table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
100790 GFP_KERNEL);
100791 if (table == NULL)
100792 goto err_alloc;
100793 @@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
100794 table[0].data = &net->nf_frag.frags.timeout;
100795 table[1].data = &net->nf_frag.frags.low_thresh;
100796 table[2].data = &net->nf_frag.frags.high_thresh;
100797 - }
100798 -
100799 - hdr = register_net_sysctl(net, "net/netfilter", table);
100800 + hdr = register_net_sysctl(net, "net/netfilter", table);
100801 + } else
100802 + hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
100803 if (hdr == NULL)
100804 goto err_reg;
100805
100806 @@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
100807 return 0;
100808
100809 err_reg:
100810 - if (!net_eq(net, &init_net))
100811 - kfree(table);
100812 + kfree(table);
100813 err_alloc:
100814 return -ENOMEM;
100815 }
100816 diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
100817 index 6179ac1..ffa0293 100644
100818 --- a/net/ipv6/output_core.c
100819 +++ b/net/ipv6/output_core.c
100820 @@ -8,7 +8,6 @@
100821 #include <net/addrconf.h>
100822 #include <net/secure_seq.h>
100823
100824 -
100825 int ip6_find_1stfragopt(struct sk_buff *skb, u8 **nexthdr)
100826 {
100827 u16 offset = sizeof(struct ipv6hdr);
100828 diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
100829 index bda7429..469b26b 100644
100830 --- a/net/ipv6/ping.c
100831 +++ b/net/ipv6/ping.c
100832 @@ -246,6 +246,24 @@ static struct pernet_operations ping_v6_net_ops = {
100833 };
100834 #endif
100835
100836 +static struct pingv6_ops real_pingv6_ops = {
100837 + .ipv6_recv_error = ipv6_recv_error,
100838 + .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
100839 + .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
100840 + .icmpv6_err_convert = icmpv6_err_convert,
100841 + .ipv6_icmp_error = ipv6_icmp_error,
100842 + .ipv6_chk_addr = ipv6_chk_addr,
100843 +};
100844 +
100845 +static struct pingv6_ops dummy_pingv6_ops = {
100846 + .ipv6_recv_error = dummy_ipv6_recv_error,
100847 + .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
100848 + .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
100849 + .icmpv6_err_convert = dummy_icmpv6_err_convert,
100850 + .ipv6_icmp_error = dummy_ipv6_icmp_error,
100851 + .ipv6_chk_addr = dummy_ipv6_chk_addr,
100852 +};
100853 +
100854 int __init pingv6_init(void)
100855 {
100856 #ifdef CONFIG_PROC_FS
100857 @@ -253,13 +271,7 @@ int __init pingv6_init(void)
100858 if (ret)
100859 return ret;
100860 #endif
100861 - pingv6_ops.ipv6_recv_error = ipv6_recv_error;
100862 - pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
100863 - pingv6_ops.ip6_datagram_recv_specific_ctl =
100864 - ip6_datagram_recv_specific_ctl;
100865 - pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
100866 - pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
100867 - pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
100868 + pingv6_ops = &real_pingv6_ops;
100869 return inet6_register_protosw(&pingv6_protosw);
100870 }
100871
100872 @@ -268,14 +280,9 @@ int __init pingv6_init(void)
100873 */
100874 void pingv6_exit(void)
100875 {
100876 - pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
100877 - pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
100878 - pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
100879 - pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
100880 - pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
100881 - pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
100882 #ifdef CONFIG_PROC_FS
100883 unregister_pernet_subsys(&ping_v6_net_ops);
100884 #endif
100885 + pingv6_ops = &dummy_pingv6_ops;
100886 inet6_unregister_protosw(&pingv6_protosw);
100887 }
100888 diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
100889 index 091d066..139d410 100644
100890 --- a/net/ipv6/proc.c
100891 +++ b/net/ipv6/proc.c
100892 @@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
100893 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
100894 goto proc_snmp6_fail;
100895
100896 - net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
100897 + net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
100898 if (!net->mib.proc_net_devsnmp6)
100899 goto proc_dev_snmp6_fail;
100900 return 0;
100901 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
100902 index 1f29996..46fe0c7 100644
100903 --- a/net/ipv6/raw.c
100904 +++ b/net/ipv6/raw.c
100905 @@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
100906 {
100907 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
100908 skb_checksum_complete(skb)) {
100909 - atomic_inc(&sk->sk_drops);
100910 + atomic_inc_unchecked(&sk->sk_drops);
100911 kfree_skb(skb);
100912 return NET_RX_DROP;
100913 }
100914 @@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
100915 struct raw6_sock *rp = raw6_sk(sk);
100916
100917 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
100918 - atomic_inc(&sk->sk_drops);
100919 + atomic_inc_unchecked(&sk->sk_drops);
100920 kfree_skb(skb);
100921 return NET_RX_DROP;
100922 }
100923 @@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
100924
100925 if (inet->hdrincl) {
100926 if (skb_checksum_complete(skb)) {
100927 - atomic_inc(&sk->sk_drops);
100928 + atomic_inc_unchecked(&sk->sk_drops);
100929 kfree_skb(skb);
100930 return NET_RX_DROP;
100931 }
100932 @@ -469,6 +469,9 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100933 if (flags & MSG_OOB)
100934 return -EOPNOTSUPP;
100935
100936 + if (addr_len)
100937 + *addr_len=sizeof(*sin6);
100938 +
100939 if (flags & MSG_ERRQUEUE)
100940 return ipv6_recv_error(sk, msg, len, addr_len);
100941
100942 @@ -507,7 +510,6 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100943 sin6->sin6_flowinfo = 0;
100944 sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
100945 IP6CB(skb)->iif);
100946 - *addr_len = sizeof(*sin6);
100947 }
100948
100949 sock_recv_ts_and_drops(msg, sk, skb);
100950 @@ -610,7 +612,7 @@ out:
100951 return err;
100952 }
100953
100954 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
100955 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
100956 struct flowi6 *fl6, struct dst_entry **dstp,
100957 unsigned int flags)
100958 {
100959 @@ -922,12 +924,15 @@ do_confirm:
100960 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
100961 char __user *optval, int optlen)
100962 {
100963 + struct icmp6_filter filter;
100964 +
100965 switch (optname) {
100966 case ICMPV6_FILTER:
100967 if (optlen > sizeof(struct icmp6_filter))
100968 optlen = sizeof(struct icmp6_filter);
100969 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
100970 + if (copy_from_user(&filter, optval, optlen))
100971 return -EFAULT;
100972 + raw6_sk(sk)->filter = filter;
100973 return 0;
100974 default:
100975 return -ENOPROTOOPT;
100976 @@ -940,6 +945,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
100977 char __user *optval, int __user *optlen)
100978 {
100979 int len;
100980 + struct icmp6_filter filter;
100981
100982 switch (optname) {
100983 case ICMPV6_FILTER:
100984 @@ -951,7 +957,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
100985 len = sizeof(struct icmp6_filter);
100986 if (put_user(len, optlen))
100987 return -EFAULT;
100988 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
100989 + filter = raw6_sk(sk)->filter;
100990 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
100991 return -EFAULT;
100992 return 0;
100993 default:
100994 diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
100995 index cc85a9b..526a133 100644
100996 --- a/net/ipv6/reassembly.c
100997 +++ b/net/ipv6/reassembly.c
100998 @@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
100999
101000 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
101001 {
101002 - struct ctl_table *table;
101003 + ctl_table_no_const *table = NULL;
101004 struct ctl_table_header *hdr;
101005
101006 - table = ip6_frags_ns_ctl_table;
101007 if (!net_eq(net, &init_net)) {
101008 - table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
101009 + table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
101010 if (table == NULL)
101011 goto err_alloc;
101012
101013 @@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
101014 /* Don't export sysctls to unprivileged users */
101015 if (net->user_ns != &init_user_ns)
101016 table[0].procname = NULL;
101017 - }
101018 + hdr = register_net_sysctl(net, "net/ipv6", table);
101019 + } else
101020 + hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
101021
101022 - hdr = register_net_sysctl(net, "net/ipv6", table);
101023 if (hdr == NULL)
101024 goto err_reg;
101025
101026 @@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
101027 return 0;
101028
101029 err_reg:
101030 - if (!net_eq(net, &init_net))
101031 - kfree(table);
101032 + kfree(table);
101033 err_alloc:
101034 return -ENOMEM;
101035 }
101036 diff --git a/net/ipv6/route.c b/net/ipv6/route.c
101037 index 6ebdb7b6..f225ab1 100644
101038 --- a/net/ipv6/route.c
101039 +++ b/net/ipv6/route.c
101040 @@ -2971,7 +2971,7 @@ struct ctl_table ipv6_route_table_template[] = {
101041
101042 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
101043 {
101044 - struct ctl_table *table;
101045 + ctl_table_no_const *table;
101046
101047 table = kmemdup(ipv6_route_table_template,
101048 sizeof(ipv6_route_table_template),
101049 diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
101050 index 4f40817..54dcbef 100644
101051 --- a/net/ipv6/sit.c
101052 +++ b/net/ipv6/sit.c
101053 @@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
101054 static void ipip6_dev_free(struct net_device *dev);
101055 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
101056 __be32 *v4dst);
101057 -static struct rtnl_link_ops sit_link_ops __read_mostly;
101058 +static struct rtnl_link_ops sit_link_ops;
101059
101060 static int sit_net_id __read_mostly;
101061 struct sit_net {
101062 @@ -1661,7 +1661,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
101063 unregister_netdevice_queue(dev, head);
101064 }
101065
101066 -static struct rtnl_link_ops sit_link_ops __read_mostly = {
101067 +static struct rtnl_link_ops sit_link_ops = {
101068 .kind = "sit",
101069 .maxtype = IFLA_IPTUN_MAX,
101070 .policy = ipip6_policy,
101071 diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
101072 index 7f405a1..eabef92 100644
101073 --- a/net/ipv6/sysctl_net_ipv6.c
101074 +++ b/net/ipv6/sysctl_net_ipv6.c
101075 @@ -54,7 +54,7 @@ static struct ctl_table ipv6_rotable[] = {
101076
101077 static int __net_init ipv6_sysctl_net_init(struct net *net)
101078 {
101079 - struct ctl_table *ipv6_table;
101080 + ctl_table_no_const *ipv6_table;
101081 struct ctl_table *ipv6_route_table;
101082 struct ctl_table *ipv6_icmp_table;
101083 int err;
101084 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
101085 index e289830..79a5718 100644
101086 --- a/net/ipv6/tcp_ipv6.c
101087 +++ b/net/ipv6/tcp_ipv6.c
101088 @@ -102,6 +102,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
101089 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
101090 }
101091
101092 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101093 +extern int grsec_enable_blackhole;
101094 +#endif
101095 +
101096 static void tcp_v6_hash(struct sock *sk)
101097 {
101098 if (sk->sk_state != TCP_CLOSE) {
101099 @@ -1416,6 +1420,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
101100 return 0;
101101
101102 reset:
101103 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101104 + if (!grsec_enable_blackhole)
101105 +#endif
101106 tcp_v6_send_reset(sk, skb);
101107 discard:
101108 if (opt_skb)
101109 @@ -1500,12 +1507,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
101110 TCP_SKB_CB(skb)->sacked = 0;
101111
101112 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
101113 - if (!sk)
101114 + if (!sk) {
101115 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101116 + ret = 1;
101117 +#endif
101118 goto no_tcp_socket;
101119 + }
101120
101121 process:
101122 - if (sk->sk_state == TCP_TIME_WAIT)
101123 + if (sk->sk_state == TCP_TIME_WAIT) {
101124 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101125 + ret = 2;
101126 +#endif
101127 goto do_time_wait;
101128 + }
101129
101130 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
101131 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
101132 @@ -1557,6 +1572,10 @@ csum_error:
101133 bad_packet:
101134 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
101135 } else {
101136 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101137 + if (!grsec_enable_blackhole || (ret == 1 &&
101138 + (skb->dev->flags & IFF_LOOPBACK)))
101139 +#endif
101140 tcp_v6_send_reset(NULL, skb);
101141 }
101142
101143 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
101144 index 20b63d2..13be908 100644
101145 --- a/net/ipv6/udp.c
101146 +++ b/net/ipv6/udp.c
101147 @@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
101148 udp_ipv6_hash_secret + net_hash_mix(net));
101149 }
101150
101151 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101152 +extern int grsec_enable_blackhole;
101153 +#endif
101154 +
101155 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
101156 {
101157 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
101158 @@ -392,6 +396,9 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
101159 int is_udp4;
101160 bool slow;
101161
101162 + if (addr_len)
101163 + *addr_len = sizeof(struct sockaddr_in6);
101164 +
101165 if (flags & MSG_ERRQUEUE)
101166 return ipv6_recv_error(sk, msg, len, addr_len);
101167
101168 @@ -435,7 +442,7 @@ try_again:
101169 if (unlikely(err)) {
101170 trace_kfree_skb(skb, udpv6_recvmsg);
101171 if (!peeked) {
101172 - atomic_inc(&sk->sk_drops);
101173 + atomic_inc_unchecked(&sk->sk_drops);
101174 if (is_udp4)
101175 UDP_INC_STATS_USER(sock_net(sk),
101176 UDP_MIB_INERRORS,
101177 @@ -475,7 +482,7 @@ try_again:
101178 ipv6_iface_scope_id(&sin6->sin6_addr,
101179 IP6CB(skb)->iif);
101180 }
101181 - *addr_len = sizeof(*sin6);
101182 +
101183 }
101184
101185 if (np->rxopt.all)
101186 @@ -690,7 +697,7 @@ csum_error:
101187 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
101188 drop:
101189 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
101190 - atomic_inc(&sk->sk_drops);
101191 + atomic_inc_unchecked(&sk->sk_drops);
101192 kfree_skb(skb);
101193 return -1;
101194 }
101195 @@ -747,7 +754,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
101196 if (likely(skb1 == NULL))
101197 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
101198 if (!skb1) {
101199 - atomic_inc(&sk->sk_drops);
101200 + atomic_inc_unchecked(&sk->sk_drops);
101201 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
101202 IS_UDPLITE(sk));
101203 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
101204 @@ -886,6 +893,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
101205 goto csum_error;
101206
101207 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
101208 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101209 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
101210 +#endif
101211 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
101212
101213 kfree_skb(skb);
101214 diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
101215 index 2a0bbda..d75ca57 100644
101216 --- a/net/ipv6/xfrm6_policy.c
101217 +++ b/net/ipv6/xfrm6_policy.c
101218 @@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
101219 }
101220 }
101221
101222 -static inline int xfrm6_garbage_collect(struct dst_ops *ops)
101223 +static int xfrm6_garbage_collect(struct dst_ops *ops)
101224 {
101225 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
101226
101227 - xfrm6_policy_afinfo.garbage_collect(net);
101228 + xfrm_garbage_collect_deferred(net);
101229 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
101230 }
101231
101232 @@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
101233
101234 static int __net_init xfrm6_net_init(struct net *net)
101235 {
101236 - struct ctl_table *table;
101237 + ctl_table_no_const *table = NULL;
101238 struct ctl_table_header *hdr;
101239
101240 - table = xfrm6_policy_table;
101241 if (!net_eq(net, &init_net)) {
101242 - table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
101243 + table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
101244 if (!table)
101245 goto err_alloc;
101246
101247 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
101248 - }
101249 + hdr = register_net_sysctl(net, "net/ipv6", table);
101250 + } else
101251 + hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
101252
101253 - hdr = register_net_sysctl(net, "net/ipv6", table);
101254 if (!hdr)
101255 goto err_reg;
101256
101257 @@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
101258 return 0;
101259
101260 err_reg:
101261 - if (!net_eq(net, &init_net))
101262 - kfree(table);
101263 + kfree(table);
101264 err_alloc:
101265 return -ENOMEM;
101266 }
101267 diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
101268 index e15c16a..7cf07aa 100644
101269 --- a/net/ipx/ipx_proc.c
101270 +++ b/net/ipx/ipx_proc.c
101271 @@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
101272 struct proc_dir_entry *p;
101273 int rc = -ENOMEM;
101274
101275 - ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
101276 + ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
101277
101278 if (!ipx_proc_dir)
101279 goto out;
101280 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
101281 index 2ba8b97..6d33010 100644
101282 --- a/net/irda/ircomm/ircomm_tty.c
101283 +++ b/net/irda/ircomm/ircomm_tty.c
101284 @@ -317,11 +317,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
101285 add_wait_queue(&port->open_wait, &wait);
101286
101287 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
101288 - __FILE__, __LINE__, tty->driver->name, port->count);
101289 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
101290
101291 spin_lock_irqsave(&port->lock, flags);
101292 if (!tty_hung_up_p(filp))
101293 - port->count--;
101294 + atomic_dec(&port->count);
101295 port->blocked_open++;
101296 spin_unlock_irqrestore(&port->lock, flags);
101297
101298 @@ -356,7 +356,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
101299 }
101300
101301 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
101302 - __FILE__, __LINE__, tty->driver->name, port->count);
101303 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
101304
101305 schedule();
101306 }
101307 @@ -366,12 +366,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
101308
101309 spin_lock_irqsave(&port->lock, flags);
101310 if (!tty_hung_up_p(filp))
101311 - port->count++;
101312 + atomic_inc(&port->count);
101313 port->blocked_open--;
101314 spin_unlock_irqrestore(&port->lock, flags);
101315
101316 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
101317 - __FILE__, __LINE__, tty->driver->name, port->count);
101318 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
101319
101320 if (!retval)
101321 port->flags |= ASYNC_NORMAL_ACTIVE;
101322 @@ -445,12 +445,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
101323
101324 /* ++ is not atomic, so this should be protected - Jean II */
101325 spin_lock_irqsave(&self->port.lock, flags);
101326 - self->port.count++;
101327 + atomic_inc(&self->port.count);
101328 spin_unlock_irqrestore(&self->port.lock, flags);
101329 tty_port_tty_set(&self->port, tty);
101330
101331 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
101332 - self->line, self->port.count);
101333 + self->line, atomic_read(&self->port.count));
101334
101335 /* Not really used by us, but lets do it anyway */
101336 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
101337 @@ -987,7 +987,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
101338 tty_kref_put(port->tty);
101339 }
101340 port->tty = NULL;
101341 - port->count = 0;
101342 + atomic_set(&port->count, 0);
101343 spin_unlock_irqrestore(&port->lock, flags);
101344
101345 wake_up_interruptible(&port->open_wait);
101346 @@ -1344,7 +1344,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
101347 seq_putc(m, '\n');
101348
101349 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
101350 - seq_printf(m, "Open count: %d\n", self->port.count);
101351 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
101352 seq_printf(m, "Max data size: %d\n", self->max_data_size);
101353 seq_printf(m, "Max header size: %d\n", self->max_header_size);
101354
101355 diff --git a/net/irda/irproc.c b/net/irda/irproc.c
101356 index b9ac598..f88cc56 100644
101357 --- a/net/irda/irproc.c
101358 +++ b/net/irda/irproc.c
101359 @@ -66,7 +66,7 @@ void __init irda_proc_register(void)
101360 {
101361 int i;
101362
101363 - proc_irda = proc_mkdir("irda", init_net.proc_net);
101364 + proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
101365 if (proc_irda == NULL)
101366 return;
101367
101368 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
101369 index 8c9d730..66c6305 100644
101370 --- a/net/iucv/af_iucv.c
101371 +++ b/net/iucv/af_iucv.c
101372 @@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
101373
101374 write_lock_bh(&iucv_sk_list.lock);
101375
101376 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
101377 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
101378 while (__iucv_get_sock_by_name(name)) {
101379 sprintf(name, "%08x",
101380 - atomic_inc_return(&iucv_sk_list.autobind_name));
101381 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
101382 }
101383
101384 write_unlock_bh(&iucv_sk_list.lock);
101385 diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
101386 index da78793..bdd78cf 100644
101387 --- a/net/iucv/iucv.c
101388 +++ b/net/iucv/iucv.c
101389 @@ -702,7 +702,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
101390 return NOTIFY_OK;
101391 }
101392
101393 -static struct notifier_block __refdata iucv_cpu_notifier = {
101394 +static struct notifier_block iucv_cpu_notifier = {
101395 .notifier_call = iucv_cpu_notify,
101396 };
101397
101398 diff --git a/net/key/af_key.c b/net/key/af_key.c
101399 index f3c8307..7127791 100644
101400 --- a/net/key/af_key.c
101401 +++ b/net/key/af_key.c
101402 @@ -3070,10 +3070,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
101403 static u32 get_acqseq(void)
101404 {
101405 u32 res;
101406 - static atomic_t acqseq;
101407 + static atomic_unchecked_t acqseq;
101408
101409 do {
101410 - res = atomic_inc_return(&acqseq);
101411 + res = atomic_inc_return_unchecked(&acqseq);
101412 } while (!res);
101413 return res;
101414 }
101415 diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
101416 index 76125c5..e474828 100644
101417 --- a/net/l2tp/l2tp_eth.c
101418 +++ b/net/l2tp/l2tp_eth.c
101419 @@ -42,12 +42,12 @@ struct l2tp_eth {
101420 struct sock *tunnel_sock;
101421 struct l2tp_session *session;
101422 struct list_head list;
101423 - atomic_long_t tx_bytes;
101424 - atomic_long_t tx_packets;
101425 - atomic_long_t tx_dropped;
101426 - atomic_long_t rx_bytes;
101427 - atomic_long_t rx_packets;
101428 - atomic_long_t rx_errors;
101429 + atomic_long_unchecked_t tx_bytes;
101430 + atomic_long_unchecked_t tx_packets;
101431 + atomic_long_unchecked_t tx_dropped;
101432 + atomic_long_unchecked_t rx_bytes;
101433 + atomic_long_unchecked_t rx_packets;
101434 + atomic_long_unchecked_t rx_errors;
101435 };
101436
101437 /* via l2tp_session_priv() */
101438 @@ -98,10 +98,10 @@ static int l2tp_eth_dev_xmit(struct sk_buff *skb, struct net_device *dev)
101439 int ret = l2tp_xmit_skb(session, skb, session->hdr_len);
101440
101441 if (likely(ret == NET_XMIT_SUCCESS)) {
101442 - atomic_long_add(len, &priv->tx_bytes);
101443 - atomic_long_inc(&priv->tx_packets);
101444 + atomic_long_add_unchecked(len, &priv->tx_bytes);
101445 + atomic_long_inc_unchecked(&priv->tx_packets);
101446 } else {
101447 - atomic_long_inc(&priv->tx_dropped);
101448 + atomic_long_inc_unchecked(&priv->tx_dropped);
101449 }
101450 return NETDEV_TX_OK;
101451 }
101452 @@ -111,12 +111,12 @@ static struct rtnl_link_stats64 *l2tp_eth_get_stats64(struct net_device *dev,
101453 {
101454 struct l2tp_eth *priv = netdev_priv(dev);
101455
101456 - stats->tx_bytes = atomic_long_read(&priv->tx_bytes);
101457 - stats->tx_packets = atomic_long_read(&priv->tx_packets);
101458 - stats->tx_dropped = atomic_long_read(&priv->tx_dropped);
101459 - stats->rx_bytes = atomic_long_read(&priv->rx_bytes);
101460 - stats->rx_packets = atomic_long_read(&priv->rx_packets);
101461 - stats->rx_errors = atomic_long_read(&priv->rx_errors);
101462 + stats->tx_bytes = atomic_long_read_unchecked(&priv->tx_bytes);
101463 + stats->tx_packets = atomic_long_read_unchecked(&priv->tx_packets);
101464 + stats->tx_dropped = atomic_long_read_unchecked(&priv->tx_dropped);
101465 + stats->rx_bytes = atomic_long_read_unchecked(&priv->rx_bytes);
101466 + stats->rx_packets = atomic_long_read_unchecked(&priv->rx_packets);
101467 + stats->rx_errors = atomic_long_read_unchecked(&priv->rx_errors);
101468 return stats;
101469 }
101470
101471 @@ -166,15 +166,15 @@ static void l2tp_eth_dev_recv(struct l2tp_session *session, struct sk_buff *skb,
101472 nf_reset(skb);
101473
101474 if (dev_forward_skb(dev, skb) == NET_RX_SUCCESS) {
101475 - atomic_long_inc(&priv->rx_packets);
101476 - atomic_long_add(data_len, &priv->rx_bytes);
101477 + atomic_long_inc_unchecked(&priv->rx_packets);
101478 + atomic_long_add_unchecked(data_len, &priv->rx_bytes);
101479 } else {
101480 - atomic_long_inc(&priv->rx_errors);
101481 + atomic_long_inc_unchecked(&priv->rx_errors);
101482 }
101483 return;
101484
101485 error:
101486 - atomic_long_inc(&priv->rx_errors);
101487 + atomic_long_inc_unchecked(&priv->rx_errors);
101488 kfree_skb(skb);
101489 }
101490
101491 diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
101492 index 3397fe6..861fd1a 100644
101493 --- a/net/l2tp/l2tp_ip.c
101494 +++ b/net/l2tp/l2tp_ip.c
101495 @@ -518,6 +518,9 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
101496 if (flags & MSG_OOB)
101497 goto out;
101498
101499 + if (addr_len)
101500 + *addr_len = sizeof(*sin);
101501 +
101502 skb = skb_recv_datagram(sk, flags, noblock, &err);
101503 if (!skb)
101504 goto out;
101505 @@ -540,7 +543,6 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
101506 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
101507 sin->sin_port = 0;
101508 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
101509 - *addr_len = sizeof(*sin);
101510 }
101511 if (inet->cmsg_flags)
101512 ip_cmsg_recv(msg, skb);
101513 diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
101514 index 1a3c7e0..80f8b0c 100644
101515 --- a/net/llc/llc_proc.c
101516 +++ b/net/llc/llc_proc.c
101517 @@ -247,7 +247,7 @@ int __init llc_proc_init(void)
101518 int rc = -ENOMEM;
101519 struct proc_dir_entry *p;
101520
101521 - llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
101522 + llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
101523 if (!llc_proc_dir)
101524 goto out;
101525
101526 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
101527 index aaa59d7..21a2c4a 100644
101528 --- a/net/mac80211/cfg.c
101529 +++ b/net/mac80211/cfg.c
101530 @@ -839,7 +839,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
101531 ret = ieee80211_vif_use_channel(sdata, chandef,
101532 IEEE80211_CHANCTX_EXCLUSIVE);
101533 }
101534 - } else if (local->open_count == local->monitors) {
101535 + } else if (local_read(&local->open_count) == local->monitors) {
101536 local->_oper_chandef = *chandef;
101537 ieee80211_hw_config(local, 0);
101538 }
101539 @@ -3440,7 +3440,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
101540 else
101541 local->probe_req_reg--;
101542
101543 - if (!local->open_count)
101544 + if (!local_read(&local->open_count))
101545 break;
101546
101547 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
101548 @@ -3903,8 +3903,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
101549 if (chanctx_conf) {
101550 *chandef = chanctx_conf->def;
101551 ret = 0;
101552 - } else if (local->open_count > 0 &&
101553 - local->open_count == local->monitors &&
101554 + } else if (local_read(&local->open_count) > 0 &&
101555 + local_read(&local->open_count) == local->monitors &&
101556 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
101557 if (local->use_chanctx)
101558 *chandef = local->monitor_chandef;
101559 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
101560 index f169b6e..a5dc4eb 100644
101561 --- a/net/mac80211/ieee80211_i.h
101562 +++ b/net/mac80211/ieee80211_i.h
101563 @@ -28,6 +28,7 @@
101564 #include <net/ieee80211_radiotap.h>
101565 #include <net/cfg80211.h>
101566 #include <net/mac80211.h>
101567 +#include <asm/local.h>
101568 #include "key.h"
101569 #include "sta_info.h"
101570 #include "debug.h"
101571 @@ -999,7 +1000,7 @@ struct ieee80211_local {
101572 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
101573 spinlock_t queue_stop_reason_lock;
101574
101575 - int open_count;
101576 + local_t open_count;
101577 int monitors, cooked_mntrs;
101578 /* number of interfaces with corresponding FIF_ flags */
101579 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
101580 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
101581 index 34799e0..b411290 100644
101582 --- a/net/mac80211/iface.c
101583 +++ b/net/mac80211/iface.c
101584 @@ -524,7 +524,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101585 break;
101586 }
101587
101588 - if (local->open_count == 0) {
101589 + if (local_read(&local->open_count) == 0) {
101590 res = drv_start(local);
101591 if (res)
101592 goto err_del_bss;
101593 @@ -571,7 +571,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101594 res = drv_add_interface(local, sdata);
101595 if (res)
101596 goto err_stop;
101597 - } else if (local->monitors == 0 && local->open_count == 0) {
101598 + } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
101599 res = ieee80211_add_virtual_monitor(local);
101600 if (res)
101601 goto err_stop;
101602 @@ -680,7 +680,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101603 atomic_inc(&local->iff_promiscs);
101604
101605 if (coming_up)
101606 - local->open_count++;
101607 + local_inc(&local->open_count);
101608
101609 if (hw_reconf_flags)
101610 ieee80211_hw_config(local, hw_reconf_flags);
101611 @@ -718,7 +718,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101612 err_del_interface:
101613 drv_remove_interface(local, sdata);
101614 err_stop:
101615 - if (!local->open_count)
101616 + if (!local_read(&local->open_count))
101617 drv_stop(local);
101618 err_del_bss:
101619 sdata->bss = NULL;
101620 @@ -871,7 +871,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101621 }
101622
101623 if (going_down)
101624 - local->open_count--;
101625 + local_dec(&local->open_count);
101626
101627 switch (sdata->vif.type) {
101628 case NL80211_IFTYPE_AP_VLAN:
101629 @@ -930,7 +930,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101630 }
101631 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
101632
101633 - if (local->open_count == 0)
101634 + if (local_read(&local->open_count) == 0)
101635 ieee80211_clear_tx_pending(local);
101636
101637 /*
101638 @@ -970,7 +970,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101639
101640 ieee80211_recalc_ps(local, -1);
101641
101642 - if (local->open_count == 0) {
101643 + if (local_read(&local->open_count) == 0) {
101644 ieee80211_stop_device(local);
101645
101646 /* no reconfiguring after stop! */
101647 @@ -981,7 +981,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101648 ieee80211_configure_filter(local);
101649 ieee80211_hw_config(local, hw_reconf_flags);
101650
101651 - if (local->monitors == local->open_count)
101652 + if (local->monitors == local_read(&local->open_count))
101653 ieee80211_add_virtual_monitor(local);
101654 }
101655
101656 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
101657 index 4c1bf61..00b449b 100644
101658 --- a/net/mac80211/main.c
101659 +++ b/net/mac80211/main.c
101660 @@ -174,7 +174,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
101661 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
101662 IEEE80211_CONF_CHANGE_POWER);
101663
101664 - if (changed && local->open_count) {
101665 + if (changed && local_read(&local->open_count)) {
101666 ret = drv_config(local, changed);
101667 /*
101668 * Goal:
101669 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
101670 index d478b88..8c8d157 100644
101671 --- a/net/mac80211/pm.c
101672 +++ b/net/mac80211/pm.c
101673 @@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101674 struct ieee80211_sub_if_data *sdata;
101675 struct sta_info *sta;
101676
101677 - if (!local->open_count)
101678 + if (!local_read(&local->open_count))
101679 goto suspend;
101680
101681 ieee80211_scan_cancel(local);
101682 @@ -58,7 +58,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101683 cancel_work_sync(&local->dynamic_ps_enable_work);
101684 del_timer_sync(&local->dynamic_ps_timer);
101685
101686 - local->wowlan = wowlan && local->open_count;
101687 + local->wowlan = wowlan && local_read(&local->open_count);
101688 if (local->wowlan) {
101689 int err = drv_suspend(local, wowlan);
101690 if (err < 0) {
101691 @@ -123,7 +123,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101692 WARN_ON(!list_empty(&local->chanctx_list));
101693
101694 /* stop hardware - this must stop RX */
101695 - if (local->open_count)
101696 + if (local_read(&local->open_count))
101697 ieee80211_stop_device(local);
101698
101699 suspend:
101700 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
101701 index 8fdadfd..a4f72b8 100644
101702 --- a/net/mac80211/rate.c
101703 +++ b/net/mac80211/rate.c
101704 @@ -720,7 +720,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
101705
101706 ASSERT_RTNL();
101707
101708 - if (local->open_count)
101709 + if (local_read(&local->open_count))
101710 return -EBUSY;
101711
101712 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
101713 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
101714 index 6ff1346..936ca9a 100644
101715 --- a/net/mac80211/rc80211_pid_debugfs.c
101716 +++ b/net/mac80211/rc80211_pid_debugfs.c
101717 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
101718
101719 spin_unlock_irqrestore(&events->lock, status);
101720
101721 - if (copy_to_user(buf, pb, p))
101722 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
101723 return -EFAULT;
101724
101725 return p;
101726 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
101727 index 3c36583..12887fe 100644
101728 --- a/net/mac80211/util.c
101729 +++ b/net/mac80211/util.c
101730 @@ -1509,7 +1509,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
101731 }
101732 #endif
101733 /* everything else happens only if HW was up & running */
101734 - if (!local->open_count)
101735 + if (!local_read(&local->open_count))
101736 goto wake_up;
101737
101738 /*
101739 @@ -1734,7 +1734,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
101740 local->in_reconfig = false;
101741 barrier();
101742
101743 - if (local->monitors == local->open_count && local->monitors > 0)
101744 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
101745 ieee80211_add_virtual_monitor(local);
101746
101747 /*
101748 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
101749 index e9410d1..77b6378 100644
101750 --- a/net/netfilter/Kconfig
101751 +++ b/net/netfilter/Kconfig
101752 @@ -1081,6 +1081,16 @@ config NETFILTER_XT_MATCH_ESP
101753
101754 To compile it as a module, choose M here. If unsure, say N.
101755
101756 +config NETFILTER_XT_MATCH_GRADM
101757 + tristate '"gradm" match support'
101758 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
101759 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
101760 + ---help---
101761 + The gradm match allows to match on grsecurity RBAC being enabled.
101762 + It is useful when iptables rules are applied early on bootup to
101763 + prevent connections to the machine (except from a trusted host)
101764 + while the RBAC system is disabled.
101765 +
101766 config NETFILTER_XT_MATCH_HASHLIMIT
101767 tristate '"hashlimit" match support'
101768 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
101769 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
101770 index bffdad7..f9317d1 100644
101771 --- a/net/netfilter/Makefile
101772 +++ b/net/netfilter/Makefile
101773 @@ -133,6 +133,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
101774 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
101775 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
101776 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
101777 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
101778 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
101779 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
101780 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
101781 diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
101782 index 1172083..986f1c1 100644
101783 --- a/net/netfilter/ipset/ip_set_core.c
101784 +++ b/net/netfilter/ipset/ip_set_core.c
101785 @@ -1924,7 +1924,7 @@ done:
101786 return ret;
101787 }
101788
101789 -static struct nf_sockopt_ops so_set __read_mostly = {
101790 +static struct nf_sockopt_ops so_set = {
101791 .pf = PF_INET,
101792 .get_optmin = SO_IP_SET,
101793 .get_optmax = SO_IP_SET + 1,
101794 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
101795 index a8eb0a8..86f2de4 100644
101796 --- a/net/netfilter/ipvs/ip_vs_conn.c
101797 +++ b/net/netfilter/ipvs/ip_vs_conn.c
101798 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
101799 /* Increase the refcnt counter of the dest */
101800 ip_vs_dest_hold(dest);
101801
101802 - conn_flags = atomic_read(&dest->conn_flags);
101803 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
101804 if (cp->protocol != IPPROTO_UDP)
101805 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
101806 flags = cp->flags;
101807 @@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
101808
101809 cp->control = NULL;
101810 atomic_set(&cp->n_control, 0);
101811 - atomic_set(&cp->in_pkts, 0);
101812 + atomic_set_unchecked(&cp->in_pkts, 0);
101813
101814 cp->packet_xmit = NULL;
101815 cp->app = NULL;
101816 @@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
101817
101818 /* Don't drop the entry if its number of incoming packets is not
101819 located in [0, 8] */
101820 - i = atomic_read(&cp->in_pkts);
101821 + i = atomic_read_unchecked(&cp->in_pkts);
101822 if (i > 8 || i < 0) return 0;
101823
101824 if (!todrop_rate[i]) return 0;
101825 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
101826 index 3d2d2c8..c87e4d3 100644
101827 --- a/net/netfilter/ipvs/ip_vs_core.c
101828 +++ b/net/netfilter/ipvs/ip_vs_core.c
101829 @@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
101830 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
101831 /* do not touch skb anymore */
101832
101833 - atomic_inc(&cp->in_pkts);
101834 + atomic_inc_unchecked(&cp->in_pkts);
101835 ip_vs_conn_put(cp);
101836 return ret;
101837 }
101838 @@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
101839 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
101840 pkts = sysctl_sync_threshold(ipvs);
101841 else
101842 - pkts = atomic_add_return(1, &cp->in_pkts);
101843 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101844
101845 if (ipvs->sync_state & IP_VS_STATE_MASTER)
101846 ip_vs_sync_conn(net, cp, pkts);
101847 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
101848 index c42e83d..a6a3f8b 100644
101849 --- a/net/netfilter/ipvs/ip_vs_ctl.c
101850 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
101851 @@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
101852 */
101853 ip_vs_rs_hash(ipvs, dest);
101854 }
101855 - atomic_set(&dest->conn_flags, conn_flags);
101856 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
101857
101858 /* bind the service */
101859 old_svc = rcu_dereference_protected(dest->svc, 1);
101860 @@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
101861 * align with netns init in ip_vs_control_net_init()
101862 */
101863
101864 -static struct ctl_table vs_vars[] = {
101865 +static ctl_table_no_const vs_vars[] __read_only = {
101866 {
101867 .procname = "amemthresh",
101868 .maxlen = sizeof(int),
101869 @@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
101870 " %-7s %-6d %-10d %-10d\n",
101871 &dest->addr.in6,
101872 ntohs(dest->port),
101873 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
101874 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
101875 atomic_read(&dest->weight),
101876 atomic_read(&dest->activeconns),
101877 atomic_read(&dest->inactconns));
101878 @@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
101879 "%-7s %-6d %-10d %-10d\n",
101880 ntohl(dest->addr.ip),
101881 ntohs(dest->port),
101882 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
101883 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
101884 atomic_read(&dest->weight),
101885 atomic_read(&dest->activeconns),
101886 atomic_read(&dest->inactconns));
101887 @@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
101888
101889 entry.addr = dest->addr.ip;
101890 entry.port = dest->port;
101891 - entry.conn_flags = atomic_read(&dest->conn_flags);
101892 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
101893 entry.weight = atomic_read(&dest->weight);
101894 entry.u_threshold = dest->u_threshold;
101895 entry.l_threshold = dest->l_threshold;
101896 @@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
101897 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
101898 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
101899 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
101900 - (atomic_read(&dest->conn_flags) &
101901 + (atomic_read_unchecked(&dest->conn_flags) &
101902 IP_VS_CONN_F_FWD_MASK)) ||
101903 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
101904 atomic_read(&dest->weight)) ||
101905 @@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
101906 {
101907 int idx;
101908 struct netns_ipvs *ipvs = net_ipvs(net);
101909 - struct ctl_table *tbl;
101910 + ctl_table_no_const *tbl;
101911
101912 atomic_set(&ipvs->dropentry, 0);
101913 spin_lock_init(&ipvs->dropentry_lock);
101914 diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
101915 index 547ff33..c8c8117 100644
101916 --- a/net/netfilter/ipvs/ip_vs_lblc.c
101917 +++ b/net/netfilter/ipvs/ip_vs_lblc.c
101918 @@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
101919 * IPVS LBLC sysctl table
101920 */
101921 #ifdef CONFIG_SYSCTL
101922 -static struct ctl_table vs_vars_table[] = {
101923 +static ctl_table_no_const vs_vars_table[] __read_only = {
101924 {
101925 .procname = "lblc_expiration",
101926 .data = NULL,
101927 diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
101928 index 3f21a2f..a112e85 100644
101929 --- a/net/netfilter/ipvs/ip_vs_lblcr.c
101930 +++ b/net/netfilter/ipvs/ip_vs_lblcr.c
101931 @@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
101932 * IPVS LBLCR sysctl table
101933 */
101934
101935 -static struct ctl_table vs_vars_table[] = {
101936 +static ctl_table_no_const vs_vars_table[] __read_only = {
101937 {
101938 .procname = "lblcr_expiration",
101939 .data = NULL,
101940 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
101941 index db80126..ef7110e 100644
101942 --- a/net/netfilter/ipvs/ip_vs_sync.c
101943 +++ b/net/netfilter/ipvs/ip_vs_sync.c
101944 @@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
101945 cp = cp->control;
101946 if (cp) {
101947 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
101948 - pkts = atomic_add_return(1, &cp->in_pkts);
101949 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101950 else
101951 pkts = sysctl_sync_threshold(ipvs);
101952 ip_vs_sync_conn(net, cp->control, pkts);
101953 @@ -771,7 +771,7 @@ control:
101954 if (!cp)
101955 return;
101956 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
101957 - pkts = atomic_add_return(1, &cp->in_pkts);
101958 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101959 else
101960 pkts = sysctl_sync_threshold(ipvs);
101961 goto sloop;
101962 @@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
101963
101964 if (opt)
101965 memcpy(&cp->in_seq, opt, sizeof(*opt));
101966 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
101967 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
101968 cp->state = state;
101969 cp->old_state = cp->state;
101970 /*
101971 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
101972 index 7f0e1cf..e9a86e6 100644
101973 --- a/net/netfilter/ipvs/ip_vs_xmit.c
101974 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
101975 @@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
101976 else
101977 rc = NF_ACCEPT;
101978 /* do not touch skb anymore */
101979 - atomic_inc(&cp->in_pkts);
101980 + atomic_inc_unchecked(&cp->in_pkts);
101981 goto out;
101982 }
101983
101984 @@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
101985 else
101986 rc = NF_ACCEPT;
101987 /* do not touch skb anymore */
101988 - atomic_inc(&cp->in_pkts);
101989 + atomic_inc_unchecked(&cp->in_pkts);
101990 goto out;
101991 }
101992
101993 diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
101994 index a4b5e2a..13b1de3 100644
101995 --- a/net/netfilter/nf_conntrack_acct.c
101996 +++ b/net/netfilter/nf_conntrack_acct.c
101997 @@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
101998 #ifdef CONFIG_SYSCTL
101999 static int nf_conntrack_acct_init_sysctl(struct net *net)
102000 {
102001 - struct ctl_table *table;
102002 + ctl_table_no_const *table;
102003
102004 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
102005 GFP_KERNEL);
102006 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
102007 index 75421f2..0e69621 100644
102008 --- a/net/netfilter/nf_conntrack_core.c
102009 +++ b/net/netfilter/nf_conntrack_core.c
102010 @@ -1789,6 +1789,10 @@ void nf_conntrack_init_end(void)
102011 #define DYING_NULLS_VAL ((1<<30)+1)
102012 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
102013
102014 +#ifdef CONFIG_GRKERNSEC_HIDESYM
102015 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
102016 +#endif
102017 +
102018 int nf_conntrack_init_net(struct net *net)
102019 {
102020 int ret = -ENOMEM;
102021 @@ -1814,7 +1818,11 @@ int nf_conntrack_init_net(struct net *net)
102022 if (!net->ct.stat)
102023 goto err_pcpu_lists;
102024
102025 +#ifdef CONFIG_GRKERNSEC_HIDESYM
102026 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08x", atomic_inc_return_unchecked(&conntrack_cache_id));
102027 +#else
102028 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
102029 +#endif
102030 if (!net->ct.slabname)
102031 goto err_slabname;
102032
102033 diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
102034 index 1df1761..ce8b88a 100644
102035 --- a/net/netfilter/nf_conntrack_ecache.c
102036 +++ b/net/netfilter/nf_conntrack_ecache.c
102037 @@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
102038 #ifdef CONFIG_SYSCTL
102039 static int nf_conntrack_event_init_sysctl(struct net *net)
102040 {
102041 - struct ctl_table *table;
102042 + ctl_table_no_const *table;
102043
102044 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
102045 GFP_KERNEL);
102046 diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
102047 index 5b3eae7..dd4b8fe 100644
102048 --- a/net/netfilter/nf_conntrack_helper.c
102049 +++ b/net/netfilter/nf_conntrack_helper.c
102050 @@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
102051
102052 static int nf_conntrack_helper_init_sysctl(struct net *net)
102053 {
102054 - struct ctl_table *table;
102055 + ctl_table_no_const *table;
102056
102057 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
102058 GFP_KERNEL);
102059 diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
102060 index b65d586..beec902 100644
102061 --- a/net/netfilter/nf_conntrack_proto.c
102062 +++ b/net/netfilter/nf_conntrack_proto.c
102063 @@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
102064
102065 static void
102066 nf_ct_unregister_sysctl(struct ctl_table_header **header,
102067 - struct ctl_table **table,
102068 + ctl_table_no_const **table,
102069 unsigned int users)
102070 {
102071 if (users > 0)
102072 diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
102073 index f641751..d3c5b51 100644
102074 --- a/net/netfilter/nf_conntrack_standalone.c
102075 +++ b/net/netfilter/nf_conntrack_standalone.c
102076 @@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
102077
102078 static int nf_conntrack_standalone_init_sysctl(struct net *net)
102079 {
102080 - struct ctl_table *table;
102081 + ctl_table_no_const *table;
102082
102083 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
102084 GFP_KERNEL);
102085 diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
102086 index 7a394df..bd91a8a 100644
102087 --- a/net/netfilter/nf_conntrack_timestamp.c
102088 +++ b/net/netfilter/nf_conntrack_timestamp.c
102089 @@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
102090 #ifdef CONFIG_SYSCTL
102091 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
102092 {
102093 - struct ctl_table *table;
102094 + ctl_table_no_const *table;
102095
102096 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
102097 GFP_KERNEL);
102098 diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
102099 index 85296d4..8becdec 100644
102100 --- a/net/netfilter/nf_log.c
102101 +++ b/net/netfilter/nf_log.c
102102 @@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
102103
102104 #ifdef CONFIG_SYSCTL
102105 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
102106 -static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
102107 +static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
102108
102109 static int nf_log_proc_dostring(struct ctl_table *table, int write,
102110 void __user *buffer, size_t *lenp, loff_t *ppos)
102111 @@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
102112 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
102113 mutex_unlock(&nf_log_mutex);
102114 } else {
102115 + ctl_table_no_const nf_log_table = *table;
102116 +
102117 mutex_lock(&nf_log_mutex);
102118 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
102119 lockdep_is_held(&nf_log_mutex));
102120 if (!logger)
102121 - table->data = "NONE";
102122 + nf_log_table.data = "NONE";
102123 else
102124 - table->data = logger->name;
102125 - r = proc_dostring(table, write, buffer, lenp, ppos);
102126 + nf_log_table.data = logger->name;
102127 + r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
102128 mutex_unlock(&nf_log_mutex);
102129 }
102130
102131 diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
102132 index f042ae5..30ea486 100644
102133 --- a/net/netfilter/nf_sockopt.c
102134 +++ b/net/netfilter/nf_sockopt.c
102135 @@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
102136 }
102137 }
102138
102139 - list_add(&reg->list, &nf_sockopts);
102140 + pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
102141 out:
102142 mutex_unlock(&nf_sockopt_mutex);
102143 return ret;
102144 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
102145 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
102146 {
102147 mutex_lock(&nf_sockopt_mutex);
102148 - list_del(&reg->list);
102149 + pax_list_del((struct list_head *)&reg->list);
102150 mutex_unlock(&nf_sockopt_mutex);
102151 }
102152 EXPORT_SYMBOL(nf_unregister_sockopt);
102153 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
102154 index d292c8d..9f1e166 100644
102155 --- a/net/netfilter/nfnetlink_log.c
102156 +++ b/net/netfilter/nfnetlink_log.c
102157 @@ -79,7 +79,7 @@ static int nfnl_log_net_id __read_mostly;
102158 struct nfnl_log_net {
102159 spinlock_t instances_lock;
102160 struct hlist_head instance_table[INSTANCE_BUCKETS];
102161 - atomic_t global_seq;
102162 + atomic_unchecked_t global_seq;
102163 };
102164
102165 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
102166 @@ -561,7 +561,7 @@ __build_packet_message(struct nfnl_log_net *log,
102167 /* global sequence number */
102168 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
102169 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
102170 - htonl(atomic_inc_return(&log->global_seq))))
102171 + htonl(atomic_inc_return_unchecked(&log->global_seq))))
102172 goto nla_put_failure;
102173
102174 if (data_len) {
102175 diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
102176 index 8a779be..1551d4c 100644
102177 --- a/net/netfilter/nft_compat.c
102178 +++ b/net/netfilter/nft_compat.c
102179 @@ -216,7 +216,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
102180 /* We want to reuse existing compat_to_user */
102181 old_fs = get_fs();
102182 set_fs(KERNEL_DS);
102183 - t->compat_to_user(out, in);
102184 + t->compat_to_user((void __force_user *)out, in);
102185 set_fs(old_fs);
102186 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
102187 kfree(out);
102188 @@ -403,7 +403,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
102189 /* We want to reuse existing compat_to_user */
102190 old_fs = get_fs();
102191 set_fs(KERNEL_DS);
102192 - m->compat_to_user(out, in);
102193 + m->compat_to_user((void __force_user *)out, in);
102194 set_fs(old_fs);
102195 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
102196 kfree(out);
102197 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
102198 new file mode 100644
102199 index 0000000..c566332
102200 --- /dev/null
102201 +++ b/net/netfilter/xt_gradm.c
102202 @@ -0,0 +1,51 @@
102203 +/*
102204 + * gradm match for netfilter
102205 + * Copyright © Zbigniew Krzystolik, 2010
102206 + *
102207 + * This program is free software; you can redistribute it and/or modify
102208 + * it under the terms of the GNU General Public License; either version
102209 + * 2 or 3 as published by the Free Software Foundation.
102210 + */
102211 +#include <linux/module.h>
102212 +#include <linux/moduleparam.h>
102213 +#include <linux/skbuff.h>
102214 +#include <linux/netfilter/x_tables.h>
102215 +#include <linux/grsecurity.h>
102216 +#include <linux/netfilter/xt_gradm.h>
102217 +
102218 +static bool
102219 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
102220 +{
102221 + const struct xt_gradm_mtinfo *info = par->matchinfo;
102222 + bool retval = false;
102223 + if (gr_acl_is_enabled())
102224 + retval = true;
102225 + return retval ^ info->invflags;
102226 +}
102227 +
102228 +static struct xt_match gradm_mt_reg __read_mostly = {
102229 + .name = "gradm",
102230 + .revision = 0,
102231 + .family = NFPROTO_UNSPEC,
102232 + .match = gradm_mt,
102233 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
102234 + .me = THIS_MODULE,
102235 +};
102236 +
102237 +static int __init gradm_mt_init(void)
102238 +{
102239 + return xt_register_match(&gradm_mt_reg);
102240 +}
102241 +
102242 +static void __exit gradm_mt_exit(void)
102243 +{
102244 + xt_unregister_match(&gradm_mt_reg);
102245 +}
102246 +
102247 +module_init(gradm_mt_init);
102248 +module_exit(gradm_mt_exit);
102249 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
102250 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
102251 +MODULE_LICENSE("GPL");
102252 +MODULE_ALIAS("ipt_gradm");
102253 +MODULE_ALIAS("ip6t_gradm");
102254 diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
102255 index a3910fc..2d2ba14 100644
102256 --- a/net/netfilter/xt_hashlimit.c
102257 +++ b/net/netfilter/xt_hashlimit.c
102258 @@ -870,11 +870,11 @@ static int __net_init hashlimit_proc_net_init(struct net *net)
102259 {
102260 struct hashlimit_net *hashlimit_net = hashlimit_pernet(net);
102261
102262 - hashlimit_net->ipt_hashlimit = proc_mkdir("ipt_hashlimit", net->proc_net);
102263 + hashlimit_net->ipt_hashlimit = proc_mkdir_restrict("ipt_hashlimit", net->proc_net);
102264 if (!hashlimit_net->ipt_hashlimit)
102265 return -ENOMEM;
102266 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
102267 - hashlimit_net->ip6t_hashlimit = proc_mkdir("ip6t_hashlimit", net->proc_net);
102268 + hashlimit_net->ip6t_hashlimit = proc_mkdir_restrict("ip6t_hashlimit", net->proc_net);
102269 if (!hashlimit_net->ip6t_hashlimit) {
102270 remove_proc_entry("ipt_hashlimit", net->proc_net);
102271 return -ENOMEM;
102272 diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c
102273 index 1e657cf..1eb1c34 100644
102274 --- a/net/netfilter/xt_recent.c
102275 +++ b/net/netfilter/xt_recent.c
102276 @@ -618,7 +618,7 @@ static int __net_init recent_proc_net_init(struct net *net)
102277 {
102278 struct recent_net *recent_net = recent_pernet(net);
102279
102280 - recent_net->xt_recent = proc_mkdir("xt_recent", net->proc_net);
102281 + recent_net->xt_recent = proc_mkdir_restrict("xt_recent", net->proc_net);
102282 if (!recent_net->xt_recent)
102283 return -ENOMEM;
102284 return 0;
102285 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
102286 index 11de55e..f25e448 100644
102287 --- a/net/netfilter/xt_statistic.c
102288 +++ b/net/netfilter/xt_statistic.c
102289 @@ -19,7 +19,7 @@
102290 #include <linux/module.h>
102291
102292 struct xt_statistic_priv {
102293 - atomic_t count;
102294 + atomic_unchecked_t count;
102295 } ____cacheline_aligned_in_smp;
102296
102297 MODULE_LICENSE("GPL");
102298 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
102299 break;
102300 case XT_STATISTIC_MODE_NTH:
102301 do {
102302 - oval = atomic_read(&info->master->count);
102303 + oval = atomic_read_unchecked(&info->master->count);
102304 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
102305 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
102306 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
102307 if (nval == 0)
102308 ret = !ret;
102309 break;
102310 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
102311 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
102312 if (info->master == NULL)
102313 return -ENOMEM;
102314 - atomic_set(&info->master->count, info->u.nth.count);
102315 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
102316
102317 return 0;
102318 }
102319 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
102320 index 6c0fe97..1d852df 100644
102321 --- a/net/netlink/af_netlink.c
102322 +++ b/net/netlink/af_netlink.c
102323 @@ -257,7 +257,7 @@ static void netlink_overrun(struct sock *sk)
102324 sk->sk_error_report(sk);
102325 }
102326 }
102327 - atomic_inc(&sk->sk_drops);
102328 + atomic_inc_unchecked(&sk->sk_drops);
102329 }
102330
102331 static void netlink_rcv_wake(struct sock *sk)
102332 @@ -3028,7 +3028,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
102333 sk_wmem_alloc_get(s),
102334 nlk->cb_running,
102335 atomic_read(&s->sk_refcnt),
102336 - atomic_read(&s->sk_drops),
102337 + atomic_read_unchecked(&s->sk_drops),
102338 sock_i_ino(s)
102339 );
102340
102341 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
102342 index ede50d1..d2468e6 100644
102343 --- a/net/netrom/af_netrom.c
102344 +++ b/net/netrom/af_netrom.c
102345 @@ -850,7 +850,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
102346 *uaddr_len = sizeof(struct full_sockaddr_ax25);
102347 } else {
102348 sax->fsa_ax25.sax25_family = AF_NETROM;
102349 - sax->fsa_ax25.sax25_ndigis = 0;
102350 sax->fsa_ax25.sax25_call = nr->source_addr;
102351 *uaddr_len = sizeof(struct sockaddr_ax25);
102352 }
102353 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
102354 index b85c67c..27c3368 100644
102355 --- a/net/packet/af_packet.c
102356 +++ b/net/packet/af_packet.c
102357 @@ -275,7 +275,7 @@ static int packet_direct_xmit(struct sk_buff *skb)
102358
102359 return ret;
102360 drop:
102361 - atomic_long_inc(&dev->tx_dropped);
102362 + atomic_long_inc_unchecked(&dev->tx_dropped);
102363 kfree_skb(skb);
102364 return NET_XMIT_DROP;
102365 }
102366 @@ -1845,7 +1845,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
102367
102368 spin_lock(&sk->sk_receive_queue.lock);
102369 po->stats.stats1.tp_packets++;
102370 - skb->dropcount = atomic_read(&sk->sk_drops);
102371 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
102372 __skb_queue_tail(&sk->sk_receive_queue, skb);
102373 spin_unlock(&sk->sk_receive_queue.lock);
102374 sk->sk_data_ready(sk);
102375 @@ -1854,7 +1854,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
102376 drop_n_acct:
102377 spin_lock(&sk->sk_receive_queue.lock);
102378 po->stats.stats1.tp_drops++;
102379 - atomic_inc(&sk->sk_drops);
102380 + atomic_inc_unchecked(&sk->sk_drops);
102381 spin_unlock(&sk->sk_receive_queue.lock);
102382
102383 drop_n_restore:
102384 @@ -3459,7 +3459,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
102385 case PACKET_HDRLEN:
102386 if (len > sizeof(int))
102387 len = sizeof(int);
102388 - if (copy_from_user(&val, optval, len))
102389 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
102390 return -EFAULT;
102391 switch (val) {
102392 case TPACKET_V1:
102393 @@ -3505,7 +3505,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
102394 len = lv;
102395 if (put_user(len, optlen))
102396 return -EFAULT;
102397 - if (copy_to_user(optval, data, len))
102398 + if (len > sizeof(st) || copy_to_user(optval, data, len))
102399 return -EFAULT;
102400 return 0;
102401 }
102402 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
102403 index 70a547e..23477fe 100644
102404 --- a/net/phonet/pep.c
102405 +++ b/net/phonet/pep.c
102406 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
102407
102408 case PNS_PEP_CTRL_REQ:
102409 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
102410 - atomic_inc(&sk->sk_drops);
102411 + atomic_inc_unchecked(&sk->sk_drops);
102412 break;
102413 }
102414 __skb_pull(skb, 4);
102415 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
102416 }
102417
102418 if (pn->rx_credits == 0) {
102419 - atomic_inc(&sk->sk_drops);
102420 + atomic_inc_unchecked(&sk->sk_drops);
102421 err = -ENOBUFS;
102422 break;
102423 }
102424 @@ -579,7 +579,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
102425 }
102426
102427 if (pn->rx_credits == 0) {
102428 - atomic_inc(&sk->sk_drops);
102429 + atomic_inc_unchecked(&sk->sk_drops);
102430 err = NET_RX_DROP;
102431 break;
102432 }
102433 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
102434 index 008214a..bb68240 100644
102435 --- a/net/phonet/socket.c
102436 +++ b/net/phonet/socket.c
102437 @@ -611,7 +611,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
102438 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
102439 sock_i_ino(sk),
102440 atomic_read(&sk->sk_refcnt), sk,
102441 - atomic_read(&sk->sk_drops));
102442 + atomic_read_unchecked(&sk->sk_drops));
102443 }
102444 seq_pad(seq, '\n');
102445 return 0;
102446 diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
102447 index c02a8c4..3c5b600 100644
102448 --- a/net/phonet/sysctl.c
102449 +++ b/net/phonet/sysctl.c
102450 @@ -67,7 +67,7 @@ static int proc_local_port_range(struct ctl_table *table, int write,
102451 {
102452 int ret;
102453 int range[2] = {local_port_range[0], local_port_range[1]};
102454 - struct ctl_table tmp = {
102455 + ctl_table_no_const tmp = {
102456 .data = &range,
102457 .maxlen = sizeof(range),
102458 .mode = table->mode,
102459 diff --git a/net/rds/cong.c b/net/rds/cong.c
102460 index e5b65ac..f3b6fb7 100644
102461 --- a/net/rds/cong.c
102462 +++ b/net/rds/cong.c
102463 @@ -78,7 +78,7 @@
102464 * finds that the saved generation number is smaller than the global generation
102465 * number, it wakes up the process.
102466 */
102467 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
102468 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
102469
102470 /*
102471 * Congestion monitoring
102472 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
102473 rdsdebug("waking map %p for %pI4\n",
102474 map, &map->m_addr);
102475 rds_stats_inc(s_cong_update_received);
102476 - atomic_inc(&rds_cong_generation);
102477 + atomic_inc_unchecked(&rds_cong_generation);
102478 if (waitqueue_active(&map->m_waitq))
102479 wake_up(&map->m_waitq);
102480 if (waitqueue_active(&rds_poll_waitq))
102481 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
102482
102483 int rds_cong_updated_since(unsigned long *recent)
102484 {
102485 - unsigned long gen = atomic_read(&rds_cong_generation);
102486 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
102487
102488 if (likely(*recent == gen))
102489 return 0;
102490 diff --git a/net/rds/ib.h b/net/rds/ib.h
102491 index 7280ab8..e04f4ea 100644
102492 --- a/net/rds/ib.h
102493 +++ b/net/rds/ib.h
102494 @@ -128,7 +128,7 @@ struct rds_ib_connection {
102495 /* sending acks */
102496 unsigned long i_ack_flags;
102497 #ifdef KERNEL_HAS_ATOMIC64
102498 - atomic64_t i_ack_next; /* next ACK to send */
102499 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
102500 #else
102501 spinlock_t i_ack_lock; /* protect i_ack_next */
102502 u64 i_ack_next; /* next ACK to send */
102503 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
102504 index 31b74f5..dc1fbfa 100644
102505 --- a/net/rds/ib_cm.c
102506 +++ b/net/rds/ib_cm.c
102507 @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
102508 /* Clear the ACK state */
102509 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
102510 #ifdef KERNEL_HAS_ATOMIC64
102511 - atomic64_set(&ic->i_ack_next, 0);
102512 + atomic64_set_unchecked(&ic->i_ack_next, 0);
102513 #else
102514 ic->i_ack_next = 0;
102515 #endif
102516 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
102517 index b7ebe23..b6352f6 100644
102518 --- a/net/rds/ib_recv.c
102519 +++ b/net/rds/ib_recv.c
102520 @@ -596,7 +596,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
102521 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
102522 int ack_required)
102523 {
102524 - atomic64_set(&ic->i_ack_next, seq);
102525 + atomic64_set_unchecked(&ic->i_ack_next, seq);
102526 if (ack_required) {
102527 smp_mb__before_clear_bit();
102528 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
102529 @@ -608,7 +608,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
102530 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
102531 smp_mb__after_clear_bit();
102532
102533 - return atomic64_read(&ic->i_ack_next);
102534 + return atomic64_read_unchecked(&ic->i_ack_next);
102535 }
102536 #endif
102537
102538 diff --git a/net/rds/iw.h b/net/rds/iw.h
102539 index 04ce3b1..48119a6 100644
102540 --- a/net/rds/iw.h
102541 +++ b/net/rds/iw.h
102542 @@ -134,7 +134,7 @@ struct rds_iw_connection {
102543 /* sending acks */
102544 unsigned long i_ack_flags;
102545 #ifdef KERNEL_HAS_ATOMIC64
102546 - atomic64_t i_ack_next; /* next ACK to send */
102547 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
102548 #else
102549 spinlock_t i_ack_lock; /* protect i_ack_next */
102550 u64 i_ack_next; /* next ACK to send */
102551 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
102552 index a91e1db..cf3053f 100644
102553 --- a/net/rds/iw_cm.c
102554 +++ b/net/rds/iw_cm.c
102555 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
102556 /* Clear the ACK state */
102557 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
102558 #ifdef KERNEL_HAS_ATOMIC64
102559 - atomic64_set(&ic->i_ack_next, 0);
102560 + atomic64_set_unchecked(&ic->i_ack_next, 0);
102561 #else
102562 ic->i_ack_next = 0;
102563 #endif
102564 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
102565 index 4503335..db566b4 100644
102566 --- a/net/rds/iw_recv.c
102567 +++ b/net/rds/iw_recv.c
102568 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
102569 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
102570 int ack_required)
102571 {
102572 - atomic64_set(&ic->i_ack_next, seq);
102573 + atomic64_set_unchecked(&ic->i_ack_next, seq);
102574 if (ack_required) {
102575 smp_mb__before_clear_bit();
102576 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
102577 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
102578 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
102579 smp_mb__after_clear_bit();
102580
102581 - return atomic64_read(&ic->i_ack_next);
102582 + return atomic64_read_unchecked(&ic->i_ack_next);
102583 }
102584 #endif
102585
102586 diff --git a/net/rds/rds.h b/net/rds/rds.h
102587 index 48f8ffc..0ef3eec 100644
102588 --- a/net/rds/rds.h
102589 +++ b/net/rds/rds.h
102590 @@ -449,7 +449,7 @@ struct rds_transport {
102591 void (*sync_mr)(void *trans_private, int direction);
102592 void (*free_mr)(void *trans_private, int invalidate);
102593 void (*flush_mrs)(void);
102594 -};
102595 +} __do_const;
102596
102597 struct rds_sock {
102598 struct sock rs_sk;
102599 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
102600 index edac9ef..16bcb98 100644
102601 --- a/net/rds/tcp.c
102602 +++ b/net/rds/tcp.c
102603 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
102604 int val = 1;
102605
102606 set_fs(KERNEL_DS);
102607 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
102608 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
102609 sizeof(val));
102610 set_fs(oldfs);
102611 }
102612 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
102613 index 81cf5a4..b5826ff 100644
102614 --- a/net/rds/tcp_send.c
102615 +++ b/net/rds/tcp_send.c
102616 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
102617
102618 oldfs = get_fs();
102619 set_fs(KERNEL_DS);
102620 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
102621 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
102622 sizeof(val));
102623 set_fs(oldfs);
102624 }
102625 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
102626 index 7b16704..9628ec6 100644
102627 --- a/net/rxrpc/af_rxrpc.c
102628 +++ b/net/rxrpc/af_rxrpc.c
102629 @@ -40,7 +40,7 @@ static const struct proto_ops rxrpc_rpc_ops;
102630 __be32 rxrpc_epoch;
102631
102632 /* current debugging ID */
102633 -atomic_t rxrpc_debug_id;
102634 +atomic_unchecked_t rxrpc_debug_id;
102635
102636 /* count of skbs currently in use */
102637 atomic_t rxrpc_n_skbs;
102638 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
102639 index c6be17a..2a6200a 100644
102640 --- a/net/rxrpc/ar-ack.c
102641 +++ b/net/rxrpc/ar-ack.c
102642 @@ -223,7 +223,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
102643
102644 _enter("{%d,%d,%d,%d},",
102645 call->acks_hard, call->acks_unacked,
102646 - atomic_read(&call->sequence),
102647 + atomic_read_unchecked(&call->sequence),
102648 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
102649
102650 stop = 0;
102651 @@ -247,7 +247,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
102652
102653 /* each Tx packet has a new serial number */
102654 sp->hdr.serial =
102655 - htonl(atomic_inc_return(&call->conn->serial));
102656 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
102657
102658 hdr = (struct rxrpc_header *) txb->head;
102659 hdr->serial = sp->hdr.serial;
102660 @@ -451,7 +451,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
102661 */
102662 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
102663 {
102664 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
102665 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
102666 }
102667
102668 /*
102669 @@ -677,7 +677,7 @@ process_further:
102670
102671 latest = ntohl(sp->hdr.serial);
102672 hard = ntohl(ack.firstPacket);
102673 - tx = atomic_read(&call->sequence);
102674 + tx = atomic_read_unchecked(&call->sequence);
102675
102676 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
102677 latest,
102678 @@ -1209,7 +1209,7 @@ void rxrpc_process_call(struct work_struct *work)
102679 goto maybe_reschedule;
102680
102681 send_ACK_with_skew:
102682 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
102683 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
102684 ntohl(ack.serial));
102685 send_ACK:
102686 mtu = call->conn->trans->peer->if_mtu;
102687 @@ -1221,7 +1221,7 @@ send_ACK:
102688 ackinfo.rxMTU = htonl(rxrpc_rx_mtu);
102689 ackinfo.jumbo_max = htonl(rxrpc_rx_jumbo_max);
102690
102691 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
102692 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
102693 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
102694 ntohl(hdr.serial),
102695 ntohs(ack.maxSkew),
102696 @@ -1239,7 +1239,7 @@ send_ACK:
102697 send_message:
102698 _debug("send message");
102699
102700 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
102701 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
102702 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
102703 send_message_2:
102704
102705 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
102706 index a9e05db..194e793 100644
102707 --- a/net/rxrpc/ar-call.c
102708 +++ b/net/rxrpc/ar-call.c
102709 @@ -232,7 +232,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
102710 spin_lock_init(&call->lock);
102711 rwlock_init(&call->state_lock);
102712 atomic_set(&call->usage, 1);
102713 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
102714 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
102715 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
102716
102717 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
102718 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
102719 index 6631f4f..bfdf056 100644
102720 --- a/net/rxrpc/ar-connection.c
102721 +++ b/net/rxrpc/ar-connection.c
102722 @@ -210,7 +210,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
102723 rwlock_init(&conn->lock);
102724 spin_lock_init(&conn->state_lock);
102725 atomic_set(&conn->usage, 1);
102726 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
102727 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
102728 conn->avail_calls = RXRPC_MAXCALLS;
102729 conn->size_align = 4;
102730 conn->header_size = sizeof(struct rxrpc_header);
102731 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
102732 index e7ed43a..6afa140 100644
102733 --- a/net/rxrpc/ar-connevent.c
102734 +++ b/net/rxrpc/ar-connevent.c
102735 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
102736
102737 len = iov[0].iov_len + iov[1].iov_len;
102738
102739 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
102740 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
102741 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
102742
102743 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
102744 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
102745 index 63b21e5..330232e 100644
102746 --- a/net/rxrpc/ar-input.c
102747 +++ b/net/rxrpc/ar-input.c
102748 @@ -338,9 +338,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
102749 /* track the latest serial number on this connection for ACK packet
102750 * information */
102751 serial = ntohl(sp->hdr.serial);
102752 - hi_serial = atomic_read(&call->conn->hi_serial);
102753 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
102754 while (serial > hi_serial)
102755 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
102756 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
102757 serial);
102758
102759 /* request ACK generation for any ACK or DATA packet that requests
102760 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
102761 index ba9fd36..9bbfe01 100644
102762 --- a/net/rxrpc/ar-internal.h
102763 +++ b/net/rxrpc/ar-internal.h
102764 @@ -272,8 +272,8 @@ struct rxrpc_connection {
102765 int error; /* error code for local abort */
102766 int debug_id; /* debug ID for printks */
102767 unsigned int call_counter; /* call ID counter */
102768 - atomic_t serial; /* packet serial number counter */
102769 - atomic_t hi_serial; /* highest serial number received */
102770 + atomic_unchecked_t serial; /* packet serial number counter */
102771 + atomic_unchecked_t hi_serial; /* highest serial number received */
102772 u8 avail_calls; /* number of calls available */
102773 u8 size_align; /* data size alignment (for security) */
102774 u8 header_size; /* rxrpc + security header size */
102775 @@ -346,7 +346,7 @@ struct rxrpc_call {
102776 spinlock_t lock;
102777 rwlock_t state_lock; /* lock for state transition */
102778 atomic_t usage;
102779 - atomic_t sequence; /* Tx data packet sequence counter */
102780 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
102781 u32 abort_code; /* local/remote abort code */
102782 enum { /* current state of call */
102783 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
102784 @@ -431,7 +431,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
102785 */
102786 extern atomic_t rxrpc_n_skbs;
102787 extern __be32 rxrpc_epoch;
102788 -extern atomic_t rxrpc_debug_id;
102789 +extern atomic_unchecked_t rxrpc_debug_id;
102790 extern struct workqueue_struct *rxrpc_workqueue;
102791
102792 /*
102793 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
102794 index 87f7135..74d3703 100644
102795 --- a/net/rxrpc/ar-local.c
102796 +++ b/net/rxrpc/ar-local.c
102797 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
102798 spin_lock_init(&local->lock);
102799 rwlock_init(&local->services_lock);
102800 atomic_set(&local->usage, 1);
102801 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
102802 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
102803 memcpy(&local->srx, srx, sizeof(*srx));
102804 }
102805
102806 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
102807 index 0b4b9a7..966ffbb 100644
102808 --- a/net/rxrpc/ar-output.c
102809 +++ b/net/rxrpc/ar-output.c
102810 @@ -682,14 +682,14 @@ static int rxrpc_send_data(struct kiocb *iocb,
102811 memset(skb_put(skb, pad), 0, pad);
102812 }
102813
102814 - seq = atomic_inc_return(&call->sequence);
102815 + seq = atomic_inc_return_unchecked(&call->sequence);
102816
102817 sp->hdr.epoch = conn->epoch;
102818 sp->hdr.cid = call->cid;
102819 sp->hdr.callNumber = call->call_id;
102820 sp->hdr.seq = htonl(seq);
102821 sp->hdr.serial =
102822 - htonl(atomic_inc_return(&conn->serial));
102823 + htonl(atomic_inc_return_unchecked(&conn->serial));
102824 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
102825 sp->hdr.userStatus = 0;
102826 sp->hdr.securityIndex = conn->security_ix;
102827 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
102828 index bebaa43..2644591 100644
102829 --- a/net/rxrpc/ar-peer.c
102830 +++ b/net/rxrpc/ar-peer.c
102831 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
102832 INIT_LIST_HEAD(&peer->error_targets);
102833 spin_lock_init(&peer->lock);
102834 atomic_set(&peer->usage, 1);
102835 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
102836 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
102837 memcpy(&peer->srx, srx, sizeof(*srx));
102838
102839 rxrpc_assess_MTU_size(peer);
102840 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
102841 index 38047f7..9f48511 100644
102842 --- a/net/rxrpc/ar-proc.c
102843 +++ b/net/rxrpc/ar-proc.c
102844 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
102845 atomic_read(&conn->usage),
102846 rxrpc_conn_states[conn->state],
102847 key_serial(conn->key),
102848 - atomic_read(&conn->serial),
102849 - atomic_read(&conn->hi_serial));
102850 + atomic_read_unchecked(&conn->serial),
102851 + atomic_read_unchecked(&conn->hi_serial));
102852
102853 return 0;
102854 }
102855 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
102856 index 1976dec..aa70be5 100644
102857 --- a/net/rxrpc/ar-transport.c
102858 +++ b/net/rxrpc/ar-transport.c
102859 @@ -51,7 +51,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
102860 spin_lock_init(&trans->client_lock);
102861 rwlock_init(&trans->conn_lock);
102862 atomic_set(&trans->usage, 1);
102863 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
102864 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
102865
102866 if (peer->srx.transport.family == AF_INET) {
102867 switch (peer->srx.transport_type) {
102868 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
102869 index f226709..0e735a8 100644
102870 --- a/net/rxrpc/rxkad.c
102871 +++ b/net/rxrpc/rxkad.c
102872 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
102873
102874 len = iov[0].iov_len + iov[1].iov_len;
102875
102876 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
102877 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
102878 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
102879
102880 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
102881 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
102882
102883 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
102884
102885 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
102886 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
102887 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
102888
102889 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
102890 diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
102891 index e1543b0..7ce8bd0 100644
102892 --- a/net/sched/sch_generic.c
102893 +++ b/net/sched/sch_generic.c
102894 @@ -310,7 +310,7 @@ void netif_carrier_on(struct net_device *dev)
102895 if (test_and_clear_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
102896 if (dev->reg_state == NETREG_UNINITIALIZED)
102897 return;
102898 - atomic_inc(&dev->carrier_changes);
102899 + atomic_inc_unchecked(&dev->carrier_changes);
102900 linkwatch_fire_event(dev);
102901 if (netif_running(dev))
102902 __netdev_watchdog_up(dev);
102903 @@ -329,7 +329,7 @@ void netif_carrier_off(struct net_device *dev)
102904 if (!test_and_set_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
102905 if (dev->reg_state == NETREG_UNINITIALIZED)
102906 return;
102907 - atomic_inc(&dev->carrier_changes);
102908 + atomic_inc_unchecked(&dev->carrier_changes);
102909 linkwatch_fire_event(dev);
102910 }
102911 }
102912 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
102913 index 2b1738e..a9d0fc9 100644
102914 --- a/net/sctp/ipv6.c
102915 +++ b/net/sctp/ipv6.c
102916 @@ -966,7 +966,7 @@ static const struct inet6_protocol sctpv6_protocol = {
102917 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
102918 };
102919
102920 -static struct sctp_af sctp_af_inet6 = {
102921 +static struct sctp_af sctp_af_inet6 __read_only = {
102922 .sa_family = AF_INET6,
102923 .sctp_xmit = sctp_v6_xmit,
102924 .setsockopt = ipv6_setsockopt,
102925 @@ -998,7 +998,7 @@ static struct sctp_af sctp_af_inet6 = {
102926 #endif
102927 };
102928
102929 -static struct sctp_pf sctp_pf_inet6 = {
102930 +static struct sctp_pf sctp_pf_inet6 __read_only = {
102931 .event_msgname = sctp_inet6_event_msgname,
102932 .skb_msgname = sctp_inet6_skb_msgname,
102933 .af_supported = sctp_inet6_af_supported,
102934 @@ -1023,7 +1023,7 @@ void sctp_v6_pf_init(void)
102935
102936 void sctp_v6_pf_exit(void)
102937 {
102938 - list_del(&sctp_af_inet6.list);
102939 + pax_list_del(&sctp_af_inet6.list);
102940 }
102941
102942 /* Initialize IPv6 support and register with socket layer. */
102943 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
102944 index 44cbb54..4c5dce6 100644
102945 --- a/net/sctp/protocol.c
102946 +++ b/net/sctp/protocol.c
102947 @@ -836,8 +836,10 @@ int sctp_register_af(struct sctp_af *af)
102948 return 0;
102949 }
102950
102951 + pax_open_kernel();
102952 INIT_LIST_HEAD(&af->list);
102953 - list_add_tail(&af->list, &sctp_address_families);
102954 + pax_close_kernel();
102955 + pax_list_add_tail(&af->list, &sctp_address_families);
102956 return 1;
102957 }
102958
102959 @@ -967,7 +969,7 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
102960
102961 static struct sctp_af sctp_af_inet;
102962
102963 -static struct sctp_pf sctp_pf_inet = {
102964 +static struct sctp_pf sctp_pf_inet __read_only = {
102965 .event_msgname = sctp_inet_event_msgname,
102966 .skb_msgname = sctp_inet_skb_msgname,
102967 .af_supported = sctp_inet_af_supported,
102968 @@ -1039,7 +1041,7 @@ static const struct net_protocol sctp_protocol = {
102969 };
102970
102971 /* IPv4 address related functions. */
102972 -static struct sctp_af sctp_af_inet = {
102973 +static struct sctp_af sctp_af_inet __read_only = {
102974 .sa_family = AF_INET,
102975 .sctp_xmit = sctp_v4_xmit,
102976 .setsockopt = ip_setsockopt,
102977 @@ -1124,7 +1126,7 @@ static void sctp_v4_pf_init(void)
102978
102979 static void sctp_v4_pf_exit(void)
102980 {
102981 - list_del(&sctp_af_inet.list);
102982 + pax_list_del(&sctp_af_inet.list);
102983 }
102984
102985 static int sctp_v4_protosw_init(void)
102986 diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
102987 index fef2acd..c705c4f 100644
102988 --- a/net/sctp/sm_sideeffect.c
102989 +++ b/net/sctp/sm_sideeffect.c
102990 @@ -439,7 +439,7 @@ static void sctp_generate_sack_event(unsigned long data)
102991 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
102992 }
102993
102994 -sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
102995 +sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
102996 NULL,
102997 sctp_generate_t1_cookie_event,
102998 sctp_generate_t1_init_event,
102999 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
103000 index fee06b9..eabc613 100644
103001 --- a/net/sctp/socket.c
103002 +++ b/net/sctp/socket.c
103003 @@ -2175,11 +2175,13 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval,
103004 {
103005 struct sctp_association *asoc;
103006 struct sctp_ulpevent *event;
103007 + struct sctp_event_subscribe subscribe;
103008
103009 if (optlen > sizeof(struct sctp_event_subscribe))
103010 return -EINVAL;
103011 - if (copy_from_user(&sctp_sk(sk)->subscribe, optval, optlen))
103012 + if (copy_from_user(&subscribe, optval, optlen))
103013 return -EFAULT;
103014 + sctp_sk(sk)->subscribe = subscribe;
103015
103016 /*
103017 * At the time when a user app subscribes to SCTP_SENDER_DRY_EVENT,
103018 @@ -4259,13 +4261,16 @@ static int sctp_getsockopt_disable_fragments(struct sock *sk, int len,
103019 static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
103020 int __user *optlen)
103021 {
103022 + struct sctp_event_subscribe subscribe;
103023 +
103024 if (len <= 0)
103025 return -EINVAL;
103026 if (len > sizeof(struct sctp_event_subscribe))
103027 len = sizeof(struct sctp_event_subscribe);
103028 if (put_user(len, optlen))
103029 return -EFAULT;
103030 - if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len))
103031 + subscribe = sctp_sk(sk)->subscribe;
103032 + if (copy_to_user(optval, &subscribe, len))
103033 return -EFAULT;
103034 return 0;
103035 }
103036 @@ -4283,6 +4288,8 @@ static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
103037 */
103038 static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optval, int __user *optlen)
103039 {
103040 + __u32 autoclose;
103041 +
103042 /* Applicable to UDP-style socket only */
103043 if (sctp_style(sk, TCP))
103044 return -EOPNOTSUPP;
103045 @@ -4291,7 +4298,8 @@ static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optv
103046 len = sizeof(int);
103047 if (put_user(len, optlen))
103048 return -EFAULT;
103049 - if (copy_to_user(optval, &sctp_sk(sk)->autoclose, sizeof(int)))
103050 + autoclose = sctp_sk(sk)->autoclose;
103051 + if (copy_to_user(optval, &autoclose, sizeof(int)))
103052 return -EFAULT;
103053 return 0;
103054 }
103055 @@ -4666,12 +4674,15 @@ static int sctp_getsockopt_delayed_ack(struct sock *sk, int len,
103056 */
103057 static int sctp_getsockopt_initmsg(struct sock *sk, int len, char __user *optval, int __user *optlen)
103058 {
103059 + struct sctp_initmsg initmsg;
103060 +
103061 if (len < sizeof(struct sctp_initmsg))
103062 return -EINVAL;
103063 len = sizeof(struct sctp_initmsg);
103064 if (put_user(len, optlen))
103065 return -EFAULT;
103066 - if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len))
103067 + initmsg = sctp_sk(sk)->initmsg;
103068 + if (copy_to_user(optval, &initmsg, len))
103069 return -EFAULT;
103070 return 0;
103071 }
103072 @@ -4712,6 +4723,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
103073 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
103074 if (space_left < addrlen)
103075 return -ENOMEM;
103076 + if (addrlen > sizeof(temp) || addrlen < 0)
103077 + return -EFAULT;
103078 if (copy_to_user(to, &temp, addrlen))
103079 return -EFAULT;
103080 to += addrlen;
103081 diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
103082 index dfa532f..1dcfb44 100644
103083 --- a/net/sctp/sysctl.c
103084 +++ b/net/sctp/sysctl.c
103085 @@ -307,7 +307,7 @@ static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
103086 loff_t *ppos)
103087 {
103088 struct net *net = current->nsproxy->net_ns;
103089 - struct ctl_table tbl;
103090 + ctl_table_no_const tbl;
103091 bool changed = false;
103092 char *none = "none";
103093 char tmp[8];
103094 @@ -355,7 +355,7 @@ static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
103095 struct net *net = current->nsproxy->net_ns;
103096 unsigned int min = *(unsigned int *) ctl->extra1;
103097 unsigned int max = *(unsigned int *) ctl->extra2;
103098 - struct ctl_table tbl;
103099 + ctl_table_no_const tbl;
103100 int ret, new_value;
103101
103102 memset(&tbl, 0, sizeof(struct ctl_table));
103103 @@ -384,7 +384,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
103104 struct net *net = current->nsproxy->net_ns;
103105 unsigned int min = *(unsigned int *) ctl->extra1;
103106 unsigned int max = *(unsigned int *) ctl->extra2;
103107 - struct ctl_table tbl;
103108 + ctl_table_no_const tbl;
103109 int ret, new_value;
103110
103111 memset(&tbl, 0, sizeof(struct ctl_table));
103112 @@ -411,7 +411,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
103113 loff_t *ppos)
103114 {
103115 struct net *net = current->nsproxy->net_ns;
103116 - struct ctl_table tbl;
103117 + ctl_table_no_const tbl;
103118 int new_value, ret;
103119
103120 memset(&tbl, 0, sizeof(struct ctl_table));
103121 @@ -438,7 +438,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
103122
103123 int sctp_sysctl_net_register(struct net *net)
103124 {
103125 - struct ctl_table *table = sctp_net_table;
103126 + ctl_table_no_const *table = NULL;
103127
103128 if (!net_eq(net, &init_net)) {
103129 int i;
103130 @@ -451,7 +451,10 @@ int sctp_sysctl_net_register(struct net *net)
103131 table[i].data += (char *)(&net->sctp) - (char *)&init_net.sctp;
103132 }
103133
103134 - net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", table);
103135 + if (!net_eq(net, &init_net))
103136 + net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", table);
103137 + else
103138 + net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", sctp_net_table);
103139 return 0;
103140 }
103141
103142 diff --git a/net/socket.c b/net/socket.c
103143 index abf56b2..b8998bc 100644
103144 --- a/net/socket.c
103145 +++ b/net/socket.c
103146 @@ -89,6 +89,7 @@
103147 #include <linux/magic.h>
103148 #include <linux/slab.h>
103149 #include <linux/xattr.h>
103150 +#include <linux/in.h>
103151
103152 #include <asm/uaccess.h>
103153 #include <asm/unistd.h>
103154 @@ -112,6 +113,8 @@ unsigned int sysctl_net_busy_read __read_mostly;
103155 unsigned int sysctl_net_busy_poll __read_mostly;
103156 #endif
103157
103158 +#include <linux/grsock.h>
103159 +
103160 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
103161 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
103162 unsigned long nr_segs, loff_t pos);
103163 @@ -163,7 +166,7 @@ static const struct file_operations socket_file_ops = {
103164 */
103165
103166 static DEFINE_SPINLOCK(net_family_lock);
103167 -static const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
103168 +const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
103169
103170 /*
103171 * Statistics counters of the socket lists
103172 @@ -329,7 +332,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
103173 &sockfs_dentry_operations, SOCKFS_MAGIC);
103174 }
103175
103176 -static struct vfsmount *sock_mnt __read_mostly;
103177 +struct vfsmount *sock_mnt __read_mostly;
103178
103179 static struct file_system_type sock_fs_type = {
103180 .name = "sockfs",
103181 @@ -1257,6 +1260,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
103182 return -EAFNOSUPPORT;
103183 if (type < 0 || type >= SOCK_MAX)
103184 return -EINVAL;
103185 + if (protocol < 0)
103186 + return -EINVAL;
103187
103188 /* Compatibility.
103189
103190 @@ -1277,6 +1282,20 @@ int __sock_create(struct net *net, int family, int type, int protocol,
103191 if (err)
103192 return err;
103193
103194 + if(!kern && !gr_search_socket(family, type, protocol)) {
103195 + if (rcu_access_pointer(net_families[family]) == NULL)
103196 + return -EAFNOSUPPORT;
103197 + else
103198 + return -EACCES;
103199 + }
103200 +
103201 + if (!kern && gr_handle_sock_all(family, type, protocol)) {
103202 + if (rcu_access_pointer(net_families[family]) == NULL)
103203 + return -EAFNOSUPPORT;
103204 + else
103205 + return -EACCES;
103206 + }
103207 +
103208 /*
103209 * Allocate the socket and allow the family to set things up. if
103210 * the protocol is 0, the family is instructed to select an appropriate
103211 @@ -1528,6 +1547,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
103212 if (sock) {
103213 err = move_addr_to_kernel(umyaddr, addrlen, &address);
103214 if (err >= 0) {
103215 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
103216 + err = -EACCES;
103217 + goto error;
103218 + }
103219 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
103220 + if (err)
103221 + goto error;
103222 +
103223 err = security_socket_bind(sock,
103224 (struct sockaddr *)&address,
103225 addrlen);
103226 @@ -1536,6 +1563,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
103227 (struct sockaddr *)
103228 &address, addrlen);
103229 }
103230 +error:
103231 fput_light(sock->file, fput_needed);
103232 }
103233 return err;
103234 @@ -1559,10 +1587,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
103235 if ((unsigned int)backlog > somaxconn)
103236 backlog = somaxconn;
103237
103238 + if (gr_handle_sock_server_other(sock->sk)) {
103239 + err = -EPERM;
103240 + goto error;
103241 + }
103242 +
103243 + err = gr_search_listen(sock);
103244 + if (err)
103245 + goto error;
103246 +
103247 err = security_socket_listen(sock, backlog);
103248 if (!err)
103249 err = sock->ops->listen(sock, backlog);
103250
103251 +error:
103252 fput_light(sock->file, fput_needed);
103253 }
103254 return err;
103255 @@ -1606,6 +1644,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
103256 newsock->type = sock->type;
103257 newsock->ops = sock->ops;
103258
103259 + if (gr_handle_sock_server_other(sock->sk)) {
103260 + err = -EPERM;
103261 + sock_release(newsock);
103262 + goto out_put;
103263 + }
103264 +
103265 + err = gr_search_accept(sock);
103266 + if (err) {
103267 + sock_release(newsock);
103268 + goto out_put;
103269 + }
103270 +
103271 /*
103272 * We don't need try_module_get here, as the listening socket (sock)
103273 * has the protocol module (sock->ops->owner) held.
103274 @@ -1651,6 +1701,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
103275 fd_install(newfd, newfile);
103276 err = newfd;
103277
103278 + gr_attach_curr_ip(newsock->sk);
103279 +
103280 out_put:
103281 fput_light(sock->file, fput_needed);
103282 out:
103283 @@ -1683,6 +1735,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
103284 int, addrlen)
103285 {
103286 struct socket *sock;
103287 + struct sockaddr *sck;
103288 struct sockaddr_storage address;
103289 int err, fput_needed;
103290
103291 @@ -1693,6 +1746,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
103292 if (err < 0)
103293 goto out_put;
103294
103295 + sck = (struct sockaddr *)&address;
103296 +
103297 + if (gr_handle_sock_client(sck)) {
103298 + err = -EACCES;
103299 + goto out_put;
103300 + }
103301 +
103302 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
103303 + if (err)
103304 + goto out_put;
103305 +
103306 err =
103307 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
103308 if (err)
103309 @@ -1774,6 +1838,8 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr,
103310 * the protocol.
103311 */
103312
103313 +asmlinkage long sys_sendto(int, void __user *, size_t, unsigned, struct sockaddr __user *, int);
103314 +
103315 SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
103316 unsigned int, flags, struct sockaddr __user *, addr,
103317 int, addr_len)
103318 @@ -1840,7 +1906,7 @@ SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size,
103319 struct socket *sock;
103320 struct iovec iov;
103321 struct msghdr msg;
103322 - struct sockaddr_storage address;
103323 + struct sockaddr_storage address = { };
103324 int err, err2;
103325 int fput_needed;
103326
103327 @@ -2066,7 +2132,7 @@ static int ___sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
103328 * checking falls down on this.
103329 */
103330 if (copy_from_user(ctl_buf,
103331 - (void __user __force *)msg_sys->msg_control,
103332 + (void __force_user *)msg_sys->msg_control,
103333 ctl_len))
103334 goto out_freectl;
103335 msg_sys->msg_control = ctl_buf;
103336 @@ -2217,7 +2283,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
103337 int err, total_len, len;
103338
103339 /* kernel mode address */
103340 - struct sockaddr_storage addr;
103341 + struct sockaddr_storage addr = { };
103342
103343 /* user mode address pointers */
103344 struct sockaddr __user *uaddr;
103345 @@ -2246,7 +2312,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
103346 /* Save the user-mode address (verify_iovec will change the
103347 * kernel msghdr to use the kernel address space)
103348 */
103349 - uaddr = (__force void __user *)msg_sys->msg_name;
103350 + uaddr = (void __force_user *)msg_sys->msg_name;
103351 uaddr_len = COMPAT_NAMELEN(msg);
103352 if (MSG_CMSG_COMPAT & flags)
103353 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
103354 @@ -2887,7 +2953,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
103355 ifr = compat_alloc_user_space(buf_size);
103356 rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
103357
103358 - if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
103359 + if (copy_in_user(ifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
103360 return -EFAULT;
103361
103362 if (put_user(convert_in ? rxnfc : compat_ptr(data),
103363 @@ -2998,7 +3064,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
103364 old_fs = get_fs();
103365 set_fs(KERNEL_DS);
103366 err = dev_ioctl(net, cmd,
103367 - (struct ifreq __user __force *) &kifr);
103368 + (struct ifreq __force_user *) &kifr);
103369 set_fs(old_fs);
103370
103371 return err;
103372 @@ -3091,7 +3157,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
103373
103374 old_fs = get_fs();
103375 set_fs(KERNEL_DS);
103376 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
103377 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
103378 set_fs(old_fs);
103379
103380 if (cmd == SIOCGIFMAP && !err) {
103381 @@ -3175,7 +3241,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
103382 ret |= get_user(rtdev, &(ur4->rt_dev));
103383 if (rtdev) {
103384 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
103385 - r4.rt_dev = (char __user __force *)devname;
103386 + r4.rt_dev = (char __force_user *)devname;
103387 devname[15] = 0;
103388 } else
103389 r4.rt_dev = NULL;
103390 @@ -3402,8 +3468,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
103391 int __user *uoptlen;
103392 int err;
103393
103394 - uoptval = (char __user __force *) optval;
103395 - uoptlen = (int __user __force *) optlen;
103396 + uoptval = (char __force_user *) optval;
103397 + uoptlen = (int __force_user *) optlen;
103398
103399 set_fs(KERNEL_DS);
103400 if (level == SOL_SOCKET)
103401 @@ -3423,7 +3489,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
103402 char __user *uoptval;
103403 int err;
103404
103405 - uoptval = (char __user __force *) optval;
103406 + uoptval = (char __force_user *) optval;
103407
103408 set_fs(KERNEL_DS);
103409 if (level == SOL_SOCKET)
103410 diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
103411 index 0f73f45..a96aa52 100644
103412 --- a/net/sunrpc/auth_gss/svcauth_gss.c
103413 +++ b/net/sunrpc/auth_gss/svcauth_gss.c
103414 @@ -1140,7 +1140,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
103415 uint64_t *handle)
103416 {
103417 struct rsc rsci, *rscp = NULL;
103418 - static atomic64_t ctxhctr;
103419 + static atomic64_unchecked_t ctxhctr = ATOMIC64_INIT(0);
103420 long long ctxh;
103421 struct gss_api_mech *gm = NULL;
103422 time_t expiry;
103423 @@ -1151,7 +1151,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
103424 status = -ENOMEM;
103425 /* the handle needs to be just a unique id,
103426 * use a static counter */
103427 - ctxh = atomic64_inc_return(&ctxhctr);
103428 + ctxh = atomic64_inc_return_unchecked(&ctxhctr);
103429
103430 /* make a copy for the caller */
103431 *handle = ctxh;
103432 diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
103433 index ae333c1..18521f0 100644
103434 --- a/net/sunrpc/cache.c
103435 +++ b/net/sunrpc/cache.c
103436 @@ -1609,7 +1609,7 @@ static int create_cache_proc_entries(struct cache_detail *cd, struct net *net)
103437 struct sunrpc_net *sn;
103438
103439 sn = net_generic(net, sunrpc_net_id);
103440 - cd->u.procfs.proc_ent = proc_mkdir(cd->name, sn->proc_net_rpc);
103441 + cd->u.procfs.proc_ent = proc_mkdir_restrict(cd->name, sn->proc_net_rpc);
103442 if (cd->u.procfs.proc_ent == NULL)
103443 goto out_nomem;
103444 cd->u.procfs.channel_ent = NULL;
103445 diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
103446 index 2e6ab10..3170800 100644
103447 --- a/net/sunrpc/clnt.c
103448 +++ b/net/sunrpc/clnt.c
103449 @@ -1425,7 +1425,9 @@ call_start(struct rpc_task *task)
103450 (RPC_IS_ASYNC(task) ? "async" : "sync"));
103451
103452 /* Increment call count */
103453 - task->tk_msg.rpc_proc->p_count++;
103454 + pax_open_kernel();
103455 + (*(unsigned int *)&task->tk_msg.rpc_proc->p_count)++;
103456 + pax_close_kernel();
103457 clnt->cl_stats->rpccnt++;
103458 task->tk_action = call_reserve;
103459 }
103460 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
103461 index 25578af..a29298d 100644
103462 --- a/net/sunrpc/sched.c
103463 +++ b/net/sunrpc/sched.c
103464 @@ -261,9 +261,9 @@ static int rpc_wait_bit_killable(void *word)
103465 #if defined(RPC_DEBUG) || defined(RPC_TRACEPOINTS)
103466 static void rpc_task_set_debuginfo(struct rpc_task *task)
103467 {
103468 - static atomic_t rpc_pid;
103469 + static atomic_unchecked_t rpc_pid;
103470
103471 - task->tk_pid = atomic_inc_return(&rpc_pid);
103472 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
103473 }
103474 #else
103475 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
103476 diff --git a/net/sunrpc/stats.c b/net/sunrpc/stats.c
103477 index 5453049..465669a 100644
103478 --- a/net/sunrpc/stats.c
103479 +++ b/net/sunrpc/stats.c
103480 @@ -267,7 +267,7 @@ int rpc_proc_init(struct net *net)
103481
103482 dprintk("RPC: registering /proc/net/rpc\n");
103483 sn = net_generic(net, sunrpc_net_id);
103484 - sn->proc_net_rpc = proc_mkdir("rpc", net->proc_net);
103485 + sn->proc_net_rpc = proc_mkdir_restrict("rpc", net->proc_net);
103486 if (sn->proc_net_rpc == NULL)
103487 return -ENOMEM;
103488
103489 diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
103490 index 5de6801..b4e330d 100644
103491 --- a/net/sunrpc/svc.c
103492 +++ b/net/sunrpc/svc.c
103493 @@ -1167,7 +1167,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
103494 svc_putnl(resv, RPC_SUCCESS);
103495
103496 /* Bump per-procedure stats counter */
103497 - procp->pc_count++;
103498 + pax_open_kernel();
103499 + (*(unsigned int *)&procp->pc_count)++;
103500 + pax_close_kernel();
103501
103502 /* Initialize storage for argp and resp */
103503 memset(rqstp->rq_argp, 0, procp->pc_argsize);
103504 diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
103505 index 621ca7b..59421dd 100644
103506 --- a/net/sunrpc/svcauth_unix.c
103507 +++ b/net/sunrpc/svcauth_unix.c
103508 @@ -414,7 +414,7 @@ struct unix_gid {
103509 struct group_info *gi;
103510 };
103511
103512 -static int unix_gid_hash(kuid_t uid)
103513 +static int __intentional_overflow(-1) unix_gid_hash(kuid_t uid)
103514 {
103515 return hash_long(from_kuid(&init_user_ns, uid), GID_HASHBITS);
103516 }
103517 @@ -470,7 +470,7 @@ static void unix_gid_request(struct cache_detail *cd,
103518 (*bpp)[-1] = '\n';
103519 }
103520
103521 -static struct unix_gid *unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
103522 +static struct unix_gid * __intentional_overflow(-1) unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
103523
103524 static int unix_gid_parse(struct cache_detail *cd,
103525 char *mesg, int mlen)
103526 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
103527 index c1b6270..05089c1 100644
103528 --- a/net/sunrpc/xprtrdma/svc_rdma.c
103529 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
103530 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
103531 static unsigned int min_max_inline = 4096;
103532 static unsigned int max_max_inline = 65536;
103533
103534 -atomic_t rdma_stat_recv;
103535 -atomic_t rdma_stat_read;
103536 -atomic_t rdma_stat_write;
103537 -atomic_t rdma_stat_sq_starve;
103538 -atomic_t rdma_stat_rq_starve;
103539 -atomic_t rdma_stat_rq_poll;
103540 -atomic_t rdma_stat_rq_prod;
103541 -atomic_t rdma_stat_sq_poll;
103542 -atomic_t rdma_stat_sq_prod;
103543 +atomic_unchecked_t rdma_stat_recv;
103544 +atomic_unchecked_t rdma_stat_read;
103545 +atomic_unchecked_t rdma_stat_write;
103546 +atomic_unchecked_t rdma_stat_sq_starve;
103547 +atomic_unchecked_t rdma_stat_rq_starve;
103548 +atomic_unchecked_t rdma_stat_rq_poll;
103549 +atomic_unchecked_t rdma_stat_rq_prod;
103550 +atomic_unchecked_t rdma_stat_sq_poll;
103551 +atomic_unchecked_t rdma_stat_sq_prod;
103552
103553 /* Temporary NFS request map and context caches */
103554 struct kmem_cache *svc_rdma_map_cachep;
103555 @@ -110,7 +110,7 @@ static int read_reset_stat(struct ctl_table *table, int write,
103556 len -= *ppos;
103557 if (len > *lenp)
103558 len = *lenp;
103559 - if (len && copy_to_user(buffer, str_buf, len))
103560 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
103561 return -EFAULT;
103562 *lenp = len;
103563 *ppos += len;
103564 @@ -151,63 +151,63 @@ static struct ctl_table svcrdma_parm_table[] = {
103565 {
103566 .procname = "rdma_stat_read",
103567 .data = &rdma_stat_read,
103568 - .maxlen = sizeof(atomic_t),
103569 + .maxlen = sizeof(atomic_unchecked_t),
103570 .mode = 0644,
103571 .proc_handler = read_reset_stat,
103572 },
103573 {
103574 .procname = "rdma_stat_recv",
103575 .data = &rdma_stat_recv,
103576 - .maxlen = sizeof(atomic_t),
103577 + .maxlen = sizeof(atomic_unchecked_t),
103578 .mode = 0644,
103579 .proc_handler = read_reset_stat,
103580 },
103581 {
103582 .procname = "rdma_stat_write",
103583 .data = &rdma_stat_write,
103584 - .maxlen = sizeof(atomic_t),
103585 + .maxlen = sizeof(atomic_unchecked_t),
103586 .mode = 0644,
103587 .proc_handler = read_reset_stat,
103588 },
103589 {
103590 .procname = "rdma_stat_sq_starve",
103591 .data = &rdma_stat_sq_starve,
103592 - .maxlen = sizeof(atomic_t),
103593 + .maxlen = sizeof(atomic_unchecked_t),
103594 .mode = 0644,
103595 .proc_handler = read_reset_stat,
103596 },
103597 {
103598 .procname = "rdma_stat_rq_starve",
103599 .data = &rdma_stat_rq_starve,
103600 - .maxlen = sizeof(atomic_t),
103601 + .maxlen = sizeof(atomic_unchecked_t),
103602 .mode = 0644,
103603 .proc_handler = read_reset_stat,
103604 },
103605 {
103606 .procname = "rdma_stat_rq_poll",
103607 .data = &rdma_stat_rq_poll,
103608 - .maxlen = sizeof(atomic_t),
103609 + .maxlen = sizeof(atomic_unchecked_t),
103610 .mode = 0644,
103611 .proc_handler = read_reset_stat,
103612 },
103613 {
103614 .procname = "rdma_stat_rq_prod",
103615 .data = &rdma_stat_rq_prod,
103616 - .maxlen = sizeof(atomic_t),
103617 + .maxlen = sizeof(atomic_unchecked_t),
103618 .mode = 0644,
103619 .proc_handler = read_reset_stat,
103620 },
103621 {
103622 .procname = "rdma_stat_sq_poll",
103623 .data = &rdma_stat_sq_poll,
103624 - .maxlen = sizeof(atomic_t),
103625 + .maxlen = sizeof(atomic_unchecked_t),
103626 .mode = 0644,
103627 .proc_handler = read_reset_stat,
103628 },
103629 {
103630 .procname = "rdma_stat_sq_prod",
103631 .data = &rdma_stat_sq_prod,
103632 - .maxlen = sizeof(atomic_t),
103633 + .maxlen = sizeof(atomic_unchecked_t),
103634 .mode = 0644,
103635 .proc_handler = read_reset_stat,
103636 },
103637 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
103638 index 8d904e4..b2fc727 100644
103639 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
103640 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
103641 @@ -504,7 +504,7 @@ next_sge:
103642 svc_rdma_put_context(ctxt, 0);
103643 goto out;
103644 }
103645 - atomic_inc(&rdma_stat_read);
103646 + atomic_inc_unchecked(&rdma_stat_read);
103647
103648 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
103649 chl_map->ch[ch_no].count -= read_wr.num_sge;
103650 @@ -607,7 +607,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
103651 dto_q);
103652 list_del_init(&ctxt->dto_q);
103653 } else {
103654 - atomic_inc(&rdma_stat_rq_starve);
103655 + atomic_inc_unchecked(&rdma_stat_rq_starve);
103656 clear_bit(XPT_DATA, &xprt->xpt_flags);
103657 ctxt = NULL;
103658 }
103659 @@ -627,7 +627,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
103660 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
103661 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
103662 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
103663 - atomic_inc(&rdma_stat_recv);
103664 + atomic_inc_unchecked(&rdma_stat_recv);
103665
103666 /* Build up the XDR from the receive buffers. */
103667 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
103668 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
103669 index 7e024a5..17f13d3 100644
103670 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
103671 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
103672 @@ -363,7 +363,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
103673 write_wr.wr.rdma.remote_addr = to;
103674
103675 /* Post It */
103676 - atomic_inc(&rdma_stat_write);
103677 + atomic_inc_unchecked(&rdma_stat_write);
103678 if (svc_rdma_send(xprt, &write_wr))
103679 goto err;
103680 return 0;
103681 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
103682 index 25688fa..dc72003 100644
103683 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
103684 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
103685 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
103686 return;
103687
103688 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
103689 - atomic_inc(&rdma_stat_rq_poll);
103690 + atomic_inc_unchecked(&rdma_stat_rq_poll);
103691
103692 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
103693 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
103694 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
103695 }
103696
103697 if (ctxt)
103698 - atomic_inc(&rdma_stat_rq_prod);
103699 + atomic_inc_unchecked(&rdma_stat_rq_prod);
103700
103701 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
103702 /*
103703 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
103704 return;
103705
103706 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
103707 - atomic_inc(&rdma_stat_sq_poll);
103708 + atomic_inc_unchecked(&rdma_stat_sq_poll);
103709 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
103710 if (wc.status != IB_WC_SUCCESS)
103711 /* Close the transport */
103712 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
103713 }
103714
103715 if (ctxt)
103716 - atomic_inc(&rdma_stat_sq_prod);
103717 + atomic_inc_unchecked(&rdma_stat_sq_prod);
103718 }
103719
103720 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
103721 @@ -1261,7 +1261,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
103722 spin_lock_bh(&xprt->sc_lock);
103723 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
103724 spin_unlock_bh(&xprt->sc_lock);
103725 - atomic_inc(&rdma_stat_sq_starve);
103726 + atomic_inc_unchecked(&rdma_stat_sq_starve);
103727
103728 /* See if we can opportunistically reap SQ WR to make room */
103729 sq_cq_reap(xprt);
103730 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
103731 index e7000be..e3b0ba7 100644
103732 --- a/net/sysctl_net.c
103733 +++ b/net/sysctl_net.c
103734 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
103735 kgid_t root_gid = make_kgid(net->user_ns, 0);
103736
103737 /* Allow network administrator to have same access as root. */
103738 - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
103739 + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
103740 uid_eq(root_uid, current_euid())) {
103741 int mode = (table->mode >> 6) & 7;
103742 return (mode << 6) | (mode << 3) | mode;
103743 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
103744 index 6424372..afd36e9 100644
103745 --- a/net/tipc/subscr.c
103746 +++ b/net/tipc/subscr.c
103747 @@ -97,7 +97,7 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
103748 struct tipc_subscriber *subscriber = sub->subscriber;
103749 struct kvec msg_sect;
103750
103751 - msg_sect.iov_base = (void *)&sub->evt;
103752 + msg_sect.iov_base = &sub->evt;
103753 msg_sect.iov_len = sizeof(struct tipc_event);
103754 sub->evt.event = htohl(event, sub->swap);
103755 sub->evt.found_lower = htohl(found_lower, sub->swap);
103756 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
103757 index bb7e8ba..9f444c6 100644
103758 --- a/net/unix/af_unix.c
103759 +++ b/net/unix/af_unix.c
103760 @@ -791,6 +791,12 @@ static struct sock *unix_find_other(struct net *net,
103761 err = -ECONNREFUSED;
103762 if (!S_ISSOCK(inode->i_mode))
103763 goto put_fail;
103764 +
103765 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
103766 + err = -EACCES;
103767 + goto put_fail;
103768 + }
103769 +
103770 u = unix_find_socket_byinode(inode);
103771 if (!u)
103772 goto put_fail;
103773 @@ -811,6 +817,13 @@ static struct sock *unix_find_other(struct net *net,
103774 if (u) {
103775 struct dentry *dentry;
103776 dentry = unix_sk(u)->path.dentry;
103777 +
103778 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
103779 + err = -EPERM;
103780 + sock_put(u);
103781 + goto fail;
103782 + }
103783 +
103784 if (dentry)
103785 touch_atime(&unix_sk(u)->path);
103786 } else
103787 @@ -844,12 +857,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
103788 */
103789 err = security_path_mknod(&path, dentry, mode, 0);
103790 if (!err) {
103791 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
103792 + err = -EACCES;
103793 + goto out;
103794 + }
103795 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
103796 if (!err) {
103797 res->mnt = mntget(path.mnt);
103798 res->dentry = dget(dentry);
103799 + gr_handle_create(dentry, path.mnt);
103800 }
103801 }
103802 +out:
103803 done_path_create(&path, dentry);
103804 return err;
103805 }
103806 @@ -2344,9 +2363,13 @@ static int unix_seq_show(struct seq_file *seq, void *v)
103807 seq_puts(seq, "Num RefCount Protocol Flags Type St "
103808 "Inode Path\n");
103809 else {
103810 - struct sock *s = v;
103811 + struct sock *s = v, *peer;
103812 struct unix_sock *u = unix_sk(s);
103813 unix_state_lock(s);
103814 + peer = unix_peer(s);
103815 + unix_state_unlock(s);
103816 +
103817 + unix_state_double_lock(s, peer);
103818
103819 seq_printf(seq, "%pK: %08X %08X %08X %04X %02X %5lu",
103820 s,
103821 @@ -2373,8 +2396,10 @@ static int unix_seq_show(struct seq_file *seq, void *v)
103822 }
103823 for ( ; i < len; i++)
103824 seq_putc(seq, u->addr->name->sun_path[i]);
103825 - }
103826 - unix_state_unlock(s);
103827 + } else if (peer)
103828 + seq_printf(seq, " P%lu", sock_i_ino(peer));
103829 +
103830 + unix_state_double_unlock(s, peer);
103831 seq_putc(seq, '\n');
103832 }
103833
103834 diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
103835 index b3d5150..ff3a837 100644
103836 --- a/net/unix/sysctl_net_unix.c
103837 +++ b/net/unix/sysctl_net_unix.c
103838 @@ -28,7 +28,7 @@ static struct ctl_table unix_table[] = {
103839
103840 int __net_init unix_sysctl_register(struct net *net)
103841 {
103842 - struct ctl_table *table;
103843 + ctl_table_no_const *table;
103844
103845 table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
103846 if (table == NULL)
103847 diff --git a/net/vmw_vsock/vmci_transport_notify.c b/net/vmw_vsock/vmci_transport_notify.c
103848 index 9b7f207..2596621 100644
103849 --- a/net/vmw_vsock/vmci_transport_notify.c
103850 +++ b/net/vmw_vsock/vmci_transport_notify.c
103851 @@ -662,19 +662,19 @@ static void vmci_transport_notify_pkt_process_negotiate(struct sock *sk)
103852
103853 /* Socket control packet based operations. */
103854 struct vmci_transport_notify_ops vmci_transport_notify_pkt_ops = {
103855 - vmci_transport_notify_pkt_socket_init,
103856 - vmci_transport_notify_pkt_socket_destruct,
103857 - vmci_transport_notify_pkt_poll_in,
103858 - vmci_transport_notify_pkt_poll_out,
103859 - vmci_transport_notify_pkt_handle_pkt,
103860 - vmci_transport_notify_pkt_recv_init,
103861 - vmci_transport_notify_pkt_recv_pre_block,
103862 - vmci_transport_notify_pkt_recv_pre_dequeue,
103863 - vmci_transport_notify_pkt_recv_post_dequeue,
103864 - vmci_transport_notify_pkt_send_init,
103865 - vmci_transport_notify_pkt_send_pre_block,
103866 - vmci_transport_notify_pkt_send_pre_enqueue,
103867 - vmci_transport_notify_pkt_send_post_enqueue,
103868 - vmci_transport_notify_pkt_process_request,
103869 - vmci_transport_notify_pkt_process_negotiate,
103870 + .socket_init = vmci_transport_notify_pkt_socket_init,
103871 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
103872 + .poll_in = vmci_transport_notify_pkt_poll_in,
103873 + .poll_out = vmci_transport_notify_pkt_poll_out,
103874 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
103875 + .recv_init = vmci_transport_notify_pkt_recv_init,
103876 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
103877 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
103878 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
103879 + .send_init = vmci_transport_notify_pkt_send_init,
103880 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
103881 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
103882 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
103883 + .process_request = vmci_transport_notify_pkt_process_request,
103884 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
103885 };
103886 diff --git a/net/vmw_vsock/vmci_transport_notify_qstate.c b/net/vmw_vsock/vmci_transport_notify_qstate.c
103887 index dc9c792..3089de0 100644
103888 --- a/net/vmw_vsock/vmci_transport_notify_qstate.c
103889 +++ b/net/vmw_vsock/vmci_transport_notify_qstate.c
103890 @@ -420,19 +420,19 @@ vmci_transport_notify_pkt_send_pre_enqueue(
103891
103892 /* Socket always on control packet based operations. */
103893 struct vmci_transport_notify_ops vmci_transport_notify_pkt_q_state_ops = {
103894 - vmci_transport_notify_pkt_socket_init,
103895 - vmci_transport_notify_pkt_socket_destruct,
103896 - vmci_transport_notify_pkt_poll_in,
103897 - vmci_transport_notify_pkt_poll_out,
103898 - vmci_transport_notify_pkt_handle_pkt,
103899 - vmci_transport_notify_pkt_recv_init,
103900 - vmci_transport_notify_pkt_recv_pre_block,
103901 - vmci_transport_notify_pkt_recv_pre_dequeue,
103902 - vmci_transport_notify_pkt_recv_post_dequeue,
103903 - vmci_transport_notify_pkt_send_init,
103904 - vmci_transport_notify_pkt_send_pre_block,
103905 - vmci_transport_notify_pkt_send_pre_enqueue,
103906 - vmci_transport_notify_pkt_send_post_enqueue,
103907 - vmci_transport_notify_pkt_process_request,
103908 - vmci_transport_notify_pkt_process_negotiate,
103909 + .socket_init = vmci_transport_notify_pkt_socket_init,
103910 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
103911 + .poll_in = vmci_transport_notify_pkt_poll_in,
103912 + .poll_out = vmci_transport_notify_pkt_poll_out,
103913 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
103914 + .recv_init = vmci_transport_notify_pkt_recv_init,
103915 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
103916 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
103917 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
103918 + .send_init = vmci_transport_notify_pkt_send_init,
103919 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
103920 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
103921 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
103922 + .process_request = vmci_transport_notify_pkt_process_request,
103923 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
103924 };
103925 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
103926 index c8717c1..08539f5 100644
103927 --- a/net/wireless/wext-core.c
103928 +++ b/net/wireless/wext-core.c
103929 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
103930 */
103931
103932 /* Support for very large requests */
103933 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
103934 - (user_length > descr->max_tokens)) {
103935 + if (user_length > descr->max_tokens) {
103936 /* Allow userspace to GET more than max so
103937 * we can support any size GET requests.
103938 * There is still a limit : -ENOMEM.
103939 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
103940 }
103941 }
103942
103943 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
103944 - /*
103945 - * If this is a GET, but not NOMAX, it means that the extra
103946 - * data is not bounded by userspace, but by max_tokens. Thus
103947 - * set the length to max_tokens. This matches the extra data
103948 - * allocation.
103949 - * The driver should fill it with the number of tokens it
103950 - * provided, and it may check iwp->length rather than having
103951 - * knowledge of max_tokens. If the driver doesn't change the
103952 - * iwp->length, this ioctl just copies back max_token tokens
103953 - * filled with zeroes. Hopefully the driver isn't claiming
103954 - * them to be valid data.
103955 - */
103956 - iwp->length = descr->max_tokens;
103957 - }
103958 -
103959 err = handler(dev, info, (union iwreq_data *) iwp, extra);
103960
103961 iwp->length += essid_compat;
103962 diff --git a/net/x25/sysctl_net_x25.c b/net/x25/sysctl_net_x25.c
103963 index 4323952..a06dfe1 100644
103964 --- a/net/x25/sysctl_net_x25.c
103965 +++ b/net/x25/sysctl_net_x25.c
103966 @@ -70,7 +70,7 @@ static struct ctl_table x25_table[] = {
103967 .mode = 0644,
103968 .proc_handler = proc_dointvec,
103969 },
103970 - { 0, },
103971 + { },
103972 };
103973
103974 void __init x25_register_sysctl(void)
103975 diff --git a/net/x25/x25_proc.c b/net/x25/x25_proc.c
103976 index 0917f04..f4e3d8c 100644
103977 --- a/net/x25/x25_proc.c
103978 +++ b/net/x25/x25_proc.c
103979 @@ -209,7 +209,7 @@ static const struct file_operations x25_seq_forward_fops = {
103980
103981 int __init x25_proc_init(void)
103982 {
103983 - if (!proc_mkdir("x25", init_net.proc_net))
103984 + if (!proc_mkdir_restrict("x25", init_net.proc_net))
103985 return -ENOMEM;
103986
103987 if (!proc_create("x25/route", S_IRUGO, init_net.proc_net,
103988 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
103989 index ed60843..311e7c7 100644
103990 --- a/net/xfrm/xfrm_policy.c
103991 +++ b/net/xfrm/xfrm_policy.c
103992 @@ -325,7 +325,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
103993 {
103994 policy->walk.dead = 1;
103995
103996 - atomic_inc(&policy->genid);
103997 + atomic_inc_unchecked(&policy->genid);
103998
103999 if (del_timer(&policy->polq.hold_timer))
104000 xfrm_pol_put(policy);
104001 @@ -659,7 +659,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
104002 hlist_add_head(&policy->bydst, chain);
104003 xfrm_pol_hold(policy);
104004 net->xfrm.policy_count[dir]++;
104005 - atomic_inc(&net->xfrm.flow_cache_genid);
104006 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
104007
104008 /* After previous checking, family can either be AF_INET or AF_INET6 */
104009 if (policy->family == AF_INET)
104010 @@ -1759,7 +1759,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
104011
104012 xdst->num_pols = num_pols;
104013 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy *) * num_pols);
104014 - xdst->policy_genid = atomic_read(&pols[0]->genid);
104015 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
104016
104017 return xdst;
104018 }
104019 @@ -2548,10 +2548,11 @@ void xfrm_garbage_collect(struct net *net)
104020 }
104021 EXPORT_SYMBOL(xfrm_garbage_collect);
104022
104023 -static void xfrm_garbage_collect_deferred(struct net *net)
104024 +void xfrm_garbage_collect_deferred(struct net *net)
104025 {
104026 flow_cache_flush_deferred(net);
104027 }
104028 +EXPORT_SYMBOL(xfrm_garbage_collect_deferred);
104029
104030 static void xfrm_init_pmtu(struct dst_entry *dst)
104031 {
104032 @@ -2601,7 +2602,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
104033 if (xdst->xfrm_genid != dst->xfrm->genid)
104034 return 0;
104035 if (xdst->num_pols > 0 &&
104036 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
104037 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
104038 return 0;
104039
104040 mtu = dst_mtu(dst->child);
104041 @@ -2689,8 +2690,6 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
104042 dst_ops->link_failure = xfrm_link_failure;
104043 if (likely(dst_ops->neigh_lookup == NULL))
104044 dst_ops->neigh_lookup = xfrm_neigh_lookup;
104045 - if (likely(afinfo->garbage_collect == NULL))
104046 - afinfo->garbage_collect = xfrm_garbage_collect_deferred;
104047 rcu_assign_pointer(xfrm_policy_afinfo[afinfo->family], afinfo);
104048 }
104049 spin_unlock(&xfrm_policy_afinfo_lock);
104050 @@ -2744,7 +2743,6 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
104051 dst_ops->check = NULL;
104052 dst_ops->negative_advice = NULL;
104053 dst_ops->link_failure = NULL;
104054 - afinfo->garbage_collect = NULL;
104055 }
104056 return err;
104057 }
104058 @@ -3139,7 +3137,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
104059 sizeof(pol->xfrm_vec[i].saddr));
104060 pol->xfrm_vec[i].encap_family = mp->new_family;
104061 /* flush bundles */
104062 - atomic_inc(&pol->genid);
104063 + atomic_inc_unchecked(&pol->genid);
104064 }
104065 }
104066
104067 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
104068 index 8e9c781..3972135 100644
104069 --- a/net/xfrm/xfrm_state.c
104070 +++ b/net/xfrm/xfrm_state.c
104071 @@ -173,12 +173,14 @@ int xfrm_register_type(const struct xfrm_type *type, unsigned short family)
104072
104073 if (unlikely(afinfo == NULL))
104074 return -EAFNOSUPPORT;
104075 - typemap = afinfo->type_map;
104076 + typemap = (const struct xfrm_type **)afinfo->type_map;
104077 spin_lock_bh(&xfrm_type_lock);
104078
104079 - if (likely(typemap[type->proto] == NULL))
104080 + if (likely(typemap[type->proto] == NULL)) {
104081 + pax_open_kernel();
104082 typemap[type->proto] = type;
104083 - else
104084 + pax_close_kernel();
104085 + } else
104086 err = -EEXIST;
104087 spin_unlock_bh(&xfrm_type_lock);
104088 xfrm_state_put_afinfo(afinfo);
104089 @@ -194,13 +196,16 @@ int xfrm_unregister_type(const struct xfrm_type *type, unsigned short family)
104090
104091 if (unlikely(afinfo == NULL))
104092 return -EAFNOSUPPORT;
104093 - typemap = afinfo->type_map;
104094 + typemap = (const struct xfrm_type **)afinfo->type_map;
104095 spin_lock_bh(&xfrm_type_lock);
104096
104097 if (unlikely(typemap[type->proto] != type))
104098 err = -ENOENT;
104099 - else
104100 + else {
104101 + pax_open_kernel();
104102 typemap[type->proto] = NULL;
104103 + pax_close_kernel();
104104 + }
104105 spin_unlock_bh(&xfrm_type_lock);
104106 xfrm_state_put_afinfo(afinfo);
104107 return err;
104108 @@ -210,7 +215,6 @@ EXPORT_SYMBOL(xfrm_unregister_type);
104109 static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
104110 {
104111 struct xfrm_state_afinfo *afinfo;
104112 - const struct xfrm_type **typemap;
104113 const struct xfrm_type *type;
104114 int modload_attempted = 0;
104115
104116 @@ -218,9 +222,8 @@ retry:
104117 afinfo = xfrm_state_get_afinfo(family);
104118 if (unlikely(afinfo == NULL))
104119 return NULL;
104120 - typemap = afinfo->type_map;
104121
104122 - type = typemap[proto];
104123 + type = afinfo->type_map[proto];
104124 if (unlikely(type && !try_module_get(type->owner)))
104125 type = NULL;
104126 if (!type && !modload_attempted) {
104127 @@ -254,7 +257,7 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
104128 return -EAFNOSUPPORT;
104129
104130 err = -EEXIST;
104131 - modemap = afinfo->mode_map;
104132 + modemap = (struct xfrm_mode **)afinfo->mode_map;
104133 spin_lock_bh(&xfrm_mode_lock);
104134 if (modemap[mode->encap])
104135 goto out;
104136 @@ -263,8 +266,10 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
104137 if (!try_module_get(afinfo->owner))
104138 goto out;
104139
104140 - mode->afinfo = afinfo;
104141 + pax_open_kernel();
104142 + *(const void **)&mode->afinfo = afinfo;
104143 modemap[mode->encap] = mode;
104144 + pax_close_kernel();
104145 err = 0;
104146
104147 out:
104148 @@ -288,10 +293,12 @@ int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
104149 return -EAFNOSUPPORT;
104150
104151 err = -ENOENT;
104152 - modemap = afinfo->mode_map;
104153 + modemap = (struct xfrm_mode **)afinfo->mode_map;
104154 spin_lock_bh(&xfrm_mode_lock);
104155 if (likely(modemap[mode->encap] == mode)) {
104156 + pax_open_kernel();
104157 modemap[mode->encap] = NULL;
104158 + pax_close_kernel();
104159 module_put(mode->afinfo->owner);
104160 err = 0;
104161 }
104162 @@ -1519,10 +1526,10 @@ EXPORT_SYMBOL(xfrm_find_acq_byseq);
104163 u32 xfrm_get_acqseq(void)
104164 {
104165 u32 res;
104166 - static atomic_t acqseq;
104167 + static atomic_unchecked_t acqseq;
104168
104169 do {
104170 - res = atomic_inc_return(&acqseq);
104171 + res = atomic_inc_return_unchecked(&acqseq);
104172 } while (!res);
104173
104174 return res;
104175 diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
104176 index 05a6e3d..6716ec9 100644
104177 --- a/net/xfrm/xfrm_sysctl.c
104178 +++ b/net/xfrm/xfrm_sysctl.c
104179 @@ -42,7 +42,7 @@ static struct ctl_table xfrm_table[] = {
104180
104181 int __net_init xfrm_sysctl_init(struct net *net)
104182 {
104183 - struct ctl_table *table;
104184 + ctl_table_no_const *table;
104185
104186 __xfrm_sysctl_init(net);
104187
104188 diff --git a/scripts/Makefile b/scripts/Makefile
104189 index 1d07860..f16fc22 100644
104190 --- a/scripts/Makefile
104191 +++ b/scripts/Makefile
104192 @@ -40,3 +40,5 @@ subdir-$(CONFIG_DTC) += dtc
104193
104194 # Let clean descend into subdirs
104195 subdir- += basic kconfig package selinux
104196 +
104197 +clean-files := randstruct.seed
104198 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
104199 index 003bc26..d5f02b0 100644
104200 --- a/scripts/Makefile.build
104201 +++ b/scripts/Makefile.build
104202 @@ -121,7 +121,7 @@ endif
104203 endif
104204
104205 # Do not include host rules unless needed
104206 -ifneq ($(hostprogs-y)$(hostprogs-m),)
104207 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
104208 include scripts/Makefile.host
104209 endif
104210
104211 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
104212 index 686cb0d..9d653bf 100644
104213 --- a/scripts/Makefile.clean
104214 +++ b/scripts/Makefile.clean
104215 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
104216 __clean-files := $(extra-y) $(always) \
104217 $(targets) $(clean-files) \
104218 $(host-progs) \
104219 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
104220 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
104221 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
104222
104223 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
104224
104225 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
104226 index 1ac414f..38575f7 100644
104227 --- a/scripts/Makefile.host
104228 +++ b/scripts/Makefile.host
104229 @@ -31,6 +31,8 @@
104230 # Note: Shared libraries consisting of C++ files are not supported
104231
104232 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
104233 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
104234 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
104235
104236 # C code
104237 # Executables compiled from a single .c file
104238 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
104239 # Shared libaries (only .c supported)
104240 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
104241 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
104242 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
104243 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
104244 # Remove .so files from "xxx-objs"
104245 host-cobjs := $(filter-out %.so,$(host-cobjs))
104246 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
104247
104248 -#Object (.o) files used by the shared libaries
104249 +# Object (.o) files used by the shared libaries
104250 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
104251 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
104252
104253 # output directory for programs/.o files
104254 # hostprogs-y := tools/build may have been specified. Retrieve directory
104255 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
104256 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
104257 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
104258 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
104259 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
104260 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
104261 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
104262 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
104263
104264 obj-dirs += $(host-objdirs)
104265 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
104266 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
104267 $(call if_changed_dep,host-cshobjs)
104268
104269 +# Compile .c file, create position independent .o file
104270 +# host-cxxshobjs -> .o
104271 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
104272 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
104273 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
104274 + $(call if_changed_dep,host-cxxshobjs)
104275 +
104276 # Link a shared library, based on position independent .o files
104277 # *.o -> .so shared library (host-cshlib)
104278 quiet_cmd_host-cshlib = HOSTLLD -shared $@
104279 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
104280 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
104281 $(call if_changed,host-cshlib)
104282
104283 +# Link a shared library, based on position independent .o files
104284 +# *.o -> .so shared library (host-cxxshlib)
104285 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
104286 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
104287 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
104288 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
104289 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
104290 + $(call if_changed,host-cxxshlib)
104291 +
104292 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
104293 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
104294 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
104295
104296 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
104297 index 078fe1d..fbdb363 100644
104298 --- a/scripts/basic/fixdep.c
104299 +++ b/scripts/basic/fixdep.c
104300 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
104301 /*
104302 * Lookup a value in the configuration string.
104303 */
104304 -static int is_defined_config(const char *name, int len, unsigned int hash)
104305 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
104306 {
104307 struct item *aux;
104308
104309 @@ -211,10 +211,10 @@ static void clear_config(void)
104310 /*
104311 * Record the use of a CONFIG_* word.
104312 */
104313 -static void use_config(const char *m, int slen)
104314 +static void use_config(const char *m, unsigned int slen)
104315 {
104316 unsigned int hash = strhash(m, slen);
104317 - int c, i;
104318 + unsigned int c, i;
104319
104320 if (is_defined_config(m, slen, hash))
104321 return;
104322 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
104323
104324 static void parse_config_file(const char *map, size_t len)
104325 {
104326 - const int *end = (const int *) (map + len);
104327 + const unsigned int *end = (const unsigned int *) (map + len);
104328 /* start at +1, so that p can never be < map */
104329 - const int *m = (const int *) map + 1;
104330 + const unsigned int *m = (const unsigned int *) map + 1;
104331 const char *p, *q;
104332
104333 for (; m < end; m++) {
104334 @@ -435,7 +435,7 @@ static void print_deps(void)
104335 static void traps(void)
104336 {
104337 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
104338 - int *p = (int *)test;
104339 + unsigned int *p = (unsigned int *)test;
104340
104341 if (*p != INT_CONF) {
104342 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianness? %#x\n",
104343 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
104344 new file mode 100644
104345 index 0000000..3fd3699
104346 --- /dev/null
104347 +++ b/scripts/gcc-plugin.sh
104348 @@ -0,0 +1,43 @@
104349 +#!/bin/bash
104350 +srctree=$(dirname "$0")
104351 +gccplugins_dir=$($3 -print-file-name=plugin)
104352 +plugincc=$($1 -E - -o /dev/null -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
104353 +#include "gcc-common.h"
104354 +#if BUILDING_GCC_VERSION >= 4008 || defined(ENABLE_BUILD_WITH_CXX)
104355 +#warning $2 CXX
104356 +#else
104357 +#warning $1 CC
104358 +#endif
104359 +EOF
104360 +)
104361 +
104362 +if [ $? -ne 0 ]
104363 +then
104364 + exit 1
104365 +fi
104366 +
104367 +if [[ "$plugincc" =~ "$1 CC" ]]
104368 +then
104369 + echo "$1"
104370 + exit 0
104371 +fi
104372 +
104373 +if [[ "$plugincc" =~ "$2 CXX" ]]
104374 +then
104375 +plugincc=$($1 -c -x c++ -std=gnu++98 - -o /dev/null -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
104376 +#include "gcc-common.h"
104377 +class test {
104378 +public:
104379 + int test;
104380 +} test = {
104381 + .test = 1
104382 +};
104383 +EOF
104384 +)
104385 +if [ $? -eq 0 ]
104386 +then
104387 + echo "$2"
104388 + exit 0
104389 +fi
104390 +fi
104391 +exit 1
104392 diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh
104393 index 5de5660..d3deb89 100644
104394 --- a/scripts/headers_install.sh
104395 +++ b/scripts/headers_install.sh
104396 @@ -32,6 +32,7 @@ do
104397 FILE="$(basename "$i")"
104398 sed -r \
104399 -e 's/([ \t(])(__user|__force|__iomem)[ \t]/\1/g' \
104400 + -e 's/__intentional_overflow\([- \t,0-9]*\)//g' \
104401 -e 's/__attribute_const__([ \t]|$)/\1/g' \
104402 -e 's@^#include <linux/compiler.h>@@' \
104403 -e 's/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g' \
104404 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
104405 index 86a4fe7..99e91f9 100644
104406 --- a/scripts/link-vmlinux.sh
104407 +++ b/scripts/link-vmlinux.sh
104408 @@ -166,7 +166,7 @@ else
104409 fi;
104410
104411 # final build of init/
104412 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
104413 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
104414
104415 kallsymso=""
104416 kallsyms_vmlinux=""
104417 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
104418 index 1924990..3de7363 100644
104419 --- a/scripts/mod/file2alias.c
104420 +++ b/scripts/mod/file2alias.c
104421 @@ -142,7 +142,7 @@ static void device_id_check(const char *modname, const char *device_id,
104422 unsigned long size, unsigned long id_size,
104423 void *symval)
104424 {
104425 - int i;
104426 + unsigned int i;
104427
104428 if (size % id_size || size < id_size) {
104429 fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
104430 @@ -171,7 +171,7 @@ static void device_id_check(const char *modname, const char *device_id,
104431 /* USB is special because the bcdDevice can be matched against a numeric range */
104432 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
104433 static void do_usb_entry(void *symval,
104434 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
104435 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
104436 unsigned char range_lo, unsigned char range_hi,
104437 unsigned char max, struct module *mod)
104438 {
104439 @@ -281,7 +281,7 @@ static void do_usb_entry_multi(void *symval, struct module *mod)
104440 {
104441 unsigned int devlo, devhi;
104442 unsigned char chi, clo, max;
104443 - int ndigits;
104444 + unsigned int ndigits;
104445
104446 DEF_FIELD(symval, usb_device_id, match_flags);
104447 DEF_FIELD(symval, usb_device_id, idVendor);
104448 @@ -534,7 +534,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
104449 for (i = 0; i < count; i++) {
104450 DEF_FIELD_ADDR(symval + i*id_size, pnp_device_id, id);
104451 char acpi_id[sizeof(*id)];
104452 - int j;
104453 + unsigned int j;
104454
104455 buf_printf(&mod->dev_table_buf,
104456 "MODULE_ALIAS(\"pnp:d%s*\");\n", *id);
104457 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
104458
104459 for (j = 0; j < PNP_MAX_DEVICES; j++) {
104460 const char *id = (char *)(*devs)[j].id;
104461 - int i2, j2;
104462 + unsigned int i2, j2;
104463 int dup = 0;
104464
104465 if (!id[0])
104466 @@ -589,7 +589,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
104467 /* add an individual alias for every device entry */
104468 if (!dup) {
104469 char acpi_id[PNP_ID_LEN];
104470 - int k;
104471 + unsigned int k;
104472
104473 buf_printf(&mod->dev_table_buf,
104474 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
104475 @@ -941,7 +941,7 @@ static void dmi_ascii_filter(char *d, const char *s)
104476 static int do_dmi_entry(const char *filename, void *symval,
104477 char *alias)
104478 {
104479 - int i, j;
104480 + unsigned int i, j;
104481 DEF_FIELD_ADDR(symval, dmi_system_id, matches);
104482 sprintf(alias, "dmi*");
104483
104484 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
104485 index 0663556..d9494f0 100644
104486 --- a/scripts/mod/modpost.c
104487 +++ b/scripts/mod/modpost.c
104488 @@ -949,6 +949,7 @@ enum mismatch {
104489 ANY_INIT_TO_ANY_EXIT,
104490 ANY_EXIT_TO_ANY_INIT,
104491 EXPORT_TO_INIT_EXIT,
104492 + DATA_TO_TEXT
104493 };
104494
104495 struct sectioncheck {
104496 @@ -1035,6 +1036,12 @@ const struct sectioncheck sectioncheck[] = {
104497 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
104498 .mismatch = EXPORT_TO_INIT_EXIT,
104499 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
104500 +},
104501 +/* Do not reference code from writable data */
104502 +{
104503 + .fromsec = { DATA_SECTIONS, NULL },
104504 + .tosec = { TEXT_SECTIONS, NULL },
104505 + .mismatch = DATA_TO_TEXT
104506 }
104507 };
104508
104509 @@ -1155,10 +1162,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
104510 continue;
104511 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
104512 continue;
104513 - if (sym->st_value == addr)
104514 - return sym;
104515 /* Find a symbol nearby - addr are maybe negative */
104516 d = sym->st_value - addr;
104517 + if (d == 0)
104518 + return sym;
104519 if (d < 0)
104520 d = addr - sym->st_value;
104521 if (d < distance) {
104522 @@ -1436,6 +1443,14 @@ static void report_sec_mismatch(const char *modname,
104523 tosym, prl_to, prl_to, tosym);
104524 free(prl_to);
104525 break;
104526 + case DATA_TO_TEXT:
104527 +#if 0
104528 + fprintf(stderr,
104529 + "The %s %s:%s references\n"
104530 + "the %s %s:%s%s\n",
104531 + from, fromsec, fromsym, to, tosec, tosym, to_p);
104532 +#endif
104533 + break;
104534 }
104535 fprintf(stderr, "\n");
104536 }
104537 @@ -1687,7 +1702,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
104538 static void check_sec_ref(struct module *mod, const char *modname,
104539 struct elf_info *elf)
104540 {
104541 - int i;
104542 + unsigned int i;
104543 Elf_Shdr *sechdrs = elf->sechdrs;
104544
104545 /* Walk through all sections */
104546 @@ -1819,7 +1834,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
104547 va_end(ap);
104548 }
104549
104550 -void buf_write(struct buffer *buf, const char *s, int len)
104551 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
104552 {
104553 if (buf->size - buf->pos < len) {
104554 buf->size += len + SZ;
104555 @@ -2038,7 +2053,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
104556 if (fstat(fileno(file), &st) < 0)
104557 goto close_write;
104558
104559 - if (st.st_size != b->pos)
104560 + if (st.st_size != (off_t)b->pos)
104561 goto close_write;
104562
104563 tmp = NOFAIL(malloc(b->pos));
104564 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
104565 index 168b43d..77914bf 100644
104566 --- a/scripts/mod/modpost.h
104567 +++ b/scripts/mod/modpost.h
104568 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
104569
104570 struct buffer {
104571 char *p;
104572 - int pos;
104573 - int size;
104574 + unsigned int pos;
104575 + unsigned int size;
104576 };
104577
104578 void __attribute__((format(printf, 2, 3)))
104579 buf_printf(struct buffer *buf, const char *fmt, ...);
104580
104581 void
104582 -buf_write(struct buffer *buf, const char *s, int len);
104583 +buf_write(struct buffer *buf, const char *s, unsigned int len);
104584
104585 struct module {
104586 struct module *next;
104587 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
104588 index deb2994..af4f63e 100644
104589 --- a/scripts/mod/sumversion.c
104590 +++ b/scripts/mod/sumversion.c
104591 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
104592 goto out;
104593 }
104594
104595 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
104596 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
104597 warn("writing sum in %s failed: %s\n",
104598 filename, strerror(errno));
104599 goto out;
104600 diff --git a/scripts/module-common.lds b/scripts/module-common.lds
104601 index 0865b3e..7235dd4 100644
104602 --- a/scripts/module-common.lds
104603 +++ b/scripts/module-common.lds
104604 @@ -6,6 +6,10 @@
104605 SECTIONS {
104606 /DISCARD/ : { *(.discard) }
104607
104608 + .rodata : {
104609 + *(.rodata) *(.rodata.*)
104610 + *(.data..read_only)
104611 + }
104612 __ksymtab : { *(SORT(___ksymtab+*)) }
104613 __ksymtab_gpl : { *(SORT(___ksymtab_gpl+*)) }
104614 __ksymtab_unused : { *(SORT(___ksymtab_unused+*)) }
104615 diff --git a/scripts/package/builddeb b/scripts/package/builddeb
104616 index 152d4d2..791684c 100644
104617 --- a/scripts/package/builddeb
104618 +++ b/scripts/package/builddeb
104619 @@ -291,6 +291,7 @@ fi
104620 (cd $srctree; find . -name Makefile\* -o -name Kconfig\* -o -name \*.pl > "$objtree/debian/hdrsrcfiles")
104621 (cd $srctree; find arch/$SRCARCH/include include scripts -type f >> "$objtree/debian/hdrsrcfiles")
104622 (cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f >> "$objtree/debian/hdrobjfiles")
104623 +(cd $objtree; find tools/gcc -name \*.so >> "$objtree/debian/hdrobjfiles")
104624 destdir=$kernel_headers_dir/usr/src/linux-headers-$version
104625 mkdir -p "$destdir"
104626 (cd $srctree; tar -c -f - -T "$objtree/debian/hdrsrcfiles") | (cd $destdir; tar -xf -)
104627 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
104628 index 68bb4ef..2f419e1 100644
104629 --- a/scripts/pnmtologo.c
104630 +++ b/scripts/pnmtologo.c
104631 @@ -244,14 +244,14 @@ static void write_header(void)
104632 fprintf(out, " * Linux logo %s\n", logoname);
104633 fputs(" */\n\n", out);
104634 fputs("#include <linux/linux_logo.h>\n\n", out);
104635 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
104636 + fprintf(out, "static unsigned char %s_data[] = {\n",
104637 logoname);
104638 }
104639
104640 static void write_footer(void)
104641 {
104642 fputs("\n};\n\n", out);
104643 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
104644 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
104645 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
104646 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
104647 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
104648 @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
104649 fputs("\n};\n\n", out);
104650
104651 /* write logo clut */
104652 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
104653 + fprintf(out, "static unsigned char %s_clut[] = {\n",
104654 logoname);
104655 write_hex_cnt = 0;
104656 for (i = 0; i < logo_clutsize; i++) {
104657 diff --git a/scripts/sortextable.h b/scripts/sortextable.h
104658 index 8fac3fd..32ff38d 100644
104659 --- a/scripts/sortextable.h
104660 +++ b/scripts/sortextable.h
104661 @@ -108,9 +108,9 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
104662 const char *secstrtab;
104663 const char *strtab;
104664 char *extab_image;
104665 - int extab_index = 0;
104666 - int i;
104667 - int idx;
104668 + unsigned int extab_index = 0;
104669 + unsigned int i;
104670 + unsigned int idx;
104671 unsigned int num_sections;
104672 unsigned int secindex_strings;
104673
104674 diff --git a/security/Kconfig b/security/Kconfig
104675 index beb86b5..40b1edb 100644
104676 --- a/security/Kconfig
104677 +++ b/security/Kconfig
104678 @@ -4,6 +4,957 @@
104679
104680 menu "Security options"
104681
104682 +menu "Grsecurity"
104683 +
104684 + config ARCH_TRACK_EXEC_LIMIT
104685 + bool
104686 +
104687 + config PAX_KERNEXEC_PLUGIN
104688 + bool
104689 +
104690 + config PAX_PER_CPU_PGD
104691 + bool
104692 +
104693 + config TASK_SIZE_MAX_SHIFT
104694 + int
104695 + depends on X86_64
104696 + default 47 if !PAX_PER_CPU_PGD
104697 + default 42 if PAX_PER_CPU_PGD
104698 +
104699 + config PAX_ENABLE_PAE
104700 + bool
104701 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
104702 +
104703 + config PAX_USERCOPY_SLABS
104704 + bool
104705 +
104706 +config GRKERNSEC
104707 + bool "Grsecurity"
104708 + select CRYPTO
104709 + select CRYPTO_SHA256
104710 + select PROC_FS
104711 + select STOP_MACHINE
104712 + select TTY
104713 + select DEBUG_KERNEL
104714 + select DEBUG_LIST
104715 + help
104716 + If you say Y here, you will be able to configure many features
104717 + that will enhance the security of your system. It is highly
104718 + recommended that you say Y here and read through the help
104719 + for each option so that you fully understand the features and
104720 + can evaluate their usefulness for your machine.
104721 +
104722 +choice
104723 + prompt "Configuration Method"
104724 + depends on GRKERNSEC
104725 + default GRKERNSEC_CONFIG_CUSTOM
104726 + help
104727 +
104728 +config GRKERNSEC_CONFIG_AUTO
104729 + bool "Automatic"
104730 + help
104731 + If you choose this configuration method, you'll be able to answer a small
104732 + number of simple questions about how you plan to use this kernel.
104733 + The settings of grsecurity and PaX will be automatically configured for
104734 + the highest commonly-used settings within the provided constraints.
104735 +
104736 + If you require additional configuration, custom changes can still be made
104737 + from the "custom configuration" menu.
104738 +
104739 +config GRKERNSEC_CONFIG_CUSTOM
104740 + bool "Custom"
104741 + help
104742 + If you choose this configuration method, you'll be able to configure all
104743 + grsecurity and PaX settings manually. Via this method, no options are
104744 + automatically enabled.
104745 +
104746 +endchoice
104747 +
104748 +choice
104749 + prompt "Usage Type"
104750 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
104751 + default GRKERNSEC_CONFIG_SERVER
104752 + help
104753 +
104754 +config GRKERNSEC_CONFIG_SERVER
104755 + bool "Server"
104756 + help
104757 + Choose this option if you plan to use this kernel on a server.
104758 +
104759 +config GRKERNSEC_CONFIG_DESKTOP
104760 + bool "Desktop"
104761 + help
104762 + Choose this option if you plan to use this kernel on a desktop.
104763 +
104764 +endchoice
104765 +
104766 +choice
104767 + prompt "Virtualization Type"
104768 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
104769 + default GRKERNSEC_CONFIG_VIRT_NONE
104770 + help
104771 +
104772 +config GRKERNSEC_CONFIG_VIRT_NONE
104773 + bool "None"
104774 + help
104775 + Choose this option if this kernel will be run on bare metal.
104776 +
104777 +config GRKERNSEC_CONFIG_VIRT_GUEST
104778 + bool "Guest"
104779 + help
104780 + Choose this option if this kernel will be run as a VM guest.
104781 +
104782 +config GRKERNSEC_CONFIG_VIRT_HOST
104783 + bool "Host"
104784 + help
104785 + Choose this option if this kernel will be run as a VM host.
104786 +
104787 +endchoice
104788 +
104789 +choice
104790 + prompt "Virtualization Hardware"
104791 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
104792 + help
104793 +
104794 +config GRKERNSEC_CONFIG_VIRT_EPT
104795 + bool "EPT/RVI Processor Support"
104796 + depends on X86
104797 + help
104798 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
104799 + hardware virtualization. This allows for additional kernel hardening protections
104800 + to operate without additional performance impact.
104801 +
104802 + To see if your Intel processor supports EPT, see:
104803 + http://ark.intel.com/Products/VirtualizationTechnology
104804 + (Most Core i3/5/7 support EPT)
104805 +
104806 + To see if your AMD processor supports RVI, see:
104807 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
104808 +
104809 +config GRKERNSEC_CONFIG_VIRT_SOFT
104810 + bool "First-gen/No Hardware Virtualization"
104811 + help
104812 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
104813 + support hardware virtualization or doesn't support the EPT/RVI extensions.
104814 +
104815 +endchoice
104816 +
104817 +choice
104818 + prompt "Virtualization Software"
104819 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
104820 + help
104821 +
104822 +config GRKERNSEC_CONFIG_VIRT_XEN
104823 + bool "Xen"
104824 + help
104825 + Choose this option if this kernel is running as a Xen guest or host.
104826 +
104827 +config GRKERNSEC_CONFIG_VIRT_VMWARE
104828 + bool "VMWare"
104829 + help
104830 + Choose this option if this kernel is running as a VMWare guest or host.
104831 +
104832 +config GRKERNSEC_CONFIG_VIRT_KVM
104833 + bool "KVM"
104834 + help
104835 + Choose this option if this kernel is running as a KVM guest or host.
104836 +
104837 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
104838 + bool "VirtualBox"
104839 + help
104840 + Choose this option if this kernel is running as a VirtualBox guest or host.
104841 +
104842 +endchoice
104843 +
104844 +choice
104845 + prompt "Required Priorities"
104846 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
104847 + default GRKERNSEC_CONFIG_PRIORITY_PERF
104848 + help
104849 +
104850 +config GRKERNSEC_CONFIG_PRIORITY_PERF
104851 + bool "Performance"
104852 + help
104853 + Choose this option if performance is of highest priority for this deployment
104854 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
104855 + clearing of structures intended for userland, and freed memory sanitizing will
104856 + be disabled.
104857 +
104858 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
104859 + bool "Security"
104860 + help
104861 + Choose this option if security is of highest priority for this deployment of
104862 + grsecurity. UDEREF, kernel stack clearing, clearing of structures intended
104863 + for userland, and freed memory sanitizing will be enabled for this kernel.
104864 + In a worst-case scenario, these features can introduce a 20% performance hit
104865 + (UDEREF on x64 contributing half of this hit).
104866 +
104867 +endchoice
104868 +
104869 +menu "Default Special Groups"
104870 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
104871 +
104872 +config GRKERNSEC_PROC_GID
104873 + int "GID exempted from /proc restrictions"
104874 + default 1001
104875 + help
104876 + Setting this GID determines which group will be exempted from
104877 + grsecurity's /proc restrictions, allowing users of the specified
104878 + group to view network statistics and the existence of other users'
104879 + processes on the system. This GID may also be chosen at boot time
104880 + via "grsec_proc_gid=" on the kernel commandline.
104881 +
104882 +config GRKERNSEC_TPE_UNTRUSTED_GID
104883 + int "GID for TPE-untrusted users"
104884 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
104885 + default 1005
104886 + help
104887 + Setting this GID determines which group untrusted users should
104888 + be added to. These users will be placed under grsecurity's Trusted Path
104889 + Execution mechanism, preventing them from executing their own binaries.
104890 + The users will only be able to execute binaries in directories owned and
104891 + writable only by the root user. If the sysctl option is enabled, a sysctl
104892 + option with name "tpe_gid" is created.
104893 +
104894 +config GRKERNSEC_TPE_TRUSTED_GID
104895 + int "GID for TPE-trusted users"
104896 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
104897 + default 1005
104898 + help
104899 + Setting this GID determines what group TPE restrictions will be
104900 + *disabled* for. If the sysctl option is enabled, a sysctl option
104901 + with name "tpe_gid" is created.
104902 +
104903 +config GRKERNSEC_SYMLINKOWN_GID
104904 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
104905 + depends on GRKERNSEC_CONFIG_SERVER
104906 + default 1006
104907 + help
104908 + Setting this GID determines what group kernel-enforced
104909 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
104910 + is enabled, a sysctl option with name "symlinkown_gid" is created.
104911 +
104912 +
104913 +endmenu
104914 +
104915 +menu "Customize Configuration"
104916 +depends on GRKERNSEC
104917 +
104918 +menu "PaX"
104919 +
104920 +config PAX
104921 + bool "Enable various PaX features"
104922 + default y if GRKERNSEC_CONFIG_AUTO
104923 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
104924 + help
104925 + This allows you to enable various PaX features. PaX adds
104926 + intrusion prevention mechanisms to the kernel that reduce
104927 + the risks posed by exploitable memory corruption bugs.
104928 +
104929 +menu "PaX Control"
104930 + depends on PAX
104931 +
104932 +config PAX_SOFTMODE
104933 + bool 'Support soft mode'
104934 + help
104935 + Enabling this option will allow you to run PaX in soft mode, that
104936 + is, PaX features will not be enforced by default, only on executables
104937 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
104938 + support as they are the only way to mark executables for soft mode use.
104939 +
104940 + Soft mode can be activated by using the "pax_softmode=1" kernel command
104941 + line option on boot. Furthermore you can control various PaX features
104942 + at runtime via the entries in /proc/sys/kernel/pax.
104943 +
104944 +config PAX_EI_PAX
104945 + bool 'Use legacy ELF header marking'
104946 + default y if GRKERNSEC_CONFIG_AUTO
104947 + help
104948 + Enabling this option will allow you to control PaX features on
104949 + a per executable basis via the 'chpax' utility available at
104950 + http://pax.grsecurity.net/. The control flags will be read from
104951 + an otherwise reserved part of the ELF header. This marking has
104952 + numerous drawbacks (no support for soft-mode, toolchain does not
104953 + know about the non-standard use of the ELF header) therefore it
104954 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
104955 + support.
104956 +
104957 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
104958 + support as well, they will override the legacy EI_PAX marks.
104959 +
104960 + If you enable none of the marking options then all applications
104961 + will run with PaX enabled on them by default.
104962 +
104963 +config PAX_PT_PAX_FLAGS
104964 + bool 'Use ELF program header marking'
104965 + default y if GRKERNSEC_CONFIG_AUTO
104966 + help
104967 + Enabling this option will allow you to control PaX features on
104968 + a per executable basis via the 'paxctl' utility available at
104969 + http://pax.grsecurity.net/. The control flags will be read from
104970 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
104971 + has the benefits of supporting both soft mode and being fully
104972 + integrated into the toolchain (the binutils patch is available
104973 + from http://pax.grsecurity.net).
104974 +
104975 + Note that if you enable the legacy EI_PAX marking support as well,
104976 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
104977 +
104978 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
104979 + must make sure that the marks are the same if a binary has both marks.
104980 +
104981 + If you enable none of the marking options then all applications
104982 + will run with PaX enabled on them by default.
104983 +
104984 +config PAX_XATTR_PAX_FLAGS
104985 + bool 'Use filesystem extended attributes marking'
104986 + default y if GRKERNSEC_CONFIG_AUTO
104987 + select CIFS_XATTR if CIFS
104988 + select F2FS_FS_XATTR if F2FS_FS
104989 + select EXT2_FS_XATTR if EXT2_FS
104990 + select EXT3_FS_XATTR if EXT3_FS
104991 + select JFFS2_FS_XATTR if JFFS2_FS
104992 + select REISERFS_FS_XATTR if REISERFS_FS
104993 + select SQUASHFS_XATTR if SQUASHFS
104994 + select TMPFS_XATTR if TMPFS
104995 + help
104996 + Enabling this option will allow you to control PaX features on
104997 + a per executable basis via the 'setfattr' utility. The control
104998 + flags will be read from the user.pax.flags extended attribute of
104999 + the file. This marking has the benefit of supporting binary-only
105000 + applications that self-check themselves (e.g., skype) and would
105001 + not tolerate chpax/paxctl changes. The main drawback is that
105002 + extended attributes are not supported by some filesystems (e.g.,
105003 + isofs, udf, vfat) so copying files through such filesystems will
105004 + lose the extended attributes and these PaX markings.
105005 +
105006 + Note that if you enable the legacy EI_PAX marking support as well,
105007 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
105008 +
105009 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
105010 + must make sure that the marks are the same if a binary has both marks.
105011 +
105012 + If you enable none of the marking options then all applications
105013 + will run with PaX enabled on them by default.
105014 +
105015 +choice
105016 + prompt 'MAC system integration'
105017 + default PAX_HAVE_ACL_FLAGS
105018 + help
105019 + Mandatory Access Control systems have the option of controlling
105020 + PaX flags on a per executable basis, choose the method supported
105021 + by your particular system.
105022 +
105023 + - "none": if your MAC system does not interact with PaX,
105024 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
105025 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
105026 +
105027 + NOTE: this option is for developers/integrators only.
105028 +
105029 + config PAX_NO_ACL_FLAGS
105030 + bool 'none'
105031 +
105032 + config PAX_HAVE_ACL_FLAGS
105033 + bool 'direct'
105034 +
105035 + config PAX_HOOK_ACL_FLAGS
105036 + bool 'hook'
105037 +endchoice
105038 +
105039 +endmenu
105040 +
105041 +menu "Non-executable pages"
105042 + depends on PAX
105043 +
105044 +config PAX_NOEXEC
105045 + bool "Enforce non-executable pages"
105046 + default y if GRKERNSEC_CONFIG_AUTO
105047 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
105048 + help
105049 + By design some architectures do not allow for protecting memory
105050 + pages against execution or even if they do, Linux does not make
105051 + use of this feature. In practice this means that if a page is
105052 + readable (such as the stack or heap) it is also executable.
105053 +
105054 + There is a well known exploit technique that makes use of this
105055 + fact and a common programming mistake where an attacker can
105056 + introduce code of his choice somewhere in the attacked program's
105057 + memory (typically the stack or the heap) and then execute it.
105058 +
105059 + If the attacked program was running with different (typically
105060 + higher) privileges than that of the attacker, then he can elevate
105061 + his own privilege level (e.g. get a root shell, write to files for
105062 + which he does not have write access to, etc).
105063 +
105064 + Enabling this option will let you choose from various features
105065 + that prevent the injection and execution of 'foreign' code in
105066 + a program.
105067 +
105068 + This will also break programs that rely on the old behaviour and
105069 + expect that dynamically allocated memory via the malloc() family
105070 + of functions is executable (which it is not). Notable examples
105071 + are the XFree86 4.x server, the java runtime and wine.
105072 +
105073 +config PAX_PAGEEXEC
105074 + bool "Paging based non-executable pages"
105075 + default y if GRKERNSEC_CONFIG_AUTO
105076 + 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)
105077 + select ARCH_TRACK_EXEC_LIMIT if X86_32
105078 + help
105079 + This implementation is based on the paging feature of the CPU.
105080 + On i386 without hardware non-executable bit support there is a
105081 + variable but usually low performance impact, however on Intel's
105082 + P4 core based CPUs it is very high so you should not enable this
105083 + for kernels meant to be used on such CPUs.
105084 +
105085 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
105086 + with hardware non-executable bit support there is no performance
105087 + impact, on ppc the impact is negligible.
105088 +
105089 + Note that several architectures require various emulations due to
105090 + badly designed userland ABIs, this will cause a performance impact
105091 + but will disappear as soon as userland is fixed. For example, ppc
105092 + userland MUST have been built with secure-plt by a recent toolchain.
105093 +
105094 +config PAX_SEGMEXEC
105095 + bool "Segmentation based non-executable pages"
105096 + default y if GRKERNSEC_CONFIG_AUTO
105097 + depends on PAX_NOEXEC && X86_32
105098 + help
105099 + This implementation is based on the segmentation feature of the
105100 + CPU and has a very small performance impact, however applications
105101 + will be limited to a 1.5 GB address space instead of the normal
105102 + 3 GB.
105103 +
105104 +config PAX_EMUTRAMP
105105 + bool "Emulate trampolines"
105106 + default y if PARISC || GRKERNSEC_CONFIG_AUTO
105107 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
105108 + help
105109 + There are some programs and libraries that for one reason or
105110 + another attempt to execute special small code snippets from
105111 + non-executable memory pages. Most notable examples are the
105112 + signal handler return code generated by the kernel itself and
105113 + the GCC trampolines.
105114 +
105115 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
105116 + such programs will no longer work under your kernel.
105117 +
105118 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
105119 + utilities to enable trampoline emulation for the affected programs
105120 + yet still have the protection provided by the non-executable pages.
105121 +
105122 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
105123 + your system will not even boot.
105124 +
105125 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
105126 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
105127 + for the affected files.
105128 +
105129 + NOTE: enabling this feature *may* open up a loophole in the
105130 + protection provided by non-executable pages that an attacker
105131 + could abuse. Therefore the best solution is to not have any
105132 + files on your system that would require this option. This can
105133 + be achieved by not using libc5 (which relies on the kernel
105134 + signal handler return code) and not using or rewriting programs
105135 + that make use of the nested function implementation of GCC.
105136 + Skilled users can just fix GCC itself so that it implements
105137 + nested function calls in a way that does not interfere with PaX.
105138 +
105139 +config PAX_EMUSIGRT
105140 + bool "Automatically emulate sigreturn trampolines"
105141 + depends on PAX_EMUTRAMP && PARISC
105142 + default y
105143 + help
105144 + Enabling this option will have the kernel automatically detect
105145 + and emulate signal return trampolines executing on the stack
105146 + that would otherwise lead to task termination.
105147 +
105148 + This solution is intended as a temporary one for users with
105149 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
105150 + Modula-3 runtime, etc) or executables linked to such, basically
105151 + everything that does not specify its own SA_RESTORER function in
105152 + normal executable memory like glibc 2.1+ does.
105153 +
105154 + On parisc you MUST enable this option, otherwise your system will
105155 + not even boot.
105156 +
105157 + NOTE: this feature cannot be disabled on a per executable basis
105158 + and since it *does* open up a loophole in the protection provided
105159 + by non-executable pages, the best solution is to not have any
105160 + files on your system that would require this option.
105161 +
105162 +config PAX_MPROTECT
105163 + bool "Restrict mprotect()"
105164 + default y if GRKERNSEC_CONFIG_AUTO
105165 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
105166 + help
105167 + Enabling this option will prevent programs from
105168 + - changing the executable status of memory pages that were
105169 + not originally created as executable,
105170 + - making read-only executable pages writable again,
105171 + - creating executable pages from anonymous memory,
105172 + - making read-only-after-relocations (RELRO) data pages writable again.
105173 +
105174 + You should say Y here to complete the protection provided by
105175 + the enforcement of non-executable pages.
105176 +
105177 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
105178 + this feature on a per file basis.
105179 +
105180 +config PAX_MPROTECT_COMPAT
105181 + bool "Use legacy/compat protection demoting (read help)"
105182 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
105183 + depends on PAX_MPROTECT
105184 + help
105185 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
105186 + by sending the proper error code to the application. For some broken
105187 + userland, this can cause problems with Python or other applications. The
105188 + current implementation however allows for applications like clamav to
105189 + detect if JIT compilation/execution is allowed and to fall back gracefully
105190 + to an interpreter-based mode if it does not. While we encourage everyone
105191 + to use the current implementation as-is and push upstream to fix broken
105192 + userland (note that the RWX logging option can assist with this), in some
105193 + environments this may not be possible. Having to disable MPROTECT
105194 + completely on certain binaries reduces the security benefit of PaX,
105195 + so this option is provided for those environments to revert to the old
105196 + behavior.
105197 +
105198 +config PAX_ELFRELOCS
105199 + bool "Allow ELF text relocations (read help)"
105200 + depends on PAX_MPROTECT
105201 + default n
105202 + help
105203 + Non-executable pages and mprotect() restrictions are effective
105204 + in preventing the introduction of new executable code into an
105205 + attacked task's address space. There remain only two venues
105206 + for this kind of attack: if the attacker can execute already
105207 + existing code in the attacked task then he can either have it
105208 + create and mmap() a file containing his code or have it mmap()
105209 + an already existing ELF library that does not have position
105210 + independent code in it and use mprotect() on it to make it
105211 + writable and copy his code there. While protecting against
105212 + the former approach is beyond PaX, the latter can be prevented
105213 + by having only PIC ELF libraries on one's system (which do not
105214 + need to relocate their code). If you are sure this is your case,
105215 + as is the case with all modern Linux distributions, then leave
105216 + this option disabled. You should say 'n' here.
105217 +
105218 +config PAX_ETEXECRELOCS
105219 + bool "Allow ELF ET_EXEC text relocations"
105220 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
105221 + select PAX_ELFRELOCS
105222 + default y
105223 + help
105224 + On some architectures there are incorrectly created applications
105225 + that require text relocations and would not work without enabling
105226 + this option. If you are an alpha, ia64 or parisc user, you should
105227 + enable this option and disable it once you have made sure that
105228 + none of your applications need it.
105229 +
105230 +config PAX_EMUPLT
105231 + bool "Automatically emulate ELF PLT"
105232 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
105233 + default y
105234 + help
105235 + Enabling this option will have the kernel automatically detect
105236 + and emulate the Procedure Linkage Table entries in ELF files.
105237 + On some architectures such entries are in writable memory, and
105238 + become non-executable leading to task termination. Therefore
105239 + it is mandatory that you enable this option on alpha, parisc,
105240 + sparc and sparc64, otherwise your system would not even boot.
105241 +
105242 + NOTE: this feature *does* open up a loophole in the protection
105243 + provided by the non-executable pages, therefore the proper
105244 + solution is to modify the toolchain to produce a PLT that does
105245 + not need to be writable.
105246 +
105247 +config PAX_DLRESOLVE
105248 + bool 'Emulate old glibc resolver stub'
105249 + depends on PAX_EMUPLT && SPARC
105250 + default n
105251 + help
105252 + This option is needed if userland has an old glibc (before 2.4)
105253 + that puts a 'save' instruction into the runtime generated resolver
105254 + stub that needs special emulation.
105255 +
105256 +config PAX_KERNEXEC
105257 + bool "Enforce non-executable kernel pages"
105258 + 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))
105259 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
105260 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
105261 + select PAX_KERNEXEC_PLUGIN if X86_64
105262 + help
105263 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
105264 + that is, enabling this option will make it harder to inject
105265 + and execute 'foreign' code in kernel memory itself.
105266 +
105267 +choice
105268 + prompt "Return Address Instrumentation Method"
105269 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
105270 + depends on PAX_KERNEXEC_PLUGIN
105271 + help
105272 + Select the method used to instrument function pointer dereferences.
105273 + Note that binary modules cannot be instrumented by this approach.
105274 +
105275 + Note that the implementation requires a gcc with plugin support,
105276 + i.e., gcc 4.5 or newer. You may need to install the supporting
105277 + headers explicitly in addition to the normal gcc package.
105278 +
105279 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
105280 + bool "bts"
105281 + help
105282 + This method is compatible with binary only modules but has
105283 + a higher runtime overhead.
105284 +
105285 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
105286 + bool "or"
105287 + depends on !PARAVIRT
105288 + help
105289 + This method is incompatible with binary only modules but has
105290 + a lower runtime overhead.
105291 +endchoice
105292 +
105293 +config PAX_KERNEXEC_PLUGIN_METHOD
105294 + string
105295 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
105296 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
105297 + default ""
105298 +
105299 +config PAX_KERNEXEC_MODULE_TEXT
105300 + int "Minimum amount of memory reserved for module code"
105301 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
105302 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
105303 + depends on PAX_KERNEXEC && X86_32
105304 + help
105305 + Due to implementation details the kernel must reserve a fixed
105306 + amount of memory for runtime allocated code (such as modules)
105307 + at compile time that cannot be changed at runtime. Here you
105308 + can specify the minimum amount in MB that will be reserved.
105309 + Due to the same implementation details this size will always
105310 + be rounded up to the next 2/4 MB boundary (depends on PAE) so
105311 + the actually available memory for runtime allocated code will
105312 + usually be more than this minimum.
105313 +
105314 + The default 4 MB should be enough for most users but if you have
105315 + an excessive number of modules (e.g., most distribution configs
105316 + compile many drivers as modules) or use huge modules such as
105317 + nvidia's kernel driver, you will need to adjust this amount.
105318 + A good rule of thumb is to look at your currently loaded kernel
105319 + modules and add up their sizes.
105320 +
105321 +endmenu
105322 +
105323 +menu "Address Space Layout Randomization"
105324 + depends on PAX
105325 +
105326 +config PAX_ASLR
105327 + bool "Address Space Layout Randomization"
105328 + default y if GRKERNSEC_CONFIG_AUTO
105329 + help
105330 + Many if not most exploit techniques rely on the knowledge of
105331 + certain addresses in the attacked program. The following options
105332 + will allow the kernel to apply a certain amount of randomization
105333 + to specific parts of the program thereby forcing an attacker to
105334 + guess them in most cases. Any failed guess will most likely crash
105335 + the attacked program which allows the kernel to detect such attempts
105336 + and react on them. PaX itself provides no reaction mechanisms,
105337 + instead it is strongly encouraged that you make use of grsecurity's
105338 + (http://www.grsecurity.net/) built-in crash detection features or
105339 + develop one yourself.
105340 +
105341 + By saying Y here you can choose to randomize the following areas:
105342 + - top of the task's kernel stack
105343 + - top of the task's userland stack
105344 + - base address for mmap() requests that do not specify one
105345 + (this includes all libraries)
105346 + - base address of the main executable
105347 +
105348 + It is strongly recommended to say Y here as address space layout
105349 + randomization has negligible impact on performance yet it provides
105350 + a very effective protection.
105351 +
105352 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
105353 + this feature on a per file basis.
105354 +
105355 +config PAX_RANDKSTACK
105356 + bool "Randomize kernel stack base"
105357 + default y if GRKERNSEC_CONFIG_AUTO && !(GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_VIRTUALBOX)
105358 + depends on X86_TSC && X86
105359 + help
105360 + By saying Y here the kernel will randomize every task's kernel
105361 + stack on every system call. This will not only force an attacker
105362 + to guess it but also prevent him from making use of possible
105363 + leaked information about it.
105364 +
105365 + Since the kernel stack is a rather scarce resource, randomization
105366 + may cause unexpected stack overflows, therefore you should very
105367 + carefully test your system. Note that once enabled in the kernel
105368 + configuration, this feature cannot be disabled on a per file basis.
105369 +
105370 +config PAX_RANDUSTACK
105371 + bool
105372 +
105373 +config PAX_RANDMMAP
105374 + bool "Randomize user stack and mmap() bases"
105375 + default y if GRKERNSEC_CONFIG_AUTO
105376 + depends on PAX_ASLR
105377 + select PAX_RANDUSTACK
105378 + help
105379 + By saying Y here the kernel will randomize every task's userland
105380 + stack and use a randomized base address for mmap() requests that
105381 + do not specify one themselves.
105382 +
105383 + The stack randomization is done in two steps where the second
105384 + one may apply a big amount of shift to the top of the stack and
105385 + cause problems for programs that want to use lots of memory (more
105386 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
105387 +
105388 + As a result of mmap randomization all dynamically loaded libraries
105389 + will appear at random addresses and therefore be harder to exploit
105390 + by a technique where an attacker attempts to execute library code
105391 + for his purposes (e.g. spawn a shell from an exploited program that
105392 + is running at an elevated privilege level).
105393 +
105394 + Furthermore, if a program is relinked as a dynamic ELF file, its
105395 + base address will be randomized as well, completing the full
105396 + randomization of the address space layout. Attacking such programs
105397 + becomes a guess game. You can find an example of doing this at
105398 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
105399 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
105400 +
105401 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
105402 + feature on a per file basis.
105403 +
105404 +endmenu
105405 +
105406 +menu "Miscellaneous hardening features"
105407 +
105408 +config PAX_MEMORY_SANITIZE
105409 + bool "Sanitize all freed memory"
105410 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
105411 + help
105412 + By saying Y here the kernel will erase memory pages and slab objects
105413 + as soon as they are freed. This in turn reduces the lifetime of data
105414 + stored in them, making it less likely that sensitive information such
105415 + as passwords, cryptographic secrets, etc stay in memory for too long.
105416 +
105417 + This is especially useful for programs whose runtime is short, long
105418 + lived processes and the kernel itself benefit from this as long as
105419 + they ensure timely freeing of memory that may hold sensitive
105420 + information.
105421 +
105422 + A nice side effect of the sanitization of slab objects is the
105423 + reduction of possible info leaks caused by padding bytes within the
105424 + leaky structures. Use-after-free bugs for structures containing
105425 + pointers can also be detected as dereferencing the sanitized pointer
105426 + will generate an access violation.
105427 +
105428 + The tradeoff is performance impact, on a single CPU system kernel
105429 + compilation sees a 3% slowdown, other systems and workloads may vary
105430 + and you are advised to test this feature on your expected workload
105431 + before deploying it.
105432 +
105433 + To reduce the performance penalty by sanitizing pages only, albeit
105434 + limiting the effectiveness of this feature at the same time, slab
105435 + sanitization can be disabled with the kernel commandline parameter
105436 + "pax_sanitize_slab=0".
105437 +
105438 + Note that this feature does not protect data stored in live pages,
105439 + e.g., process memory swapped to disk may stay there for a long time.
105440 +
105441 +config PAX_MEMORY_STACKLEAK
105442 + bool "Sanitize kernel stack"
105443 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
105444 + depends on X86
105445 + help
105446 + By saying Y here the kernel will erase the kernel stack before it
105447 + returns from a system call. This in turn reduces the information
105448 + that a kernel stack leak bug can reveal.
105449 +
105450 + Note that such a bug can still leak information that was put on
105451 + the stack by the current system call (the one eventually triggering
105452 + the bug) but traces of earlier system calls on the kernel stack
105453 + cannot leak anymore.
105454 +
105455 + The tradeoff is performance impact: on a single CPU system kernel
105456 + compilation sees a 1% slowdown, other systems and workloads may vary
105457 + and you are advised to test this feature on your expected workload
105458 + before deploying it.
105459 +
105460 + Note that the full feature requires a gcc with plugin support,
105461 + i.e., gcc 4.5 or newer. You may need to install the supporting
105462 + headers explicitly in addition to the normal gcc package. Using
105463 + older gcc versions means that functions with large enough stack
105464 + frames may leave uninitialized memory behind that may be exposed
105465 + to a later syscall leaking the stack.
105466 +
105467 +config PAX_MEMORY_STRUCTLEAK
105468 + bool "Forcibly initialize local variables copied to userland"
105469 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
105470 + help
105471 + By saying Y here the kernel will zero initialize some local
105472 + variables that are going to be copied to userland. This in
105473 + turn prevents unintended information leakage from the kernel
105474 + stack should later code forget to explicitly set all parts of
105475 + the copied variable.
105476 +
105477 + The tradeoff is less performance impact than PAX_MEMORY_STACKLEAK
105478 + at a much smaller coverage.
105479 +
105480 + Note that the implementation requires a gcc with plugin support,
105481 + i.e., gcc 4.5 or newer. You may need to install the supporting
105482 + headers explicitly in addition to the normal gcc package.
105483 +
105484 +config PAX_MEMORY_UDEREF
105485 + bool "Prevent invalid userland pointer dereference"
105486 + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (!X86 || GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
105487 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
105488 + select PAX_PER_CPU_PGD if X86_64
105489 + help
105490 + By saying Y here the kernel will be prevented from dereferencing
105491 + userland pointers in contexts where the kernel expects only kernel
105492 + pointers. This is both a useful runtime debugging feature and a
105493 + security measure that prevents exploiting a class of kernel bugs.
105494 +
105495 + The tradeoff is that some virtualization solutions may experience
105496 + a huge slowdown and therefore you should not enable this feature
105497 + for kernels meant to run in such environments. Whether a given VM
105498 + solution is affected or not is best determined by simply trying it
105499 + out, the performance impact will be obvious right on boot as this
105500 + mechanism engages from very early on. A good rule of thumb is that
105501 + VMs running on CPUs without hardware virtualization support (i.e.,
105502 + the majority of IA-32 CPUs) will likely experience the slowdown.
105503 +
105504 + On X86_64 the kernel will make use of PCID support when available
105505 + (Intel's Westmere, Sandy Bridge, etc) for better security (default)
105506 + or performance impact. Pass pax_weakuderef on the kernel command
105507 + line to choose the latter.
105508 +
105509 +config PAX_REFCOUNT
105510 + bool "Prevent various kernel object reference counter overflows"
105511 + default y if GRKERNSEC_CONFIG_AUTO
105512 + depends on GRKERNSEC && ((ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || MIPS || SPARC64 || X86)
105513 + help
105514 + By saying Y here the kernel will detect and prevent overflowing
105515 + various (but not all) kinds of object reference counters. Such
105516 + overflows can normally occur due to bugs only and are often, if
105517 + not always, exploitable.
105518 +
105519 + The tradeoff is that data structures protected by an overflowed
105520 + refcount will never be freed and therefore will leak memory. Note
105521 + that this leak also happens even without this protection but in
105522 + that case the overflow can eventually trigger the freeing of the
105523 + data structure while it is still being used elsewhere, resulting
105524 + in the exploitable situation that this feature prevents.
105525 +
105526 + Since this has a negligible performance impact, you should enable
105527 + this feature.
105528 +
105529 +config PAX_CONSTIFY_PLUGIN
105530 + bool "Automatically constify eligible structures"
105531 + default y
105532 + depends on !UML && PAX_KERNEXEC
105533 + help
105534 + By saying Y here the compiler will automatically constify a class
105535 + of types that contain only function pointers. This reduces the
105536 + kernel's attack surface and also produces a better memory layout.
105537 +
105538 + Note that the implementation requires a gcc with plugin support,
105539 + i.e., gcc 4.5 or newer. You may need to install the supporting
105540 + headers explicitly in addition to the normal gcc package.
105541 +
105542 + Note that if some code really has to modify constified variables
105543 + then the source code will have to be patched to allow it. Examples
105544 + can be found in PaX itself (the no_const attribute) and for some
105545 + out-of-tree modules at http://www.grsecurity.net/~paxguy1/ .
105546 +
105547 +config PAX_USERCOPY
105548 + bool "Harden heap object copies between kernel and userland"
105549 + default y if GRKERNSEC_CONFIG_AUTO
105550 + depends on ARM || IA64 || PPC || SPARC || X86
105551 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
105552 + select PAX_USERCOPY_SLABS
105553 + help
105554 + By saying Y here the kernel will enforce the size of heap objects
105555 + when they are copied in either direction between the kernel and
105556 + userland, even if only a part of the heap object is copied.
105557 +
105558 + Specifically, this checking prevents information leaking from the
105559 + kernel heap during kernel to userland copies (if the kernel heap
105560 + object is otherwise fully initialized) and prevents kernel heap
105561 + overflows during userland to kernel copies.
105562 +
105563 + Note that the current implementation provides the strictest bounds
105564 + checks for the SLUB allocator.
105565 +
105566 + Enabling this option also enables per-slab cache protection against
105567 + data in a given cache being copied into/out of via userland
105568 + accessors. Though the whitelist of regions will be reduced over
105569 + time, it notably protects important data structures like task structs.
105570 +
105571 + If frame pointers are enabled on x86, this option will also restrict
105572 + copies into and out of the kernel stack to local variables within a
105573 + single frame.
105574 +
105575 + Since this has a negligible performance impact, you should enable
105576 + this feature.
105577 +
105578 +config PAX_USERCOPY_DEBUG
105579 + bool
105580 + depends on X86 && PAX_USERCOPY
105581 + default n
105582 +
105583 +config PAX_SIZE_OVERFLOW
105584 + bool "Prevent various integer overflows in function size parameters"
105585 + default y if GRKERNSEC_CONFIG_AUTO
105586 + depends on X86
105587 + help
105588 + By saying Y here the kernel recomputes expressions of function
105589 + arguments marked by a size_overflow attribute with double integer
105590 + precision (DImode/TImode for 32/64 bit integer types).
105591 +
105592 + The recomputed argument is checked against TYPE_MAX and an event
105593 + is logged on overflow and the triggering process is killed.
105594 +
105595 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
105596 +
105597 + Note that the implementation requires a gcc with plugin support,
105598 + i.e., gcc 4.5 or newer. You may need to install the supporting
105599 + headers explicitly in addition to the normal gcc package.
105600 +
105601 +config PAX_LATENT_ENTROPY
105602 + bool "Generate some entropy during boot and runtime"
105603 + default y if GRKERNSEC_CONFIG_AUTO
105604 + help
105605 + By saying Y here the kernel will instrument some kernel code to
105606 + extract some entropy from both original and artificially created
105607 + program state. This will help especially embedded systems where
105608 + there is little 'natural' source of entropy normally. The cost
105609 + is some slowdown of the boot process and fork and irq processing.
105610 +
105611 + When pax_extra_latent_entropy is passed on the kernel command line,
105612 + entropy will be extracted from up to the first 4GB of RAM while the
105613 + runtime memory allocator is being initialized. This costs even more
105614 + slowdown of the boot process.
105615 +
105616 + Note that the implementation requires a gcc with plugin support,
105617 + i.e., gcc 4.5 or newer. You may need to install the supporting
105618 + headers explicitly in addition to the normal gcc package.
105619 +
105620 + Note that entropy extracted this way is not cryptographically
105621 + secure!
105622 +
105623 +endmenu
105624 +
105625 +endmenu
105626 +
105627 +source grsecurity/Kconfig
105628 +
105629 +endmenu
105630 +
105631 +endmenu
105632 +
105633 source security/keys/Kconfig
105634
105635 config SECURITY_DMESG_RESTRICT
105636 @@ -103,7 +1054,7 @@ config INTEL_TXT
105637 config LSM_MMAP_MIN_ADDR
105638 int "Low address space for LSM to protect from user allocation"
105639 depends on SECURITY && SECURITY_SELINUX
105640 - default 32768 if ARM || (ARM64 && COMPAT)
105641 + default 32768 if ALPHA || ARM || (ARM64 && COMPAT) || PARISC || SPARC32
105642 default 65536
105643 help
105644 This is the portion of low virtual memory which should be protected
105645 diff --git a/security/apparmor/file.c b/security/apparmor/file.c
105646 index fdaa50c..2761dcb 100644
105647 --- a/security/apparmor/file.c
105648 +++ b/security/apparmor/file.c
105649 @@ -348,8 +348,8 @@ static inline bool xindex_is_subset(u32 link, u32 target)
105650 int aa_path_link(struct aa_profile *profile, struct dentry *old_dentry,
105651 struct path *new_dir, struct dentry *new_dentry)
105652 {
105653 - struct path link = { new_dir->mnt, new_dentry };
105654 - struct path target = { new_dir->mnt, old_dentry };
105655 + struct path link = { .mnt = new_dir->mnt, .dentry = new_dentry };
105656 + struct path target = { .mnt = new_dir->mnt, .dentry = old_dentry };
105657 struct path_cond cond = {
105658 old_dentry->d_inode->i_uid,
105659 old_dentry->d_inode->i_mode
105660 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
105661 index 9981000..eb21356 100644
105662 --- a/security/apparmor/lsm.c
105663 +++ b/security/apparmor/lsm.c
105664 @@ -186,7 +186,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
105665 struct dentry *dentry, u32 mask,
105666 struct path_cond *cond)
105667 {
105668 - struct path path = { dir->mnt, dentry };
105669 + struct path path = { .mnt = dir->mnt, .dentry = dentry };
105670
105671 return common_perm(op, &path, mask, cond);
105672 }
105673 @@ -203,7 +203,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
105674 static int common_perm_mnt_dentry(int op, struct vfsmount *mnt,
105675 struct dentry *dentry, u32 mask)
105676 {
105677 - struct path path = { mnt, dentry };
105678 + struct path path = { .mnt = mnt, .dentry = dentry };
105679 struct path_cond cond = { dentry->d_inode->i_uid,
105680 dentry->d_inode->i_mode
105681 };
105682 @@ -325,8 +325,8 @@ static int apparmor_path_rename(struct path *old_dir, struct dentry *old_dentry,
105683
105684 profile = aa_current_profile();
105685 if (!unconfined(profile)) {
105686 - struct path old_path = { old_dir->mnt, old_dentry };
105687 - struct path new_path = { new_dir->mnt, new_dentry };
105688 + struct path old_path = { .mnt = old_dir->mnt, .dentry = old_dentry };
105689 + struct path new_path = { .mnt = new_dir->mnt, .dentry = new_dentry };
105690 struct path_cond cond = { old_dentry->d_inode->i_uid,
105691 old_dentry->d_inode->i_mode
105692 };
105693 @@ -615,7 +615,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
105694 return error;
105695 }
105696
105697 -static struct security_operations apparmor_ops = {
105698 +static struct security_operations apparmor_ops __read_only = {
105699 .name = "apparmor",
105700
105701 .ptrace_access_check = apparmor_ptrace_access_check,
105702 diff --git a/security/commoncap.c b/security/commoncap.c
105703 index b9d613e..f68305c 100644
105704 --- a/security/commoncap.c
105705 +++ b/security/commoncap.c
105706 @@ -424,6 +424,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
105707 return 0;
105708 }
105709
105710 +/* returns:
105711 + 1 for suid privilege
105712 + 2 for sgid privilege
105713 + 3 for fscap privilege
105714 +*/
105715 +int is_privileged_binary(const struct dentry *dentry)
105716 +{
105717 + struct cpu_vfs_cap_data capdata;
105718 + struct inode *inode = dentry->d_inode;
105719 +
105720 + if (!inode || S_ISDIR(inode->i_mode))
105721 + return 0;
105722 +
105723 + if (inode->i_mode & S_ISUID)
105724 + return 1;
105725 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
105726 + return 2;
105727 +
105728 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
105729 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
105730 + return 3;
105731 + }
105732 +
105733 + return 0;
105734 +}
105735 +
105736 /*
105737 * Attempt to get the on-exec apply capability sets for an executable file from
105738 * its xattrs and, if present, apply them to the proposed credentials being
105739 @@ -592,6 +618,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
105740 const struct cred *cred = current_cred();
105741 kuid_t root_uid = make_kuid(cred->user_ns, 0);
105742
105743 + if (gr_acl_enable_at_secure())
105744 + return 1;
105745 +
105746 if (!uid_eq(cred->uid, root_uid)) {
105747 if (bprm->cap_effective)
105748 return 1;
105749 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
105750 index f79fa8b..6161868 100644
105751 --- a/security/integrity/ima/ima.h
105752 +++ b/security/integrity/ima/ima.h
105753 @@ -118,8 +118,8 @@ int ima_init_template(void);
105754 extern spinlock_t ima_queue_lock;
105755
105756 struct ima_h_table {
105757 - atomic_long_t len; /* number of stored measurements in the list */
105758 - atomic_long_t violations;
105759 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
105760 + atomic_long_unchecked_t violations;
105761 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
105762 };
105763 extern struct ima_h_table ima_htable;
105764 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
105765 index d9cd5ce..c5c29ac 100644
105766 --- a/security/integrity/ima/ima_api.c
105767 +++ b/security/integrity/ima/ima_api.c
105768 @@ -137,7 +137,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename,
105769 int result;
105770
105771 /* can overflow, only indicator */
105772 - atomic_long_inc(&ima_htable.violations);
105773 + atomic_long_inc_unchecked(&ima_htable.violations);
105774
105775 result = ima_alloc_init_template(NULL, file, filename,
105776 NULL, 0, &entry);
105777 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
105778 index da92fcc..8a5d390 100644
105779 --- a/security/integrity/ima/ima_fs.c
105780 +++ b/security/integrity/ima/ima_fs.c
105781 @@ -28,12 +28,12 @@
105782 static int valid_policy = 1;
105783 #define TMPBUFLEN 12
105784 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
105785 - loff_t *ppos, atomic_long_t *val)
105786 + loff_t *ppos, atomic_long_unchecked_t *val)
105787 {
105788 char tmpbuf[TMPBUFLEN];
105789 ssize_t len;
105790
105791 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
105792 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
105793 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
105794 }
105795
105796 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
105797 index 552705d..9920f4fb 100644
105798 --- a/security/integrity/ima/ima_queue.c
105799 +++ b/security/integrity/ima/ima_queue.c
105800 @@ -83,7 +83,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
105801 INIT_LIST_HEAD(&qe->later);
105802 list_add_tail_rcu(&qe->later, &ima_measurements);
105803
105804 - atomic_long_inc(&ima_htable.len);
105805 + atomic_long_inc_unchecked(&ima_htable.len);
105806 key = ima_hash_key(entry->digest);
105807 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
105808 return 0;
105809 diff --git a/security/keys/compat.c b/security/keys/compat.c
105810 index 3478965..ec7bb9e 100644
105811 --- a/security/keys/compat.c
105812 +++ b/security/keys/compat.c
105813 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
105814 if (ret == 0)
105815 goto no_payload_free;
105816
105817 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
105818 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
105819 err:
105820 if (iov != iovstack)
105821 kfree(iov);
105822 diff --git a/security/keys/internal.h b/security/keys/internal.h
105823 index 80b2aac..bb7ee65 100644
105824 --- a/security/keys/internal.h
105825 +++ b/security/keys/internal.h
105826 @@ -253,7 +253,7 @@ extern long keyctl_instantiate_key_iov(key_serial_t,
105827 extern long keyctl_invalidate_key(key_serial_t);
105828
105829 extern long keyctl_instantiate_key_common(key_serial_t,
105830 - const struct iovec *,
105831 + const struct iovec __user *,
105832 unsigned, size_t, key_serial_t);
105833 #ifdef CONFIG_PERSISTENT_KEYRINGS
105834 extern long keyctl_get_persistent(uid_t, key_serial_t);
105835 diff --git a/security/keys/key.c b/security/keys/key.c
105836 index 6e21c11..9ed67ca 100644
105837 --- a/security/keys/key.c
105838 +++ b/security/keys/key.c
105839 @@ -285,7 +285,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
105840
105841 atomic_set(&key->usage, 1);
105842 init_rwsem(&key->sem);
105843 - lockdep_set_class(&key->sem, &type->lock_class);
105844 + lockdep_set_class(&key->sem, (struct lock_class_key *)&type->lock_class);
105845 key->index_key.type = type;
105846 key->user = user;
105847 key->quotalen = quotalen;
105848 @@ -1036,7 +1036,9 @@ int register_key_type(struct key_type *ktype)
105849 struct key_type *p;
105850 int ret;
105851
105852 - memset(&ktype->lock_class, 0, sizeof(ktype->lock_class));
105853 + pax_open_kernel();
105854 + memset((void *)&ktype->lock_class, 0, sizeof(ktype->lock_class));
105855 + pax_close_kernel();
105856
105857 ret = -EEXIST;
105858 down_write(&key_types_sem);
105859 @@ -1048,7 +1050,7 @@ int register_key_type(struct key_type *ktype)
105860 }
105861
105862 /* store the type */
105863 - list_add(&ktype->link, &key_types_list);
105864 + pax_list_add((struct list_head *)&ktype->link, &key_types_list);
105865
105866 pr_notice("Key type %s registered\n", ktype->name);
105867 ret = 0;
105868 @@ -1070,7 +1072,7 @@ EXPORT_SYMBOL(register_key_type);
105869 void unregister_key_type(struct key_type *ktype)
105870 {
105871 down_write(&key_types_sem);
105872 - list_del_init(&ktype->link);
105873 + pax_list_del_init((struct list_head *)&ktype->link);
105874 downgrade_write(&key_types_sem);
105875 key_gc_keytype(ktype);
105876 pr_notice("Key type %s unregistered\n", ktype->name);
105877 @@ -1088,10 +1090,10 @@ void __init key_init(void)
105878 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
105879
105880 /* add the special key types */
105881 - list_add_tail(&key_type_keyring.link, &key_types_list);
105882 - list_add_tail(&key_type_dead.link, &key_types_list);
105883 - list_add_tail(&key_type_user.link, &key_types_list);
105884 - list_add_tail(&key_type_logon.link, &key_types_list);
105885 + pax_list_add_tail((struct list_head *)&key_type_keyring.link, &key_types_list);
105886 + pax_list_add_tail((struct list_head *)&key_type_dead.link, &key_types_list);
105887 + pax_list_add_tail((struct list_head *)&key_type_user.link, &key_types_list);
105888 + pax_list_add_tail((struct list_head *)&key_type_logon.link, &key_types_list);
105889
105890 /* record the root user tracking */
105891 rb_link_node(&root_key_user.node,
105892 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
105893 index cee72ce..e46074a 100644
105894 --- a/security/keys/keyctl.c
105895 +++ b/security/keys/keyctl.c
105896 @@ -987,7 +987,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
105897 /*
105898 * Copy the iovec data from userspace
105899 */
105900 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
105901 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
105902 unsigned ioc)
105903 {
105904 for (; ioc > 0; ioc--) {
105905 @@ -1009,7 +1009,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
105906 * If successful, 0 will be returned.
105907 */
105908 long keyctl_instantiate_key_common(key_serial_t id,
105909 - const struct iovec *payload_iov,
105910 + const struct iovec __user *payload_iov,
105911 unsigned ioc,
105912 size_t plen,
105913 key_serial_t ringid)
105914 @@ -1104,7 +1104,7 @@ long keyctl_instantiate_key(key_serial_t id,
105915 [0].iov_len = plen
105916 };
105917
105918 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
105919 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
105920 }
105921
105922 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
105923 @@ -1137,7 +1137,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
105924 if (ret == 0)
105925 goto no_payload_free;
105926
105927 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
105928 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
105929 err:
105930 if (iov != iovstack)
105931 kfree(iov);
105932 diff --git a/security/min_addr.c b/security/min_addr.c
105933 index f728728..6457a0c 100644
105934 --- a/security/min_addr.c
105935 +++ b/security/min_addr.c
105936 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
105937 */
105938 static void update_mmap_min_addr(void)
105939 {
105940 +#ifndef SPARC
105941 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
105942 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
105943 mmap_min_addr = dac_mmap_min_addr;
105944 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
105945 #else
105946 mmap_min_addr = dac_mmap_min_addr;
105947 #endif
105948 +#endif
105949 }
105950
105951 /*
105952 diff --git a/security/security.c b/security/security.c
105953 index 8b774f3..a396233 100644
105954 --- a/security/security.c
105955 +++ b/security/security.c
105956 @@ -33,8 +33,8 @@
105957 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
105958 CONFIG_DEFAULT_SECURITY;
105959
105960 -static struct security_operations *security_ops;
105961 -static struct security_operations default_security_ops = {
105962 +struct security_operations *security_ops __read_only;
105963 +struct security_operations default_security_ops __read_only = {
105964 .name = "default",
105965 };
105966
105967 @@ -73,11 +73,6 @@ int __init security_init(void)
105968 return 0;
105969 }
105970
105971 -void reset_security_ops(void)
105972 -{
105973 - security_ops = &default_security_ops;
105974 -}
105975 -
105976 /* Save user chosen LSM */
105977 static int __init choose_lsm(char *str)
105978 {
105979 diff --git a/security/selinux/avc.c b/security/selinux/avc.c
105980 index fc3e662..7844c60 100644
105981 --- a/security/selinux/avc.c
105982 +++ b/security/selinux/avc.c
105983 @@ -59,7 +59,7 @@ struct avc_node {
105984 struct avc_cache {
105985 struct hlist_head slots[AVC_CACHE_SLOTS]; /* head for avc_node->list */
105986 spinlock_t slots_lock[AVC_CACHE_SLOTS]; /* lock for writes */
105987 - atomic_t lru_hint; /* LRU hint for reclaim scan */
105988 + atomic_unchecked_t lru_hint; /* LRU hint for reclaim scan */
105989 atomic_t active_nodes;
105990 u32 latest_notif; /* latest revocation notification */
105991 };
105992 @@ -167,7 +167,7 @@ void __init avc_init(void)
105993 spin_lock_init(&avc_cache.slots_lock[i]);
105994 }
105995 atomic_set(&avc_cache.active_nodes, 0);
105996 - atomic_set(&avc_cache.lru_hint, 0);
105997 + atomic_set_unchecked(&avc_cache.lru_hint, 0);
105998
105999 avc_node_cachep = kmem_cache_create("avc_node", sizeof(struct avc_node),
106000 0, SLAB_PANIC, NULL);
106001 @@ -242,7 +242,7 @@ static inline int avc_reclaim_node(void)
106002 spinlock_t *lock;
106003
106004 for (try = 0, ecx = 0; try < AVC_CACHE_SLOTS; try++) {
106005 - hvalue = atomic_inc_return(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
106006 + hvalue = atomic_inc_return_unchecked(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
106007 head = &avc_cache.slots[hvalue];
106008 lock = &avc_cache.slots_lock[hvalue];
106009
106010 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
106011 index 2c7341d..1da068e 100644
106012 --- a/security/selinux/hooks.c
106013 +++ b/security/selinux/hooks.c
106014 @@ -95,8 +95,6 @@
106015 #include "audit.h"
106016 #include "avc_ss.h"
106017
106018 -extern struct security_operations *security_ops;
106019 -
106020 /* SECMARK reference count */
106021 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
106022
106023 @@ -5758,7 +5756,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
106024
106025 #endif
106026
106027 -static struct security_operations selinux_ops = {
106028 +static struct security_operations selinux_ops __read_only = {
106029 .name = "selinux",
106030
106031 .ptrace_access_check = selinux_ptrace_access_check,
106032 @@ -6111,6 +6109,9 @@ static void selinux_nf_ip_exit(void)
106033 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
106034 static int selinux_disabled;
106035
106036 +extern struct security_operations *security_ops;
106037 +extern struct security_operations default_security_ops;
106038 +
106039 int selinux_disable(void)
106040 {
106041 if (ss_initialized) {
106042 @@ -6128,7 +6129,9 @@ int selinux_disable(void)
106043 selinux_disabled = 1;
106044 selinux_enabled = 0;
106045
106046 - reset_security_ops();
106047 + pax_open_kernel();
106048 + security_ops = &default_security_ops;
106049 + pax_close_kernel();
106050
106051 /* Try to destroy the avc node cache */
106052 avc_disable();
106053 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
106054 index 1450f85..a91e0bc 100644
106055 --- a/security/selinux/include/xfrm.h
106056 +++ b/security/selinux/include/xfrm.h
106057 @@ -48,7 +48,7 @@ static inline void selinux_xfrm_notify_policyload(void)
106058
106059 rtnl_lock();
106060 for_each_net(net) {
106061 - atomic_inc(&net->xfrm.flow_cache_genid);
106062 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
106063 rt_genid_bump_all(net);
106064 }
106065 rtnl_unlock();
106066 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
106067 index 14f52be..7352368 100644
106068 --- a/security/smack/smack_lsm.c
106069 +++ b/security/smack/smack_lsm.c
106070 @@ -3726,7 +3726,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
106071 return 0;
106072 }
106073
106074 -struct security_operations smack_ops = {
106075 +struct security_operations smack_ops __read_only = {
106076 .name = "smack",
106077
106078 .ptrace_access_check = smack_ptrace_access_check,
106079 diff --git a/security/tomoyo/file.c b/security/tomoyo/file.c
106080 index 4003907..13a2b55 100644
106081 --- a/security/tomoyo/file.c
106082 +++ b/security/tomoyo/file.c
106083 @@ -692,7 +692,7 @@ int tomoyo_path_number_perm(const u8 type, struct path *path,
106084 {
106085 struct tomoyo_request_info r;
106086 struct tomoyo_obj_info obj = {
106087 - .path1 = *path,
106088 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
106089 };
106090 int error = -ENOMEM;
106091 struct tomoyo_path_info buf;
106092 @@ -740,7 +740,7 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
106093 struct tomoyo_path_info buf;
106094 struct tomoyo_request_info r;
106095 struct tomoyo_obj_info obj = {
106096 - .path1 = *path,
106097 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
106098 };
106099 int idx;
106100
106101 @@ -786,7 +786,7 @@ int tomoyo_path_perm(const u8 operation, struct path *path, const char *target)
106102 {
106103 struct tomoyo_request_info r;
106104 struct tomoyo_obj_info obj = {
106105 - .path1 = *path,
106106 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
106107 };
106108 int error;
106109 struct tomoyo_path_info buf;
106110 @@ -843,7 +843,7 @@ int tomoyo_mkdev_perm(const u8 operation, struct path *path,
106111 {
106112 struct tomoyo_request_info r;
106113 struct tomoyo_obj_info obj = {
106114 - .path1 = *path,
106115 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
106116 };
106117 int error = -ENOMEM;
106118 struct tomoyo_path_info buf;
106119 @@ -890,8 +890,8 @@ int tomoyo_path2_perm(const u8 operation, struct path *path1,
106120 struct tomoyo_path_info buf2;
106121 struct tomoyo_request_info r;
106122 struct tomoyo_obj_info obj = {
106123 - .path1 = *path1,
106124 - .path2 = *path2,
106125 + .path1 = { .mnt = path1->mnt, .dentry = path1->dentry },
106126 + .path2 = { .mnt = path2->mnt, .dentry = path2->dentry }
106127 };
106128 int idx;
106129
106130 diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c
106131 index 390c646..f2f8db3 100644
106132 --- a/security/tomoyo/mount.c
106133 +++ b/security/tomoyo/mount.c
106134 @@ -118,6 +118,10 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r,
106135 type == tomoyo_mounts[TOMOYO_MOUNT_MOVE]) {
106136 need_dev = -1; /* dev_name is a directory */
106137 } else {
106138 + if (!capable(CAP_SYS_ADMIN)) {
106139 + error = -EPERM;
106140 + goto out;
106141 + }
106142 fstype = get_fs_type(type);
106143 if (!fstype) {
106144 error = -ENODEV;
106145 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
106146 index f0b756e..8aa497b 100644
106147 --- a/security/tomoyo/tomoyo.c
106148 +++ b/security/tomoyo/tomoyo.c
106149 @@ -146,7 +146,7 @@ static int tomoyo_bprm_check_security(struct linux_binprm *bprm)
106150 */
106151 static int tomoyo_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
106152 {
106153 - struct path path = { mnt, dentry };
106154 + struct path path = { .mnt = mnt, .dentry = dentry };
106155 return tomoyo_path_perm(TOMOYO_TYPE_GETATTR, &path, NULL);
106156 }
106157
106158 @@ -172,7 +172,7 @@ static int tomoyo_path_truncate(struct path *path)
106159 */
106160 static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
106161 {
106162 - struct path path = { parent->mnt, dentry };
106163 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
106164 return tomoyo_path_perm(TOMOYO_TYPE_UNLINK, &path, NULL);
106165 }
106166
106167 @@ -188,7 +188,7 @@ static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
106168 static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
106169 umode_t mode)
106170 {
106171 - struct path path = { parent->mnt, dentry };
106172 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
106173 return tomoyo_path_number_perm(TOMOYO_TYPE_MKDIR, &path,
106174 mode & S_IALLUGO);
106175 }
106176 @@ -203,7 +203,7 @@ static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
106177 */
106178 static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
106179 {
106180 - struct path path = { parent->mnt, dentry };
106181 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
106182 return tomoyo_path_perm(TOMOYO_TYPE_RMDIR, &path, NULL);
106183 }
106184
106185 @@ -219,7 +219,7 @@ static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
106186 static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
106187 const char *old_name)
106188 {
106189 - struct path path = { parent->mnt, dentry };
106190 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
106191 return tomoyo_path_perm(TOMOYO_TYPE_SYMLINK, &path, old_name);
106192 }
106193
106194 @@ -236,7 +236,7 @@ static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
106195 static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
106196 umode_t mode, unsigned int dev)
106197 {
106198 - struct path path = { parent->mnt, dentry };
106199 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
106200 int type = TOMOYO_TYPE_CREATE;
106201 const unsigned int perm = mode & S_IALLUGO;
106202
106203 @@ -275,8 +275,8 @@ static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
106204 static int tomoyo_path_link(struct dentry *old_dentry, struct path *new_dir,
106205 struct dentry *new_dentry)
106206 {
106207 - struct path path1 = { new_dir->mnt, old_dentry };
106208 - struct path path2 = { new_dir->mnt, new_dentry };
106209 + struct path path1 = { .mnt = new_dir->mnt, .dentry = old_dentry };
106210 + struct path path2 = { .mnt = new_dir->mnt, .dentry = new_dentry };
106211 return tomoyo_path2_perm(TOMOYO_TYPE_LINK, &path1, &path2);
106212 }
106213
106214 @@ -295,8 +295,8 @@ static int tomoyo_path_rename(struct path *old_parent,
106215 struct path *new_parent,
106216 struct dentry *new_dentry)
106217 {
106218 - struct path path1 = { old_parent->mnt, old_dentry };
106219 - struct path path2 = { new_parent->mnt, new_dentry };
106220 + struct path path1 = { .mnt = old_parent->mnt, .dentry = old_dentry };
106221 + struct path path2 = { .mnt = new_parent->mnt, .dentry = new_dentry };
106222 return tomoyo_path2_perm(TOMOYO_TYPE_RENAME, &path1, &path2);
106223 }
106224
106225 @@ -424,7 +424,7 @@ static int tomoyo_sb_mount(const char *dev_name, struct path *path,
106226 */
106227 static int tomoyo_sb_umount(struct vfsmount *mnt, int flags)
106228 {
106229 - struct path path = { mnt, mnt->mnt_root };
106230 + struct path path = { .mnt = mnt, .dentry = mnt->mnt_root };
106231 return tomoyo_path_perm(TOMOYO_TYPE_UMOUNT, &path, NULL);
106232 }
106233
106234 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
106235 * tomoyo_security_ops is a "struct security_operations" which is used for
106236 * registering TOMOYO.
106237 */
106238 -static struct security_operations tomoyo_security_ops = {
106239 +static struct security_operations tomoyo_security_ops __read_only = {
106240 .name = "tomoyo",
106241 .cred_alloc_blank = tomoyo_cred_alloc_blank,
106242 .cred_prepare = tomoyo_cred_prepare,
106243 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
106244 index 20ef514..4182bed 100644
106245 --- a/security/yama/Kconfig
106246 +++ b/security/yama/Kconfig
106247 @@ -1,6 +1,6 @@
106248 config SECURITY_YAMA
106249 bool "Yama support"
106250 - depends on SECURITY
106251 + depends on SECURITY && !GRKERNSEC
106252 select SECURITYFS
106253 select SECURITY_PATH
106254 default n
106255 diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
106256 index 13c88fbc..f8c115e 100644
106257 --- a/security/yama/yama_lsm.c
106258 +++ b/security/yama/yama_lsm.c
106259 @@ -365,7 +365,7 @@ int yama_ptrace_traceme(struct task_struct *parent)
106260 }
106261
106262 #ifndef CONFIG_SECURITY_YAMA_STACKED
106263 -static struct security_operations yama_ops = {
106264 +static struct security_operations yama_ops __read_only = {
106265 .name = "yama",
106266
106267 .ptrace_access_check = yama_ptrace_access_check,
106268 @@ -376,28 +376,24 @@ static struct security_operations yama_ops = {
106269 #endif
106270
106271 #ifdef CONFIG_SYSCTL
106272 +static int zero __read_only;
106273 +static int max_scope __read_only = YAMA_SCOPE_NO_ATTACH;
106274 +
106275 static int yama_dointvec_minmax(struct ctl_table *table, int write,
106276 void __user *buffer, size_t *lenp, loff_t *ppos)
106277 {
106278 - int rc;
106279 + ctl_table_no_const yama_table;
106280
106281 if (write && !capable(CAP_SYS_PTRACE))
106282 return -EPERM;
106283
106284 - rc = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
106285 - if (rc)
106286 - return rc;
106287 -
106288 + yama_table = *table;
106289 /* Lock the max value if it ever gets set. */
106290 - if (write && *(int *)table->data == *(int *)table->extra2)
106291 - table->extra1 = table->extra2;
106292 -
106293 - return rc;
106294 + if (ptrace_scope == max_scope)
106295 + yama_table.extra1 = &max_scope;
106296 + return proc_dointvec_minmax(&yama_table, write, buffer, lenp, ppos);
106297 }
106298
106299 -static int zero;
106300 -static int max_scope = YAMA_SCOPE_NO_ATTACH;
106301 -
106302 struct ctl_path yama_sysctl_path[] = {
106303 { .procname = "kernel", },
106304 { .procname = "yama", },
106305 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
106306 index f01bffb..bdda392 100644
106307 --- a/sound/aoa/codecs/onyx.c
106308 +++ b/sound/aoa/codecs/onyx.c
106309 @@ -54,7 +54,7 @@ struct onyx {
106310 spdif_locked:1,
106311 analog_locked:1,
106312 original_mute:2;
106313 - int open_count;
106314 + local_t open_count;
106315 struct codec_info *codec_info;
106316
106317 /* mutex serializes concurrent access to the device
106318 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
106319 struct onyx *onyx = cii->codec_data;
106320
106321 mutex_lock(&onyx->mutex);
106322 - onyx->open_count++;
106323 + local_inc(&onyx->open_count);
106324 mutex_unlock(&onyx->mutex);
106325
106326 return 0;
106327 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
106328 struct onyx *onyx = cii->codec_data;
106329
106330 mutex_lock(&onyx->mutex);
106331 - onyx->open_count--;
106332 - if (!onyx->open_count)
106333 + if (local_dec_and_test(&onyx->open_count))
106334 onyx->spdif_locked = onyx->analog_locked = 0;
106335 mutex_unlock(&onyx->mutex);
106336
106337 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
106338 index ffd2025..df062c9 100644
106339 --- a/sound/aoa/codecs/onyx.h
106340 +++ b/sound/aoa/codecs/onyx.h
106341 @@ -11,6 +11,7 @@
106342 #include <linux/i2c.h>
106343 #include <asm/pmac_low_i2c.h>
106344 #include <asm/prom.h>
106345 +#include <asm/local.h>
106346
106347 /* PCM3052 register definitions */
106348
106349 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
106350 index ada69d7..5f65386 100644
106351 --- a/sound/core/oss/pcm_oss.c
106352 +++ b/sound/core/oss/pcm_oss.c
106353 @@ -1190,10 +1190,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
106354 if (in_kernel) {
106355 mm_segment_t fs;
106356 fs = snd_enter_user();
106357 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
106358 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
106359 snd_leave_user(fs);
106360 } else {
106361 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
106362 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
106363 }
106364 if (ret != -EPIPE && ret != -ESTRPIPE)
106365 break;
106366 @@ -1233,10 +1233,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
106367 if (in_kernel) {
106368 mm_segment_t fs;
106369 fs = snd_enter_user();
106370 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
106371 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
106372 snd_leave_user(fs);
106373 } else {
106374 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
106375 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
106376 }
106377 if (ret == -EPIPE) {
106378 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
106379 @@ -1332,7 +1332,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
106380 struct snd_pcm_plugin_channel *channels;
106381 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
106382 if (!in_kernel) {
106383 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
106384 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
106385 return -EFAULT;
106386 buf = runtime->oss.buffer;
106387 }
106388 @@ -1402,7 +1402,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
106389 }
106390 } else {
106391 tmp = snd_pcm_oss_write2(substream,
106392 - (const char __force *)buf,
106393 + (const char __force_kernel *)buf,
106394 runtime->oss.period_bytes, 0);
106395 if (tmp <= 0)
106396 goto err;
106397 @@ -1428,7 +1428,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
106398 struct snd_pcm_runtime *runtime = substream->runtime;
106399 snd_pcm_sframes_t frames, frames1;
106400 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
106401 - char __user *final_dst = (char __force __user *)buf;
106402 + char __user *final_dst = (char __force_user *)buf;
106403 if (runtime->oss.plugin_first) {
106404 struct snd_pcm_plugin_channel *channels;
106405 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
106406 @@ -1490,7 +1490,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
106407 xfer += tmp;
106408 runtime->oss.buffer_used -= tmp;
106409 } else {
106410 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
106411 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
106412 runtime->oss.period_bytes, 0);
106413 if (tmp <= 0)
106414 goto err;
106415 @@ -1659,7 +1659,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
106416 size1);
106417 size1 /= runtime->channels; /* frames */
106418 fs = snd_enter_user();
106419 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
106420 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
106421 snd_leave_user(fs);
106422 }
106423 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
106424 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
106425 index af49721..e85058e 100644
106426 --- a/sound/core/pcm_compat.c
106427 +++ b/sound/core/pcm_compat.c
106428 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
106429 int err;
106430
106431 fs = snd_enter_user();
106432 - err = snd_pcm_delay(substream, &delay);
106433 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
106434 snd_leave_user(fs);
106435 if (err < 0)
106436 return err;
106437 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
106438 index b653ab0..a4738e3 100644
106439 --- a/sound/core/pcm_native.c
106440 +++ b/sound/core/pcm_native.c
106441 @@ -2812,11 +2812,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
106442 switch (substream->stream) {
106443 case SNDRV_PCM_STREAM_PLAYBACK:
106444 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
106445 - (void __user *)arg);
106446 + (void __force_user *)arg);
106447 break;
106448 case SNDRV_PCM_STREAM_CAPTURE:
106449 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
106450 - (void __user *)arg);
106451 + (void __force_user *)arg);
106452 break;
106453 default:
106454 result = -EINVAL;
106455 diff --git a/sound/core/seq/oss/seq_oss.c b/sound/core/seq/oss/seq_oss.c
106456 index 16d4267..fe8b49b 100644
106457 --- a/sound/core/seq/oss/seq_oss.c
106458 +++ b/sound/core/seq/oss/seq_oss.c
106459 @@ -69,8 +69,8 @@ static int __init alsa_seq_oss_init(void)
106460 {
106461 int rc;
106462 static struct snd_seq_dev_ops ops = {
106463 - snd_seq_oss_synth_register,
106464 - snd_seq_oss_synth_unregister,
106465 + .init_device = snd_seq_oss_synth_register,
106466 + .free_device = snd_seq_oss_synth_unregister,
106467 };
106468
106469 snd_seq_autoload_lock();
106470 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
106471 index 91a786a..4c07ed4 100644
106472 --- a/sound/core/seq/seq_device.c
106473 +++ b/sound/core/seq/seq_device.c
106474 @@ -64,7 +64,7 @@ struct ops_list {
106475 int argsize; /* argument size */
106476
106477 /* operators */
106478 - struct snd_seq_dev_ops ops;
106479 + struct snd_seq_dev_ops *ops;
106480
106481 /* registered devices */
106482 struct list_head dev_list; /* list of devices */
106483 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
106484
106485 mutex_lock(&ops->reg_mutex);
106486 /* copy driver operators */
106487 - ops->ops = *entry;
106488 + ops->ops = entry;
106489 ops->driver |= DRIVER_LOADED;
106490 ops->argsize = argsize;
106491
106492 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
106493 dev->name, ops->id, ops->argsize, dev->argsize);
106494 return -EINVAL;
106495 }
106496 - if (ops->ops.init_device(dev) >= 0) {
106497 + if (ops->ops->init_device(dev) >= 0) {
106498 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
106499 ops->num_init_devices++;
106500 } else {
106501 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
106502 dev->name, ops->id, ops->argsize, dev->argsize);
106503 return -EINVAL;
106504 }
106505 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
106506 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
106507 dev->status = SNDRV_SEQ_DEVICE_FREE;
106508 dev->driver_data = NULL;
106509 ops->num_init_devices--;
106510 diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c
106511 index 3e05c55..0f02efc 100644
106512 --- a/sound/core/seq/seq_midi.c
106513 +++ b/sound/core/seq/seq_midi.c
106514 @@ -462,8 +462,8 @@ snd_seq_midisynth_unregister_port(struct snd_seq_device *dev)
106515 static int __init alsa_seq_midi_init(void)
106516 {
106517 static struct snd_seq_dev_ops ops = {
106518 - snd_seq_midisynth_register_port,
106519 - snd_seq_midisynth_unregister_port,
106520 + .init_device = snd_seq_midisynth_register_port,
106521 + .free_device = snd_seq_midisynth_unregister_port,
106522 };
106523 memset(&synths, 0, sizeof(synths));
106524 snd_seq_autoload_lock();
106525 diff --git a/sound/core/sound.c b/sound/core/sound.c
106526 index 38ad1a0..5010a40 100644
106527 --- a/sound/core/sound.c
106528 +++ b/sound/core/sound.c
106529 @@ -86,7 +86,7 @@ static void snd_request_other(int minor)
106530 case SNDRV_MINOR_TIMER: str = "snd-timer"; break;
106531 default: return;
106532 }
106533 - request_module(str);
106534 + request_module("%s", str);
106535 }
106536
106537 #endif /* modular kernel */
106538 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
106539 index f5fd448..6ae276da 100644
106540 --- a/sound/drivers/mts64.c
106541 +++ b/sound/drivers/mts64.c
106542 @@ -29,6 +29,7 @@
106543 #include <sound/initval.h>
106544 #include <sound/rawmidi.h>
106545 #include <sound/control.h>
106546 +#include <asm/local.h>
106547
106548 #define CARD_NAME "Miditerminal 4140"
106549 #define DRIVER_NAME "MTS64"
106550 @@ -67,7 +68,7 @@ struct mts64 {
106551 struct pardevice *pardev;
106552 int pardev_claimed;
106553
106554 - int open_count;
106555 + local_t open_count;
106556 int current_midi_output_port;
106557 int current_midi_input_port;
106558 u8 mode[MTS64_NUM_INPUT_PORTS];
106559 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
106560 {
106561 struct mts64 *mts = substream->rmidi->private_data;
106562
106563 - if (mts->open_count == 0) {
106564 + if (local_read(&mts->open_count) == 0) {
106565 /* We don't need a spinlock here, because this is just called
106566 if the device has not been opened before.
106567 So there aren't any IRQs from the device */
106568 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
106569
106570 msleep(50);
106571 }
106572 - ++(mts->open_count);
106573 + local_inc(&mts->open_count);
106574
106575 return 0;
106576 }
106577 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
106578 struct mts64 *mts = substream->rmidi->private_data;
106579 unsigned long flags;
106580
106581 - --(mts->open_count);
106582 - if (mts->open_count == 0) {
106583 + if (local_dec_return(&mts->open_count) == 0) {
106584 /* We need the spinlock_irqsave here because we can still
106585 have IRQs at this point */
106586 spin_lock_irqsave(&mts->lock, flags);
106587 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
106588
106589 msleep(500);
106590
106591 - } else if (mts->open_count < 0)
106592 - mts->open_count = 0;
106593 + } else if (local_read(&mts->open_count) < 0)
106594 + local_set(&mts->open_count, 0);
106595
106596 return 0;
106597 }
106598 diff --git a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c
106599 index 6839953..7a0f4b9 100644
106600 --- a/sound/drivers/opl3/opl3_seq.c
106601 +++ b/sound/drivers/opl3/opl3_seq.c
106602 @@ -281,8 +281,8 @@ static int __init alsa_opl3_seq_init(void)
106603 {
106604 static struct snd_seq_dev_ops ops =
106605 {
106606 - snd_opl3_seq_new_device,
106607 - snd_opl3_seq_delete_device
106608 + .init_device = snd_opl3_seq_new_device,
106609 + .free_device = snd_opl3_seq_delete_device
106610 };
106611
106612 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL3, &ops,
106613 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
106614 index b953fb4..1999c01 100644
106615 --- a/sound/drivers/opl4/opl4_lib.c
106616 +++ b/sound/drivers/opl4/opl4_lib.c
106617 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
106618 MODULE_DESCRIPTION("OPL4 driver");
106619 MODULE_LICENSE("GPL");
106620
106621 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
106622 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
106623 {
106624 int timeout = 10;
106625 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
106626 diff --git a/sound/drivers/opl4/opl4_seq.c b/sound/drivers/opl4/opl4_seq.c
106627 index 9919769..d7de36c 100644
106628 --- a/sound/drivers/opl4/opl4_seq.c
106629 +++ b/sound/drivers/opl4/opl4_seq.c
106630 @@ -198,8 +198,8 @@ static int snd_opl4_seq_delete_device(struct snd_seq_device *dev)
106631 static int __init alsa_opl4_synth_init(void)
106632 {
106633 static struct snd_seq_dev_ops ops = {
106634 - snd_opl4_seq_new_device,
106635 - snd_opl4_seq_delete_device
106636 + .init_device = snd_opl4_seq_new_device,
106637 + .free_device = snd_opl4_seq_delete_device
106638 };
106639
106640 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL4, &ops,
106641 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
106642 index 78ccfa4..7a0857b 100644
106643 --- a/sound/drivers/portman2x4.c
106644 +++ b/sound/drivers/portman2x4.c
106645 @@ -48,6 +48,7 @@
106646 #include <sound/initval.h>
106647 #include <sound/rawmidi.h>
106648 #include <sound/control.h>
106649 +#include <asm/local.h>
106650
106651 #define CARD_NAME "Portman 2x4"
106652 #define DRIVER_NAME "portman"
106653 @@ -85,7 +86,7 @@ struct portman {
106654 struct pardevice *pardev;
106655 int pardev_claimed;
106656
106657 - int open_count;
106658 + local_t open_count;
106659 int mode[PORTMAN_NUM_INPUT_PORTS];
106660 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
106661 };
106662 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
106663 index 9048777..2d8b1fc 100644
106664 --- a/sound/firewire/amdtp.c
106665 +++ b/sound/firewire/amdtp.c
106666 @@ -488,7 +488,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
106667 ptr = s->pcm_buffer_pointer + data_blocks;
106668 if (ptr >= pcm->runtime->buffer_size)
106669 ptr -= pcm->runtime->buffer_size;
106670 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
106671 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
106672
106673 s->pcm_period_pointer += data_blocks;
106674 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
106675 @@ -655,7 +655,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
106676 */
106677 void amdtp_out_stream_update(struct amdtp_out_stream *s)
106678 {
106679 - ACCESS_ONCE(s->source_node_id_field) =
106680 + ACCESS_ONCE_RW(s->source_node_id_field) =
106681 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
106682 }
106683 EXPORT_SYMBOL(amdtp_out_stream_update);
106684 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
106685 index 2746ecd..c35dedd 100644
106686 --- a/sound/firewire/amdtp.h
106687 +++ b/sound/firewire/amdtp.h
106688 @@ -135,7 +135,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
106689 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
106690 struct snd_pcm_substream *pcm)
106691 {
106692 - ACCESS_ONCE(s->pcm) = pcm;
106693 + ACCESS_ONCE_RW(s->pcm) = pcm;
106694 }
106695
106696 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
106697 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
106698 index 7ac9443..0ec6274 100644
106699 --- a/sound/firewire/isight.c
106700 +++ b/sound/firewire/isight.c
106701 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
106702 ptr += count;
106703 if (ptr >= runtime->buffer_size)
106704 ptr -= runtime->buffer_size;
106705 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
106706 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
106707
106708 isight->period_counter += count;
106709 if (isight->period_counter >= runtime->period_size) {
106710 @@ -299,7 +299,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
106711 if (err < 0)
106712 return err;
106713
106714 - ACCESS_ONCE(isight->pcm_active) = true;
106715 + ACCESS_ONCE_RW(isight->pcm_active) = true;
106716
106717 return 0;
106718 }
106719 @@ -337,7 +337,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
106720 {
106721 struct isight *isight = substream->private_data;
106722
106723 - ACCESS_ONCE(isight->pcm_active) = false;
106724 + ACCESS_ONCE_RW(isight->pcm_active) = false;
106725
106726 mutex_lock(&isight->mutex);
106727 isight_stop_streaming(isight);
106728 @@ -430,10 +430,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
106729
106730 switch (cmd) {
106731 case SNDRV_PCM_TRIGGER_START:
106732 - ACCESS_ONCE(isight->pcm_running) = true;
106733 + ACCESS_ONCE_RW(isight->pcm_running) = true;
106734 break;
106735 case SNDRV_PCM_TRIGGER_STOP:
106736 - ACCESS_ONCE(isight->pcm_running) = false;
106737 + ACCESS_ONCE_RW(isight->pcm_running) = false;
106738 break;
106739 default:
106740 return -EINVAL;
106741 diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
106742 index 2dba848..c682aef 100644
106743 --- a/sound/firewire/scs1x.c
106744 +++ b/sound/firewire/scs1x.c
106745 @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
106746 {
106747 struct scs *scs = stream->rmidi->private_data;
106748
106749 - ACCESS_ONCE(scs->output) = up ? stream : NULL;
106750 + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
106751 if (up) {
106752 scs->output_idle = false;
106753 tasklet_schedule(&scs->tasklet);
106754 @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
106755 {
106756 struct scs *scs = stream->rmidi->private_data;
106757
106758 - ACCESS_ONCE(scs->input) = up ? stream : NULL;
106759 + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
106760 }
106761
106762 static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
106763 @@ -473,8 +473,8 @@ static void scs_remove(struct fw_unit *unit)
106764
106765 snd_card_disconnect(scs->card);
106766
106767 - ACCESS_ONCE(scs->output) = NULL;
106768 - ACCESS_ONCE(scs->input) = NULL;
106769 + ACCESS_ONCE_RW(scs->output) = NULL;
106770 + ACCESS_ONCE_RW(scs->input) = NULL;
106771
106772 wait_event(scs->idle_wait, scs->output_idle);
106773
106774 diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c
106775 index 4e3fcfb..ab45a9d 100644
106776 --- a/sound/isa/sb/emu8000_synth.c
106777 +++ b/sound/isa/sb/emu8000_synth.c
106778 @@ -120,8 +120,8 @@ static int __init alsa_emu8000_init(void)
106779 {
106780
106781 static struct snd_seq_dev_ops ops = {
106782 - snd_emu8000_new_device,
106783 - snd_emu8000_delete_device,
106784 + .init_device = snd_emu8000_new_device,
106785 + .free_device = snd_emu8000_delete_device,
106786 };
106787 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU8000, &ops,
106788 sizeof(struct snd_emu8000*));
106789 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
106790 index 048439a..3be9f6f 100644
106791 --- a/sound/oss/sb_audio.c
106792 +++ b/sound/oss/sb_audio.c
106793 @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
106794 buf16 = (signed short *)(localbuf + localoffs);
106795 while (c)
106796 {
106797 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
106798 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
106799 if (copy_from_user(lbuf8,
106800 userbuf+useroffs + p,
106801 locallen))
106802 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
106803 index f851fd0..92576fb 100644
106804 --- a/sound/oss/swarm_cs4297a.c
106805 +++ b/sound/oss/swarm_cs4297a.c
106806 @@ -2623,7 +2623,6 @@ static int __init cs4297a_init(void)
106807 {
106808 struct cs4297a_state *s;
106809 u32 pwr, id;
106810 - mm_segment_t fs;
106811 int rval;
106812 #ifndef CONFIG_BCM_CS4297A_CSWARM
106813 u64 cfg;
106814 @@ -2713,22 +2712,23 @@ static int __init cs4297a_init(void)
106815 if (!rval) {
106816 char *sb1250_duart_present;
106817
106818 +#if 0
106819 + mm_segment_t fs;
106820 fs = get_fs();
106821 set_fs(KERNEL_DS);
106822 -#if 0
106823 val = SOUND_MASK_LINE;
106824 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
106825 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
106826 val = initvol[i].vol;
106827 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
106828 }
106829 + set_fs(fs);
106830 // cs4297a_write_ac97(s, 0x18, 0x0808);
106831 #else
106832 // cs4297a_write_ac97(s, 0x5e, 0x180);
106833 cs4297a_write_ac97(s, 0x02, 0x0808);
106834 cs4297a_write_ac97(s, 0x18, 0x0808);
106835 #endif
106836 - set_fs(fs);
106837
106838 list_add(&s->list, &cs4297a_devs);
106839
106840 diff --git a/sound/pci/emu10k1/emu10k1_synth.c b/sound/pci/emu10k1/emu10k1_synth.c
106841 index 4c41c90..37f3631 100644
106842 --- a/sound/pci/emu10k1/emu10k1_synth.c
106843 +++ b/sound/pci/emu10k1/emu10k1_synth.c
106844 @@ -108,8 +108,8 @@ static int __init alsa_emu10k1_synth_init(void)
106845 {
106846
106847 static struct snd_seq_dev_ops ops = {
106848 - snd_emu10k1_synth_new_device,
106849 - snd_emu10k1_synth_delete_device,
106850 + .init_device = snd_emu10k1_synth_new_device,
106851 + .free_device = snd_emu10k1_synth_delete_device,
106852 };
106853 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops,
106854 sizeof(struct snd_emu10k1_synth_arg));
106855 diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
106856 index 4c20277..91abdce 100644
106857 --- a/sound/pci/hda/hda_codec.c
106858 +++ b/sound/pci/hda/hda_codec.c
106859 @@ -966,14 +966,10 @@ find_codec_preset(struct hda_codec *codec)
106860 mutex_unlock(&preset_mutex);
106861
106862 if (mod_requested < HDA_MODREQ_MAX_COUNT) {
106863 - char name[32];
106864 if (!mod_requested)
106865 - snprintf(name, sizeof(name), "snd-hda-codec-id:%08x",
106866 - codec->vendor_id);
106867 + request_module("snd-hda-codec-id:%08x", codec->vendor_id);
106868 else
106869 - snprintf(name, sizeof(name), "snd-hda-codec-id:%04x*",
106870 - (codec->vendor_id >> 16) & 0xffff);
106871 - request_module(name);
106872 + request_module("snd-hda-codec-id:%04x*", (codec->vendor_id >> 16) & 0xffff);
106873 mod_requested++;
106874 goto again;
106875 }
106876 @@ -2777,7 +2773,7 @@ static int get_kctl_0dB_offset(struct snd_kcontrol *kctl, int *step_to_check)
106877 /* FIXME: set_fs() hack for obtaining user-space TLV data */
106878 mm_segment_t fs = get_fs();
106879 set_fs(get_ds());
106880 - if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), _tlv))
106881 + if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), (unsigned int __force_user *)_tlv))
106882 tlv = _tlv;
106883 set_fs(fs);
106884 } else if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_READ)
106885 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
106886 index 4631a23..001ae57 100644
106887 --- a/sound/pci/ymfpci/ymfpci.h
106888 +++ b/sound/pci/ymfpci/ymfpci.h
106889 @@ -358,7 +358,7 @@ struct snd_ymfpci {
106890 spinlock_t reg_lock;
106891 spinlock_t voice_lock;
106892 wait_queue_head_t interrupt_sleep;
106893 - atomic_t interrupt_sleep_count;
106894 + atomic_unchecked_t interrupt_sleep_count;
106895 struct snd_info_entry *proc_entry;
106896 const struct firmware *dsp_microcode;
106897 const struct firmware *controller_microcode;
106898 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
106899 index 81c916a..516f0bf 100644
106900 --- a/sound/pci/ymfpci/ymfpci_main.c
106901 +++ b/sound/pci/ymfpci/ymfpci_main.c
106902 @@ -204,8 +204,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
106903 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
106904 break;
106905 }
106906 - if (atomic_read(&chip->interrupt_sleep_count)) {
106907 - atomic_set(&chip->interrupt_sleep_count, 0);
106908 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
106909 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
106910 wake_up(&chip->interrupt_sleep);
106911 }
106912 __end:
106913 @@ -789,7 +789,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
106914 continue;
106915 init_waitqueue_entry(&wait, current);
106916 add_wait_queue(&chip->interrupt_sleep, &wait);
106917 - atomic_inc(&chip->interrupt_sleep_count);
106918 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
106919 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
106920 remove_wait_queue(&chip->interrupt_sleep, &wait);
106921 }
106922 @@ -827,8 +827,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
106923 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
106924 spin_unlock(&chip->reg_lock);
106925
106926 - if (atomic_read(&chip->interrupt_sleep_count)) {
106927 - atomic_set(&chip->interrupt_sleep_count, 0);
106928 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
106929 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
106930 wake_up(&chip->interrupt_sleep);
106931 }
106932 }
106933 @@ -2423,7 +2423,7 @@ int snd_ymfpci_create(struct snd_card *card,
106934 spin_lock_init(&chip->reg_lock);
106935 spin_lock_init(&chip->voice_lock);
106936 init_waitqueue_head(&chip->interrupt_sleep);
106937 - atomic_set(&chip->interrupt_sleep_count, 0);
106938 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
106939 chip->card = card;
106940 chip->pci = pci;
106941 chip->irq = -1;
106942 diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
106943 index 5428a1f..474f651 100644
106944 --- a/sound/soc/fsl/fsl_ssi.c
106945 +++ b/sound/soc/fsl/fsl_ssi.c
106946 @@ -1255,7 +1255,6 @@ static int fsl_ssi_probe(struct platform_device *pdev)
106947 {
106948 struct fsl_ssi_private *ssi_private;
106949 int ret = 0;
106950 - struct device_attribute *dev_attr = NULL;
106951 struct device_node *np = pdev->dev.of_node;
106952 const struct of_device_id *of_id;
106953 enum fsl_ssi_type hw_type;
106954 @@ -1481,7 +1480,7 @@ static int fsl_ssi_probe(struct platform_device *pdev)
106955 &ssi_private->cpu_dai_drv, 1);
106956 if (ret) {
106957 dev_err(&pdev->dev, "failed to register DAI: %d\n", ret);
106958 - goto error_dev;
106959 + goto error_clk;
106960 }
106961
106962 ret = fsl_ssi_debugfs_create(ssi_private, &pdev->dev);
106963 @@ -1562,9 +1561,6 @@ error_pcm:
106964 error_dbgfs:
106965 snd_soc_unregister_component(&pdev->dev);
106966
106967 -error_dev:
106968 - device_remove_file(&pdev->dev, dev_attr);
106969 -
106970 error_clk:
106971 if (ssi_private->ssi_on_imx) {
106972 if (!IS_ERR(ssi_private->baudclk))
106973 diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
106974 index 051c006..70598e8 100644
106975 --- a/sound/soc/soc-core.c
106976 +++ b/sound/soc/soc-core.c
106977 @@ -2255,8 +2255,10 @@ int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
106978 if (ret)
106979 return ret;
106980
106981 - ops->warm_reset = snd_soc_ac97_warm_reset;
106982 - ops->reset = snd_soc_ac97_reset;
106983 + pax_open_kernel();
106984 + *(void **)&ops->warm_reset = snd_soc_ac97_warm_reset;
106985 + *(void **)&ops->reset = snd_soc_ac97_reset;
106986 + pax_close_kernel();
106987
106988 snd_ac97_rst_cfg = cfg;
106989 return 0;
106990 diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
106991 index 7778b8e..3d619fc 100644
106992 --- a/sound/synth/emux/emux_seq.c
106993 +++ b/sound/synth/emux/emux_seq.c
106994 @@ -33,13 +33,13 @@ static int snd_emux_unuse(void *private_data, struct snd_seq_port_subscribe *inf
106995 * MIDI emulation operators
106996 */
106997 static struct snd_midi_op emux_ops = {
106998 - snd_emux_note_on,
106999 - snd_emux_note_off,
107000 - snd_emux_key_press,
107001 - snd_emux_terminate_note,
107002 - snd_emux_control,
107003 - snd_emux_nrpn,
107004 - snd_emux_sysex,
107005 + .note_on = snd_emux_note_on,
107006 + .note_off = snd_emux_note_off,
107007 + .key_press = snd_emux_key_press,
107008 + .note_terminate = snd_emux_terminate_note,
107009 + .control = snd_emux_control,
107010 + .nrpn = snd_emux_nrpn,
107011 + .sysex = snd_emux_sysex,
107012 };
107013
107014
107015 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
107016 new file mode 100644
107017 index 0000000..de92ed9
107018 --- /dev/null
107019 +++ b/tools/gcc/.gitignore
107020 @@ -0,0 +1 @@
107021 +randomize_layout_seed.h
107022 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
107023 new file mode 100644
107024 index 0000000..7b8921f
107025 --- /dev/null
107026 +++ b/tools/gcc/Makefile
107027 @@ -0,0 +1,52 @@
107028 +#CC := gcc
107029 +#PLUGIN_SOURCE_FILES := pax_plugin.c
107030 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
107031 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
107032 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
107033 +
107034 +ifeq ($(PLUGINCC),$(HOSTCC))
107035 +HOSTLIBS := hostlibs
107036 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu99 -ggdb
107037 +export HOST_EXTRACFLAGS
107038 +else
107039 +HOSTLIBS := hostcxxlibs
107040 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu++98 -fno-rtti -ggdb -Wno-unused-parameter -Wno-narrowing -Wno-unused-variable
107041 +export HOST_EXTRACXXFLAGS
107042 +endif
107043 +
107044 +export GCCPLUGINS_DIR HOSTLIBS
107045 +
107046 +$(HOSTLIBS)-$(CONFIG_PAX_CONSTIFY_PLUGIN) := constify_plugin.so
107047 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
107048 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
107049 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
107050 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
107051 +$(HOSTLIBS)-y += colorize_plugin.so
107052 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
107053 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STRUCTLEAK) += structleak_plugin.so
107054 +$(HOSTLIBS)-$(CONFIG_GRKERNSEC_RANDSTRUCT) += randomize_layout_plugin.so
107055 +
107056 +subdir-$(CONFIG_PAX_SIZE_OVERFLOW) := size_overflow_plugin
107057 +subdir- += size_overflow_plugin
107058 +
107059 +always := $($(HOSTLIBS)-y)
107060 +
107061 +constify_plugin-objs := constify_plugin.o
107062 +stackleak_plugin-objs := stackleak_plugin.o
107063 +kallocstat_plugin-objs := kallocstat_plugin.o
107064 +kernexec_plugin-objs := kernexec_plugin.o
107065 +checker_plugin-objs := checker_plugin.o
107066 +colorize_plugin-objs := colorize_plugin.o
107067 +latent_entropy_plugin-objs := latent_entropy_plugin.o
107068 +structleak_plugin-objs := structleak_plugin.o
107069 +randomize_layout_plugin-objs := randomize_layout_plugin.o
107070 +
107071 +$(obj)/randomize_layout_plugin.o: $(objtree)/$(obj)/randomize_layout_seed.h
107072 +
107073 +quiet_cmd_create_randomize_layout_seed = GENSEED $@
107074 + cmd_create_randomize_layout_seed = \
107075 + $(CONFIG_SHELL) $(srctree)/$(src)/gen-random-seed.sh $@ $(objtree)/include/generated/randomize_layout_hash.h
107076 +$(objtree)/$(obj)/randomize_layout_seed.h: FORCE
107077 + $(call if_changed,create_randomize_layout_seed)
107078 +
107079 +targets += randomize_layout_seed.h randomize_layout_hash.h
107080 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
107081 new file mode 100644
107082 index 0000000..5452feea
107083 --- /dev/null
107084 +++ b/tools/gcc/checker_plugin.c
107085 @@ -0,0 +1,150 @@
107086 +/*
107087 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
107088 + * Licensed under the GPL v2
107089 + *
107090 + * Note: the choice of the license means that the compilation process is
107091 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
107092 + * but for the kernel it doesn't matter since it doesn't link against
107093 + * any of the gcc libraries
107094 + *
107095 + * gcc plugin to implement various sparse (source code checker) features
107096 + *
107097 + * TODO:
107098 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
107099 + *
107100 + * BUGS:
107101 + * - none known
107102 + */
107103 +
107104 +#include "gcc-common.h"
107105 +
107106 +extern void c_register_addr_space (const char *str, addr_space_t as);
107107 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
107108 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
107109 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
107110 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
107111 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
107112 +
107113 +int plugin_is_GPL_compatible;
107114 +
107115 +static struct plugin_info checker_plugin_info = {
107116 + .version = "201304082245",
107117 + .help = NULL,
107118 +};
107119 +
107120 +#define ADDR_SPACE_KERNEL 0
107121 +#define ADDR_SPACE_FORCE_KERNEL 1
107122 +#define ADDR_SPACE_USER 2
107123 +#define ADDR_SPACE_FORCE_USER 3
107124 +#define ADDR_SPACE_IOMEM 0
107125 +#define ADDR_SPACE_FORCE_IOMEM 0
107126 +#define ADDR_SPACE_PERCPU 0
107127 +#define ADDR_SPACE_FORCE_PERCPU 0
107128 +#define ADDR_SPACE_RCU 0
107129 +#define ADDR_SPACE_FORCE_RCU 0
107130 +
107131 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
107132 +{
107133 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
107134 +}
107135 +
107136 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
107137 +{
107138 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
107139 +}
107140 +
107141 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
107142 +{
107143 + return default_addr_space_valid_pointer_mode(mode, as);
107144 +}
107145 +
107146 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
107147 +{
107148 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
107149 +}
107150 +
107151 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
107152 +{
107153 + return default_addr_space_legitimize_address(x, oldx, mode, as);
107154 +}
107155 +
107156 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
107157 +{
107158 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
107159 + return true;
107160 +
107161 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
107162 + return true;
107163 +
107164 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
107165 + return true;
107166 +
107167 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
107168 + return true;
107169 +
107170 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
107171 + return true;
107172 +
107173 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
107174 + return true;
107175 +
107176 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
107177 + return true;
107178 +
107179 + return subset == superset;
107180 +}
107181 +
107182 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
107183 +{
107184 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
107185 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
107186 +
107187 + return op;
107188 +}
107189 +
107190 +static void register_checker_address_spaces(void *event_data, void *data)
107191 +{
107192 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
107193 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
107194 + c_register_addr_space("__user", ADDR_SPACE_USER);
107195 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
107196 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
107197 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
107198 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
107199 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
107200 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
107201 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
107202 +
107203 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
107204 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
107205 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
107206 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
107207 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
107208 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
107209 + targetm.addr_space.convert = checker_addr_space_convert;
107210 +}
107211 +
107212 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
107213 +{
107214 + const char * const plugin_name = plugin_info->base_name;
107215 + const int argc = plugin_info->argc;
107216 + const struct plugin_argument * const argv = plugin_info->argv;
107217 + int i;
107218 +
107219 + if (!plugin_default_version_check(version, &gcc_version)) {
107220 + error(G_("incompatible gcc/plugin versions"));
107221 + return 1;
107222 + }
107223 +
107224 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
107225 +
107226 + for (i = 0; i < argc; ++i)
107227 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
107228 +
107229 + if (TARGET_64BIT == 0)
107230 + return 0;
107231 +
107232 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
107233 +
107234 + return 0;
107235 +}
107236 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
107237 new file mode 100644
107238 index 0000000..54461af
107239 --- /dev/null
107240 +++ b/tools/gcc/colorize_plugin.c
107241 @@ -0,0 +1,210 @@
107242 +/*
107243 + * Copyright 2012-2014 by PaX Team <pageexec@freemail.hu>
107244 + * Licensed under the GPL v2
107245 + *
107246 + * Note: the choice of the license means that the compilation process is
107247 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
107248 + * but for the kernel it doesn't matter since it doesn't link against
107249 + * any of the gcc libraries
107250 + *
107251 + * gcc plugin to colorize diagnostic output
107252 + *
107253 + */
107254 +
107255 +#include "gcc-common.h"
107256 +
107257 +int plugin_is_GPL_compatible;
107258 +
107259 +static struct plugin_info colorize_plugin_info = {
107260 + .version = "201404202350",
107261 + .help = "color=[never|always|auto]\tdetermine when to colorize\n",
107262 +};
107263 +
107264 +#define GREEN "\033[32m\033[K"
107265 +#define LIGHTGREEN "\033[1;32m\033[K"
107266 +#define YELLOW "\033[33m\033[K"
107267 +#define LIGHTYELLOW "\033[1;33m\033[K"
107268 +#define RED "\033[31m\033[K"
107269 +#define LIGHTRED "\033[1;31m\033[K"
107270 +#define BLUE "\033[34m\033[K"
107271 +#define LIGHTBLUE "\033[1;34m\033[K"
107272 +#define BRIGHT "\033[1;m\033[K"
107273 +#define NORMAL "\033[m\033[K"
107274 +
107275 +static diagnostic_starter_fn old_starter;
107276 +static diagnostic_finalizer_fn old_finalizer;
107277 +
107278 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
107279 +{
107280 + const char *color;
107281 + char *newprefix;
107282 +
107283 + switch (diagnostic->kind) {
107284 + case DK_NOTE:
107285 + color = LIGHTBLUE;
107286 + break;
107287 +
107288 + case DK_PEDWARN:
107289 + case DK_WARNING:
107290 + color = LIGHTYELLOW;
107291 + break;
107292 +
107293 + case DK_ERROR:
107294 + case DK_FATAL:
107295 + case DK_ICE:
107296 + case DK_PERMERROR:
107297 + case DK_SORRY:
107298 + color = LIGHTRED;
107299 + break;
107300 +
107301 + default:
107302 + color = NORMAL;
107303 + }
107304 +
107305 + old_starter(context, diagnostic);
107306 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
107307 + return;
107308 + pp_destroy_prefix(context->printer);
107309 + pp_set_prefix(context->printer, newprefix);
107310 +}
107311 +
107312 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
107313 +{
107314 + old_finalizer(context, diagnostic);
107315 +}
107316 +
107317 +static void colorize_arm(void)
107318 +{
107319 + old_starter = diagnostic_starter(global_dc);
107320 + old_finalizer = diagnostic_finalizer(global_dc);
107321 +
107322 + diagnostic_starter(global_dc) = start_colorize;
107323 + diagnostic_finalizer(global_dc) = finalize_colorize;
107324 +}
107325 +
107326 +static unsigned int execute_colorize_rearm(void)
107327 +{
107328 + if (diagnostic_starter(global_dc) == start_colorize)
107329 + return 0;
107330 +
107331 + colorize_arm();
107332 + return 0;
107333 +}
107334 +
107335 +#if BUILDING_GCC_VERSION >= 4009
107336 +static const struct pass_data colorize_rearm_pass_data = {
107337 +#else
107338 +struct simple_ipa_opt_pass colorize_rearm_pass = {
107339 + .pass = {
107340 +#endif
107341 + .type = SIMPLE_IPA_PASS,
107342 + .name = "colorize_rearm",
107343 +#if BUILDING_GCC_VERSION >= 4008
107344 + .optinfo_flags = OPTGROUP_NONE,
107345 +#endif
107346 +#if BUILDING_GCC_VERSION >= 4009
107347 + .has_gate = false,
107348 + .has_execute = true,
107349 +#else
107350 + .gate = NULL,
107351 + .execute = execute_colorize_rearm,
107352 + .sub = NULL,
107353 + .next = NULL,
107354 + .static_pass_number = 0,
107355 +#endif
107356 + .tv_id = TV_NONE,
107357 + .properties_required = 0,
107358 + .properties_provided = 0,
107359 + .properties_destroyed = 0,
107360 + .todo_flags_start = 0,
107361 + .todo_flags_finish = 0
107362 +#if BUILDING_GCC_VERSION < 4009
107363 + }
107364 +#endif
107365 +};
107366 +
107367 +#if BUILDING_GCC_VERSION >= 4009
107368 +namespace {
107369 +class colorize_rearm_pass : public simple_ipa_opt_pass {
107370 +public:
107371 + colorize_rearm_pass() : simple_ipa_opt_pass(colorize_rearm_pass_data, g) {}
107372 + unsigned int execute() { return execute_colorize_rearm(); }
107373 +};
107374 +}
107375 +
107376 +static opt_pass *make_colorize_rearm_pass(void)
107377 +{
107378 + return new colorize_rearm_pass();
107379 +}
107380 +#else
107381 +static struct opt_pass *make_colorize_rearm_pass(void)
107382 +{
107383 + return &colorize_rearm_pass.pass;
107384 +}
107385 +#endif
107386 +
107387 +static void colorize_start_unit(void *gcc_data, void *user_data)
107388 +{
107389 + colorize_arm();
107390 +}
107391 +
107392 +static bool should_colorize(void)
107393 +{
107394 +#if BUILDING_GCC_VERSION >= 4009
107395 + return false;
107396 +#else
107397 + char const *t = getenv("TERM");
107398 +
107399 + return t && strcmp(t, "dumb") && isatty(STDERR_FILENO);
107400 +#endif
107401 +}
107402 +
107403 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
107404 +{
107405 + const char * const plugin_name = plugin_info->base_name;
107406 + const int argc = plugin_info->argc;
107407 + const struct plugin_argument * const argv = plugin_info->argv;
107408 + int i;
107409 + struct register_pass_info colorize_rearm_pass_info;
107410 + bool colorize;
107411 +
107412 + colorize_rearm_pass_info.pass = make_colorize_rearm_pass();
107413 + colorize_rearm_pass_info.reference_pass_name = "*free_lang_data";
107414 + colorize_rearm_pass_info.ref_pass_instance_number = 1;
107415 + colorize_rearm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
107416 +
107417 + if (!plugin_default_version_check(version, &gcc_version)) {
107418 + error(G_("incompatible gcc/plugin versions"));
107419 + return 1;
107420 + }
107421 +
107422 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
107423 +
107424 + colorize = getenv("GCC_COLORS") ? should_colorize() : false;
107425 +
107426 + for (i = 0; i < argc; ++i) {
107427 + if (!strcmp(argv[i].key, "color")) {
107428 + if (!argv[i].value) {
107429 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
107430 + continue;
107431 + }
107432 + if (!strcmp(argv[i].value, "always"))
107433 + colorize = true;
107434 + else if (!strcmp(argv[i].value, "never"))
107435 + colorize = false;
107436 + else if (!strcmp(argv[i].value, "auto"))
107437 + colorize = should_colorize();
107438 + else
107439 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
107440 + continue;
107441 + }
107442 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
107443 + }
107444 +
107445 + if (colorize) {
107446 + // TODO: parse GCC_COLORS as used by gcc 4.9+
107447 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
107448 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
107449 + }
107450 + return 0;
107451 +}
107452 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
107453 new file mode 100644
107454 index 0000000..82bc5a8
107455 --- /dev/null
107456 +++ b/tools/gcc/constify_plugin.c
107457 @@ -0,0 +1,557 @@
107458 +/*
107459 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
107460 + * Copyright 2011-2014 by PaX Team <pageexec@freemail.hu>
107461 + * Licensed under the GPL v2, or (at your option) v3
107462 + *
107463 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
107464 + *
107465 + * Homepage:
107466 + * http://www.grsecurity.net/~ephox/const_plugin/
107467 + *
107468 + * Usage:
107469 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
107470 + * $ gcc -fplugin=constify_plugin.so test.c -O2
107471 + */
107472 +
107473 +#include "gcc-common.h"
107474 +
107475 +// unused C type flag in all versions 4.5-4.9
107476 +#define TYPE_CONSTIFY_VISITED(TYPE) TYPE_LANG_FLAG_4(TYPE)
107477 +
107478 +int plugin_is_GPL_compatible;
107479 +
107480 +static struct plugin_info const_plugin_info = {
107481 + .version = "201401270210",
107482 + .help = "no-constify\tturn off constification\n",
107483 +};
107484 +
107485 +typedef struct {
107486 + bool has_fptr_field;
107487 + bool has_writable_field;
107488 + bool has_do_const_field;
107489 + bool has_no_const_field;
107490 +} constify_info;
107491 +
107492 +static const_tree get_field_type(const_tree field)
107493 +{
107494 + return strip_array_types(TREE_TYPE(field));
107495 +}
107496 +
107497 +static bool is_fptr(const_tree field)
107498 +{
107499 + const_tree ptr = get_field_type(field);
107500 +
107501 + if (TREE_CODE(ptr) != POINTER_TYPE)
107502 + return false;
107503 +
107504 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
107505 +}
107506 +
107507 +/*
107508 + * determine whether the given structure type meets the requirements for automatic constification,
107509 + * including the constification attributes on nested structure types
107510 + */
107511 +static void constifiable(const_tree node, constify_info *cinfo)
107512 +{
107513 + const_tree field;
107514 +
107515 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
107516 +
107517 + // e.g., pointer to structure fields while still constructing the structure type
107518 + if (TYPE_FIELDS(node) == NULL_TREE)
107519 + return;
107520 +
107521 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
107522 + const_tree type = get_field_type(field);
107523 + enum tree_code code = TREE_CODE(type);
107524 +
107525 + if (node == type)
107526 + continue;
107527 +
107528 + if (is_fptr(field))
107529 + cinfo->has_fptr_field = true;
107530 + else if (!TREE_READONLY(field))
107531 + cinfo->has_writable_field = true;
107532 +
107533 + if (code == RECORD_TYPE || code == UNION_TYPE) {
107534 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
107535 + cinfo->has_do_const_field = true;
107536 + else if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
107537 + cinfo->has_no_const_field = true;
107538 + else
107539 + constifiable(type, cinfo);
107540 + }
107541 + }
107542 +}
107543 +
107544 +static bool constified(const_tree node)
107545 +{
107546 + constify_info cinfo = {
107547 + .has_fptr_field = false,
107548 + .has_writable_field = false,
107549 + .has_do_const_field = false,
107550 + .has_no_const_field = false
107551 + };
107552 +
107553 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
107554 +
107555 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
107556 +// gcc_assert(!TYPE_READONLY(node));
107557 + return false;
107558 + }
107559 +
107560 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node))) {
107561 + gcc_assert(TYPE_READONLY(node));
107562 + return true;
107563 + }
107564 +
107565 + constifiable(node, &cinfo);
107566 + if ((!cinfo.has_fptr_field || cinfo.has_writable_field) && !cinfo.has_do_const_field)
107567 + return false;
107568 +
107569 + return TYPE_READONLY(node);
107570 +}
107571 +
107572 +static void deconstify_tree(tree node);
107573 +
107574 +static void deconstify_type(tree type)
107575 +{
107576 + tree field;
107577 +
107578 + gcc_assert(TREE_CODE(type) == RECORD_TYPE || TREE_CODE(type) == UNION_TYPE);
107579 +
107580 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
107581 + const_tree fieldtype = get_field_type(field);
107582 +
107583 + // special case handling of simple ptr-to-same-array-type members
107584 + if (TREE_CODE(TREE_TYPE(field)) == POINTER_TYPE) {
107585 + tree ptrtype = TREE_TYPE(TREE_TYPE(field));
107586 +
107587 + if (TREE_TYPE(TREE_TYPE(field)) == type)
107588 + continue;
107589 + if (TREE_CODE(ptrtype) != RECORD_TYPE && TREE_CODE(ptrtype) != UNION_TYPE)
107590 + continue;
107591 + if (!constified(ptrtype))
107592 + continue;
107593 + if (TYPE_MAIN_VARIANT(ptrtype) == TYPE_MAIN_VARIANT(type)) {
107594 + TREE_TYPE(field) = copy_node(TREE_TYPE(field));
107595 + TREE_TYPE(TREE_TYPE(field)) = build_qualified_type(type, TYPE_QUALS(ptrtype) & ~TYPE_QUAL_CONST);
107596 + }
107597 + continue;
107598 + }
107599 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
107600 + continue;
107601 + if (!constified(fieldtype))
107602 + continue;
107603 +
107604 + deconstify_tree(field);
107605 + TREE_READONLY(field) = 0;
107606 + }
107607 + TYPE_READONLY(type) = 0;
107608 + C_TYPE_FIELDS_READONLY(type) = 0;
107609 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
107610 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
107611 + TYPE_ATTRIBUTES(type) = remove_attribute("do_const", TYPE_ATTRIBUTES(type));
107612 + }
107613 +}
107614 +
107615 +static void deconstify_tree(tree node)
107616 +{
107617 + tree old_type, new_type, field;
107618 +
107619 + old_type = TREE_TYPE(node);
107620 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
107621 + node = TREE_TYPE(node) = copy_node(old_type);
107622 + old_type = TREE_TYPE(old_type);
107623 + }
107624 +
107625 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
107626 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
107627 +
107628 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
107629 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
107630 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
107631 + DECL_FIELD_CONTEXT(field) = new_type;
107632 +
107633 + deconstify_type(new_type);
107634 +
107635 + TREE_TYPE(node) = new_type;
107636 +}
107637 +
107638 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
107639 +{
107640 + tree type;
107641 + constify_info cinfo = {
107642 + .has_fptr_field = false,
107643 + .has_writable_field = false,
107644 + .has_do_const_field = false,
107645 + .has_no_const_field = false
107646 + };
107647 +
107648 + *no_add_attrs = true;
107649 + if (TREE_CODE(*node) == FUNCTION_DECL) {
107650 + error("%qE attribute does not apply to functions (%qF)", name, *node);
107651 + return NULL_TREE;
107652 + }
107653 +
107654 + if (TREE_CODE(*node) == PARM_DECL) {
107655 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
107656 + return NULL_TREE;
107657 + }
107658 +
107659 + if (TREE_CODE(*node) == VAR_DECL) {
107660 + error("%qE attribute does not apply to variables (%qD)", name, *node);
107661 + return NULL_TREE;
107662 + }
107663 +
107664 + if (TYPE_P(*node)) {
107665 + type = *node;
107666 + } else {
107667 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
107668 + type = TREE_TYPE(*node);
107669 + }
107670 +
107671 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
107672 + error("%qE attribute used on %qT applies to struct and union types only", name, type);
107673 + return NULL_TREE;
107674 + }
107675 +
107676 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
107677 + error("%qE attribute is already applied to the type %qT", name, type);
107678 + return NULL_TREE;
107679 + }
107680 +
107681 + if (TYPE_P(*node)) {
107682 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
107683 + error("%qE attribute used on type %qT is incompatible with 'do_const'", name, type);
107684 + else
107685 + *no_add_attrs = false;
107686 + return NULL_TREE;
107687 + }
107688 +
107689 + constifiable(type, &cinfo);
107690 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
107691 + deconstify_tree(*node);
107692 + TYPE_CONSTIFY_VISITED(TREE_TYPE(*node)) = 1;
107693 + return NULL_TREE;
107694 + }
107695 +
107696 + error("%qE attribute used on type %qT that is not constified", name, type);
107697 + return NULL_TREE;
107698 +}
107699 +
107700 +static void constify_type(tree type)
107701 +{
107702 + TYPE_READONLY(type) = 1;
107703 + C_TYPE_FIELDS_READONLY(type) = 1;
107704 + TYPE_CONSTIFY_VISITED(type) = 1;
107705 +// TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
107706 +// TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("do_const"), NULL_TREE, TYPE_ATTRIBUTES(type));
107707 +}
107708 +
107709 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
107710 +{
107711 + *no_add_attrs = true;
107712 + if (!TYPE_P(*node)) {
107713 + error("%qE attribute applies to types only (%qD)", name, *node);
107714 + return NULL_TREE;
107715 + }
107716 +
107717 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
107718 + error("%qE attribute used on %qT applies to struct and union types only", name, *node);
107719 + return NULL_TREE;
107720 + }
107721 +
107722 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(*node))) {
107723 + error("%qE attribute used on %qT is already applied to the type", name, *node);
107724 + return NULL_TREE;
107725 + }
107726 +
107727 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(*node))) {
107728 + error("%qE attribute used on %qT is incompatible with 'no_const'", name, *node);
107729 + return NULL_TREE;
107730 + }
107731 +
107732 + *no_add_attrs = false;
107733 + return NULL_TREE;
107734 +}
107735 +
107736 +static struct attribute_spec no_const_attr = {
107737 + .name = "no_const",
107738 + .min_length = 0,
107739 + .max_length = 0,
107740 + .decl_required = false,
107741 + .type_required = false,
107742 + .function_type_required = false,
107743 + .handler = handle_no_const_attribute,
107744 +#if BUILDING_GCC_VERSION >= 4007
107745 + .affects_type_identity = true
107746 +#endif
107747 +};
107748 +
107749 +static struct attribute_spec do_const_attr = {
107750 + .name = "do_const",
107751 + .min_length = 0,
107752 + .max_length = 0,
107753 + .decl_required = false,
107754 + .type_required = false,
107755 + .function_type_required = false,
107756 + .handler = handle_do_const_attribute,
107757 +#if BUILDING_GCC_VERSION >= 4007
107758 + .affects_type_identity = true
107759 +#endif
107760 +};
107761 +
107762 +static void register_attributes(void *event_data, void *data)
107763 +{
107764 + register_attribute(&no_const_attr);
107765 + register_attribute(&do_const_attr);
107766 +}
107767 +
107768 +static void finish_type(void *event_data, void *data)
107769 +{
107770 + tree type = (tree)event_data;
107771 + constify_info cinfo = {
107772 + .has_fptr_field = false,
107773 + .has_writable_field = false,
107774 + .has_do_const_field = false,
107775 + .has_no_const_field = false
107776 + };
107777 +
107778 + if (type == NULL_TREE || type == error_mark_node)
107779 + return;
107780 +
107781 + if (TYPE_FIELDS(type) == NULL_TREE || TYPE_CONSTIFY_VISITED(type))
107782 + return;
107783 +
107784 + constifiable(type, &cinfo);
107785 +
107786 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type))) {
107787 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || cinfo.has_do_const_field) {
107788 + deconstify_type(type);
107789 + TYPE_CONSTIFY_VISITED(type) = 1;
107790 + } else
107791 + error("'no_const' attribute used on type %qT that is not constified", type);
107792 + return;
107793 + }
107794 +
107795 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
107796 + if (!cinfo.has_writable_field) {
107797 + error("'do_const' attribute used on type %qT that is%sconstified", type, cinfo.has_fptr_field ? " " : " not ");
107798 + return;
107799 + }
107800 + constify_type(type);
107801 + return;
107802 + }
107803 +
107804 + if (cinfo.has_fptr_field && !cinfo.has_writable_field) {
107805 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
107806 + error("'do_const' attribute used on type %qT that is constified", type);
107807 + return;
107808 + }
107809 + constify_type(type);
107810 + return;
107811 + }
107812 +
107813 + deconstify_type(type);
107814 + TYPE_CONSTIFY_VISITED(type) = 1;
107815 +}
107816 +
107817 +static void check_global_variables(void *event_data, void *data)
107818 +{
107819 +#if BUILDING_GCC_VERSION >= 4009
107820 + varpool_node *node;
107821 +#else
107822 + struct varpool_node *node;
107823 +#endif
107824 +
107825 + FOR_EACH_VARIABLE(node) {
107826 + tree var = NODE_DECL(node);
107827 + tree type = TREE_TYPE(var);
107828 +
107829 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
107830 + continue;
107831 +
107832 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
107833 + continue;
107834 +
107835 + if (!TYPE_CONSTIFY_VISITED(type))
107836 + continue;
107837 +
107838 + if (DECL_EXTERNAL(var))
107839 + continue;
107840 +
107841 + if (DECL_INITIAL(var))
107842 + continue;
107843 +
107844 + // this works around a gcc bug/feature where uninitialized globals
107845 + // are moved into the .bss section regardless of any constification
107846 + DECL_INITIAL(var) = build_constructor(type, NULL);
107847 +// inform(DECL_SOURCE_LOCATION(var), "constified variable %qE moved into .rodata", var);
107848 + }
107849 +}
107850 +
107851 +static unsigned int check_local_variables(void)
107852 +{
107853 + unsigned int ret = 0;
107854 + tree var;
107855 +
107856 + unsigned int i;
107857 +
107858 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
107859 + tree type = TREE_TYPE(var);
107860 +
107861 + gcc_assert(DECL_P(var));
107862 + if (is_global_var(var))
107863 + continue;
107864 +
107865 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
107866 + continue;
107867 +
107868 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
107869 + continue;
107870 +
107871 + if (!TYPE_CONSTIFY_VISITED(type))
107872 + continue;
107873 +
107874 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
107875 + ret = 1;
107876 + }
107877 + return ret;
107878 +}
107879 +
107880 +#if BUILDING_GCC_VERSION >= 4009
107881 +static const struct pass_data check_local_variables_pass_data = {
107882 +#else
107883 +static struct gimple_opt_pass check_local_variables_pass = {
107884 + .pass = {
107885 +#endif
107886 + .type = GIMPLE_PASS,
107887 + .name = "check_local_variables",
107888 +#if BUILDING_GCC_VERSION >= 4008
107889 + .optinfo_flags = OPTGROUP_NONE,
107890 +#endif
107891 +#if BUILDING_GCC_VERSION >= 4009
107892 + .has_gate = false,
107893 + .has_execute = true,
107894 +#else
107895 + .gate = NULL,
107896 + .execute = check_local_variables,
107897 + .sub = NULL,
107898 + .next = NULL,
107899 + .static_pass_number = 0,
107900 +#endif
107901 + .tv_id = TV_NONE,
107902 + .properties_required = 0,
107903 + .properties_provided = 0,
107904 + .properties_destroyed = 0,
107905 + .todo_flags_start = 0,
107906 + .todo_flags_finish = 0
107907 +#if BUILDING_GCC_VERSION < 4009
107908 + }
107909 +#endif
107910 +};
107911 +
107912 +#if BUILDING_GCC_VERSION >= 4009
107913 +namespace {
107914 +class check_local_variables_pass : public gimple_opt_pass {
107915 +public:
107916 + check_local_variables_pass() : gimple_opt_pass(check_local_variables_pass_data, g) {}
107917 + unsigned int execute() { return check_local_variables(); }
107918 +};
107919 +}
107920 +
107921 +static opt_pass *make_check_local_variables_pass(void)
107922 +{
107923 + return new check_local_variables_pass();
107924 +}
107925 +#else
107926 +static struct opt_pass *make_check_local_variables_pass(void)
107927 +{
107928 + return &check_local_variables_pass.pass;
107929 +}
107930 +#endif
107931 +
107932 +static struct {
107933 + const char *name;
107934 + const char *asm_op;
107935 +} sections[] = {
107936 + {".init.rodata", "\t.section\t.init.rodata,\"a\""},
107937 + {".ref.rodata", "\t.section\t.ref.rodata,\"a\""},
107938 + {".devinit.rodata", "\t.section\t.devinit.rodata,\"a\""},
107939 + {".devexit.rodata", "\t.section\t.devexit.rodata,\"a\""},
107940 + {".cpuinit.rodata", "\t.section\t.cpuinit.rodata,\"a\""},
107941 + {".cpuexit.rodata", "\t.section\t.cpuexit.rodata,\"a\""},
107942 + {".meminit.rodata", "\t.section\t.meminit.rodata,\"a\""},
107943 + {".memexit.rodata", "\t.section\t.memexit.rodata,\"a\""},
107944 + {".data..read_only", "\t.section\t.data..read_only,\"a\""},
107945 +};
107946 +
107947 +static unsigned int (*old_section_type_flags)(tree decl, const char *name, int reloc);
107948 +
107949 +static unsigned int constify_section_type_flags(tree decl, const char *name, int reloc)
107950 +{
107951 + size_t i;
107952 +
107953 + for (i = 0; i < ARRAY_SIZE(sections); i++)
107954 + if (!strcmp(sections[i].name, name))
107955 + return 0;
107956 + return old_section_type_flags(decl, name, reloc);
107957 +}
107958 +
107959 +static void constify_start_unit(void *gcc_data, void *user_data)
107960 +{
107961 +// size_t i;
107962 +
107963 +// for (i = 0; i < ARRAY_SIZE(sections); i++)
107964 +// sections[i].section = get_unnamed_section(0, output_section_asm_op, sections[i].asm_op);
107965 +// sections[i].section = get_section(sections[i].name, 0, NULL);
107966 +
107967 + old_section_type_flags = targetm.section_type_flags;
107968 + targetm.section_type_flags = constify_section_type_flags;
107969 +}
107970 +
107971 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
107972 +{
107973 + const char * const plugin_name = plugin_info->base_name;
107974 + const int argc = plugin_info->argc;
107975 + const struct plugin_argument * const argv = plugin_info->argv;
107976 + int i;
107977 + bool constify = true;
107978 +
107979 + struct register_pass_info check_local_variables_pass_info;
107980 +
107981 + check_local_variables_pass_info.pass = make_check_local_variables_pass();
107982 + check_local_variables_pass_info.reference_pass_name = "ssa";
107983 + check_local_variables_pass_info.ref_pass_instance_number = 1;
107984 + check_local_variables_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
107985 +
107986 + if (!plugin_default_version_check(version, &gcc_version)) {
107987 + error(G_("incompatible gcc/plugin versions"));
107988 + return 1;
107989 + }
107990 +
107991 + for (i = 0; i < argc; ++i) {
107992 + if (!(strcmp(argv[i].key, "no-constify"))) {
107993 + constify = false;
107994 + continue;
107995 + }
107996 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
107997 + }
107998 +
107999 + if (strcmp(lang_hooks.name, "GNU C")) {
108000 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
108001 + constify = false;
108002 + }
108003 +
108004 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
108005 + if (constify) {
108006 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
108007 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
108008 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &check_local_variables_pass_info);
108009 + register_callback(plugin_name, PLUGIN_START_UNIT, constify_start_unit, NULL);
108010 + }
108011 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
108012 +
108013 + return 0;
108014 +}
108015 diff --git a/tools/gcc/gcc-common.h b/tools/gcc/gcc-common.h
108016 new file mode 100644
108017 index 0000000..e90c205
108018 --- /dev/null
108019 +++ b/tools/gcc/gcc-common.h
108020 @@ -0,0 +1,295 @@
108021 +#ifndef GCC_COMMON_H_INCLUDED
108022 +#define GCC_COMMON_H_INCLUDED
108023 +
108024 +#include "plugin.h"
108025 +#include "bversion.h"
108026 +#include "plugin-version.h"
108027 +#include "config.h"
108028 +#include "system.h"
108029 +#include "coretypes.h"
108030 +#include "tm.h"
108031 +#include "line-map.h"
108032 +#include "input.h"
108033 +#include "tree.h"
108034 +
108035 +#include "tree-inline.h"
108036 +#include "version.h"
108037 +#include "rtl.h"
108038 +#include "tm_p.h"
108039 +#include "flags.h"
108040 +//#include "insn-attr.h"
108041 +//#include "insn-config.h"
108042 +//#include "insn-flags.h"
108043 +#include "hard-reg-set.h"
108044 +//#include "recog.h"
108045 +#include "output.h"
108046 +#include "except.h"
108047 +#include "function.h"
108048 +#include "toplev.h"
108049 +//#include "expr.h"
108050 +#include "basic-block.h"
108051 +#include "intl.h"
108052 +#include "ggc.h"
108053 +//#include "regs.h"
108054 +#include "timevar.h"
108055 +
108056 +#include "params.h"
108057 +#include "pointer-set.h"
108058 +#include "emit-rtl.h"
108059 +//#include "reload.h"
108060 +//#include "ira.h"
108061 +//#include "dwarf2asm.h"
108062 +#include "debug.h"
108063 +#include "target.h"
108064 +#include "langhooks.h"
108065 +#include "cfgloop.h"
108066 +//#include "hosthooks.h"
108067 +#include "cgraph.h"
108068 +#include "opts.h"
108069 +//#include "coverage.h"
108070 +//#include "value-prof.h"
108071 +
108072 +#if BUILDING_GCC_VERSION >= 4007
108073 +#include "tree-pretty-print.h"
108074 +#include "gimple-pretty-print.h"
108075 +#include "c-tree.h"
108076 +//#include "alloc-pool.h"
108077 +#endif
108078 +
108079 +#if BUILDING_GCC_VERSION <= 4008
108080 +#include "tree-flow.h"
108081 +#else
108082 +#include "tree-cfgcleanup.h"
108083 +#endif
108084 +
108085 +#include "diagnostic.h"
108086 +//#include "tree-diagnostic.h"
108087 +#include "tree-dump.h"
108088 +#include "tree-pass.h"
108089 +//#include "df.h"
108090 +#include "predict.h"
108091 +#include "ipa-utils.h"
108092 +
108093 +#if BUILDING_GCC_VERSION >= 4009
108094 +#include "varasm.h"
108095 +#include "stor-layout.h"
108096 +#include "internal-fn.h"
108097 +#include "gimple-expr.h"
108098 +//#include "diagnostic-color.h"
108099 +#include "context.h"
108100 +#include "tree-ssa-alias.h"
108101 +#include "stringpool.h"
108102 +#include "tree-ssanames.h"
108103 +#include "print-tree.h"
108104 +#include "tree-eh.h"
108105 +#include "stmt.h"
108106 +#endif
108107 +
108108 +#include "gimple.h"
108109 +
108110 +#if BUILDING_GCC_VERSION >= 4009
108111 +#include "tree-ssa-operands.h"
108112 +#include "tree-phinodes.h"
108113 +#include "tree-cfg.h"
108114 +#include "gimple-iterator.h"
108115 +#include "gimple-ssa.h"
108116 +#include "ssa-iterators.h"
108117 +#endif
108118 +
108119 +//#include "lto/lto.h"
108120 +//#include "data-streamer.h"
108121 +//#include "lto-compress.h"
108122 +
108123 +//#include "expr.h" where are you...
108124 +extern rtx emit_move_insn(rtx x, rtx y);
108125 +
108126 +// missing from basic_block.h...
108127 +extern void debug_dominance_info(enum cdi_direction dir);
108128 +extern void debug_dominance_tree(enum cdi_direction dir, basic_block root);
108129 +
108130 +#define __unused __attribute__((__unused__))
108131 +
108132 +#define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
108133 +#define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
108134 +#define TYPE_NAME_POINTER(node) IDENTIFIER_POINTER(TYPE_NAME(node))
108135 +#define TYPE_NAME_LENGTH(node) IDENTIFIER_LENGTH(TYPE_NAME(node))
108136 +
108137 +#if BUILDING_GCC_VERSION == 4005
108138 +#define FOR_EACH_LOCAL_DECL(FUN, I, D) for (tree vars = (FUN)->local_decls; vars && (D = TREE_VALUE(vars)); vars = TREE_CHAIN(vars), I)
108139 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
108140 +#define FOR_EACH_VEC_ELT(T, V, I, P) for (I = 0; VEC_iterate(T, (V), (I), (P)); ++(I))
108141 +#define TODO_rebuild_cgraph_edges 0
108142 +
108143 +static inline bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
108144 +{
108145 + tree fndecl;
108146 +
108147 + if (!is_gimple_call(stmt))
108148 + return false;
108149 + fndecl = gimple_call_fndecl(stmt);
108150 + if (!fndecl || DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
108151 + return false;
108152 +// print_node(stderr, "pax", fndecl, 4);
108153 + return DECL_FUNCTION_CODE(fndecl) == code;
108154 +}
108155 +
108156 +static inline bool is_simple_builtin(tree decl)
108157 +{
108158 + if (decl && DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL)
108159 + return false;
108160 +
108161 + switch (DECL_FUNCTION_CODE(decl)) {
108162 + /* Builtins that expand to constants. */
108163 + case BUILT_IN_CONSTANT_P:
108164 + case BUILT_IN_EXPECT:
108165 + case BUILT_IN_OBJECT_SIZE:
108166 + case BUILT_IN_UNREACHABLE:
108167 + /* Simple register moves or loads from stack. */
108168 + case BUILT_IN_RETURN_ADDRESS:
108169 + case BUILT_IN_EXTRACT_RETURN_ADDR:
108170 + case BUILT_IN_FROB_RETURN_ADDR:
108171 + case BUILT_IN_RETURN:
108172 + case BUILT_IN_AGGREGATE_INCOMING_ADDRESS:
108173 + case BUILT_IN_FRAME_ADDRESS:
108174 + case BUILT_IN_VA_END:
108175 + case BUILT_IN_STACK_SAVE:
108176 + case BUILT_IN_STACK_RESTORE:
108177 + /* Exception state returns or moves registers around. */
108178 + case BUILT_IN_EH_FILTER:
108179 + case BUILT_IN_EH_POINTER:
108180 + case BUILT_IN_EH_COPY_VALUES:
108181 + return true;
108182 +
108183 + default:
108184 + return false;
108185 + }
108186 +}
108187 +#endif
108188 +
108189 +#if BUILDING_GCC_VERSION <= 4006
108190 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
108191 +#define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4(EXP)
108192 +
108193 +// should come from c-tree.h if only it were installed for gcc 4.5...
108194 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
108195 +
108196 +#define get_random_seed(noinit) ({ \
108197 + unsigned HOST_WIDE_INT seed; \
108198 + sscanf(get_random_seed(noinit), "%" HOST_WIDE_INT_PRINT "x", &seed); \
108199 + seed * seed; })
108200 +
108201 +static inline bool gimple_clobber_p(gimple s)
108202 +{
108203 + return false;
108204 +}
108205 +
108206 +static inline tree builtin_decl_implicit(enum built_in_function fncode)
108207 +{
108208 + return implicit_built_in_decls[fncode];
108209 +}
108210 +
108211 +static inline struct cgraph_node *cgraph_get_create_node(tree decl)
108212 +{
108213 + struct cgraph_node *node = cgraph_get_node(decl);
108214 +
108215 + return node ? node : cgraph_node(decl);
108216 +}
108217 +
108218 +static inline bool cgraph_function_with_gimple_body_p(struct cgraph_node *node)
108219 +{
108220 + return node->analyzed && !node->thunk.thunk_p && !node->alias;
108221 +}
108222 +
108223 +static inline struct cgraph_node *cgraph_first_function_with_gimple_body(void)
108224 +{
108225 + struct cgraph_node *node;
108226 +
108227 + for (node = cgraph_nodes; node; node = node->next)
108228 + if (cgraph_function_with_gimple_body_p(node))
108229 + return node;
108230 + return NULL;
108231 +}
108232 +
108233 +static inline struct cgraph_node *cgraph_next_function_with_gimple_body(struct cgraph_node *node)
108234 +{
108235 + for (node = node->next; node; node = node->next)
108236 + if (cgraph_function_with_gimple_body_p(node))
108237 + return node;
108238 + return NULL;
108239 +}
108240 +
108241 +#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
108242 + for ((node) = cgraph_first_function_with_gimple_body(); (node); \
108243 + (node) = cgraph_next_function_with_gimple_body(node))
108244 +#endif
108245 +
108246 +#if BUILDING_GCC_VERSION == 4006
108247 +extern void debug_gimple_stmt(gimple);
108248 +extern void debug_gimple_seq(gimple_seq);
108249 +extern void print_gimple_seq(FILE *, gimple_seq, int, int);
108250 +extern void print_gimple_stmt(FILE *, gimple, int, int);
108251 +extern void print_gimple_expr(FILE *, gimple, int, int);
108252 +extern void dump_gimple_stmt(pretty_printer *, gimple, int, int);
108253 +#endif
108254 +
108255 +#if BUILDING_GCC_VERSION <= 4007
108256 +#define FOR_EACH_VARIABLE(node) for (node = varpool_nodes; node; node = node->next)
108257 +#define PROP_loops 0
108258 +
108259 +static inline int bb_loop_depth(const_basic_block bb)
108260 +{
108261 + return bb->loop_father ? loop_depth(bb->loop_father) : 0;
108262 +}
108263 +
108264 +static inline bool gimple_store_p(gimple gs)
108265 +{
108266 + tree lhs = gimple_get_lhs(gs);
108267 + return lhs && !is_gimple_reg(lhs);
108268 +}
108269 +#endif
108270 +
108271 +#if BUILDING_GCC_VERSION >= 4007
108272 +#define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \
108273 + cgraph_create_edge((caller), (callee), (call_stmt), (count), (freq))
108274 +#define cgraph_create_edge_including_clones(caller, callee, old_call_stmt, call_stmt, count, freq, nest, reason) \
108275 + cgraph_create_edge_including_clones((caller), (callee), (old_call_stmt), (call_stmt), (count), (freq), (reason))
108276 +#endif
108277 +
108278 +#if BUILDING_GCC_VERSION <= 4008
108279 +#define ENTRY_BLOCK_PTR_FOR_FN(FN) ENTRY_BLOCK_PTR_FOR_FUNCTION(FN)
108280 +#define EXIT_BLOCK_PTR_FOR_FN(FN) EXIT_BLOCK_PTR_FOR_FUNCTION(FN)
108281 +#define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info)
108282 +#define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks)
108283 +#define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges)
108284 +#define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block)
108285 +#define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map)
108286 +#define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status)
108287 +
108288 +static inline const char *get_tree_code_name(enum tree_code code)
108289 +{
108290 + gcc_assert(code < MAX_TREE_CODES);
108291 + return tree_code_name[code];
108292 +}
108293 +
108294 +#define ipa_remove_stmt_references(cnode, stmt)
108295 +#endif
108296 +
108297 +#if BUILDING_GCC_VERSION == 4008
108298 +#define NODE_DECL(node) node->symbol.decl
108299 +#else
108300 +#define NODE_DECL(node) node->decl
108301 +#endif
108302 +
108303 +#if BUILDING_GCC_VERSION >= 4008
108304 +#define add_referenced_var(var)
108305 +#define mark_sym_for_renaming(var)
108306 +#define varpool_mark_needed_node(node)
108307 +#define TODO_dump_func 0
108308 +#define TODO_dump_cgraph 0
108309 +#endif
108310 +
108311 +#if BUILDING_GCC_VERSION >= 4009
108312 +#define TODO_ggc_collect 0
108313 +#endif
108314 +
108315 +#endif
108316 diff --git a/tools/gcc/gen-random-seed.sh b/tools/gcc/gen-random-seed.sh
108317 new file mode 100644
108318 index 0000000..7514850
108319 --- /dev/null
108320 +++ b/tools/gcc/gen-random-seed.sh
108321 @@ -0,0 +1,8 @@
108322 +#!/bin/sh
108323 +
108324 +if [ ! -f "$1" ]; then
108325 + SEED=`od -A n -t x8 -N 32 /dev/urandom | tr -d ' \n'`
108326 + echo "const char *randstruct_seed = \"$SEED\";" > "$1"
108327 + HASH=`echo -n "$SEED" | sha256sum | cut -d" " -f1 | tr -d ' \n'`
108328 + echo "#define RANDSTRUCT_HASHED_SEED \"$HASH\"" > "$2"
108329 +fi
108330 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
108331 new file mode 100644
108332 index 0000000..d81c094
108333 --- /dev/null
108334 +++ b/tools/gcc/kallocstat_plugin.c
108335 @@ -0,0 +1,183 @@
108336 +/*
108337 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
108338 + * Licensed under the GPL v2
108339 + *
108340 + * Note: the choice of the license means that the compilation process is
108341 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
108342 + * but for the kernel it doesn't matter since it doesn't link against
108343 + * any of the gcc libraries
108344 + *
108345 + * gcc plugin to find the distribution of k*alloc sizes
108346 + *
108347 + * TODO:
108348 + *
108349 + * BUGS:
108350 + * - none known
108351 + */
108352 +
108353 +#include "gcc-common.h"
108354 +
108355 +int plugin_is_GPL_compatible;
108356 +
108357 +static struct plugin_info kallocstat_plugin_info = {
108358 + .version = "201401260140",
108359 + .help = NULL
108360 +};
108361 +
108362 +static const char * const kalloc_functions[] = {
108363 + "__kmalloc",
108364 + "kmalloc",
108365 + "kmalloc_large",
108366 + "kmalloc_node",
108367 + "kmalloc_order",
108368 + "kmalloc_order_trace",
108369 + "kmalloc_slab",
108370 + "kzalloc",
108371 + "kzalloc_node",
108372 +};
108373 +
108374 +static bool is_kalloc(const char *fnname)
108375 +{
108376 + size_t i;
108377 +
108378 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
108379 + if (!strcmp(fnname, kalloc_functions[i]))
108380 + return true;
108381 + return false;
108382 +}
108383 +
108384 +static unsigned int execute_kallocstat(void)
108385 +{
108386 + basic_block bb;
108387 +
108388 + // 1. loop through BBs and GIMPLE statements
108389 + FOR_EACH_BB_FN(bb, cfun) {
108390 + gimple_stmt_iterator gsi;
108391 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
108392 + // gimple match:
108393 + tree fndecl, size;
108394 + gimple stmt;
108395 + const char *fnname;
108396 +
108397 + // is it a call
108398 + stmt = gsi_stmt(gsi);
108399 + if (!is_gimple_call(stmt))
108400 + continue;
108401 + fndecl = gimple_call_fndecl(stmt);
108402 + if (fndecl == NULL_TREE)
108403 + continue;
108404 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
108405 + continue;
108406 +
108407 + // is it a call to k*alloc
108408 + fnname = DECL_NAME_POINTER(fndecl);
108409 + if (!is_kalloc(fnname))
108410 + continue;
108411 +
108412 + // is the size arg const or the result of a simple const assignment
108413 + size = gimple_call_arg(stmt, 0);
108414 + while (true) {
108415 + expanded_location xloc;
108416 + size_t size_val;
108417 +
108418 + if (TREE_CONSTANT(size)) {
108419 + xloc = expand_location(gimple_location(stmt));
108420 + if (!xloc.file)
108421 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
108422 + size_val = TREE_INT_CST_LOW(size);
108423 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
108424 + break;
108425 + }
108426 +
108427 + if (TREE_CODE(size) != SSA_NAME)
108428 + break;
108429 + stmt = SSA_NAME_DEF_STMT(size);
108430 +//debug_gimple_stmt(stmt);
108431 +//debug_tree(size);
108432 + if (!stmt || !is_gimple_assign(stmt))
108433 + break;
108434 + if (gimple_num_ops(stmt) != 2)
108435 + break;
108436 + size = gimple_assign_rhs1(stmt);
108437 + }
108438 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
108439 +//debug_tree(gimple_call_fn(call_stmt));
108440 +//print_node(stderr, "pax", fndecl, 4);
108441 + }
108442 + }
108443 +
108444 + return 0;
108445 +}
108446 +
108447 +#if BUILDING_GCC_VERSION >= 4009
108448 +static const struct pass_data kallocstat_pass_data = {
108449 +#else
108450 +static struct gimple_opt_pass kallocstat_pass = {
108451 + .pass = {
108452 +#endif
108453 + .type = GIMPLE_PASS,
108454 + .name = "kallocstat",
108455 +#if BUILDING_GCC_VERSION >= 4008
108456 + .optinfo_flags = OPTGROUP_NONE,
108457 +#endif
108458 +#if BUILDING_GCC_VERSION >= 4009
108459 + .has_gate = false,
108460 + .has_execute = true,
108461 +#else
108462 + .gate = NULL,
108463 + .execute = execute_kallocstat,
108464 + .sub = NULL,
108465 + .next = NULL,
108466 + .static_pass_number = 0,
108467 +#endif
108468 + .tv_id = TV_NONE,
108469 + .properties_required = 0,
108470 + .properties_provided = 0,
108471 + .properties_destroyed = 0,
108472 + .todo_flags_start = 0,
108473 + .todo_flags_finish = 0
108474 +#if BUILDING_GCC_VERSION < 4009
108475 + }
108476 +#endif
108477 +};
108478 +
108479 +#if BUILDING_GCC_VERSION >= 4009
108480 +namespace {
108481 +class kallocstat_pass : public gimple_opt_pass {
108482 +public:
108483 + kallocstat_pass() : gimple_opt_pass(kallocstat_pass_data, g) {}
108484 + unsigned int execute() { return execute_kallocstat(); }
108485 +};
108486 +}
108487 +
108488 +static opt_pass *make_kallocstat_pass(void)
108489 +{
108490 + return new kallocstat_pass();
108491 +}
108492 +#else
108493 +static struct opt_pass *make_kallocstat_pass(void)
108494 +{
108495 + return &kallocstat_pass.pass;
108496 +}
108497 +#endif
108498 +
108499 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
108500 +{
108501 + const char * const plugin_name = plugin_info->base_name;
108502 + struct register_pass_info kallocstat_pass_info;
108503 +
108504 + kallocstat_pass_info.pass = make_kallocstat_pass();
108505 + kallocstat_pass_info.reference_pass_name = "ssa";
108506 + kallocstat_pass_info.ref_pass_instance_number = 1;
108507 + kallocstat_pass_info.pos_op = PASS_POS_INSERT_AFTER;
108508 +
108509 + if (!plugin_default_version_check(version, &gcc_version)) {
108510 + error(G_("incompatible gcc/plugin versions"));
108511 + return 1;
108512 + }
108513 +
108514 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
108515 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
108516 +
108517 + return 0;
108518 +}
108519 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
108520 new file mode 100644
108521 index 0000000..89f256d
108522 --- /dev/null
108523 +++ b/tools/gcc/kernexec_plugin.c
108524 @@ -0,0 +1,522 @@
108525 +/*
108526 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
108527 + * Licensed under the GPL v2
108528 + *
108529 + * Note: the choice of the license means that the compilation process is
108530 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
108531 + * but for the kernel it doesn't matter since it doesn't link against
108532 + * any of the gcc libraries
108533 + *
108534 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
108535 + *
108536 + * TODO:
108537 + *
108538 + * BUGS:
108539 + * - none known
108540 + */
108541 +
108542 +#include "gcc-common.h"
108543 +
108544 +int plugin_is_GPL_compatible;
108545 +
108546 +static struct plugin_info kernexec_plugin_info = {
108547 + .version = "201401260140",
108548 + .help = "method=[bts|or]\tinstrumentation method\n"
108549 +};
108550 +
108551 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
108552 +static void (*kernexec_instrument_retaddr)(rtx);
108553 +
108554 +/*
108555 + * add special KERNEXEC instrumentation: reload %r12 after it has been clobbered
108556 + */
108557 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
108558 +{
108559 + gimple asm_movabs_stmt;
108560 +
108561 + // build asm volatile("movabs $0x8000000000000000, %%r12\n\t" : : : );
108562 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r12\n\t", NULL, NULL, NULL, NULL);
108563 + gimple_asm_set_volatile(asm_movabs_stmt, true);
108564 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
108565 + update_stmt(asm_movabs_stmt);
108566 +}
108567 +
108568 +/*
108569 + * find all asm() stmts that clobber r12 and add a reload of r12
108570 + */
108571 +static unsigned int execute_kernexec_reload(void)
108572 +{
108573 + basic_block bb;
108574 +
108575 + // 1. loop through BBs and GIMPLE statements
108576 + FOR_EACH_BB_FN(bb, cfun) {
108577 + gimple_stmt_iterator gsi;
108578 +
108579 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
108580 + // gimple match: __asm__ ("" : : : "r12");
108581 + gimple asm_stmt;
108582 + size_t nclobbers;
108583 +
108584 + // is it an asm ...
108585 + asm_stmt = gsi_stmt(gsi);
108586 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
108587 + continue;
108588 +
108589 + // ... clobbering r12
108590 + nclobbers = gimple_asm_nclobbers(asm_stmt);
108591 + while (nclobbers--) {
108592 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
108593 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r12"))
108594 + continue;
108595 + kernexec_reload_fptr_mask(&gsi);
108596 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
108597 + break;
108598 + }
108599 + }
108600 + }
108601 +
108602 + return 0;
108603 +}
108604 +
108605 +/*
108606 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
108607 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
108608 + */
108609 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
108610 +{
108611 + gimple assign_intptr, assign_new_fptr, call_stmt;
108612 + tree intptr, orptr, old_fptr, new_fptr, kernexec_mask;
108613 +
108614 + call_stmt = gsi_stmt(*gsi);
108615 + old_fptr = gimple_call_fn(call_stmt);
108616 +
108617 + // create temporary unsigned long variable used for bitops and cast fptr to it
108618 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
108619 + add_referenced_var(intptr);
108620 + intptr = make_ssa_name(intptr, NULL);
108621 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
108622 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
108623 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
108624 + update_stmt(assign_intptr);
108625 +
108626 + // apply logical or to temporary unsigned long and bitmask
108627 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
108628 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
108629 + orptr = fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask);
108630 + intptr = make_ssa_name(SSA_NAME_VAR(intptr), NULL);
108631 + assign_intptr = gimple_build_assign(intptr, orptr);
108632 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
108633 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
108634 + update_stmt(assign_intptr);
108635 +
108636 + // cast temporary unsigned long back to a temporary fptr variable
108637 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
108638 + add_referenced_var(new_fptr);
108639 + new_fptr = make_ssa_name(new_fptr, NULL);
108640 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
108641 + SSA_NAME_DEF_STMT(new_fptr) = assign_new_fptr;
108642 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
108643 + update_stmt(assign_new_fptr);
108644 +
108645 + // replace call stmt fn with the new fptr
108646 + gimple_call_set_fn(call_stmt, new_fptr);
108647 + update_stmt(call_stmt);
108648 +}
108649 +
108650 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
108651 +{
108652 + gimple asm_or_stmt, call_stmt;
108653 + tree old_fptr, new_fptr, input, output;
108654 +#if BUILDING_GCC_VERSION <= 4007
108655 + VEC(tree, gc) *inputs = NULL;
108656 + VEC(tree, gc) *outputs = NULL;
108657 +#else
108658 + vec<tree, va_gc> *inputs = NULL;
108659 + vec<tree, va_gc> *outputs = NULL;
108660 +#endif
108661 +
108662 + call_stmt = gsi_stmt(*gsi);
108663 + old_fptr = gimple_call_fn(call_stmt);
108664 +
108665 + // create temporary fptr variable
108666 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
108667 + add_referenced_var(new_fptr);
108668 + new_fptr = make_ssa_name(new_fptr, NULL);
108669 +
108670 + // build asm volatile("orq %%r12, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
108671 + input = build_tree_list(NULL_TREE, build_string(1, "0"));
108672 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
108673 + output = build_tree_list(NULL_TREE, build_string(2, "=r"));
108674 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
108675 +#if BUILDING_GCC_VERSION <= 4007
108676 + VEC_safe_push(tree, gc, inputs, input);
108677 + VEC_safe_push(tree, gc, outputs, output);
108678 +#else
108679 + vec_safe_push(inputs, input);
108680 + vec_safe_push(outputs, output);
108681 +#endif
108682 + asm_or_stmt = gimple_build_asm_vec("orq %%r12, %0\n\t", inputs, outputs, NULL, NULL);
108683 + SSA_NAME_DEF_STMT(new_fptr) = asm_or_stmt;
108684 + gimple_asm_set_volatile(asm_or_stmt, true);
108685 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
108686 + update_stmt(asm_or_stmt);
108687 +
108688 + // replace call stmt fn with the new fptr
108689 + gimple_call_set_fn(call_stmt, new_fptr);
108690 + update_stmt(call_stmt);
108691 +}
108692 +
108693 +/*
108694 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
108695 + */
108696 +static unsigned int execute_kernexec_fptr(void)
108697 +{
108698 + basic_block bb;
108699 +
108700 + // 1. loop through BBs and GIMPLE statements
108701 + FOR_EACH_BB_FN(bb, cfun) {
108702 + gimple_stmt_iterator gsi;
108703 +
108704 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
108705 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
108706 + tree fn;
108707 + gimple call_stmt;
108708 +
108709 + // is it a call ...
108710 + call_stmt = gsi_stmt(gsi);
108711 + if (!is_gimple_call(call_stmt))
108712 + continue;
108713 + fn = gimple_call_fn(call_stmt);
108714 + if (TREE_CODE(fn) == ADDR_EXPR)
108715 + continue;
108716 + if (TREE_CODE(fn) != SSA_NAME)
108717 + gcc_unreachable();
108718 +
108719 + // ... through a function pointer
108720 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
108721 + fn = SSA_NAME_VAR(fn);
108722 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
108723 + debug_tree(fn);
108724 + gcc_unreachable();
108725 + }
108726 + }
108727 + fn = TREE_TYPE(fn);
108728 + if (TREE_CODE(fn) != POINTER_TYPE)
108729 + continue;
108730 + fn = TREE_TYPE(fn);
108731 + if (TREE_CODE(fn) != FUNCTION_TYPE)
108732 + continue;
108733 +
108734 + kernexec_instrument_fptr(&gsi);
108735 +
108736 +//debug_tree(gimple_call_fn(call_stmt));
108737 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
108738 + }
108739 + }
108740 +
108741 + return 0;
108742 +}
108743 +
108744 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
108745 +static void kernexec_instrument_retaddr_bts(rtx insn)
108746 +{
108747 + rtx btsq;
108748 + rtvec argvec, constraintvec, labelvec;
108749 + int line;
108750 +
108751 + // create asm volatile("btsq $63,(%%rsp)":::)
108752 + argvec = rtvec_alloc(0);
108753 + constraintvec = rtvec_alloc(0);
108754 + labelvec = rtvec_alloc(0);
108755 + line = expand_location(RTL_LOCATION(insn)).line;
108756 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
108757 + MEM_VOLATILE_P(btsq) = 1;
108758 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
108759 + emit_insn_before(btsq, insn);
108760 +}
108761 +
108762 +// add special KERNEXEC instrumentation: orq %r12,(%rsp) just before retn
108763 +static void kernexec_instrument_retaddr_or(rtx insn)
108764 +{
108765 + rtx orq;
108766 + rtvec argvec, constraintvec, labelvec;
108767 + int line;
108768 +
108769 + // create asm volatile("orq %%r12,(%%rsp)":::)
108770 + argvec = rtvec_alloc(0);
108771 + constraintvec = rtvec_alloc(0);
108772 + labelvec = rtvec_alloc(0);
108773 + line = expand_location(RTL_LOCATION(insn)).line;
108774 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r12,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
108775 + MEM_VOLATILE_P(orq) = 1;
108776 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
108777 + emit_insn_before(orq, insn);
108778 +}
108779 +
108780 +/*
108781 + * find all asm level function returns and forcibly set the highest bit of the return address
108782 + */
108783 +static unsigned int execute_kernexec_retaddr(void)
108784 +{
108785 + rtx insn;
108786 +
108787 +// if (stack_realign_drap)
108788 +// inform(DECL_SOURCE_LOCATION(current_function_decl), "drap detected in %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
108789 +
108790 + // 1. find function returns
108791 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
108792 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
108793 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
108794 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
108795 + rtx body;
108796 +
108797 + // is it a retn
108798 + if (!JUMP_P(insn))
108799 + continue;
108800 + body = PATTERN(insn);
108801 + if (GET_CODE(body) == PARALLEL)
108802 + body = XVECEXP(body, 0, 0);
108803 + if (!ANY_RETURN_P(body))
108804 + continue;
108805 + kernexec_instrument_retaddr(insn);
108806 + }
108807 +
108808 +// print_simple_rtl(stderr, get_insns());
108809 +// print_rtl(stderr, get_insns());
108810 +
108811 + return 0;
108812 +}
108813 +
108814 +static bool kernexec_cmodel_check(void)
108815 +{
108816 + tree section;
108817 +
108818 + if (ix86_cmodel != CM_KERNEL)
108819 + return false;
108820 +
108821 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
108822 + if (!section || !TREE_VALUE(section))
108823 + return true;
108824 +
108825 + section = TREE_VALUE(TREE_VALUE(section));
108826 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
108827 + return true;
108828 +
108829 + return false;
108830 +}
108831 +
108832 +#if BUILDING_GCC_VERSION >= 4009
108833 +static const struct pass_data kernexec_reload_pass_data = {
108834 +#else
108835 +static struct gimple_opt_pass kernexec_reload_pass = {
108836 + .pass = {
108837 +#endif
108838 + .type = GIMPLE_PASS,
108839 + .name = "kernexec_reload",
108840 +#if BUILDING_GCC_VERSION >= 4008
108841 + .optinfo_flags = OPTGROUP_NONE,
108842 +#endif
108843 +#if BUILDING_GCC_VERSION >= 4009
108844 + .has_gate = true,
108845 + .has_execute = true,
108846 +#else
108847 + .gate = kernexec_cmodel_check,
108848 + .execute = execute_kernexec_reload,
108849 + .sub = NULL,
108850 + .next = NULL,
108851 + .static_pass_number = 0,
108852 +#endif
108853 + .tv_id = TV_NONE,
108854 + .properties_required = 0,
108855 + .properties_provided = 0,
108856 + .properties_destroyed = 0,
108857 + .todo_flags_start = 0,
108858 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
108859 +#if BUILDING_GCC_VERSION < 4009
108860 + }
108861 +#endif
108862 +};
108863 +
108864 +#if BUILDING_GCC_VERSION >= 4009
108865 +static const struct pass_data kernexec_fptr_pass_data = {
108866 +#else
108867 +static struct gimple_opt_pass kernexec_fptr_pass = {
108868 + .pass = {
108869 +#endif
108870 + .type = GIMPLE_PASS,
108871 + .name = "kernexec_fptr",
108872 +#if BUILDING_GCC_VERSION >= 4008
108873 + .optinfo_flags = OPTGROUP_NONE,
108874 +#endif
108875 +#if BUILDING_GCC_VERSION >= 4009
108876 + .has_gate = true,
108877 + .has_execute = true,
108878 +#else
108879 + .gate = kernexec_cmodel_check,
108880 + .execute = execute_kernexec_fptr,
108881 + .sub = NULL,
108882 + .next = NULL,
108883 + .static_pass_number = 0,
108884 +#endif
108885 + .tv_id = TV_NONE,
108886 + .properties_required = 0,
108887 + .properties_provided = 0,
108888 + .properties_destroyed = 0,
108889 + .todo_flags_start = 0,
108890 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
108891 +#if BUILDING_GCC_VERSION < 4009
108892 + }
108893 +#endif
108894 +};
108895 +
108896 +#if BUILDING_GCC_VERSION >= 4009
108897 +static const struct pass_data kernexec_retaddr_pass_data = {
108898 +#else
108899 +static struct rtl_opt_pass kernexec_retaddr_pass = {
108900 + .pass = {
108901 +#endif
108902 + .type = RTL_PASS,
108903 + .name = "kernexec_retaddr",
108904 +#if BUILDING_GCC_VERSION >= 4008
108905 + .optinfo_flags = OPTGROUP_NONE,
108906 +#endif
108907 +#if BUILDING_GCC_VERSION >= 4009
108908 + .has_gate = true,
108909 + .has_execute = true,
108910 +#else
108911 + .gate = kernexec_cmodel_check,
108912 + .execute = execute_kernexec_retaddr,
108913 + .sub = NULL,
108914 + .next = NULL,
108915 + .static_pass_number = 0,
108916 +#endif
108917 + .tv_id = TV_NONE,
108918 + .properties_required = 0,
108919 + .properties_provided = 0,
108920 + .properties_destroyed = 0,
108921 + .todo_flags_start = 0,
108922 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
108923 +#if BUILDING_GCC_VERSION < 4009
108924 + }
108925 +#endif
108926 +};
108927 +
108928 +#if BUILDING_GCC_VERSION >= 4009
108929 +namespace {
108930 +class kernexec_reload_pass : public gimple_opt_pass {
108931 +public:
108932 + kernexec_reload_pass() : gimple_opt_pass(kernexec_reload_pass_data, g) {}
108933 + bool gate() { return kernexec_cmodel_check(); }
108934 + unsigned int execute() { return execute_kernexec_reload(); }
108935 +};
108936 +
108937 +class kernexec_fptr_pass : public gimple_opt_pass {
108938 +public:
108939 + kernexec_fptr_pass() : gimple_opt_pass(kernexec_fptr_pass_data, g) {}
108940 + bool gate() { return kernexec_cmodel_check(); }
108941 + unsigned int execute() { return execute_kernexec_fptr(); }
108942 +};
108943 +
108944 +class kernexec_retaddr_pass : public rtl_opt_pass {
108945 +public:
108946 + kernexec_retaddr_pass() : rtl_opt_pass(kernexec_retaddr_pass_data, g) {}
108947 + bool gate() { return kernexec_cmodel_check(); }
108948 + unsigned int execute() { return execute_kernexec_retaddr(); }
108949 +};
108950 +}
108951 +
108952 +static opt_pass *make_kernexec_reload_pass(void)
108953 +{
108954 + return new kernexec_reload_pass();
108955 +}
108956 +
108957 +static opt_pass *make_kernexec_fptr_pass(void)
108958 +{
108959 + return new kernexec_fptr_pass();
108960 +}
108961 +
108962 +static opt_pass *make_kernexec_retaddr_pass(void)
108963 +{
108964 + return new kernexec_retaddr_pass();
108965 +}
108966 +#else
108967 +static struct opt_pass *make_kernexec_reload_pass(void)
108968 +{
108969 + return &kernexec_reload_pass.pass;
108970 +}
108971 +
108972 +static struct opt_pass *make_kernexec_fptr_pass(void)
108973 +{
108974 + return &kernexec_fptr_pass.pass;
108975 +}
108976 +
108977 +static struct opt_pass *make_kernexec_retaddr_pass(void)
108978 +{
108979 + return &kernexec_retaddr_pass.pass;
108980 +}
108981 +#endif
108982 +
108983 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
108984 +{
108985 + const char * const plugin_name = plugin_info->base_name;
108986 + const int argc = plugin_info->argc;
108987 + const struct plugin_argument * const argv = plugin_info->argv;
108988 + int i;
108989 + struct register_pass_info kernexec_reload_pass_info;
108990 + struct register_pass_info kernexec_fptr_pass_info;
108991 + struct register_pass_info kernexec_retaddr_pass_info;
108992 +
108993 + kernexec_reload_pass_info.pass = make_kernexec_reload_pass();
108994 + kernexec_reload_pass_info.reference_pass_name = "ssa";
108995 + kernexec_reload_pass_info.ref_pass_instance_number = 1;
108996 + kernexec_reload_pass_info.pos_op = PASS_POS_INSERT_AFTER;
108997 +
108998 + kernexec_fptr_pass_info.pass = make_kernexec_fptr_pass();
108999 + kernexec_fptr_pass_info.reference_pass_name = "ssa";
109000 + kernexec_fptr_pass_info.ref_pass_instance_number = 1;
109001 + kernexec_fptr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
109002 +
109003 + kernexec_retaddr_pass_info.pass = make_kernexec_retaddr_pass();
109004 + kernexec_retaddr_pass_info.reference_pass_name = "pro_and_epilogue";
109005 + kernexec_retaddr_pass_info.ref_pass_instance_number = 1;
109006 + kernexec_retaddr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
109007 +
109008 + if (!plugin_default_version_check(version, &gcc_version)) {
109009 + error(G_("incompatible gcc/plugin versions"));
109010 + return 1;
109011 + }
109012 +
109013 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
109014 +
109015 + if (TARGET_64BIT == 0)
109016 + return 0;
109017 +
109018 + for (i = 0; i < argc; ++i) {
109019 + if (!strcmp(argv[i].key, "method")) {
109020 + if (!argv[i].value) {
109021 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
109022 + continue;
109023 + }
109024 + if (!strcmp(argv[i].value, "bts")) {
109025 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
109026 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
109027 + } else if (!strcmp(argv[i].value, "or")) {
109028 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
109029 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
109030 + fix_register("r12", 1, 1);
109031 + } else
109032 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
109033 + continue;
109034 + }
109035 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
109036 + }
109037 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
109038 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
109039 +
109040 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
109041 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
109042 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
109043 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
109044 +
109045 + return 0;
109046 +}
109047 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
109048 new file mode 100644
109049 index 0000000..39d7cc7
109050 --- /dev/null
109051 +++ b/tools/gcc/latent_entropy_plugin.c
109052 @@ -0,0 +1,462 @@
109053 +/*
109054 + * Copyright 2012-2014 by the PaX Team <pageexec@freemail.hu>
109055 + * Licensed under the GPL v2
109056 + *
109057 + * Note: the choice of the license means that the compilation process is
109058 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
109059 + * but for the kernel it doesn't matter since it doesn't link against
109060 + * any of the gcc libraries
109061 + *
109062 + * gcc plugin to help generate a little bit of entropy from program state,
109063 + * used throughout the uptime of the kernel
109064 + *
109065 + * TODO:
109066 + * - add ipa pass to identify not explicitly marked candidate functions
109067 + * - mix in more program state (function arguments/return values, loop variables, etc)
109068 + * - more instrumentation control via attribute parameters
109069 + *
109070 + * BUGS:
109071 + * - LTO needs -flto-partition=none for now
109072 + */
109073 +
109074 +#include "gcc-common.h"
109075 +
109076 +int plugin_is_GPL_compatible;
109077 +
109078 +static tree latent_entropy_decl;
109079 +
109080 +static struct plugin_info latent_entropy_plugin_info = {
109081 + .version = "201403280150",
109082 + .help = NULL
109083 +};
109084 +
109085 +static unsigned HOST_WIDE_INT seed;
109086 +static unsigned HOST_WIDE_INT get_random_const(void)
109087 +{
109088 + unsigned int i;
109089 + unsigned HOST_WIDE_INT ret = 0;
109090 +
109091 + for (i = 0; i < 8 * sizeof ret; i++) {
109092 + ret = (ret << 1) | (seed & 1);
109093 + seed >>= 1;
109094 + if (ret & 1)
109095 + seed ^= 0xD800000000000000ULL;
109096 + }
109097 +
109098 + return ret;
109099 +}
109100 +
109101 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
109102 +{
109103 + tree type;
109104 + unsigned long long mask;
109105 +#if BUILDING_GCC_VERSION <= 4007
109106 + VEC(constructor_elt, gc) *vals;
109107 +#else
109108 + vec<constructor_elt, va_gc> *vals;
109109 +#endif
109110 +
109111 + switch (TREE_CODE(*node)) {
109112 + default:
109113 + *no_add_attrs = true;
109114 + error("%qE attribute only applies to functions and variables", name);
109115 + break;
109116 +
109117 + case VAR_DECL:
109118 + if (DECL_INITIAL(*node)) {
109119 + *no_add_attrs = true;
109120 + error("variable %qD with %qE attribute must not be initialized", *node, name);
109121 + break;
109122 + }
109123 +
109124 + if (!TREE_STATIC(*node)) {
109125 + *no_add_attrs = true;
109126 + error("variable %qD with %qE attribute must not be local", *node, name);
109127 + break;
109128 + }
109129 +
109130 + type = TREE_TYPE(*node);
109131 + switch (TREE_CODE(type)) {
109132 + default:
109133 + *no_add_attrs = true;
109134 + 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);
109135 + break;
109136 +
109137 + case RECORD_TYPE: {
109138 + tree field;
109139 + unsigned int nelt = 0;
109140 +
109141 + for (field = TYPE_FIELDS(type); field; nelt++, field = TREE_CHAIN(field)) {
109142 + tree fieldtype;
109143 +
109144 + fieldtype = TREE_TYPE(field);
109145 + if (TREE_CODE(fieldtype) != INTEGER_TYPE) {
109146 + *no_add_attrs = true;
109147 + error("structure variable %qD with %qE attribute has a non-integer field %qE", *node, name, field);
109148 + break;
109149 + }
109150 + }
109151 +
109152 + if (field)
109153 + break;
109154 +
109155 +#if BUILDING_GCC_VERSION <= 4007
109156 + vals = VEC_alloc(constructor_elt, gc, nelt);
109157 +#else
109158 + vec_alloc(vals, nelt);
109159 +#endif
109160 +
109161 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
109162 + tree fieldtype;
109163 +
109164 + fieldtype = TREE_TYPE(field);
109165 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(fieldtype)) - 1);
109166 + mask = 2 * (mask - 1) + 1;
109167 +
109168 + if (TYPE_UNSIGNED(fieldtype))
109169 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cstu(fieldtype, mask & get_random_const()));
109170 + else
109171 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cst(fieldtype, mask & get_random_const()));
109172 + }
109173 +
109174 + DECL_INITIAL(*node) = build_constructor(type, vals);
109175 +//debug_tree(DECL_INITIAL(*node));
109176 + break;
109177 + }
109178 +
109179 + case INTEGER_TYPE:
109180 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(type)) - 1);
109181 + mask = 2 * (mask - 1) + 1;
109182 +
109183 + if (TYPE_UNSIGNED(type))
109184 + DECL_INITIAL(*node) = build_int_cstu(type, mask & get_random_const());
109185 + else
109186 + DECL_INITIAL(*node) = build_int_cst(type, mask & get_random_const());
109187 + break;
109188 +
109189 + case ARRAY_TYPE: {
109190 + tree elt_type, array_size, elt_size;
109191 + unsigned int i, nelt;
109192 +
109193 + elt_type = TREE_TYPE(type);
109194 + elt_size = TYPE_SIZE_UNIT(TREE_TYPE(type));
109195 + array_size = TYPE_SIZE_UNIT(type);
109196 +
109197 + if (TREE_CODE(elt_type) != INTEGER_TYPE || !array_size || TREE_CODE(array_size) != INTEGER_CST) {
109198 + *no_add_attrs = true;
109199 + error("array variable %qD with %qE attribute must be a fixed length integer array type", *node, name);
109200 + break;
109201 + }
109202 +
109203 + nelt = TREE_INT_CST_LOW(array_size) / TREE_INT_CST_LOW(elt_size);
109204 +#if BUILDING_GCC_VERSION <= 4007
109205 + vals = VEC_alloc(constructor_elt, gc, nelt);
109206 +#else
109207 + vec_alloc(vals, nelt);
109208 +#endif
109209 +
109210 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(elt_type)) - 1);
109211 + mask = 2 * (mask - 1) + 1;
109212 +
109213 + for (i = 0; i < nelt; i++)
109214 + if (TYPE_UNSIGNED(elt_type))
109215 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cstu(elt_type, mask & get_random_const()));
109216 + else
109217 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cst(elt_type, mask & get_random_const()));
109218 +
109219 + DECL_INITIAL(*node) = build_constructor(type, vals);
109220 +//debug_tree(DECL_INITIAL(*node));
109221 + break;
109222 + }
109223 + }
109224 + break;
109225 +
109226 + case FUNCTION_DECL:
109227 + break;
109228 + }
109229 +
109230 + return NULL_TREE;
109231 +}
109232 +
109233 +static struct attribute_spec latent_entropy_attr = {
109234 + .name = "latent_entropy",
109235 + .min_length = 0,
109236 + .max_length = 0,
109237 + .decl_required = true,
109238 + .type_required = false,
109239 + .function_type_required = false,
109240 + .handler = handle_latent_entropy_attribute,
109241 +#if BUILDING_GCC_VERSION >= 4007
109242 + .affects_type_identity = false
109243 +#endif
109244 +};
109245 +
109246 +static void register_attributes(void *event_data, void *data)
109247 +{
109248 + register_attribute(&latent_entropy_attr);
109249 +}
109250 +
109251 +static bool gate_latent_entropy(void)
109252 +{
109253 + // don't bother with noreturn functions for now
109254 + if (TREE_THIS_VOLATILE(current_function_decl))
109255 + return false;
109256 +
109257 + return lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl)) != NULL_TREE;
109258 +}
109259 +
109260 +static enum tree_code get_op(tree *rhs)
109261 +{
109262 + static enum tree_code op;
109263 + unsigned HOST_WIDE_INT random_const;
109264 +
109265 + random_const = get_random_const();
109266 +
109267 + switch (op) {
109268 + case BIT_XOR_EXPR:
109269 + op = PLUS_EXPR;
109270 + break;
109271 +
109272 + case PLUS_EXPR:
109273 + if (rhs) {
109274 + op = LROTATE_EXPR;
109275 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
109276 + break;
109277 + }
109278 +
109279 + case LROTATE_EXPR:
109280 + default:
109281 + op = BIT_XOR_EXPR;
109282 + break;
109283 + }
109284 + if (rhs)
109285 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
109286 + return op;
109287 +}
109288 +
109289 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
109290 +{
109291 + gimple_stmt_iterator gsi;
109292 + gimple assign;
109293 + tree addxorrol, rhs;
109294 + enum tree_code op;
109295 +
109296 + op = get_op(&rhs);
109297 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
109298 + assign = gimple_build_assign(local_entropy, addxorrol);
109299 + gsi = gsi_after_labels(bb);
109300 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
109301 + update_stmt(assign);
109302 +//debug_bb(bb);
109303 +}
109304 +
109305 +static void perturb_latent_entropy(basic_block bb, tree rhs)
109306 +{
109307 + gimple_stmt_iterator gsi;
109308 + gimple assign;
109309 + tree addxorrol, temp;
109310 +
109311 + // 1. create temporary copy of latent_entropy
109312 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
109313 + add_referenced_var(temp);
109314 +
109315 + // 2. read...
109316 + temp = make_ssa_name(temp, NULL);
109317 + assign = gimple_build_assign(temp, latent_entropy_decl);
109318 + SSA_NAME_DEF_STMT(temp) = assign;
109319 + add_referenced_var(latent_entropy_decl);
109320 + gsi = gsi_after_labels(bb);
109321 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
109322 + update_stmt(assign);
109323 +
109324 + // 3. ...modify...
109325 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
109326 + temp = make_ssa_name(SSA_NAME_VAR(temp), NULL);
109327 + assign = gimple_build_assign(temp, addxorrol);
109328 + SSA_NAME_DEF_STMT(temp) = assign;
109329 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
109330 + update_stmt(assign);
109331 +
109332 + // 4. ...write latent_entropy
109333 + assign = gimple_build_assign(latent_entropy_decl, temp);
109334 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
109335 + update_stmt(assign);
109336 +}
109337 +
109338 +static unsigned int execute_latent_entropy(void)
109339 +{
109340 + basic_block bb;
109341 + gimple assign;
109342 + gimple_stmt_iterator gsi;
109343 + tree local_entropy;
109344 +
109345 + if (!latent_entropy_decl) {
109346 +#if BUILDING_GCC_VERSION >= 4009
109347 + varpool_node *node;
109348 +#else
109349 + struct varpool_node *node;
109350 +#endif
109351 +
109352 + FOR_EACH_VARIABLE(node) {
109353 + tree var = NODE_DECL(node);
109354 +
109355 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
109356 + continue;
109357 + latent_entropy_decl = var;
109358 +// debug_tree(var);
109359 + break;
109360 + }
109361 + if (!latent_entropy_decl) {
109362 +// debug_tree(current_function_decl);
109363 + return 0;
109364 + }
109365 + }
109366 +
109367 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
109368 +
109369 + // 1. create local entropy variable
109370 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
109371 + add_referenced_var(local_entropy);
109372 + mark_sym_for_renaming(local_entropy);
109373 +
109374 + // 2. initialize local entropy variable
109375 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
109376 + if (dom_info_available_p(CDI_DOMINATORS))
109377 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
109378 + gsi = gsi_start_bb(bb);
109379 +
109380 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
109381 +// gimple_set_location(assign, loc);
109382 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
109383 + update_stmt(assign);
109384 +//debug_bb(bb);
109385 + gcc_assert(single_succ_p(bb));
109386 + bb = single_succ(bb);
109387 +
109388 + // 3. instrument each BB with an operation on the local entropy variable
109389 + while (bb != EXIT_BLOCK_PTR_FOR_FN(cfun)) {
109390 + perturb_local_entropy(bb, local_entropy);
109391 +//debug_bb(bb);
109392 + bb = bb->next_bb;
109393 + };
109394 +
109395 + // 4. mix local entropy into the global entropy variable
109396 + gcc_assert(single_pred_p(EXIT_BLOCK_PTR_FOR_FN(cfun)));
109397 + perturb_latent_entropy(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)), local_entropy);
109398 +//debug_bb(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)));
109399 + return 0;
109400 +}
109401 +
109402 +static void latent_entropy_start_unit(void *gcc_data, void *user_data)
109403 +{
109404 + tree latent_entropy_type;
109405 +
109406 + seed = get_random_seed(false);
109407 +
109408 + if (in_lto_p)
109409 + return;
109410 +
109411 + // extern volatile u64 latent_entropy
109412 + gcc_assert(TYPE_PRECISION(long_long_unsigned_type_node) == 64);
109413 + latent_entropy_type = build_qualified_type(long_long_unsigned_type_node, TYPE_QUALS(long_long_unsigned_type_node) | TYPE_QUAL_VOLATILE);
109414 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), latent_entropy_type);
109415 +
109416 + TREE_STATIC(latent_entropy_decl) = 1;
109417 + TREE_PUBLIC(latent_entropy_decl) = 1;
109418 + TREE_USED(latent_entropy_decl) = 1;
109419 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
109420 + DECL_EXTERNAL(latent_entropy_decl) = 1;
109421 + DECL_ARTIFICIAL(latent_entropy_decl) = 1;
109422 + lang_hooks.decls.pushdecl(latent_entropy_decl);
109423 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
109424 +// varpool_finalize_decl(latent_entropy_decl);
109425 +// varpool_mark_needed_node(latent_entropy_decl);
109426 +}
109427 +
109428 +#if BUILDING_GCC_VERSION >= 4009
109429 +static const struct pass_data latent_entropy_pass_data = {
109430 +#else
109431 +static struct gimple_opt_pass latent_entropy_pass = {
109432 + .pass = {
109433 +#endif
109434 + .type = GIMPLE_PASS,
109435 + .name = "latent_entropy",
109436 +#if BUILDING_GCC_VERSION >= 4008
109437 + .optinfo_flags = OPTGROUP_NONE,
109438 +#endif
109439 +#if BUILDING_GCC_VERSION >= 4009
109440 + .has_gate = true,
109441 + .has_execute = true,
109442 +#else
109443 + .gate = gate_latent_entropy,
109444 + .execute = execute_latent_entropy,
109445 + .sub = NULL,
109446 + .next = NULL,
109447 + .static_pass_number = 0,
109448 +#endif
109449 + .tv_id = TV_NONE,
109450 + .properties_required = PROP_gimple_leh | PROP_cfg,
109451 + .properties_provided = 0,
109452 + .properties_destroyed = 0,
109453 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
109454 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
109455 +#if BUILDING_GCC_VERSION < 4009
109456 + }
109457 +#endif
109458 +};
109459 +
109460 +#if BUILDING_GCC_VERSION >= 4009
109461 +namespace {
109462 +class latent_entropy_pass : public gimple_opt_pass {
109463 +public:
109464 + latent_entropy_pass() : gimple_opt_pass(latent_entropy_pass_data, g) {}
109465 + bool gate() { return gate_latent_entropy(); }
109466 + unsigned int execute() { return execute_latent_entropy(); }
109467 +};
109468 +}
109469 +
109470 +static opt_pass *make_latent_entropy_pass(void)
109471 +{
109472 + return new latent_entropy_pass();
109473 +}
109474 +#else
109475 +static struct opt_pass *make_latent_entropy_pass(void)
109476 +{
109477 + return &latent_entropy_pass.pass;
109478 +}
109479 +#endif
109480 +
109481 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
109482 +{
109483 + const char * const plugin_name = plugin_info->base_name;
109484 + struct register_pass_info latent_entropy_pass_info;
109485 +
109486 + latent_entropy_pass_info.pass = make_latent_entropy_pass();
109487 + latent_entropy_pass_info.reference_pass_name = "optimized";
109488 + latent_entropy_pass_info.ref_pass_instance_number = 1;
109489 + latent_entropy_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
109490 + static const struct ggc_root_tab gt_ggc_r_gt_latent_entropy[] = {
109491 + {
109492 + .base = &latent_entropy_decl,
109493 + .nelt = 1,
109494 + .stride = sizeof(latent_entropy_decl),
109495 + .cb = &gt_ggc_mx_tree_node,
109496 + .pchw = &gt_pch_nx_tree_node
109497 + },
109498 + LAST_GGC_ROOT_TAB
109499 + };
109500 +
109501 + if (!plugin_default_version_check(version, &gcc_version)) {
109502 + error(G_("incompatible gcc/plugin versions"));
109503 + return 1;
109504 + }
109505 +
109506 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
109507 + register_callback(plugin_name, PLUGIN_START_UNIT, &latent_entropy_start_unit, NULL);
109508 + if (!in_lto_p)
109509 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_latent_entropy);
109510 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
109511 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
109512 +
109513 + return 0;
109514 +}
109515 diff --git a/tools/gcc/randomize_layout_plugin.c b/tools/gcc/randomize_layout_plugin.c
109516 new file mode 100644
109517 index 0000000..a5cb46b
109518 --- /dev/null
109519 +++ b/tools/gcc/randomize_layout_plugin.c
109520 @@ -0,0 +1,915 @@
109521 +/*
109522 + * Copyright 2014 by Open Source Security, Inc., Brad Spengler <spender@grsecurity.net>
109523 + * and PaX Team <pageexec@freemail.hu>
109524 + * Licensed under the GPL v2
109525 + *
109526 + * Usage:
109527 + * $ # for 4.5/4.6/C based 4.7
109528 + * $ 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
109529 + * $ # for C++ based 4.7/4.8+
109530 + * $ 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
109531 + * $ gcc -fplugin=./randomize_layout_plugin.so test.c -O2
109532 + */
109533 +
109534 +#include "gcc-common.h"
109535 +#include "randomize_layout_seed.h"
109536 +
109537 +#if BUILDING_GCC_MAJOR < 4 || BUILDING_GCC_MINOR < 6 || (BUILDING_GCC_MINOR == 6 && BUILDING_GCC_PATCHLEVEL < 4)
109538 +#error "The RANDSTRUCT plugin requires GCC 4.6.4 or newer."
109539 +#endif
109540 +
109541 +#define ORIG_TYPE_NAME(node) \
109542 + (TYPE_NAME(TYPE_MAIN_VARIANT(node)) != NULL_TREE ? ((const unsigned char *)IDENTIFIER_POINTER(TYPE_NAME(TYPE_MAIN_VARIANT(node)))) : (const unsigned char *)"anonymous")
109543 +
109544 +int plugin_is_GPL_compatible;
109545 +
109546 +static int performance_mode;
109547 +
109548 +static struct plugin_info randomize_layout_plugin_info = {
109549 + .version = "201402201816",
109550 + .help = "disable\t\t\tdo not activate plugin\n"
109551 + "performance-mode\tenable cacheline-aware layout randomization\n"
109552 +};
109553 +
109554 +/* from old Linux dcache.h */
109555 +static inline unsigned long
109556 +partial_name_hash(unsigned long c, unsigned long prevhash)
109557 +{
109558 + return (prevhash + (c << 4) + (c >> 4)) * 11;
109559 +}
109560 +static inline unsigned int
109561 +name_hash(const unsigned char *name)
109562 +{
109563 + unsigned long hash = 0;
109564 + unsigned int len = strlen((const char *)name);
109565 + while (len--)
109566 + hash = partial_name_hash(*name++, hash);
109567 + return (unsigned int)hash;
109568 +}
109569 +
109570 +static tree handle_randomize_layout_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
109571 +{
109572 + tree type;
109573 +
109574 + *no_add_attrs = true;
109575 + if (TREE_CODE(*node) == FUNCTION_DECL) {
109576 + error("%qE attribute does not apply to functions (%qF)", name, *node);
109577 + return NULL_TREE;
109578 + }
109579 +
109580 + if (TREE_CODE(*node) == PARM_DECL) {
109581 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
109582 + return NULL_TREE;
109583 + }
109584 +
109585 + if (TREE_CODE(*node) == VAR_DECL) {
109586 + error("%qE attribute does not apply to variables (%qD)", name, *node);
109587 + return NULL_TREE;
109588 + }
109589 +
109590 + if (TYPE_P(*node)) {
109591 + type = *node;
109592 + } else {
109593 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
109594 + type = TREE_TYPE(*node);
109595 + }
109596 +
109597 + if (TREE_CODE(type) != RECORD_TYPE) {
109598 + error("%qE attribute used on %qT applies to struct types only", name, type);
109599 + return NULL_TREE;
109600 + }
109601 +
109602 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
109603 + error("%qE attribute is already applied to the type %qT", name, type);
109604 + return NULL_TREE;
109605 + }
109606 +
109607 + *no_add_attrs = false;
109608 +
109609 + return NULL_TREE;
109610 +}
109611 +
109612 +/* set on complete types that we don't need to inspect further at all */
109613 +static tree handle_randomize_considered_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
109614 +{
109615 + *no_add_attrs = false;
109616 + return NULL_TREE;
109617 +}
109618 +
109619 +/*
109620 + * set on types that we've performed a shuffle on, to prevent re-shuffling
109621 + * this does not preclude us from inspecting its fields for potential shuffles
109622 + */
109623 +static tree handle_randomize_performed_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
109624 +{
109625 + *no_add_attrs = false;
109626 + return NULL_TREE;
109627 +}
109628 +
109629 +/*
109630 + * 64bit variant of Bob Jenkins' public domain PRNG
109631 + * 256 bits of internal state
109632 + */
109633 +
109634 +typedef unsigned long long u64;
109635 +
109636 +typedef struct ranctx { u64 a; u64 b; u64 c; u64 d; } ranctx;
109637 +
109638 +#define rot(x,k) (((x)<<(k))|((x)>>(64-(k))))
109639 +static u64 ranval(ranctx *x) {
109640 + u64 e = x->a - rot(x->b, 7);
109641 + x->a = x->b ^ rot(x->c, 13);
109642 + x->b = x->c + rot(x->d, 37);
109643 + x->c = x->d + e;
109644 + x->d = e + x->a;
109645 + return x->d;
109646 +}
109647 +
109648 +static void raninit(ranctx *x, u64 *seed) {
109649 + int i;
109650 +
109651 + x->a = seed[0];
109652 + x->b = seed[1];
109653 + x->c = seed[2];
109654 + x->d = seed[3];
109655 +
109656 + for (i=0; i < 30; ++i)
109657 + (void)ranval(x);
109658 +}
109659 +
109660 +static u64 shuffle_seed[4];
109661 +
109662 +struct partition_group {
109663 + tree tree_start;
109664 + unsigned long start;
109665 + unsigned long length;
109666 +};
109667 +
109668 +static void partition_struct(tree *fields, unsigned long length, struct partition_group *size_groups, unsigned long *num_groups)
109669 +{
109670 + unsigned long i;
109671 + unsigned long accum_size = 0;
109672 + unsigned long accum_length = 0;
109673 + unsigned long group_idx = 0;
109674 +
109675 + gcc_assert(length < INT_MAX);
109676 +
109677 + memset(size_groups, 0, sizeof(struct partition_group) * length);
109678 +
109679 + for (i = 0; i < length; i++) {
109680 + if (size_groups[group_idx].tree_start == NULL_TREE) {
109681 + size_groups[group_idx].tree_start = fields[i];
109682 + size_groups[group_idx].start = i;
109683 + accum_length = 0;
109684 + accum_size = 0;
109685 + }
109686 + accum_size += (unsigned long)int_size_in_bytes(TREE_TYPE(fields[i]));
109687 + accum_length++;
109688 + if (accum_size >= 64) {
109689 + size_groups[group_idx].length = accum_length;
109690 + accum_length = 0;
109691 + group_idx++;
109692 + }
109693 + }
109694 +
109695 + if (size_groups[group_idx].tree_start != NULL_TREE &&
109696 + !size_groups[group_idx].length) {
109697 + size_groups[group_idx].length = accum_length;
109698 + group_idx++;
109699 + }
109700 +
109701 + *num_groups = group_idx;
109702 +}
109703 +
109704 +static void performance_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
109705 +{
109706 + unsigned long i, x;
109707 + struct partition_group size_group[length];
109708 + unsigned long num_groups = 0;
109709 + unsigned long randnum;
109710 +
109711 + partition_struct(newtree, length, (struct partition_group *)&size_group, &num_groups);
109712 + for (i = num_groups - 1; i > 0; i--) {
109713 + struct partition_group tmp;
109714 + randnum = ranval(prng_state) % (i + 1);
109715 + tmp = size_group[i];
109716 + size_group[i] = size_group[randnum];
109717 + size_group[randnum] = tmp;
109718 + }
109719 +
109720 + for (x = 0; x < num_groups; x++) {
109721 + for (i = size_group[x].start + size_group[x].length - 1; i > size_group[x].start; i--) {
109722 + tree tmp;
109723 + if (DECL_BIT_FIELD_TYPE(newtree[i]))
109724 + continue;
109725 + randnum = ranval(prng_state) % (i + 1);
109726 + // we could handle this case differently if desired
109727 + if (DECL_BIT_FIELD_TYPE(newtree[randnum]))
109728 + continue;
109729 + tmp = newtree[i];
109730 + newtree[i] = newtree[randnum];
109731 + newtree[randnum] = tmp;
109732 + }
109733 + }
109734 +}
109735 +
109736 +static void full_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
109737 +{
109738 + unsigned long i, randnum;
109739 +
109740 + for (i = length - 1; i > 0; i--) {
109741 + tree tmp;
109742 + randnum = ranval(prng_state) % (i + 1);
109743 + tmp = newtree[i];
109744 + newtree[i] = newtree[randnum];
109745 + newtree[randnum] = tmp;
109746 + }
109747 +}
109748 +
109749 +/* modern in-place Fisher-Yates shuffle */
109750 +static void shuffle(const_tree type, tree *newtree, unsigned long length)
109751 +{
109752 + unsigned long i;
109753 + u64 seed[4];
109754 + ranctx prng_state;
109755 + const unsigned char *structname;
109756 +
109757 + if (length == 0)
109758 + return;
109759 +
109760 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
109761 +
109762 + structname = ORIG_TYPE_NAME(type);
109763 +
109764 +#ifdef __DEBUG_PLUGIN
109765 + fprintf(stderr, "Shuffling struct %s %p\n", (const char *)structname, type);
109766 +#ifdef __DEBUG_VERBOSE
109767 + debug_tree((tree)type);
109768 +#endif
109769 +#endif
109770 +
109771 + for (i = 0; i < 4; i++) {
109772 + seed[i] = shuffle_seed[i];
109773 + seed[i] ^= name_hash(structname);
109774 + }
109775 +
109776 + raninit(&prng_state, (u64 *)&seed);
109777 +
109778 + if (performance_mode)
109779 + performance_shuffle(newtree, length, &prng_state);
109780 + else
109781 + full_shuffle(newtree, length, &prng_state);
109782 +}
109783 +
109784 +static bool is_flexible_array(const_tree field)
109785 +{
109786 + const_tree fieldtype;
109787 + const_tree typesize;
109788 + const_tree elemtype;
109789 + const_tree elemsize;
109790 +
109791 + fieldtype = TREE_TYPE(field);
109792 + typesize = TYPE_SIZE(fieldtype);
109793 +
109794 + if (TREE_CODE(fieldtype) != ARRAY_TYPE)
109795 + return false;
109796 +
109797 + elemtype = TREE_TYPE(fieldtype);
109798 + elemsize = TYPE_SIZE(elemtype);
109799 +
109800 + /* size of type is represented in bits */
109801 +
109802 + if (typesize == NULL_TREE && TYPE_DOMAIN(fieldtype) != NULL_TREE &&
109803 + TYPE_MAX_VALUE(TYPE_DOMAIN(fieldtype)) == NULL_TREE)
109804 + return true;
109805 +
109806 + if (typesize != NULL_TREE &&
109807 + (TREE_CONSTANT(typesize) && (!TREE_INT_CST_LOW(typesize) ||
109808 + TREE_INT_CST_LOW(typesize) == TREE_INT_CST_LOW(elemsize))))
109809 + return true;
109810 +
109811 + return false;
109812 +}
109813 +
109814 +static int relayout_struct(tree type)
109815 +{
109816 + unsigned long num_fields = (unsigned long)list_length(TYPE_FIELDS(type));
109817 + unsigned long shuffle_length = num_fields;
109818 + tree field;
109819 + tree newtree[num_fields];
109820 + unsigned long i;
109821 + tree list;
109822 + tree variant;
109823 + expanded_location xloc;
109824 +
109825 + if (TYPE_FIELDS(type) == NULL_TREE)
109826 + return 0;
109827 +
109828 + if (num_fields < 2)
109829 + return 0;
109830 +
109831 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
109832 +
109833 + gcc_assert(num_fields < INT_MAX);
109834 +
109835 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)) ||
109836 + lookup_attribute("no_randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))))
109837 + return 0;
109838 +
109839 + /* Workaround for 3rd-party VirtualBox source that we can't modify ourselves */
109840 + if (!strcmp((const char *)ORIG_TYPE_NAME(type), "INTNETTRUNKFACTORY") ||
109841 + !strcmp((const char *)ORIG_TYPE_NAME(type), "RAWPCIFACTORY"))
109842 + return 0;
109843 +
109844 + /* throw out any structs in uapi */
109845 + xloc = expand_location(DECL_SOURCE_LOCATION(TYPE_FIELDS(type)));
109846 +
109847 + if (strstr(xloc.file, "/uapi/"))
109848 + error(G_("attempted to randomize userland API struct %s"), ORIG_TYPE_NAME(type));
109849 +
109850 + for (field = TYPE_FIELDS(type), i = 0; field; field = TREE_CHAIN(field), i++) {
109851 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
109852 + newtree[i] = field;
109853 + }
109854 +
109855 + /*
109856 + * enforce that we don't randomize the layout of the last
109857 + * element of a struct if it's a 0 or 1-length array
109858 + * or a proper flexible array
109859 + */
109860 + if (is_flexible_array(newtree[num_fields - 1]))
109861 + shuffle_length--;
109862 +
109863 + shuffle(type, (tree *)newtree, shuffle_length);
109864 +
109865 + /*
109866 + * set up a bogus anonymous struct field designed to error out on unnamed struct initializers
109867 + * as gcc provides no other way to detect such code
109868 + */
109869 + list = make_node(FIELD_DECL);
109870 + TREE_CHAIN(list) = newtree[0];
109871 + TREE_TYPE(list) = void_type_node;
109872 + DECL_SIZE(list) = bitsize_zero_node;
109873 + DECL_NONADDRESSABLE_P(list) = 1;
109874 + DECL_FIELD_BIT_OFFSET(list) = bitsize_zero_node;
109875 + DECL_SIZE_UNIT(list) = size_zero_node;
109876 + DECL_FIELD_OFFSET(list) = size_zero_node;
109877 + // to satisfy the constify plugin
109878 + TREE_READONLY(list) = 1;
109879 +
109880 + for (i = 0; i < num_fields - 1; i++)
109881 + TREE_CHAIN(newtree[i]) = newtree[i+1];
109882 + TREE_CHAIN(newtree[num_fields - 1]) = NULL_TREE;
109883 +
109884 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
109885 + TYPE_FIELDS(variant) = list;
109886 + TYPE_ATTRIBUTES(variant) = copy_list(TYPE_ATTRIBUTES(variant));
109887 + TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("randomize_performed"), NULL_TREE, TYPE_ATTRIBUTES(variant));
109888 + // force a re-layout
109889 + TYPE_SIZE(variant) = NULL_TREE;
109890 + layout_type(variant);
109891 + }
109892 +
109893 + return 1;
109894 +}
109895 +
109896 +/* from constify plugin */
109897 +static const_tree get_field_type(const_tree field)
109898 +{
109899 + return strip_array_types(TREE_TYPE(field));
109900 +}
109901 +
109902 +/* from constify plugin */
109903 +static bool is_fptr(const_tree fieldtype)
109904 +{
109905 + if (TREE_CODE(fieldtype) != POINTER_TYPE)
109906 + return false;
109907 +
109908 + return TREE_CODE(TREE_TYPE(fieldtype)) == FUNCTION_TYPE;
109909 +}
109910 +
109911 +/* derived from constify plugin */
109912 +static int is_pure_ops_struct(const_tree node)
109913 +{
109914 + const_tree field;
109915 +
109916 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
109917 +
109918 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
109919 + const_tree fieldtype = get_field_type(field);
109920 + enum tree_code code = TREE_CODE(fieldtype);
109921 +
109922 + if (node == fieldtype)
109923 + continue;
109924 +
109925 + if (!is_fptr(fieldtype))
109926 + return 0;
109927 +
109928 + if (code != RECORD_TYPE && code != UNION_TYPE)
109929 + continue;
109930 +
109931 + if (!is_pure_ops_struct(fieldtype))
109932 + return 0;
109933 + }
109934 +
109935 + return 1;
109936 +}
109937 +
109938 +static void randomize_type(tree type)
109939 +{
109940 + tree variant;
109941 +
109942 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
109943 +
109944 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
109945 + return;
109946 +
109947 + if (lookup_attribute("randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))) || is_pure_ops_struct(type))
109948 + relayout_struct(type);
109949 +
109950 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
109951 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
109952 + TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("randomize_considered"), NULL_TREE, TYPE_ATTRIBUTES(type));
109953 + }
109954 +#ifdef __DEBUG_PLUGIN
109955 + fprintf(stderr, "Marking randomize_considered on struct %s\n", ORIG_TYPE_NAME(type));
109956 +#ifdef __DEBUG_VERBOSE
109957 + debug_tree(type);
109958 +#endif
109959 +#endif
109960 +}
109961 +
109962 +static void randomize_layout_finish_decl(void *event_data, void *data)
109963 +{
109964 + tree decl = (tree)event_data;
109965 + tree type;
109966 +
109967 + if (decl == NULL_TREE || decl == error_mark_node)
109968 + return;
109969 +
109970 + type = TREE_TYPE(decl);
109971 +
109972 + if (TREE_CODE(decl) != VAR_DECL)
109973 + return;
109974 +
109975 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
109976 + return;
109977 +
109978 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)))
109979 + return;
109980 +
109981 + relayout_decl(decl);
109982 +}
109983 +
109984 +static void finish_type(void *event_data, void *data)
109985 +{
109986 + tree type = (tree)event_data;
109987 +
109988 + if (type == NULL_TREE || type == error_mark_node)
109989 + return;
109990 +
109991 + if (TREE_CODE(type) != RECORD_TYPE)
109992 + return;
109993 +
109994 + if (TYPE_FIELDS(type) == NULL_TREE)
109995 + return;
109996 +
109997 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
109998 + return;
109999 +
110000 +#ifdef __DEBUG_PLUGIN
110001 + fprintf(stderr, "Calling randomize_type on %s\n", ORIG_TYPE_NAME(type));
110002 +#endif
110003 +#ifdef __DEBUG_VERBOSE
110004 + debug_tree(type);
110005 +#endif
110006 + randomize_type(type);
110007 +
110008 + return;
110009 +}
110010 +
110011 +static struct attribute_spec randomize_layout_attr = {
110012 + .name = "randomize_layout",
110013 + // related to args
110014 + .min_length = 0,
110015 + .max_length = 0,
110016 + .decl_required = false,
110017 + // need type declaration
110018 + .type_required = true,
110019 + .function_type_required = false,
110020 + .handler = handle_randomize_layout_attr,
110021 +#if BUILDING_GCC_VERSION >= 4007
110022 + .affects_type_identity = true
110023 +#endif
110024 +};
110025 +
110026 +static struct attribute_spec no_randomize_layout_attr = {
110027 + .name = "no_randomize_layout",
110028 + // related to args
110029 + .min_length = 0,
110030 + .max_length = 0,
110031 + .decl_required = false,
110032 + // need type declaration
110033 + .type_required = true,
110034 + .function_type_required = false,
110035 + .handler = handle_randomize_layout_attr,
110036 +#if BUILDING_GCC_VERSION >= 4007
110037 + .affects_type_identity = true
110038 +#endif
110039 +};
110040 +
110041 +static struct attribute_spec randomize_considered_attr = {
110042 + .name = "randomize_considered",
110043 + // related to args
110044 + .min_length = 0,
110045 + .max_length = 0,
110046 + .decl_required = false,
110047 + // need type declaration
110048 + .type_required = true,
110049 + .function_type_required = false,
110050 + .handler = handle_randomize_considered_attr,
110051 +#if BUILDING_GCC_VERSION >= 4007
110052 + .affects_type_identity = false
110053 +#endif
110054 +};
110055 +
110056 +static struct attribute_spec randomize_performed_attr = {
110057 + .name = "randomize_performed",
110058 + // related to args
110059 + .min_length = 0,
110060 + .max_length = 0,
110061 + .decl_required = false,
110062 + // need type declaration
110063 + .type_required = true,
110064 + .function_type_required = false,
110065 + .handler = handle_randomize_performed_attr,
110066 +#if BUILDING_GCC_VERSION >= 4007
110067 + .affects_type_identity = false
110068 +#endif
110069 +};
110070 +
110071 +static void register_attributes(void *event_data, void *data)
110072 +{
110073 + register_attribute(&randomize_layout_attr);
110074 + register_attribute(&no_randomize_layout_attr);
110075 + register_attribute(&randomize_considered_attr);
110076 + register_attribute(&randomize_performed_attr);
110077 +}
110078 +
110079 +static void check_bad_casts_in_constructor(tree var, tree init)
110080 +{
110081 + unsigned HOST_WIDE_INT idx;
110082 + tree field, val;
110083 + tree field_type, val_type;
110084 +
110085 + FOR_EACH_CONSTRUCTOR_ELT(CONSTRUCTOR_ELTS(init), idx, field, val) {
110086 + if (TREE_CODE(val) == CONSTRUCTOR) {
110087 + check_bad_casts_in_constructor(var, val);
110088 + continue;
110089 + }
110090 +
110091 + /* pipacs' plugin creates franken-arrays that differ from those produced by
110092 + normal code which all have valid 'field' trees. work around this */
110093 + if (field == NULL_TREE)
110094 + continue;
110095 + field_type = TREE_TYPE(field);
110096 + val_type = TREE_TYPE(val);
110097 +
110098 + if (TREE_CODE(field_type) != POINTER_TYPE || TREE_CODE(val_type) != POINTER_TYPE)
110099 + continue;
110100 +
110101 + if (field_type == val_type)
110102 + continue;
110103 +
110104 + field_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(field_type))));
110105 + val_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(val_type))));
110106 +
110107 + if (field_type == void_type_node)
110108 + continue;
110109 + if (field_type == val_type)
110110 + continue;
110111 + if (TREE_CODE(val_type) != RECORD_TYPE)
110112 + continue;
110113 +
110114 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(val_type)))
110115 + continue;
110116 + inform(DECL_SOURCE_LOCATION(var), "found mismatched struct pointer types: %qT and %qT\n", TYPE_MAIN_VARIANT(field_type), TYPE_MAIN_VARIANT(val_type));
110117 + }
110118 +}
110119 +
110120 +/* derived from the constify plugin */
110121 +static void check_global_variables(void *event_data, void *data)
110122 +{
110123 + struct varpool_node *node;
110124 + tree init;
110125 +
110126 + FOR_EACH_VARIABLE(node) {
110127 + tree var = NODE_DECL(node);
110128 + init = DECL_INITIAL(var);
110129 + if (init == NULL_TREE)
110130 + continue;
110131 +
110132 + if (TREE_CODE(init) != CONSTRUCTOR)
110133 + continue;
110134 +
110135 + check_bad_casts_in_constructor(var, init);
110136 + }
110137 +}
110138 +
110139 +static bool dominated_by_is_err(const_tree rhs, basic_block bb)
110140 +{
110141 + basic_block dom;
110142 + gimple dom_stmt;
110143 + gimple call_stmt;
110144 + const_tree dom_lhs;
110145 + const_tree poss_is_err_cond;
110146 + const_tree poss_is_err_func;
110147 + const_tree is_err_arg;
110148 +
110149 + dom = get_immediate_dominator(CDI_DOMINATORS, bb);
110150 + if (!dom)
110151 + return false;
110152 +
110153 + dom_stmt = last_stmt(dom);
110154 + if (!dom_stmt)
110155 + return false;
110156 +
110157 + if (gimple_code(dom_stmt) != GIMPLE_COND)
110158 + return false;
110159 +
110160 + if (gimple_cond_code(dom_stmt) != NE_EXPR)
110161 + return false;
110162 +
110163 + if (!integer_zerop(gimple_cond_rhs(dom_stmt)))
110164 + return false;
110165 +
110166 + poss_is_err_cond = gimple_cond_lhs(dom_stmt);
110167 +
110168 + if (TREE_CODE(poss_is_err_cond) != SSA_NAME)
110169 + return false;
110170 +
110171 + call_stmt = SSA_NAME_DEF_STMT(poss_is_err_cond);
110172 +
110173 + if (gimple_code(call_stmt) != GIMPLE_CALL)
110174 + return false;
110175 +
110176 + dom_lhs = gimple_get_lhs(call_stmt);
110177 + poss_is_err_func = gimple_call_fndecl(call_stmt);
110178 + if (!poss_is_err_func)
110179 + return false;
110180 + if (dom_lhs != poss_is_err_cond)
110181 + return false;
110182 + if (strcmp(DECL_NAME_POINTER(poss_is_err_func), "IS_ERR"))
110183 + return false;
110184 +
110185 + is_err_arg = gimple_call_arg(call_stmt, 0);
110186 + if (!is_err_arg)
110187 + return false;
110188 +
110189 + if (is_err_arg != rhs)
110190 + return false;
110191 +
110192 + return true;
110193 +}
110194 +
110195 +static void handle_local_var_initializers(void)
110196 +{
110197 + tree var;
110198 + unsigned int i;
110199 +
110200 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
110201 + tree init = DECL_INITIAL(var);
110202 + if (!init)
110203 + continue;
110204 + if (TREE_CODE(init) != CONSTRUCTOR)
110205 + continue;
110206 + check_bad_casts_in_constructor(var, init);
110207 + }
110208 +}
110209 +
110210 +/*
110211 + * iterate over all statements to find "bad" casts:
110212 + * those where the address of the start of a structure is cast
110213 + * to a pointer of a structure of a different type, or a
110214 + * structure pointer type is cast to a different structure pointer type
110215 + */
110216 +static unsigned int find_bad_casts(void)
110217 +{
110218 + basic_block bb;
110219 +
110220 + handle_local_var_initializers();
110221 +
110222 + FOR_ALL_BB_FN(bb, cfun) {
110223 + gimple_stmt_iterator gsi;
110224 +
110225 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
110226 + gimple stmt;
110227 + const_tree lhs;
110228 + const_tree lhs_type;
110229 + const_tree rhs1;
110230 + const_tree rhs_type;
110231 + const_tree ptr_lhs_type;
110232 + const_tree ptr_rhs_type;
110233 + const_tree op0;
110234 + const_tree op0_type;
110235 + enum tree_code rhs_code;
110236 +
110237 + stmt = gsi_stmt(gsi);
110238 +
110239 +#ifdef __DEBUG_PLUGIN
110240 +#ifdef __DEBUG_VERBOSE
110241 + debug_gimple_stmt(stmt);
110242 + debug_tree(gimple_get_lhs(stmt));
110243 +#endif
110244 +#endif
110245 +
110246 + if (gimple_code(stmt) != GIMPLE_ASSIGN)
110247 + continue;
110248 +
110249 +#ifdef __DEBUG_PLUGIN
110250 +#ifdef __DEBUG_VERBOSE
110251 + debug_tree(gimple_assign_rhs1(stmt));
110252 +#endif
110253 +#endif
110254 +
110255 + rhs_code = gimple_assign_rhs_code(stmt);
110256 +
110257 + if (rhs_code != ADDR_EXPR && rhs_code != SSA_NAME)
110258 + continue;
110259 +
110260 + lhs = gimple_get_lhs(stmt);
110261 + lhs_type = TREE_TYPE(lhs);
110262 + rhs1 = gimple_assign_rhs1(stmt);
110263 + rhs_type = TREE_TYPE(rhs1);
110264 +
110265 + if (TREE_CODE(rhs_type) != POINTER_TYPE ||
110266 + TREE_CODE(lhs_type) != POINTER_TYPE)
110267 + continue;
110268 +
110269 + ptr_lhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(lhs_type))));
110270 + ptr_rhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(rhs_type))));
110271 +
110272 + if (ptr_rhs_type == void_type_node)
110273 + continue;
110274 +
110275 + if (ptr_lhs_type == void_type_node)
110276 + continue;
110277 +
110278 + if (dominated_by_is_err(rhs1, bb))
110279 + continue;
110280 +
110281 + if (TREE_CODE(ptr_rhs_type) != RECORD_TYPE) {
110282 +#ifndef __DEBUG_PLUGIN
110283 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_lhs_type)))
110284 +#endif
110285 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
110286 + continue;
110287 + }
110288 +
110289 + if (rhs_code == SSA_NAME && ptr_lhs_type == ptr_rhs_type)
110290 + continue;
110291 +
110292 + if (rhs_code == ADDR_EXPR) {
110293 + op0 = TREE_OPERAND(rhs1, 0);
110294 +
110295 + if (op0 == NULL_TREE)
110296 + continue;
110297 +
110298 + if (TREE_CODE(op0) != VAR_DECL)
110299 + continue;
110300 +
110301 + op0_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(op0))));
110302 + if (op0_type == ptr_lhs_type)
110303 + continue;
110304 +
110305 +#ifndef __DEBUG_PLUGIN
110306 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(op0_type)))
110307 +#endif
110308 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, op0_type);
110309 + } else {
110310 + const_tree ssa_name_var = SSA_NAME_VAR(rhs1);
110311 + /* skip bogus type casts introduced by container_of */
110312 + if (ssa_name_var != NULL_TREE && DECL_NAME(ssa_name_var) &&
110313 + !strcmp((const char *)DECL_NAME_POINTER(ssa_name_var), "__mptr"))
110314 + continue;
110315 +#ifndef __DEBUG_PLUGIN
110316 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_rhs_type)))
110317 +#endif
110318 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
110319 + }
110320 +
110321 + }
110322 + }
110323 + return 0;
110324 +}
110325 +
110326 +#if BUILDING_GCC_VERSION >= 4009
110327 +static const struct pass_data randomize_layout_bad_cast_data = {
110328 +#else
110329 +static struct gimple_opt_pass randomize_layout_bad_cast = {
110330 + .pass = {
110331 +#endif
110332 + .type = GIMPLE_PASS,
110333 + .name = "randomize_layout_bad_cast",
110334 +#if BUILDING_GCC_VERSION >= 4008
110335 + .optinfo_flags = OPTGROUP_NONE,
110336 +#endif
110337 +#if BUILDING_GCC_VERSION >= 4009
110338 + .has_gate = false,
110339 + .has_execute = true,
110340 +#else
110341 + .gate = NULL,
110342 + .execute = find_bad_casts,
110343 + .sub = NULL,
110344 + .next = NULL,
110345 + .static_pass_number = 0,
110346 +#endif
110347 + .tv_id = TV_NONE,
110348 + .properties_required = PROP_cfg,
110349 + .properties_provided = 0,
110350 + .properties_destroyed = 0,
110351 + .todo_flags_start = 0,
110352 + .todo_flags_finish = TODO_dump_func
110353 +#if BUILDING_GCC_VERSION < 4009
110354 + }
110355 +#endif
110356 +};
110357 +
110358 +#if BUILDING_GCC_VERSION >= 4009
110359 +namespace {
110360 +class randomize_layout_bad_cast : public gimple_opt_pass {
110361 +public:
110362 + randomize_layout_bad_cast() : gimple_opt_pass(randomize_layout_bad_cast_data, g) {}
110363 + unsigned int execute() { return find_bad_casts(); }
110364 +};
110365 +}
110366 +#endif
110367 +
110368 +static struct opt_pass *make_randomize_layout_bad_cast(void)
110369 +{
110370 +#if BUILDING_GCC_VERSION >= 4009
110371 + return new randomize_layout_bad_cast();
110372 +#else
110373 + return &randomize_layout_bad_cast.pass;
110374 +#endif
110375 +}
110376 +
110377 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
110378 +{
110379 + int i;
110380 + const char * const plugin_name = plugin_info->base_name;
110381 + const int argc = plugin_info->argc;
110382 + const struct plugin_argument * const argv = plugin_info->argv;
110383 + bool enable = true;
110384 + int obtained_seed = 0;
110385 + struct register_pass_info randomize_layout_bad_cast_info;
110386 +
110387 + randomize_layout_bad_cast_info.pass = make_randomize_layout_bad_cast();
110388 + randomize_layout_bad_cast_info.reference_pass_name = "ssa";
110389 + randomize_layout_bad_cast_info.ref_pass_instance_number = 1;
110390 + randomize_layout_bad_cast_info.pos_op = PASS_POS_INSERT_AFTER;
110391 +
110392 + if (!plugin_default_version_check(version, &gcc_version)) {
110393 + error(G_("incompatible gcc/plugin versions"));
110394 + return 1;
110395 + }
110396 +
110397 + if (strcmp(lang_hooks.name, "GNU C")) {
110398 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
110399 + enable = false;
110400 + }
110401 +
110402 + for (i = 0; i < argc; ++i) {
110403 + if (!strcmp(argv[i].key, "disable")) {
110404 + enable = false;
110405 + continue;
110406 + }
110407 + if (!strcmp(argv[i].key, "performance-mode")) {
110408 + performance_mode = 1;
110409 + continue;
110410 + }
110411 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
110412 + }
110413 +
110414 + if (strlen(randstruct_seed) != 64) {
110415 + error(G_("invalid seed value supplied for %s plugin"), plugin_name);
110416 + return 1;
110417 + }
110418 + obtained_seed = sscanf(randstruct_seed, "%016llx%016llx%016llx%016llx",
110419 + &shuffle_seed[0], &shuffle_seed[1], &shuffle_seed[2], &shuffle_seed[3]);
110420 + if (obtained_seed != 4) {
110421 + error(G_("Invalid seed supplied for %s plugin"), plugin_name);
110422 + return 1;
110423 + }
110424 +
110425 + register_callback(plugin_name, PLUGIN_INFO, NULL, &randomize_layout_plugin_info);
110426 + if (enable) {
110427 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
110428 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &randomize_layout_bad_cast_info);
110429 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
110430 + register_callback(plugin_name, PLUGIN_FINISH_DECL, randomize_layout_finish_decl, NULL);
110431 + }
110432 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
110433 +
110434 + return 0;
110435 +}
110436 diff --git a/tools/gcc/size_overflow_plugin/.gitignore b/tools/gcc/size_overflow_plugin/.gitignore
110437 new file mode 100644
110438 index 0000000..1f0214f
110439 --- /dev/null
110440 +++ b/tools/gcc/size_overflow_plugin/.gitignore
110441 @@ -0,0 +1,3 @@
110442 +randomize_layout_seed.h
110443 +size_overflow_hash.h
110444 +size_overflow_hash_aux.h
110445 diff --git a/tools/gcc/size_overflow_plugin/Makefile b/tools/gcc/size_overflow_plugin/Makefile
110446 new file mode 100644
110447 index 0000000..1ae2ed5
110448 --- /dev/null
110449 +++ b/tools/gcc/size_overflow_plugin/Makefile
110450 @@ -0,0 +1,20 @@
110451 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
110452 +always := $($(HOSTLIBS)-y)
110453 +
110454 +size_overflow_plugin-objs := $(patsubst $(srctree)/$(src)/%.c,%.o,$(wildcard $(srctree)/$(src)/*.c))
110455 +
110456 +$(patsubst $(srctree)/$(src)/%.c,$(obj)/%.o,$(wildcard $(srctree)/$(src)/*.c)): $(objtree)/$(obj)/size_overflow_hash.h $(objtree)/$(obj)/size_overflow_hash_aux.h
110457 +
110458 +quiet_cmd_build_size_overflow_hash = GENHASH $@
110459 + cmd_build_size_overflow_hash = \
110460 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash -d $< -o $@
110461 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
110462 + $(call if_changed,build_size_overflow_hash)
110463 +
110464 +quiet_cmd_build_size_overflow_hash_aux = GENHASH $@
110465 + cmd_build_size_overflow_hash_aux = \
110466 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash_aux -d $< -o $@
110467 +$(objtree)/$(obj)/size_overflow_hash_aux.h: $(src)/size_overflow_hash_aux.data FORCE
110468 + $(call if_changed,build_size_overflow_hash_aux)
110469 +
110470 +targets += size_overflow_hash.h size_overflow_hash_aux.h
110471 diff --git a/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
110472 new file mode 100644
110473 index 0000000..12b1e3b
110474 --- /dev/null
110475 +++ b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
110476 @@ -0,0 +1,102 @@
110477 +#!/bin/bash
110478 +
110479 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
110480 +
110481 +header1="size_overflow_hash.h"
110482 +database="size_overflow_hash.data"
110483 +n=65536
110484 +hashtable_name="size_overflow_hash"
110485 +
110486 +usage() {
110487 +cat <<EOF
110488 +usage: $0 options
110489 +OPTIONS:
110490 + -h|--help help
110491 + -o header file
110492 + -d database file
110493 + -n hash array size
110494 + -s name of the hash table
110495 +EOF
110496 + return 0
110497 +}
110498 +
110499 +while true
110500 +do
110501 + case "$1" in
110502 + -h|--help) usage && exit 0;;
110503 + -n) n=$2; shift 2;;
110504 + -o) header1="$2"; shift 2;;
110505 + -d) database="$2"; shift 2;;
110506 + -s) hashtable_name="$2"; shift 2;;
110507 + --) shift 1; break ;;
110508 + *) break ;;
110509 + esac
110510 +done
110511 +
110512 +create_defines() {
110513 + for i in `seq 0 31`
110514 + do
110515 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
110516 + done
110517 + echo >> "$header1"
110518 +}
110519 +
110520 +create_structs() {
110521 + rm -f "$header1"
110522 +
110523 + create_defines
110524 +
110525 + cat "$database" | while read data
110526 + do
110527 + data_array=($data)
110528 + struct_hash_name="${data_array[0]}"
110529 + funcn="${data_array[1]}"
110530 + params="${data_array[2]}"
110531 + next="${data_array[4]}"
110532 +
110533 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
110534 +
110535 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
110536 + echo -en "\t.param\t= " >> "$header1"
110537 + line=
110538 + for param_num in ${params//-/ };
110539 + do
110540 + line="${line}PARAM"$param_num"|"
110541 + done
110542 +
110543 + echo -e "${line%?},\n};\n" >> "$header1"
110544 + done
110545 +}
110546 +
110547 +create_headers() {
110548 + echo "const struct size_overflow_hash * const $hashtable_name[$n] = {" >> "$header1"
110549 +}
110550 +
110551 +create_array_elements() {
110552 + index=0
110553 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
110554 + do
110555 + data_array=($data)
110556 + i="${data_array[3]}"
110557 + hash="${data_array[0]}"
110558 + while [[ $index -lt $i ]]
110559 + do
110560 + echo -e "\t["$index"]\t= NULL," >> "$header1"
110561 + index=$(($index + 1))
110562 + done
110563 + index=$(($index + 1))
110564 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
110565 + done
110566 + echo '};' >> $header1
110567 +}
110568 +
110569 +size_overflow_plugin_dir=`dirname $header1`
110570 +if [ "$size_overflow_plugin_dir" != '.' ]; then
110571 + mkdir -p "$size_overflow_plugin_dir" 2> /dev/null
110572 +fi
110573 +
110574 +create_structs
110575 +create_headers
110576 +create_array_elements
110577 +
110578 +exit 0
110579 diff --git a/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
110580 new file mode 100644
110581 index 0000000..c43901f
110582 --- /dev/null
110583 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
110584 @@ -0,0 +1,748 @@
110585 +/*
110586 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
110587 + * Licensed under the GPL v2, or (at your option) v3
110588 + *
110589 + * Homepage:
110590 + * http://www.grsecurity.net/~ephox/overflow_plugin/
110591 + *
110592 + * Documentation:
110593 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
110594 + *
110595 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
110596 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
110597 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
110598 + *
110599 + * Usage:
110600 + * $ make
110601 + * $ make run
110602 + */
110603 +
110604 +#include "gcc-common.h"
110605 +#include "size_overflow.h"
110606 +
110607 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs);
110608 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs);
110609 +
110610 +// data for the size_overflow asm stmt
110611 +struct asm_data {
110612 + gimple def_stmt;
110613 + tree input;
110614 + tree output;
110615 +};
110616 +
110617 +#if BUILDING_GCC_VERSION <= 4007
110618 +static VEC(tree, gc) *create_asm_io_list(tree string, tree io)
110619 +#else
110620 +static vec<tree, va_gc> *create_asm_io_list(tree string, tree io)
110621 +#endif
110622 +{
110623 + tree list;
110624 +#if BUILDING_GCC_VERSION <= 4007
110625 + VEC(tree, gc) *vec_list = NULL;
110626 +#else
110627 + vec<tree, va_gc> *vec_list = NULL;
110628 +#endif
110629 +
110630 + list = build_tree_list(NULL_TREE, string);
110631 + list = chainon(NULL_TREE, build_tree_list(list, io));
110632 +#if BUILDING_GCC_VERSION <= 4007
110633 + VEC_safe_push(tree, gc, vec_list, list);
110634 +#else
110635 + vec_safe_push(vec_list, list);
110636 +#endif
110637 + return vec_list;
110638 +}
110639 +
110640 +static void create_asm_stmt(const char *str, tree str_input, tree str_output, struct asm_data *asm_data)
110641 +{
110642 + gimple asm_stmt;
110643 + gimple_stmt_iterator gsi;
110644 +#if BUILDING_GCC_VERSION <= 4007
110645 + VEC(tree, gc) *input, *output = NULL;
110646 +#else
110647 + vec<tree, va_gc> *input, *output = NULL;
110648 +#endif
110649 +
110650 + input = create_asm_io_list(str_input, asm_data->input);
110651 +
110652 + if (asm_data->output)
110653 + output = create_asm_io_list(str_output, asm_data->output);
110654 +
110655 + asm_stmt = gimple_build_asm_vec(str, input, output, NULL, NULL);
110656 + gsi = gsi_for_stmt(asm_data->def_stmt);
110657 + gsi_insert_after(&gsi, asm_stmt, GSI_NEW_STMT);
110658 +
110659 + if (asm_data->output)
110660 + SSA_NAME_DEF_STMT(asm_data->output) = asm_stmt;
110661 +}
110662 +
110663 +static void replace_call_lhs(const struct asm_data *asm_data)
110664 +{
110665 + gimple_set_lhs(asm_data->def_stmt, asm_data->input);
110666 + update_stmt(asm_data->def_stmt);
110667 + SSA_NAME_DEF_STMT(asm_data->input) = asm_data->def_stmt;
110668 +}
110669 +
110670 +static enum mark search_intentional_phi(struct pointer_set_t *visited, const_tree result)
110671 +{
110672 + enum mark cur_fndecl_attr;
110673 + gimple phi = get_def_stmt(result);
110674 + unsigned int i, n = gimple_phi_num_args(phi);
110675 +
110676 + pointer_set_insert(visited, phi);
110677 + for (i = 0; i < n; i++) {
110678 + tree arg = gimple_phi_arg_def(phi, i);
110679 +
110680 + cur_fndecl_attr = search_intentional(visited, arg);
110681 + if (cur_fndecl_attr != MARK_NO)
110682 + return cur_fndecl_attr;
110683 + }
110684 + return MARK_NO;
110685 +}
110686 +
110687 +static enum mark search_intentional_binary(struct pointer_set_t *visited, const_tree lhs)
110688 +{
110689 + enum mark cur_fndecl_attr;
110690 + const_tree rhs1, rhs2;
110691 + gimple def_stmt = get_def_stmt(lhs);
110692 +
110693 + rhs1 = gimple_assign_rhs1(def_stmt);
110694 + rhs2 = gimple_assign_rhs2(def_stmt);
110695 +
110696 + cur_fndecl_attr = search_intentional(visited, rhs1);
110697 + if (cur_fndecl_attr != MARK_NO)
110698 + return cur_fndecl_attr;
110699 + return search_intentional(visited, rhs2);
110700 +}
110701 +
110702 +// Look up the intentional_overflow attribute on the caller and the callee functions.
110703 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs)
110704 +{
110705 + const_gimple def_stmt;
110706 +
110707 + if (TREE_CODE(lhs) != SSA_NAME)
110708 + return get_intentional_attr_type(lhs);
110709 +
110710 + def_stmt = get_def_stmt(lhs);
110711 + if (!def_stmt)
110712 + return MARK_NO;
110713 +
110714 + if (pointer_set_contains(visited, def_stmt))
110715 + return MARK_NO;
110716 +
110717 + switch (gimple_code(def_stmt)) {
110718 + case GIMPLE_NOP:
110719 + return search_intentional(visited, SSA_NAME_VAR(lhs));
110720 + case GIMPLE_ASM:
110721 + if (is_size_overflow_intentional_asm_turn_off(def_stmt))
110722 + return MARK_TURN_OFF;
110723 + return MARK_NO;
110724 + case GIMPLE_CALL:
110725 + return MARK_NO;
110726 + case GIMPLE_PHI:
110727 + return search_intentional_phi(visited, lhs);
110728 + case GIMPLE_ASSIGN:
110729 + switch (gimple_num_ops(def_stmt)) {
110730 + case 2:
110731 + return search_intentional(visited, gimple_assign_rhs1(def_stmt));
110732 + case 3:
110733 + return search_intentional_binary(visited, lhs);
110734 + }
110735 + case GIMPLE_RETURN:
110736 + return MARK_NO;
110737 + default:
110738 + debug_gimple_stmt((gimple)def_stmt);
110739 + error("%s: unknown gimple code", __func__);
110740 + gcc_unreachable();
110741 + }
110742 +}
110743 +
110744 +// Check the intentional_overflow attribute and create the asm comment string for the size_overflow asm stmt.
110745 +static enum mark check_intentional_attribute_gimple(const_tree arg, const_gimple stmt, unsigned int argnum)
110746 +{
110747 + const_tree fndecl;
110748 + struct pointer_set_t *visited;
110749 + enum mark cur_fndecl_attr, decl_attr = MARK_NO;
110750 +
110751 + fndecl = get_interesting_orig_fndecl(stmt, argnum);
110752 + if (is_end_intentional_intentional_attr(fndecl, argnum))
110753 + decl_attr = MARK_NOT_INTENTIONAL;
110754 + else if (is_yes_intentional_attr(fndecl, argnum))
110755 + decl_attr = MARK_YES;
110756 + else if (is_turn_off_intentional_attr(fndecl) || is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
110757 + return MARK_TURN_OFF;
110758 + }
110759 +
110760 + visited = pointer_set_create();
110761 + cur_fndecl_attr = search_intentional(visited, arg);
110762 + pointer_set_destroy(visited);
110763 +
110764 + switch (cur_fndecl_attr) {
110765 + case MARK_NO:
110766 + case MARK_TURN_OFF:
110767 + return cur_fndecl_attr;
110768 + default:
110769 + print_missing_intentional(decl_attr, cur_fndecl_attr, fndecl, argnum);
110770 + return MARK_YES;
110771 + }
110772 +}
110773 +
110774 +static void check_missing_size_overflow_attribute(tree var)
110775 +{
110776 + tree orig_fndecl;
110777 + unsigned int num;
110778 +
110779 + if (is_a_return_check(var))
110780 + orig_fndecl = DECL_ORIGIN(var);
110781 + else
110782 + orig_fndecl = DECL_ORIGIN(current_function_decl);
110783 +
110784 + num = get_function_num(var, orig_fndecl);
110785 + if (num == CANNOT_FIND_ARG)
110786 + return;
110787 +
110788 + is_missing_function(orig_fndecl, num);
110789 +}
110790 +
110791 +static void search_size_overflow_attribute_phi(struct pointer_set_t *visited, const_tree result)
110792 +{
110793 + gimple phi = get_def_stmt(result);
110794 + unsigned int i, n = gimple_phi_num_args(phi);
110795 +
110796 + pointer_set_insert(visited, phi);
110797 + for (i = 0; i < n; i++) {
110798 + tree arg = gimple_phi_arg_def(phi, i);
110799 +
110800 + search_size_overflow_attribute(visited, arg);
110801 + }
110802 +}
110803 +
110804 +static void search_size_overflow_attribute_binary(struct pointer_set_t *visited, const_tree lhs)
110805 +{
110806 + const_gimple def_stmt = get_def_stmt(lhs);
110807 + tree rhs1, rhs2;
110808 +
110809 + rhs1 = gimple_assign_rhs1(def_stmt);
110810 + rhs2 = gimple_assign_rhs2(def_stmt);
110811 +
110812 + search_size_overflow_attribute(visited, rhs1);
110813 + search_size_overflow_attribute(visited, rhs2);
110814 +}
110815 +
110816 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs)
110817 +{
110818 + const_gimple def_stmt;
110819 +
110820 + if (TREE_CODE(lhs) == PARM_DECL) {
110821 + check_missing_size_overflow_attribute(lhs);
110822 + return;
110823 + }
110824 +
110825 + def_stmt = get_def_stmt(lhs);
110826 + if (!def_stmt)
110827 + return;
110828 +
110829 + if (pointer_set_insert(visited, def_stmt))
110830 + return;
110831 +
110832 + switch (gimple_code(def_stmt)) {
110833 + case GIMPLE_NOP:
110834 + return search_size_overflow_attribute(visited, SSA_NAME_VAR(lhs));
110835 + case GIMPLE_ASM:
110836 + return;
110837 + case GIMPLE_CALL: {
110838 + tree fndecl = gimple_call_fndecl(def_stmt);
110839 +
110840 + if (fndecl == NULL_TREE)
110841 + return;
110842 + check_missing_size_overflow_attribute(fndecl);
110843 + return;
110844 + }
110845 + case GIMPLE_PHI:
110846 + return search_size_overflow_attribute_phi(visited, lhs);
110847 + case GIMPLE_ASSIGN:
110848 + switch (gimple_num_ops(def_stmt)) {
110849 + case 2:
110850 + return search_size_overflow_attribute(visited, gimple_assign_rhs1(def_stmt));
110851 + case 3:
110852 + return search_size_overflow_attribute_binary(visited, lhs);
110853 + }
110854 + default:
110855 + debug_gimple_stmt((gimple)def_stmt);
110856 + error("%s: unknown gimple code", __func__);
110857 + gcc_unreachable();
110858 + }
110859 +}
110860 +
110861 +// Search missing entries in the hash table (invoked from the gimple pass)
110862 +static void search_missing_size_overflow_attribute_gimple(const_gimple stmt, unsigned int num)
110863 +{
110864 + tree fndecl = NULL_TREE;
110865 + tree lhs;
110866 + struct pointer_set_t *visited;
110867 +
110868 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl)))
110869 + return;
110870 +
110871 + if (num == 0) {
110872 + gcc_assert(gimple_code(stmt) == GIMPLE_RETURN);
110873 + lhs = gimple_return_retval(stmt);
110874 + } else {
110875 + gcc_assert(is_gimple_call(stmt));
110876 + lhs = gimple_call_arg(stmt, num - 1);
110877 + fndecl = gimple_call_fndecl(stmt);
110878 + }
110879 +
110880 + if (fndecl != NULL_TREE && is_turn_off_intentional_attr(DECL_ORIGIN(fndecl)))
110881 + return;
110882 +
110883 + visited = pointer_set_create();
110884 + search_size_overflow_attribute(visited, lhs);
110885 + pointer_set_destroy(visited);
110886 +}
110887 +
110888 +static void create_output_from_phi(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
110889 +{
110890 + gimple_stmt_iterator gsi;
110891 + gimple assign;
110892 +
110893 + assign = gimple_build_assign(asm_data->input, asm_data->output);
110894 + gsi = gsi_for_stmt(stmt);
110895 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
110896 + asm_data->def_stmt = assign;
110897 +
110898 + asm_data->output = create_new_var(TREE_TYPE(asm_data->output));
110899 + asm_data->output = make_ssa_name(asm_data->output, stmt);
110900 + if (gimple_code(stmt) == GIMPLE_RETURN)
110901 + gimple_return_set_retval(stmt, asm_data->output);
110902 + else
110903 + gimple_call_set_arg(stmt, argnum - 1, asm_data->output);
110904 + update_stmt(stmt);
110905 +}
110906 +
110907 +static char *create_asm_comment(unsigned int argnum, const_gimple stmt , const char *mark_str)
110908 +{
110909 + const char *fn_name;
110910 + char *asm_comment;
110911 + unsigned int len;
110912 +
110913 + if (argnum == 0)
110914 + fn_name = DECL_NAME_POINTER(current_function_decl);
110915 + else
110916 + fn_name = DECL_NAME_POINTER(gimple_call_fndecl(stmt));
110917 +
110918 + len = asprintf(&asm_comment, "%s %s %u", mark_str, fn_name, argnum);
110919 + gcc_assert(len > 0);
110920 +
110921 + return asm_comment;
110922 +}
110923 +
110924 +static const char *convert_mark_to_str(enum mark mark)
110925 +{
110926 + switch (mark) {
110927 + case MARK_NO:
110928 + return OK_ASM_STR;
110929 + case MARK_YES:
110930 + case MARK_NOT_INTENTIONAL:
110931 + return YES_ASM_STR;
110932 + case MARK_TURN_OFF:
110933 + return TURN_OFF_ASM_STR;
110934 + }
110935 +
110936 + gcc_unreachable();
110937 +}
110938 +
110939 +/* Create the input of the size_overflow asm stmt.
110940 + * When the arg of the callee function is a parm_decl it creates this kind of size_overflow asm stmt:
110941 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
110942 + * The input field in asm_data will be empty if there is no need for further size_overflow asm stmt insertion.
110943 + * otherwise create the input (for a phi stmt the output too) of the asm stmt.
110944 + */
110945 +static void create_asm_input(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
110946 +{
110947 + if (!asm_data->def_stmt) {
110948 + asm_data->input = NULL_TREE;
110949 + return;
110950 + }
110951 +
110952 + asm_data->input = create_new_var(TREE_TYPE(asm_data->output));
110953 + asm_data->input = make_ssa_name(asm_data->input, asm_data->def_stmt);
110954 +
110955 + switch (gimple_code(asm_data->def_stmt)) {
110956 + case GIMPLE_ASSIGN:
110957 + case GIMPLE_CALL:
110958 + replace_call_lhs(asm_data);
110959 + break;
110960 + case GIMPLE_PHI:
110961 + create_output_from_phi(stmt, argnum, asm_data);
110962 + break;
110963 + case GIMPLE_NOP: {
110964 + enum mark mark;
110965 + const char *mark_str;
110966 + char *asm_comment;
110967 +
110968 + mark = check_intentional_attribute_gimple(asm_data->output, stmt, argnum);
110969 +
110970 + asm_data->input = asm_data->output;
110971 + asm_data->output = NULL;
110972 + asm_data->def_stmt = stmt;
110973 +
110974 + mark_str = convert_mark_to_str(mark);
110975 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
110976 +
110977 + create_asm_stmt(asm_comment, build_string(3, "rm"), NULL, asm_data);
110978 + free(asm_comment);
110979 + asm_data->input = NULL_TREE;
110980 + break;
110981 + }
110982 + case GIMPLE_ASM:
110983 + if (is_size_overflow_asm(asm_data->def_stmt)) {
110984 + asm_data->input = NULL_TREE;
110985 + break;
110986 + }
110987 + default:
110988 + debug_gimple_stmt(asm_data->def_stmt);
110989 + gcc_unreachable();
110990 + }
110991 +}
110992 +
110993 +/* This is the gimple part of searching for a missing size_overflow attribute. If the intentional_overflow attribute type
110994 + * is of the right kind create the appropriate size_overflow asm stmts:
110995 + * __asm__("# size_overflow" : =rm" D.3344_8 : "0" cicus.4_16);
110996 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
110997 + */
110998 +static void create_size_overflow_asm(gimple stmt, tree output_node, unsigned int argnum)
110999 +{
111000 + struct asm_data asm_data;
111001 + const char *mark_str;
111002 + char *asm_comment;
111003 + enum mark mark;
111004 +
111005 + if (is_gimple_constant(output_node))
111006 + return;
111007 +
111008 + asm_data.output = output_node;
111009 + mark = check_intentional_attribute_gimple(asm_data.output, stmt, argnum);
111010 + if (mark != MARK_TURN_OFF)
111011 + search_missing_size_overflow_attribute_gimple(stmt, argnum);
111012 +
111013 + asm_data.def_stmt = get_def_stmt(asm_data.output);
111014 + if (is_size_overflow_intentional_asm_turn_off(asm_data.def_stmt))
111015 + return;
111016 +
111017 + create_asm_input(stmt, argnum, &asm_data);
111018 + if (asm_data.input == NULL_TREE)
111019 + return;
111020 +
111021 + mark_str = convert_mark_to_str(mark);
111022 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
111023 + create_asm_stmt(asm_comment, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
111024 + free(asm_comment);
111025 +}
111026 +
111027 +// Insert an asm stmt with "MARK_TURN_OFF", "MARK_YES" or "MARK_NOT_INTENTIONAL".
111028 +static bool create_mark_asm(gimple stmt, enum mark mark)
111029 +{
111030 + struct asm_data asm_data;
111031 + const char *asm_str;
111032 +
111033 + switch (mark) {
111034 + case MARK_TURN_OFF:
111035 + asm_str = TURN_OFF_ASM_STR;
111036 + break;
111037 + case MARK_NOT_INTENTIONAL:
111038 + case MARK_YES:
111039 + asm_str = YES_ASM_STR;
111040 + break;
111041 + default:
111042 + gcc_unreachable();
111043 + }
111044 +
111045 + asm_data.def_stmt = stmt;
111046 + asm_data.output = gimple_call_lhs(stmt);
111047 +
111048 + if (asm_data.output == NULL_TREE) {
111049 + asm_data.input = gimple_call_arg(stmt, 0);
111050 + if (is_gimple_constant(asm_data.input))
111051 + return false;
111052 + asm_data.output = NULL;
111053 + create_asm_stmt(asm_str, build_string(3, "rm"), NULL, &asm_data);
111054 + return true;
111055 + }
111056 +
111057 + create_asm_input(stmt, 0, &asm_data);
111058 + gcc_assert(asm_data.input != NULL_TREE);
111059 +
111060 + create_asm_stmt(asm_str, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
111061 + return true;
111062 +}
111063 +
111064 +static void walk_use_def_ptr(struct pointer_set_t *visited, const_tree lhs)
111065 +{
111066 + gimple def_stmt;
111067 +
111068 + def_stmt = get_def_stmt(lhs);
111069 + if (!def_stmt)
111070 + return;
111071 +
111072 + if (pointer_set_insert(visited, def_stmt))
111073 + return;
111074 +
111075 + switch (gimple_code(def_stmt)) {
111076 + case GIMPLE_NOP:
111077 + case GIMPLE_ASM:
111078 + case GIMPLE_CALL:
111079 + break;
111080 + case GIMPLE_PHI: {
111081 + unsigned int i, n = gimple_phi_num_args(def_stmt);
111082 +
111083 + pointer_set_insert(visited, def_stmt);
111084 +
111085 + for (i = 0; i < n; i++) {
111086 + tree arg = gimple_phi_arg_def(def_stmt, i);
111087 +
111088 + walk_use_def_ptr(visited, arg);
111089 + }
111090 + }
111091 + case GIMPLE_ASSIGN:
111092 + switch (gimple_num_ops(def_stmt)) {
111093 + case 2:
111094 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
111095 + return;
111096 + case 3:
111097 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
111098 + walk_use_def_ptr(visited, gimple_assign_rhs2(def_stmt));
111099 + return;
111100 + default:
111101 + return;
111102 + }
111103 + default:
111104 + debug_gimple_stmt((gimple)def_stmt);
111105 + error("%s: unknown gimple code", __func__);
111106 + gcc_unreachable();
111107 + }
111108 +}
111109 +
111110 +// Look for a ptr - ptr expression (e.g., cpuset_common_file_read() s - page)
111111 +static void insert_mark_not_intentional_asm_at_ptr(const_tree arg)
111112 +{
111113 + struct pointer_set_t *visited;
111114 +
111115 + visited = pointer_set_create();
111116 + walk_use_def_ptr(visited, arg);
111117 + pointer_set_destroy(visited);
111118 +}
111119 +
111120 +// Determine the return value and insert the asm stmt to mark the return stmt.
111121 +static void insert_asm_ret(gimple stmt)
111122 +{
111123 + tree ret;
111124 +
111125 + ret = gimple_return_retval(stmt);
111126 + create_size_overflow_asm(stmt, ret, 0);
111127 +}
111128 +
111129 +// Determine the correct arg index and arg and insert the asm stmt to mark the stmt.
111130 +static void insert_asm_arg(gimple stmt, unsigned int orig_argnum)
111131 +{
111132 + tree arg;
111133 + unsigned int argnum;
111134 +
111135 + argnum = get_correct_arg_count(orig_argnum, gimple_call_fndecl(stmt));
111136 + gcc_assert(argnum != 0);
111137 + if (argnum == CANNOT_FIND_ARG)
111138 + return;
111139 +
111140 + arg = gimple_call_arg(stmt, argnum - 1);
111141 + gcc_assert(arg != NULL_TREE);
111142 +
111143 + // skip all ptr - ptr expressions
111144 + insert_mark_not_intentional_asm_at_ptr(arg);
111145 +
111146 + create_size_overflow_asm(stmt, arg, argnum);
111147 +}
111148 +
111149 +// If a function arg or the return value is marked by the size_overflow attribute then set its index in the array.
111150 +static void set_argnum_attribute(const_tree attr, bool *argnums)
111151 +{
111152 + unsigned int argnum;
111153 + tree attr_value;
111154 +
111155 + for (attr_value = TREE_VALUE(attr); attr_value; attr_value = TREE_CHAIN(attr_value)) {
111156 + argnum = TREE_INT_CST_LOW(TREE_VALUE(attr_value));
111157 + argnums[argnum] = true;
111158 + }
111159 +}
111160 +
111161 +// If a function arg or the return value is in the hash table then set its index in the array.
111162 +static void set_argnum_hash(tree fndecl, bool *argnums)
111163 +{
111164 + unsigned int num;
111165 + const struct size_overflow_hash *hash;
111166 +
111167 + hash = get_function_hash(DECL_ORIGIN(fndecl));
111168 + if (!hash)
111169 + return;
111170 +
111171 + for (num = 0; num <= MAX_PARAM; num++) {
111172 + if (!(hash->param & (1U << num)))
111173 + continue;
111174 +
111175 + argnums[num] = true;
111176 + }
111177 +}
111178 +
111179 +static bool is_all_the_argnums_empty(bool *argnums)
111180 +{
111181 + unsigned int i;
111182 +
111183 + for (i = 0; i <= MAX_PARAM; i++)
111184 + if (argnums[i])
111185 + return false;
111186 + return true;
111187 +}
111188 +
111189 +// Check whether the arguments or the return value of the function are in the hash table or are marked by the size_overflow attribute.
111190 +static void search_interesting_args(tree fndecl, bool *argnums)
111191 +{
111192 + const_tree attr;
111193 +
111194 + set_argnum_hash(fndecl, argnums);
111195 + if (!is_all_the_argnums_empty(argnums))
111196 + return;
111197 +
111198 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
111199 + if (attr && TREE_VALUE(attr))
111200 + set_argnum_attribute(attr, argnums);
111201 +}
111202 +
111203 +/*
111204 + * Look up the intentional_overflow attribute that turns off ipa based duplication
111205 + * on the callee function.
111206 + */
111207 +static bool is_mark_turn_off_attribute(gimple stmt)
111208 +{
111209 + enum mark mark;
111210 + const_tree fndecl = gimple_call_fndecl(stmt);
111211 +
111212 + mark = get_intentional_attr_type(DECL_ORIGIN(fndecl));
111213 + if (mark == MARK_TURN_OFF)
111214 + return true;
111215 + return false;
111216 +}
111217 +
111218 +// 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
111219 +static void handle_interesting_function(gimple stmt)
111220 +{
111221 + unsigned int argnum;
111222 + tree fndecl;
111223 + bool orig_argnums[MAX_PARAM + 1] = {false};
111224 +
111225 + if (gimple_call_num_args(stmt) == 0)
111226 + return;
111227 + fndecl = gimple_call_fndecl(stmt);
111228 + if (fndecl == NULL_TREE)
111229 + return;
111230 + fndecl = DECL_ORIGIN(fndecl);
111231 +
111232 + if (is_mark_turn_off_attribute(stmt)) {
111233 + create_mark_asm(stmt, MARK_TURN_OFF);
111234 + return;
111235 + }
111236 +
111237 + search_interesting_args(fndecl, orig_argnums);
111238 +
111239 + for (argnum = 1; argnum < MAX_PARAM; argnum++)
111240 + if (orig_argnums[argnum])
111241 + insert_asm_arg(stmt, argnum);
111242 +}
111243 +
111244 +// 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
111245 +static void handle_interesting_ret(gimple stmt)
111246 +{
111247 + bool orig_argnums[MAX_PARAM + 1] = {false};
111248 +
111249 + search_interesting_args(current_function_decl, orig_argnums);
111250 +
111251 + if (orig_argnums[0])
111252 + insert_asm_ret(stmt);
111253 +}
111254 +
111255 +// Iterate over all the stmts and search for call and return stmts and mark them if they're in the hash table
111256 +static unsigned int search_interesting_functions(void)
111257 +{
111258 + basic_block bb;
111259 +
111260 + FOR_ALL_BB_FN(bb, cfun) {
111261 + gimple_stmt_iterator gsi;
111262 +
111263 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
111264 + gimple stmt = gsi_stmt(gsi);
111265 +
111266 + if (is_size_overflow_asm(stmt))
111267 + continue;
111268 +
111269 + if (is_gimple_call(stmt))
111270 + handle_interesting_function(stmt);
111271 + else if (gimple_code(stmt) == GIMPLE_RETURN)
111272 + handle_interesting_ret(stmt);
111273 + }
111274 + }
111275 + return 0;
111276 +}
111277 +
111278 +/*
111279 + * A lot of functions get inlined before the ipa passes so after the build_ssa gimple pass
111280 + * this pass inserts asm stmts to mark the interesting args
111281 + * that the ipa pass will detect and insert the size overflow checks for.
111282 + */
111283 +#if BUILDING_GCC_VERSION >= 4009
111284 +static const struct pass_data insert_size_overflow_asm_pass_data = {
111285 +#else
111286 +static struct gimple_opt_pass insert_size_overflow_asm_pass = {
111287 + .pass = {
111288 +#endif
111289 + .type = GIMPLE_PASS,
111290 + .name = "insert_size_overflow_asm",
111291 +#if BUILDING_GCC_VERSION >= 4008
111292 + .optinfo_flags = OPTGROUP_NONE,
111293 +#endif
111294 +#if BUILDING_GCC_VERSION >= 4009
111295 + .has_gate = false,
111296 + .has_execute = true,
111297 +#else
111298 + .gate = NULL,
111299 + .execute = search_interesting_functions,
111300 + .sub = NULL,
111301 + .next = NULL,
111302 + .static_pass_number = 0,
111303 +#endif
111304 + .tv_id = TV_NONE,
111305 + .properties_required = PROP_cfg,
111306 + .properties_provided = 0,
111307 + .properties_destroyed = 0,
111308 + .todo_flags_start = 0,
111309 + .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
111310 +#if BUILDING_GCC_VERSION < 4009
111311 + }
111312 +#endif
111313 +};
111314 +
111315 +#if BUILDING_GCC_VERSION >= 4009
111316 +namespace {
111317 +class insert_size_overflow_asm_pass : public gimple_opt_pass {
111318 +public:
111319 + insert_size_overflow_asm_pass() : gimple_opt_pass(insert_size_overflow_asm_pass_data, g) {}
111320 + unsigned int execute() { return search_interesting_functions(); }
111321 +};
111322 +}
111323 +#endif
111324 +
111325 +struct opt_pass *make_insert_size_overflow_asm_pass(void)
111326 +{
111327 +#if BUILDING_GCC_VERSION >= 4009
111328 + return new insert_size_overflow_asm_pass();
111329 +#else
111330 + return &insert_size_overflow_asm_pass.pass;
111331 +#endif
111332 +}
111333 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
111334 new file mode 100644
111335 index 0000000..73f0a12
111336 --- /dev/null
111337 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_core.c
111338 @@ -0,0 +1,943 @@
111339 +/*
111340 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
111341 + * Licensed under the GPL v2, or (at your option) v3
111342 + *
111343 + * Homepage:
111344 + * http://www.grsecurity.net/~ephox/overflow_plugin/
111345 + *
111346 + * Documentation:
111347 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
111348 + *
111349 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
111350 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
111351 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
111352 + *
111353 + * Usage:
111354 + * $ make
111355 + * $ make run
111356 + */
111357 +
111358 +#include "gcc-common.h"
111359 +#include "size_overflow.h"
111360 +
111361 +#define MIN_CHECK true
111362 +#define MAX_CHECK false
111363 +
111364 +static tree get_size_overflow_type(struct visited *visited, const_gimple stmt, const_tree node)
111365 +{
111366 + const_tree type;
111367 + tree new_type;
111368 +
111369 + gcc_assert(node != NULL_TREE);
111370 +
111371 + type = TREE_TYPE(node);
111372 +
111373 + if (pointer_set_contains(visited->my_stmts, stmt))
111374 + return TREE_TYPE(node);
111375 +
111376 + switch (TYPE_MODE(type)) {
111377 + case QImode:
111378 + new_type = size_overflow_type_HI;
111379 + break;
111380 + case HImode:
111381 + new_type = size_overflow_type_SI;
111382 + break;
111383 + case SImode:
111384 + new_type = size_overflow_type_DI;
111385 + break;
111386 + case DImode:
111387 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
111388 + new_type = TYPE_UNSIGNED(type) ? unsigned_intDI_type_node : intDI_type_node;
111389 + else
111390 + new_type = size_overflow_type_TI;
111391 + break;
111392 + case TImode:
111393 + gcc_assert(!TYPE_UNSIGNED(type));
111394 + new_type = size_overflow_type_TI;
111395 + break;
111396 + default:
111397 + debug_tree((tree)node);
111398 + error("%s: unsupported gcc configuration (%qE).", __func__, current_function_decl);
111399 + gcc_unreachable();
111400 + }
111401 +
111402 + if (TYPE_QUALS(type) != 0)
111403 + return build_qualified_type(new_type, TYPE_QUALS(type));
111404 + return new_type;
111405 +}
111406 +
111407 +static tree get_lhs(const_gimple stmt)
111408 +{
111409 + switch (gimple_code(stmt)) {
111410 + case GIMPLE_ASSIGN:
111411 + case GIMPLE_CALL:
111412 + return gimple_get_lhs(stmt);
111413 + case GIMPLE_PHI:
111414 + return gimple_phi_result(stmt);
111415 + default:
111416 + return NULL_TREE;
111417 + }
111418 +}
111419 +
111420 +static tree cast_to_new_size_overflow_type(struct visited *visited, gimple stmt, tree rhs, tree size_overflow_type, bool before)
111421 +{
111422 + gimple_stmt_iterator gsi;
111423 + tree lhs;
111424 + gimple new_stmt;
111425 +
111426 + if (rhs == NULL_TREE)
111427 + return NULL_TREE;
111428 +
111429 + gsi = gsi_for_stmt(stmt);
111430 + new_stmt = build_cast_stmt(visited, size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before, false);
111431 + pointer_set_insert(visited->my_stmts, new_stmt);
111432 +
111433 + lhs = get_lhs(new_stmt);
111434 + gcc_assert(lhs != NULL_TREE);
111435 + return lhs;
111436 +}
111437 +
111438 +tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before)
111439 +{
111440 + tree lhs, dst_type;
111441 + gimple_stmt_iterator gsi;
111442 +
111443 + if (rhs1 == NULL_TREE) {
111444 + debug_gimple_stmt(oldstmt);
111445 + error("%s: rhs1 is NULL_TREE", __func__);
111446 + gcc_unreachable();
111447 + }
111448 +
111449 + switch (gimple_code(oldstmt)) {
111450 + case GIMPLE_ASM:
111451 + lhs = rhs1;
111452 + break;
111453 + case GIMPLE_CALL:
111454 + case GIMPLE_ASSIGN:
111455 + lhs = gimple_get_lhs(oldstmt);
111456 + break;
111457 + default:
111458 + debug_gimple_stmt(oldstmt);
111459 + gcc_unreachable();
111460 + }
111461 +
111462 + gsi = gsi_for_stmt(oldstmt);
111463 + pointer_set_insert(visited->stmts, oldstmt);
111464 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
111465 + basic_block next_bb, cur_bb;
111466 + const_edge e;
111467 +
111468 + gcc_assert(before == false);
111469 + gcc_assert(stmt_can_throw_internal(oldstmt));
111470 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
111471 + gcc_assert(!gsi_end_p(gsi));
111472 +
111473 + cur_bb = gimple_bb(oldstmt);
111474 + next_bb = cur_bb->next_bb;
111475 + e = find_edge(cur_bb, next_bb);
111476 + gcc_assert(e != NULL);
111477 + gcc_assert(e->flags & EDGE_FALLTHRU);
111478 +
111479 + gsi = gsi_after_labels(next_bb);
111480 + gcc_assert(!gsi_end_p(gsi));
111481 +
111482 + before = true;
111483 + oldstmt = gsi_stmt(gsi);
111484 + }
111485 +
111486 + dst_type = get_size_overflow_type(visited, oldstmt, lhs);
111487 +
111488 + if (is_gimple_constant(rhs1))
111489 + return cast_a_tree(dst_type, rhs1);
111490 + return cast_to_new_size_overflow_type(visited, oldstmt, rhs1, dst_type, before);
111491 +}
111492 +
111493 +tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
111494 +{
111495 + gimple stmt;
111496 + gimple_stmt_iterator gsi;
111497 + tree size_overflow_type, new_var, lhs = gimple_assign_lhs(oldstmt);
111498 +
111499 + if (pointer_set_contains(visited->my_stmts, oldstmt))
111500 + return lhs;
111501 +
111502 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
111503 + rhs1 = gimple_assign_rhs1(oldstmt);
111504 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
111505 + }
111506 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
111507 + rhs2 = gimple_assign_rhs2(oldstmt);
111508 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
111509 + }
111510 +
111511 + stmt = gimple_copy(oldstmt);
111512 + gimple_set_location(stmt, gimple_location(oldstmt));
111513 + pointer_set_insert(visited->my_stmts, stmt);
111514 +
111515 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
111516 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
111517 +
111518 + size_overflow_type = get_size_overflow_type(visited, oldstmt, node);
111519 +
111520 + new_var = create_new_var(size_overflow_type);
111521 + new_var = make_ssa_name(new_var, stmt);
111522 + gimple_assign_set_lhs(stmt, new_var);
111523 +
111524 + if (rhs1 != NULL_TREE)
111525 + gimple_assign_set_rhs1(stmt, rhs1);
111526 +
111527 + if (rhs2 != NULL_TREE)
111528 + gimple_assign_set_rhs2(stmt, rhs2);
111529 +#if BUILDING_GCC_VERSION >= 4006
111530 + if (rhs3 != NULL_TREE)
111531 + gimple_assign_set_rhs3(stmt, rhs3);
111532 +#endif
111533 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
111534 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
111535 +
111536 + gsi = gsi_for_stmt(oldstmt);
111537 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
111538 + update_stmt(stmt);
111539 + pointer_set_insert(visited->stmts, oldstmt);
111540 + return gimple_assign_lhs(stmt);
111541 +}
111542 +
111543 +static tree cast_parm_decl(struct visited *visited, tree phi_ssa_name, tree arg, tree size_overflow_type, basic_block bb)
111544 +{
111545 + gimple assign;
111546 + gimple_stmt_iterator gsi;
111547 + basic_block first_bb;
111548 +
111549 + gcc_assert(SSA_NAME_IS_DEFAULT_DEF(arg));
111550 +
111551 + if (bb->index == 0) {
111552 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
111553 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
111554 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
111555 + bb = first_bb;
111556 + }
111557 +
111558 + gsi = gsi_after_labels(bb);
111559 + assign = build_cast_stmt(visited, size_overflow_type, arg, phi_ssa_name, &gsi, BEFORE_STMT, false);
111560 + pointer_set_insert(visited->my_stmts, assign);
111561 +
111562 + return gimple_assign_lhs(assign);
111563 +}
111564 +
111565 +static tree use_phi_ssa_name(struct visited *visited, tree ssa_name_var, tree new_arg)
111566 +{
111567 + gimple_stmt_iterator gsi;
111568 + gimple assign, def_stmt = get_def_stmt(new_arg);
111569 +
111570 + if (gimple_code(def_stmt) == GIMPLE_PHI) {
111571 + gsi = gsi_after_labels(gimple_bb(def_stmt));
111572 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, BEFORE_STMT, true);
111573 + } else {
111574 + gsi = gsi_for_stmt(def_stmt);
111575 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, AFTER_STMT, true);
111576 + }
111577 +
111578 + pointer_set_insert(visited->my_stmts, assign);
111579 + return gimple_assign_lhs(assign);
111580 +}
111581 +
111582 +static tree cast_visited_phi_arg(struct visited *visited, tree ssa_name_var, tree arg, tree size_overflow_type)
111583 +{
111584 + basic_block bb;
111585 + gimple_stmt_iterator gsi;
111586 + const_gimple def_stmt;
111587 + gimple assign;
111588 +
111589 + def_stmt = get_def_stmt(arg);
111590 + bb = gimple_bb(def_stmt);
111591 + gcc_assert(bb->index != 0);
111592 + gsi = gsi_after_labels(bb);
111593 +
111594 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, BEFORE_STMT, false);
111595 + pointer_set_insert(visited->my_stmts, assign);
111596 + return gimple_assign_lhs(assign);
111597 +}
111598 +
111599 +static tree create_new_phi_arg(struct visited *visited, tree ssa_name_var, tree new_arg, gimple oldstmt, unsigned int i)
111600 +{
111601 + tree size_overflow_type;
111602 + tree arg;
111603 + const_gimple def_stmt;
111604 +
111605 + if (new_arg != NULL_TREE && is_gimple_constant(new_arg))
111606 + return new_arg;
111607 +
111608 + arg = gimple_phi_arg_def(oldstmt, i);
111609 + def_stmt = get_def_stmt(arg);
111610 + gcc_assert(def_stmt != NULL);
111611 + size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
111612 +
111613 + switch (gimple_code(def_stmt)) {
111614 + case GIMPLE_PHI:
111615 + return cast_visited_phi_arg(visited, ssa_name_var, arg, size_overflow_type);
111616 + case GIMPLE_NOP: {
111617 + basic_block bb;
111618 +
111619 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
111620 + return cast_parm_decl(visited, ssa_name_var, arg, size_overflow_type, bb);
111621 + }
111622 + case GIMPLE_ASM: {
111623 + gimple_stmt_iterator gsi;
111624 + gimple assign, stmt = get_def_stmt(arg);
111625 +
111626 + gsi = gsi_for_stmt(stmt);
111627 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, AFTER_STMT, false);
111628 + pointer_set_insert(visited->my_stmts, assign);
111629 + return gimple_assign_lhs(assign);
111630 + }
111631 + default:
111632 + gcc_assert(new_arg != NULL_TREE);
111633 + gcc_assert(types_compatible_p(TREE_TYPE(new_arg), size_overflow_type));
111634 + return use_phi_ssa_name(visited, ssa_name_var, new_arg);
111635 + }
111636 +}
111637 +
111638 +static gimple overflow_create_phi_node(struct visited *visited, gimple oldstmt, tree result)
111639 +{
111640 + basic_block bb;
111641 + gimple phi;
111642 + gimple_seq seq;
111643 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
111644 +
111645 + bb = gsi_bb(gsi);
111646 +
111647 + if (result == NULL_TREE) {
111648 + tree old_result = gimple_phi_result(oldstmt);
111649 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, old_result);
111650 +
111651 + result = create_new_var(size_overflow_type);
111652 + }
111653 +
111654 + phi = create_phi_node(result, bb);
111655 + gimple_phi_set_result(phi, make_ssa_name(result, phi));
111656 + seq = phi_nodes(bb);
111657 + gsi = gsi_last(seq);
111658 + gsi_remove(&gsi, false);
111659 +
111660 + gsi = gsi_for_stmt(oldstmt);
111661 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
111662 + gimple_set_bb(phi, bb);
111663 + return phi;
111664 +}
111665 +
111666 +#if BUILDING_GCC_VERSION <= 4007
111667 +static tree create_new_phi_node(struct visited *visited, VEC(tree, heap) **args, tree ssa_name_var, gimple oldstmt)
111668 +#else
111669 +static tree create_new_phi_node(struct visited *visited, vec<tree, va_heap, vl_embed> *&args, tree ssa_name_var, gimple oldstmt)
111670 +#endif
111671 +{
111672 + gimple new_phi;
111673 + unsigned int i;
111674 + tree arg, result;
111675 + location_t loc = gimple_location(oldstmt);
111676 +
111677 +#if BUILDING_GCC_VERSION <= 4007
111678 + gcc_assert(!VEC_empty(tree, *args));
111679 +#else
111680 + gcc_assert(!args->is_empty());
111681 +#endif
111682 +
111683 + new_phi = overflow_create_phi_node(visited, oldstmt, ssa_name_var);
111684 + result = gimple_phi_result(new_phi);
111685 + ssa_name_var = SSA_NAME_VAR(result);
111686 +
111687 +#if BUILDING_GCC_VERSION <= 4007
111688 + FOR_EACH_VEC_ELT(tree, *args, i, arg) {
111689 +#else
111690 + FOR_EACH_VEC_SAFE_ELT(args, i, arg) {
111691 +#endif
111692 + arg = create_new_phi_arg(visited, ssa_name_var, arg, oldstmt, i);
111693 + add_phi_arg(new_phi, arg, gimple_phi_arg_edge(oldstmt, i), loc);
111694 + }
111695 +
111696 +#if BUILDING_GCC_VERSION <= 4007
111697 + VEC_free(tree, heap, *args);
111698 +#else
111699 + vec_free(args);
111700 +#endif
111701 + update_stmt(new_phi);
111702 + pointer_set_insert(visited->my_stmts, new_phi);
111703 + return result;
111704 +}
111705 +
111706 +static tree handle_phi(struct visited *visited, struct cgraph_node *caller_node, tree orig_result)
111707 +{
111708 + tree ssa_name_var = NULL_TREE;
111709 +#if BUILDING_GCC_VERSION <= 4007
111710 + VEC(tree, heap) *args = NULL;
111711 +#else
111712 + vec<tree, va_heap, vl_embed> *args = NULL;
111713 +#endif
111714 + gimple oldstmt = get_def_stmt(orig_result);
111715 + unsigned int i, len = gimple_phi_num_args(oldstmt);
111716 +
111717 + pointer_set_insert(visited->stmts, oldstmt);
111718 + for (i = 0; i < len; i++) {
111719 + tree arg, new_arg;
111720 +
111721 + arg = gimple_phi_arg_def(oldstmt, i);
111722 + new_arg = expand(visited, caller_node, arg);
111723 +
111724 + if (ssa_name_var == NULL_TREE && new_arg != NULL_TREE)
111725 + ssa_name_var = SSA_NAME_VAR(new_arg);
111726 +
111727 + if (is_gimple_constant(arg)) {
111728 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
111729 +
111730 + new_arg = cast_a_tree(size_overflow_type, arg);
111731 + }
111732 +
111733 +#if BUILDING_GCC_VERSION <= 4007
111734 + VEC_safe_push(tree, heap, args, new_arg);
111735 +#else
111736 + vec_safe_push(args, new_arg);
111737 +#endif
111738 + }
111739 +
111740 +#if BUILDING_GCC_VERSION <= 4007
111741 + return create_new_phi_node(visited, &args, ssa_name_var, oldstmt);
111742 +#else
111743 + return create_new_phi_node(visited, args, ssa_name_var, oldstmt);
111744 +#endif
111745 +}
111746 +
111747 +static tree create_cast_assign(struct visited *visited, gimple stmt)
111748 +{
111749 + tree rhs1 = gimple_assign_rhs1(stmt);
111750 + tree lhs = gimple_assign_lhs(stmt);
111751 + const_tree rhs1_type = TREE_TYPE(rhs1);
111752 + const_tree lhs_type = TREE_TYPE(lhs);
111753 +
111754 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
111755 + return create_assign(visited, stmt, lhs, AFTER_STMT);
111756 +
111757 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
111758 +}
111759 +
111760 +static bool skip_lhs_cast_check(const_gimple stmt)
111761 +{
111762 + const_tree rhs = gimple_assign_rhs1(stmt);
111763 + const_gimple def_stmt = get_def_stmt(rhs);
111764 +
111765 + // 3.8.2 kernel/futex_compat.c compat_exit_robust_list(): get_user() 64 ulong -> int (compat_long_t), int max
111766 + if (gimple_code(def_stmt) == GIMPLE_ASM)
111767 + return true;
111768 +
111769 + if (is_const_plus_unsigned_signed_truncation(rhs))
111770 + return true;
111771 +
111772 + return false;
111773 +}
111774 +
111775 +static tree create_string_param(tree string)
111776 +{
111777 + tree i_type, a_type;
111778 + const int length = TREE_STRING_LENGTH(string);
111779 +
111780 + gcc_assert(length > 0);
111781 +
111782 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
111783 + a_type = build_array_type(char_type_node, i_type);
111784 +
111785 + TREE_TYPE(string) = a_type;
111786 + TREE_CONSTANT(string) = 1;
111787 + TREE_READONLY(string) = 1;
111788 +
111789 + return build1(ADDR_EXPR, ptr_type_node, string);
111790 +}
111791 +
111792 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
111793 +{
111794 + gimple cond_stmt;
111795 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
111796 +
111797 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
111798 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
111799 + update_stmt(cond_stmt);
111800 +}
111801 +
111802 +static void insert_cond_result(struct cgraph_node *caller_node, basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
111803 +{
111804 + gimple func_stmt;
111805 + const_gimple def_stmt;
111806 + const_tree loc_line;
111807 + tree loc_file, ssa_name, current_func;
111808 + expanded_location xloc;
111809 + char *ssa_name_buf;
111810 + int len;
111811 + struct cgraph_edge *edge;
111812 + struct cgraph_node *callee_node;
111813 + int frequency;
111814 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
111815 +
111816 + def_stmt = get_def_stmt(arg);
111817 + xloc = expand_location(gimple_location(def_stmt));
111818 +
111819 + if (!gimple_has_location(def_stmt)) {
111820 + xloc = expand_location(gimple_location(stmt));
111821 + if (!gimple_has_location(stmt))
111822 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
111823 + }
111824 +
111825 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
111826 +
111827 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
111828 + loc_file = create_string_param(loc_file);
111829 +
111830 + current_func = build_string(DECL_NAME_LENGTH(current_function_decl) + 1, DECL_NAME_POINTER(current_function_decl));
111831 + current_func = create_string_param(current_func);
111832 +
111833 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
111834 + call_count++;
111835 + 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);
111836 + gcc_assert(len > 0);
111837 + ssa_name = build_string(len + 1, ssa_name_buf);
111838 + free(ssa_name_buf);
111839 + ssa_name = create_string_param(ssa_name);
111840 +
111841 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
111842 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
111843 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
111844 +
111845 + callee_node = cgraph_get_create_node(report_size_overflow_decl);
111846 + frequency = compute_call_stmt_bb_frequency(current_function_decl, bb_true);
111847 +
111848 + edge = cgraph_create_edge(caller_node, callee_node, func_stmt, bb_true->count, frequency, bb_true->loop_depth);
111849 + gcc_assert(edge != NULL);
111850 +}
111851 +
111852 +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)
111853 +{
111854 + basic_block cond_bb, join_bb, bb_true;
111855 + edge e;
111856 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
111857 +
111858 + cond_bb = gimple_bb(stmt);
111859 + if (before)
111860 + gsi_prev(&gsi);
111861 + if (gsi_end_p(gsi))
111862 + e = split_block_after_labels(cond_bb);
111863 + else
111864 + e = split_block(cond_bb, gsi_stmt(gsi));
111865 + cond_bb = e->src;
111866 + join_bb = e->dest;
111867 + e->flags = EDGE_FALSE_VALUE;
111868 + e->probability = REG_BR_PROB_BASE;
111869 +
111870 + bb_true = create_empty_bb(cond_bb);
111871 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
111872 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
111873 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
111874 +
111875 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
111876 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
111877 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
111878 +
111879 + if (current_loops != NULL) {
111880 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
111881 + add_bb_to_loop(bb_true, cond_bb->loop_father);
111882 + }
111883 +
111884 + insert_cond(cond_bb, arg, cond_code, type_value);
111885 + insert_cond_result(caller_node, bb_true, stmt, arg, min);
111886 +
111887 +// print_the_code_insertions(stmt);
111888 +}
111889 +
111890 +void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
111891 +{
111892 + const_tree rhs_type = TREE_TYPE(rhs);
111893 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
111894 +
111895 + gcc_assert(rhs_type != NULL_TREE);
111896 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
111897 + return;
111898 +
111899 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
111900 +
111901 + if (is_const_plus_unsigned_signed_truncation(rhs))
111902 + return;
111903 +
111904 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
111905 + // typemax (-1) < typemin (0)
111906 + if (TREE_OVERFLOW(type_max))
111907 + return;
111908 +
111909 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
111910 +
111911 + cast_rhs_type = TREE_TYPE(cast_rhs);
111912 + type_max_type = TREE_TYPE(type_max);
111913 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
111914 +
111915 + insert_check_size_overflow(caller_node, stmt, GT_EXPR, cast_rhs, type_max, before, MAX_CHECK);
111916 +
111917 + // special case: get_size_overflow_type(), 32, u64->s
111918 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && TYPE_UNSIGNED(size_overflow_type) && !TYPE_UNSIGNED(rhs_type))
111919 + return;
111920 +
111921 + type_min_type = TREE_TYPE(type_min);
111922 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
111923 + insert_check_size_overflow(caller_node, stmt, LT_EXPR, cast_rhs, type_min, before, MIN_CHECK);
111924 +}
111925 +
111926 +static tree create_cast_overflow_check(struct visited *visited, struct cgraph_node *caller_node, tree new_rhs1, gimple stmt)
111927 +{
111928 + bool cast_lhs, cast_rhs;
111929 + tree lhs = gimple_assign_lhs(stmt);
111930 + tree rhs = gimple_assign_rhs1(stmt);
111931 + const_tree lhs_type = TREE_TYPE(lhs);
111932 + const_tree rhs_type = TREE_TYPE(rhs);
111933 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
111934 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
111935 + unsigned int lhs_size = GET_MODE_BITSIZE(lhs_mode);
111936 + unsigned int rhs_size = GET_MODE_BITSIZE(rhs_mode);
111937 +
111938 + static bool check_lhs[3][4] = {
111939 + // ss su us uu
111940 + { false, true, true, false }, // lhs > rhs
111941 + { false, false, false, false }, // lhs = rhs
111942 + { true, true, true, true }, // lhs < rhs
111943 + };
111944 +
111945 + static bool check_rhs[3][4] = {
111946 + // ss su us uu
111947 + { true, false, true, true }, // lhs > rhs
111948 + { true, false, true, true }, // lhs = rhs
111949 + { true, false, true, true }, // lhs < rhs
111950 + };
111951 +
111952 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast !!!!
111953 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
111954 + return create_assign(visited, stmt, lhs, AFTER_STMT);
111955 +
111956 + if (lhs_size > rhs_size) {
111957 + cast_lhs = check_lhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
111958 + cast_rhs = check_rhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
111959 + } else if (lhs_size == rhs_size) {
111960 + cast_lhs = check_lhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
111961 + cast_rhs = check_rhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
111962 + } else {
111963 + cast_lhs = check_lhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
111964 + cast_rhs = check_rhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
111965 + }
111966 +
111967 + if (!cast_lhs && !cast_rhs)
111968 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
111969 +
111970 + if (cast_lhs && !skip_lhs_cast_check(stmt))
111971 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, lhs, BEFORE_STMT);
111972 +
111973 + if (cast_rhs)
111974 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, rhs, BEFORE_STMT);
111975 +
111976 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
111977 +}
111978 +
111979 +static tree handle_unary_rhs(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
111980 +{
111981 + enum tree_code rhs_code;
111982 + tree rhs1, new_rhs1, lhs = gimple_assign_lhs(stmt);
111983 +
111984 + if (pointer_set_contains(visited->my_stmts, stmt))
111985 + return lhs;
111986 +
111987 + rhs1 = gimple_assign_rhs1(stmt);
111988 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
111989 + return create_assign(visited, stmt, lhs, AFTER_STMT);
111990 +
111991 + new_rhs1 = expand(visited, caller_node, rhs1);
111992 +
111993 + if (new_rhs1 == NULL_TREE)
111994 + return create_cast_assign(visited, stmt);
111995 +
111996 + if (pointer_set_contains(visited->no_cast_check, stmt))
111997 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
111998 +
111999 + rhs_code = gimple_assign_rhs_code(stmt);
112000 + if (rhs_code == BIT_NOT_EXPR || rhs_code == NEGATE_EXPR) {
112001 + tree size_overflow_type = get_size_overflow_type(visited, stmt, rhs1);
112002 +
112003 + new_rhs1 = cast_to_new_size_overflow_type(visited, stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
112004 + check_size_overflow(caller_node, stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
112005 + return create_assign(visited, stmt, lhs, AFTER_STMT);
112006 + }
112007 +
112008 + if (!gimple_assign_cast_p(stmt))
112009 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
112010 +
112011 + return create_cast_overflow_check(visited, caller_node, new_rhs1, stmt);
112012 +}
112013 +
112014 +static tree handle_unary_ops(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
112015 +{
112016 + tree rhs1, lhs = gimple_assign_lhs(stmt);
112017 + gimple def_stmt = get_def_stmt(lhs);
112018 +
112019 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
112020 + rhs1 = gimple_assign_rhs1(def_stmt);
112021 +
112022 + if (is_gimple_constant(rhs1))
112023 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
112024 +
112025 + switch (TREE_CODE(rhs1)) {
112026 + case SSA_NAME: {
112027 + tree ret = handle_unary_rhs(visited, caller_node, def_stmt);
112028 +
112029 + if (gimple_assign_cast_p(stmt))
112030 + unsigned_signed_cast_intentional_overflow(visited, stmt);
112031 + return ret;
112032 + }
112033 + case ARRAY_REF:
112034 + case BIT_FIELD_REF:
112035 + case ADDR_EXPR:
112036 + case COMPONENT_REF:
112037 + case INDIRECT_REF:
112038 +#if BUILDING_GCC_VERSION >= 4006
112039 + case MEM_REF:
112040 +#endif
112041 + case TARGET_MEM_REF:
112042 + case VIEW_CONVERT_EXPR:
112043 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
112044 + case PARM_DECL:
112045 + case VAR_DECL:
112046 + return create_assign(visited, stmt, lhs, AFTER_STMT);
112047 +
112048 + default:
112049 + debug_gimple_stmt(def_stmt);
112050 + debug_tree(rhs1);
112051 + gcc_unreachable();
112052 + }
112053 +}
112054 +
112055 +static void __unused print_the_code_insertions(const_gimple stmt)
112056 +{
112057 + location_t loc = gimple_location(stmt);
112058 +
112059 + inform(loc, "Integer size_overflow check applied here.");
112060 +}
112061 +
112062 +static bool is_from_cast(const_tree node)
112063 +{
112064 + gimple def_stmt = get_def_stmt(node);
112065 +
112066 + if (!def_stmt)
112067 + return false;
112068 +
112069 + if (gimple_assign_cast_p(def_stmt))
112070 + return true;
112071 +
112072 + return false;
112073 +}
112074 +
112075 +// Skip duplication when there is a minus expr and the type of rhs1 or rhs2 is a pointer_type.
112076 +static bool is_a_ptr_minus(gimple stmt)
112077 +{
112078 + const_tree rhs1, rhs2, ptr1_rhs, ptr2_rhs;
112079 +
112080 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
112081 + return false;
112082 +
112083 + rhs1 = gimple_assign_rhs1(stmt);
112084 + if (!is_from_cast(rhs1))
112085 + return false;
112086 +
112087 + rhs2 = gimple_assign_rhs2(stmt);
112088 + if (!is_from_cast(rhs2))
112089 + return false;
112090 +
112091 + ptr1_rhs = gimple_assign_rhs1(get_def_stmt(rhs1));
112092 + ptr2_rhs = gimple_assign_rhs1(get_def_stmt(rhs2));
112093 +
112094 + if (TREE_CODE(TREE_TYPE(ptr1_rhs)) != POINTER_TYPE && TREE_CODE(TREE_TYPE(ptr2_rhs)) != POINTER_TYPE)
112095 + return false;
112096 +
112097 + return true;
112098 +}
112099 +
112100 +static tree handle_binary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
112101 +{
112102 + enum intentional_overflow_type res;
112103 + tree rhs1, rhs2, new_lhs;
112104 + gimple def_stmt = get_def_stmt(lhs);
112105 + tree new_rhs1 = NULL_TREE;
112106 + tree new_rhs2 = NULL_TREE;
112107 +
112108 + if (is_a_ptr_minus(def_stmt))
112109 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
112110 +
112111 + rhs1 = gimple_assign_rhs1(def_stmt);
112112 + rhs2 = gimple_assign_rhs2(def_stmt);
112113 +
112114 + /* no DImode/TImode division in the 32/64 bit kernel */
112115 + switch (gimple_assign_rhs_code(def_stmt)) {
112116 + case RDIV_EXPR:
112117 + case TRUNC_DIV_EXPR:
112118 + case CEIL_DIV_EXPR:
112119 + case FLOOR_DIV_EXPR:
112120 + case ROUND_DIV_EXPR:
112121 + case TRUNC_MOD_EXPR:
112122 + case CEIL_MOD_EXPR:
112123 + case FLOOR_MOD_EXPR:
112124 + case ROUND_MOD_EXPR:
112125 + case EXACT_DIV_EXPR:
112126 + case POINTER_PLUS_EXPR:
112127 + case BIT_AND_EXPR:
112128 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
112129 + default:
112130 + break;
112131 + }
112132 +
112133 + new_lhs = handle_integer_truncation(visited, caller_node, lhs);
112134 + if (new_lhs != NULL_TREE)
112135 + return new_lhs;
112136 +
112137 + if (TREE_CODE(rhs1) == SSA_NAME)
112138 + new_rhs1 = expand(visited, caller_node, rhs1);
112139 + if (TREE_CODE(rhs2) == SSA_NAME)
112140 + new_rhs2 = expand(visited, caller_node, rhs2);
112141 +
112142 + res = add_mul_intentional_overflow(def_stmt);
112143 + if (res != NO_INTENTIONAL_OVERFLOW) {
112144 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
112145 + insert_cast_expr(visited, get_def_stmt(new_lhs), res);
112146 + return new_lhs;
112147 + }
112148 +
112149 + if (skip_expr_on_double_type(def_stmt)) {
112150 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
112151 + insert_cast_expr(visited, get_def_stmt(new_lhs), NO_INTENTIONAL_OVERFLOW);
112152 + return new_lhs;
112153 + }
112154 +
112155 + if (is_a_neg_overflow(def_stmt, rhs2))
112156 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs1, NULL_TREE);
112157 + if (is_a_neg_overflow(def_stmt, rhs1))
112158 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs2, new_rhs2);
112159 +
112160 +
112161 + if (is_a_constant_overflow(def_stmt, rhs2))
112162 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, NULL_TREE);
112163 + if (is_a_constant_overflow(def_stmt, rhs1))
112164 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, new_rhs2);
112165 +
112166 + // the const is between 0 and (signed) MAX
112167 + if (is_gimple_constant(rhs1))
112168 + new_rhs1 = create_assign(visited, def_stmt, rhs1, BEFORE_STMT);
112169 + if (is_gimple_constant(rhs2))
112170 + new_rhs2 = create_assign(visited, def_stmt, rhs2, BEFORE_STMT);
112171 +
112172 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
112173 +}
112174 +
112175 +#if BUILDING_GCC_VERSION >= 4006
112176 +static tree get_new_rhs(struct visited *visited, struct cgraph_node *caller_node, tree size_overflow_type, tree rhs)
112177 +{
112178 + if (is_gimple_constant(rhs))
112179 + return cast_a_tree(size_overflow_type, rhs);
112180 + if (TREE_CODE(rhs) != SSA_NAME)
112181 + return NULL_TREE;
112182 + return expand(visited, caller_node, rhs);
112183 +}
112184 +
112185 +static tree handle_ternary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
112186 +{
112187 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
112188 + gimple def_stmt = get_def_stmt(lhs);
112189 +
112190 + size_overflow_type = get_size_overflow_type(visited, def_stmt, lhs);
112191 +
112192 + rhs1 = gimple_assign_rhs1(def_stmt);
112193 + rhs2 = gimple_assign_rhs2(def_stmt);
112194 + rhs3 = gimple_assign_rhs3(def_stmt);
112195 + new_rhs1 = get_new_rhs(visited, caller_node, size_overflow_type, rhs1);
112196 + new_rhs2 = get_new_rhs(visited, caller_node, size_overflow_type, rhs2);
112197 + new_rhs3 = get_new_rhs(visited, caller_node, size_overflow_type, rhs3);
112198 +
112199 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
112200 +}
112201 +#endif
112202 +
112203 +static tree get_my_stmt_lhs(struct visited *visited, gimple stmt)
112204 +{
112205 + gimple_stmt_iterator gsi;
112206 + gimple next_stmt = NULL;
112207 +
112208 + gsi = gsi_for_stmt(stmt);
112209 +
112210 + do {
112211 + gsi_next(&gsi);
112212 + next_stmt = gsi_stmt(gsi);
112213 +
112214 + if (gimple_code(stmt) == GIMPLE_PHI && !pointer_set_contains(visited->my_stmts, next_stmt))
112215 + return NULL_TREE;
112216 +
112217 + if (pointer_set_contains(visited->my_stmts, next_stmt) && !pointer_set_contains(visited->skip_expr_casts, next_stmt))
112218 + break;
112219 +
112220 + gcc_assert(pointer_set_contains(visited->my_stmts, next_stmt));
112221 + } while (!gsi_end_p(gsi));
112222 +
112223 + gcc_assert(next_stmt);
112224 + return get_lhs(next_stmt);
112225 +}
112226 +
112227 +static tree expand_visited(struct visited *visited, gimple def_stmt)
112228 +{
112229 + gimple_stmt_iterator gsi;
112230 + enum gimple_code code = gimple_code(def_stmt);
112231 +
112232 + if (code == GIMPLE_ASM)
112233 + return NULL_TREE;
112234 +
112235 + gsi = gsi_for_stmt(def_stmt);
112236 + gsi_next(&gsi);
112237 +
112238 + if (gimple_code(def_stmt) == GIMPLE_PHI && gsi_end_p(gsi))
112239 + return NULL_TREE;
112240 + return get_my_stmt_lhs(visited, def_stmt);
112241 +}
112242 +
112243 +tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
112244 +{
112245 + gimple def_stmt;
112246 +
112247 + def_stmt = get_def_stmt(lhs);
112248 +
112249 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
112250 + return NULL_TREE;
112251 +
112252 + if (pointer_set_contains(visited->my_stmts, def_stmt))
112253 + return lhs;
112254 +
112255 + if (pointer_set_contains(visited->stmts, def_stmt))
112256 + return expand_visited(visited, def_stmt);
112257 +
112258 + switch (gimple_code(def_stmt)) {
112259 + case GIMPLE_PHI:
112260 + return handle_phi(visited, caller_node, lhs);
112261 + case GIMPLE_CALL:
112262 + case GIMPLE_ASM:
112263 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
112264 + case GIMPLE_ASSIGN:
112265 + switch (gimple_num_ops(def_stmt)) {
112266 + case 2:
112267 + return handle_unary_ops(visited, caller_node, def_stmt);
112268 + case 3:
112269 + return handle_binary_ops(visited, caller_node, lhs);
112270 +#if BUILDING_GCC_VERSION >= 4006
112271 + case 4:
112272 + return handle_ternary_ops(visited, caller_node, lhs);
112273 +#endif
112274 + }
112275 + default:
112276 + debug_gimple_stmt(def_stmt);
112277 + error("%s: unknown gimple code", __func__);
112278 + gcc_unreachable();
112279 + }
112280 +}
112281 +
112282 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
112283 new file mode 100644
112284 index 0000000..df50164
112285 --- /dev/null
112286 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_ipa.c
112287 @@ -0,0 +1,1141 @@
112288 +/*
112289 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
112290 + * Licensed under the GPL v2, or (at your option) v3
112291 + *
112292 + * Homepage:
112293 + * http://www.grsecurity.net/~ephox/overflow_plugin/
112294 + *
112295 + * Documentation:
112296 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
112297 + *
112298 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
112299 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
112300 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
112301 + *
112302 + * Usage:
112303 + * $ make
112304 + * $ make run
112305 + */
112306 +
112307 +#include "gcc-common.h"
112308 +#include "size_overflow.h"
112309 +
112310 +#define VEC_LEN 128
112311 +#define RET_CHECK NULL_TREE
112312 +#define WRONG_NODE 32
112313 +#define NOT_INTENTIONAL_ASM NULL
112314 +
112315 +unsigned int call_count;
112316 +
112317 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs);
112318 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs);
112319 +
112320 +struct visited_fns {
112321 + struct visited_fns *next;
112322 + const_tree fndecl;
112323 + unsigned int num;
112324 + const_gimple first_stmt;
112325 +};
112326 +
112327 +struct next_cgraph_node {
112328 + struct next_cgraph_node *next;
112329 + struct cgraph_node *current_function;
112330 + tree callee_fndecl;
112331 + unsigned int num;
112332 +};
112333 +
112334 +// Don't want to duplicate entries in next_cgraph_node
112335 +static bool is_in_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, const_tree fndecl, unsigned int num)
112336 +{
112337 + const_tree new_callee_fndecl;
112338 + struct next_cgraph_node *cur_node;
112339 +
112340 + if (fndecl == RET_CHECK)
112341 + new_callee_fndecl = NODE_DECL(node);
112342 + else
112343 + new_callee_fndecl = fndecl;
112344 +
112345 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
112346 + if (!operand_equal_p(NODE_DECL(cur_node->current_function), NODE_DECL(node), 0))
112347 + continue;
112348 + if (!operand_equal_p(cur_node->callee_fndecl, new_callee_fndecl, 0))
112349 + continue;
112350 + if (num == cur_node->num)
112351 + return true;
112352 + }
112353 + return false;
112354 +}
112355 +
112356 +/* Add a next_cgraph_node into the list for handle_function().
112357 + * handle_function() iterates over all the next cgraph nodes and
112358 + * starts the overflow check insertion process.
112359 + */
112360 +static struct next_cgraph_node *create_new_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, tree fndecl, unsigned int num)
112361 +{
112362 + struct next_cgraph_node *new_node;
112363 +
112364 + if (is_in_next_cgraph_node(head, node, fndecl, num))
112365 + return head;
112366 +
112367 + new_node = (struct next_cgraph_node *)xmalloc(sizeof(*new_node));
112368 + new_node->current_function = node;
112369 + new_node->next = NULL;
112370 + new_node->num = num;
112371 + if (fndecl == RET_CHECK)
112372 + new_node->callee_fndecl = NODE_DECL(node);
112373 + else
112374 + new_node->callee_fndecl = fndecl;
112375 +
112376 + if (!head)
112377 + return new_node;
112378 +
112379 + new_node->next = head;
112380 + return new_node;
112381 +}
112382 +
112383 +static struct next_cgraph_node *create_new_next_cgraph_nodes(struct next_cgraph_node *head, struct cgraph_node *node, unsigned int num)
112384 +{
112385 + struct cgraph_edge *e;
112386 +
112387 + if (num == 0)
112388 + return create_new_next_cgraph_node(head, node, RET_CHECK, num);
112389 +
112390 + for (e = node->callers; e; e = e->next_caller) {
112391 + tree fndecl = gimple_call_fndecl(e->call_stmt);
112392 +
112393 + gcc_assert(fndecl != NULL_TREE);
112394 + head = create_new_next_cgraph_node(head, e->caller, fndecl, num);
112395 + }
112396 +
112397 + return head;
112398 +}
112399 +
112400 +struct missing_functions {
112401 + struct missing_functions *next;
112402 + const_tree node;
112403 + tree fndecl;
112404 +};
112405 +
112406 +static struct missing_functions *create_new_missing_function(struct missing_functions *missing_fn_head, tree node)
112407 +{
112408 + struct missing_functions *new_function;
112409 +
112410 + new_function = (struct missing_functions *)xmalloc(sizeof(*new_function));
112411 + new_function->node = node;
112412 + new_function->next = NULL;
112413 +
112414 + if (TREE_CODE(node) == FUNCTION_DECL)
112415 + new_function->fndecl = node;
112416 + else
112417 + new_function->fndecl = current_function_decl;
112418 + gcc_assert(new_function->fndecl);
112419 +
112420 + if (!missing_fn_head)
112421 + return new_function;
112422 +
112423 + new_function->next = missing_fn_head;
112424 + return new_function;
112425 +}
112426 +
112427 +/* If the function is missing from the hash table and it is a static function
112428 + * then create a next_cgraph_node from it for handle_function()
112429 + */
112430 +static struct next_cgraph_node *check_missing_overflow_attribute_and_create_next_node(struct next_cgraph_node *cnodes, struct missing_functions *missing_fn_head)
112431 +{
112432 + unsigned int num;
112433 + const_tree orig_fndecl;
112434 + struct cgraph_node *next_node = NULL;
112435 +
112436 + orig_fndecl = DECL_ORIGIN(missing_fn_head->fndecl);
112437 +
112438 + num = get_function_num(missing_fn_head->node, orig_fndecl);
112439 + if (num == CANNOT_FIND_ARG)
112440 + return cnodes;
112441 +
112442 + if (!is_missing_function(orig_fndecl, num))
112443 + return cnodes;
112444 +
112445 + next_node = cgraph_get_node(missing_fn_head->fndecl);
112446 + if (next_node && next_node->local.local)
112447 + cnodes = create_new_next_cgraph_nodes(cnodes, next_node, num);
112448 + return cnodes;
112449 +}
112450 +
112451 +/* Search for missing size_overflow attributes on the last nodes in ipa and collect them
112452 + * into the next_cgraph_node list. They will be the next interesting returns or callees.
112453 + */
112454 +static struct next_cgraph_node *search_overflow_attribute(struct next_cgraph_node *cnodes, struct interesting_node *cur_node)
112455 +{
112456 + unsigned int i;
112457 + tree node;
112458 + struct missing_functions *cur, *missing_fn_head = NULL;
112459 +
112460 +#if BUILDING_GCC_VERSION <= 4007
112461 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, node) {
112462 +#else
112463 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, node) {
112464 +#endif
112465 + switch (TREE_CODE(node)) {
112466 + case PARM_DECL:
112467 + if (TREE_CODE(TREE_TYPE(node)) != INTEGER_TYPE)
112468 + break;
112469 + case FUNCTION_DECL:
112470 + missing_fn_head = create_new_missing_function(missing_fn_head, node);
112471 + break;
112472 + default:
112473 + break;
112474 + }
112475 + }
112476 +
112477 + while (missing_fn_head) {
112478 + cnodes = check_missing_overflow_attribute_and_create_next_node(cnodes, missing_fn_head);
112479 +
112480 + cur = missing_fn_head->next;
112481 + free(missing_fn_head);
112482 + missing_fn_head = cur;
112483 + }
112484 +
112485 + return cnodes;
112486 +}
112487 +
112488 +static void walk_phi_set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree result)
112489 +{
112490 + gimple phi = get_def_stmt(result);
112491 + unsigned int i, n = gimple_phi_num_args(phi);
112492 +
112493 + pointer_set_insert(visited, phi);
112494 + for (i = 0; i < n; i++) {
112495 + const_tree arg = gimple_phi_arg_def(phi, i);
112496 +
112497 + set_conditions(visited, interesting_conditions, arg);
112498 + }
112499 +}
112500 +
112501 +enum conditions {
112502 + FROM_CONST, NOT_UNARY, CAST, RET, PHI
112503 +};
112504 +
112505 +// Search for constants, cast assignments and binary/ternary assignments
112506 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs)
112507 +{
112508 + gimple def_stmt = get_def_stmt(lhs);
112509 +
112510 + if (is_gimple_constant(lhs)) {
112511 + interesting_conditions[FROM_CONST] = true;
112512 + return;
112513 + }
112514 +
112515 + if (!def_stmt)
112516 + return;
112517 +
112518 + if (pointer_set_contains(visited, def_stmt))
112519 + return;
112520 +
112521 + switch (gimple_code(def_stmt)) {
112522 + case GIMPLE_CALL:
112523 + if (lhs == gimple_call_lhs(def_stmt))
112524 + interesting_conditions[RET] = true;
112525 + return;
112526 + case GIMPLE_NOP:
112527 + case GIMPLE_ASM:
112528 + return;
112529 + case GIMPLE_PHI:
112530 + interesting_conditions[PHI] = true;
112531 + return walk_phi_set_conditions(visited, interesting_conditions, lhs);
112532 + case GIMPLE_ASSIGN:
112533 + if (gimple_num_ops(def_stmt) == 2) {
112534 + const_tree rhs = gimple_assign_rhs1(def_stmt);
112535 +
112536 + if (gimple_assign_cast_p(def_stmt))
112537 + interesting_conditions[CAST] = true;
112538 +
112539 + return set_conditions(visited, interesting_conditions, rhs);
112540 + } else {
112541 + interesting_conditions[NOT_UNARY] = true;
112542 + return;
112543 + }
112544 + default:
112545 + debug_gimple_stmt(def_stmt);
112546 + gcc_unreachable();
112547 + }
112548 +}
112549 +
112550 +// determine whether duplication will be necessary or not.
112551 +static void search_interesting_conditions(struct interesting_node *cur_node, bool *interesting_conditions)
112552 +{
112553 + struct pointer_set_t *visited;
112554 +
112555 + if (gimple_assign_cast_p(cur_node->first_stmt))
112556 + interesting_conditions[CAST] = true;
112557 + else if (is_gimple_assign(cur_node->first_stmt) && gimple_num_ops(cur_node->first_stmt) > 2)
112558 + interesting_conditions[NOT_UNARY] = true;
112559 +
112560 + visited = pointer_set_create();
112561 + set_conditions(visited, interesting_conditions, cur_node->node);
112562 + pointer_set_destroy(visited);
112563 +}
112564 +
112565 +// Remove the size_overflow asm stmt and create an assignment from the input and output of the asm
112566 +static void replace_size_overflow_asm_with_assign(gimple asm_stmt, tree lhs, tree rhs)
112567 +{
112568 + gimple assign;
112569 + gimple_stmt_iterator gsi;
112570 +
112571 + // already removed
112572 + if (gimple_bb(asm_stmt) == NULL)
112573 + return;
112574 + gsi = gsi_for_stmt(asm_stmt);
112575 +
112576 + assign = gimple_build_assign(lhs, rhs);
112577 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
112578 + SSA_NAME_DEF_STMT(lhs) = assign;
112579 +
112580 + gsi_remove(&gsi, true);
112581 +}
112582 +
112583 +/* Get the fndecl of an interesting stmt, the fndecl is the caller function if the interesting
112584 + * stmt is a return otherwise it is the callee function.
112585 + */
112586 +const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum)
112587 +{
112588 + const_tree fndecl;
112589 +
112590 + if (argnum == 0)
112591 + fndecl = current_function_decl;
112592 + else
112593 + fndecl = gimple_call_fndecl(stmt);
112594 +
112595 + if (fndecl == NULL_TREE)
112596 + return NULL_TREE;
112597 +
112598 + return DECL_ORIGIN(fndecl);
112599 +}
112600 +
112601 +// e.g., 3.8.2, 64, arch/x86/ia32/ia32_signal.c copy_siginfo_from_user32(): compat_ptr() u32 max
112602 +static bool skip_asm(const_tree arg)
112603 +{
112604 + gimple def_stmt = get_def_stmt(arg);
112605 +
112606 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
112607 + return false;
112608 +
112609 + def_stmt = get_def_stmt(gimple_assign_rhs1(def_stmt));
112610 + return def_stmt && gimple_code(def_stmt) == GIMPLE_ASM;
112611 +}
112612 +
112613 +static void walk_use_def_phi(struct pointer_set_t *visited, struct interesting_node *cur_node, tree result)
112614 +{
112615 + gimple phi = get_def_stmt(result);
112616 + unsigned int i, n = gimple_phi_num_args(phi);
112617 +
112618 + pointer_set_insert(visited, phi);
112619 + for (i = 0; i < n; i++) {
112620 + tree arg = gimple_phi_arg_def(phi, i);
112621 +
112622 + walk_use_def(visited, cur_node, arg);
112623 + }
112624 +}
112625 +
112626 +static void walk_use_def_binary(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
112627 +{
112628 + gimple def_stmt = get_def_stmt(lhs);
112629 + tree rhs1, rhs2;
112630 +
112631 + rhs1 = gimple_assign_rhs1(def_stmt);
112632 + rhs2 = gimple_assign_rhs2(def_stmt);
112633 +
112634 + walk_use_def(visited, cur_node, rhs1);
112635 + walk_use_def(visited, cur_node, rhs2);
112636 +}
112637 +
112638 +static void insert_last_node(struct interesting_node *cur_node, tree node)
112639 +{
112640 + unsigned int i;
112641 + tree element;
112642 + enum tree_code code;
112643 +
112644 + gcc_assert(node != NULL_TREE);
112645 +
112646 + if (is_gimple_constant(node))
112647 + return;
112648 +
112649 + code = TREE_CODE(node);
112650 + if (code == VAR_DECL) {
112651 + node = DECL_ORIGIN(node);
112652 + code = TREE_CODE(node);
112653 + }
112654 +
112655 + if (code != PARM_DECL && code != FUNCTION_DECL && code != COMPONENT_REF)
112656 + return;
112657 +
112658 +#if BUILDING_GCC_VERSION <= 4007
112659 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, element) {
112660 +#else
112661 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, element) {
112662 +#endif
112663 + if (operand_equal_p(node, element, 0))
112664 + return;
112665 + }
112666 +
112667 +#if BUILDING_GCC_VERSION <= 4007
112668 + gcc_assert(VEC_length(tree, cur_node->last_nodes) < VEC_LEN);
112669 + VEC_safe_push(tree, gc, cur_node->last_nodes, node);
112670 +#else
112671 + gcc_assert(cur_node->last_nodes->length() < VEC_LEN);
112672 + vec_safe_push(cur_node->last_nodes, node);
112673 +#endif
112674 +}
112675 +
112676 +// a size_overflow asm stmt in the control flow doesn't stop the recursion
112677 +static void handle_asm_stmt(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs, const_gimple stmt)
112678 +{
112679 + if (!is_size_overflow_asm(stmt))
112680 + walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
112681 +}
112682 +
112683 +/* collect the parm_decls and fndecls (for checking a missing size_overflow attribute (ret or arg) or intentional_overflow)
112684 + * and component refs (for checking the intentional_overflow attribute).
112685 + */
112686 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
112687 +{
112688 + const_gimple def_stmt;
112689 +
112690 + if (TREE_CODE(lhs) != SSA_NAME) {
112691 + insert_last_node(cur_node, lhs);
112692 + return;
112693 + }
112694 +
112695 + def_stmt = get_def_stmt(lhs);
112696 + if (!def_stmt)
112697 + return;
112698 +
112699 + if (pointer_set_insert(visited, def_stmt))
112700 + return;
112701 +
112702 + switch (gimple_code(def_stmt)) {
112703 + case GIMPLE_NOP:
112704 + return walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
112705 + case GIMPLE_ASM:
112706 + return handle_asm_stmt(visited, cur_node, lhs, def_stmt);
112707 + case GIMPLE_CALL: {
112708 + tree fndecl = gimple_call_fndecl(def_stmt);
112709 +
112710 + if (fndecl == NULL_TREE)
112711 + return;
112712 + insert_last_node(cur_node, fndecl);
112713 + return;
112714 + }
112715 + case GIMPLE_PHI:
112716 + return walk_use_def_phi(visited, cur_node, lhs);
112717 + case GIMPLE_ASSIGN:
112718 + switch (gimple_num_ops(def_stmt)) {
112719 + case 2:
112720 + return walk_use_def(visited, cur_node, gimple_assign_rhs1(def_stmt));
112721 + case 3:
112722 + return walk_use_def_binary(visited, cur_node, lhs);
112723 + }
112724 + default:
112725 + debug_gimple_stmt((gimple)def_stmt);
112726 + error("%s: unknown gimple code", __func__);
112727 + gcc_unreachable();
112728 + }
112729 +}
112730 +
112731 +// Collect all the last nodes for checking the intentional_overflow and size_overflow attributes
112732 +static void set_last_nodes(struct interesting_node *cur_node)
112733 +{
112734 + struct pointer_set_t *visited;
112735 +
112736 + visited = pointer_set_create();
112737 + walk_use_def(visited, cur_node, cur_node->node);
112738 + pointer_set_destroy(visited);
112739 +}
112740 +
112741 +enum precond {
112742 + NO_ATTRIBUTE_SEARCH, NO_CHECK_INSERT, NONE
112743 +};
112744 +
112745 +/* 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.
112746 + * There is only missing size_overflow attribute checking if the intentional_overflow attribute is the mark_no type.
112747 + * Stmt duplication is unnecessary if there are no binary/ternary assignements or if the unary assignment isn't a cast.
112748 + * It skips the possible error codes too.
112749 + */
112750 +static enum precond check_preconditions(struct interesting_node *cur_node)
112751 +{
112752 + bool interesting_conditions[5] = {false, false, false, false, false};
112753 +
112754 + set_last_nodes(cur_node);
112755 +
112756 + check_intentional_attribute_ipa(cur_node);
112757 + if (cur_node->intentional_attr_decl == MARK_TURN_OFF || cur_node->intentional_attr_cur_fndecl == MARK_TURN_OFF)
112758 + return NO_ATTRIBUTE_SEARCH;
112759 +
112760 + search_interesting_conditions(cur_node, interesting_conditions);
112761 +
112762 + // error code: a phi, unary assign (not cast) and returns only
112763 + if (!interesting_conditions[NOT_UNARY] && interesting_conditions[PHI] && interesting_conditions[RET] && !interesting_conditions[CAST])
112764 + return NO_ATTRIBUTE_SEARCH;
112765 +
112766 + // error code: def_stmts trace back to a constant and there are no binary/ternary assigments
112767 + if (interesting_conditions[CAST] && interesting_conditions[FROM_CONST] && !interesting_conditions[NOT_UNARY])
112768 + return NO_ATTRIBUTE_SEARCH;
112769 +
112770 + // unnecessary overflow check
112771 + if (!interesting_conditions[CAST] && !interesting_conditions[NOT_UNARY])
112772 + return NO_CHECK_INSERT;
112773 +
112774 + if (cur_node->intentional_attr_cur_fndecl != MARK_NO)
112775 + return NO_CHECK_INSERT;
112776 +
112777 + return NONE;
112778 +}
112779 +
112780 +static tree cast_to_orig_type(struct visited *visited, gimple stmt, const_tree orig_node, tree new_node)
112781 +{
112782 + const_gimple assign;
112783 + tree orig_type = TREE_TYPE(orig_node);
112784 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
112785 +
112786 + assign = build_cast_stmt(visited, orig_type, new_node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
112787 + return gimple_assign_lhs(assign);
112788 +}
112789 +
112790 +static void change_orig_node(struct visited *visited, struct interesting_node *cur_node, tree new_node)
112791 +{
112792 + void (*set_rhs)(gimple, tree);
112793 + gimple stmt = cur_node->first_stmt;
112794 + const_tree orig_node = cur_node->node;
112795 +
112796 + switch (gimple_code(stmt)) {
112797 + case GIMPLE_RETURN:
112798 + gimple_return_set_retval(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
112799 + break;
112800 + case GIMPLE_CALL:
112801 + gimple_call_set_arg(stmt, cur_node->num - 1, cast_to_orig_type(visited, stmt, orig_node, new_node));
112802 + break;
112803 + case GIMPLE_ASSIGN:
112804 + switch (cur_node->num) {
112805 + case 1:
112806 + set_rhs = &gimple_assign_set_rhs1;
112807 + break;
112808 + case 2:
112809 + set_rhs = &gimple_assign_set_rhs2;
112810 + break;
112811 +#if BUILDING_GCC_VERSION >= 4006
112812 + case 3:
112813 + set_rhs = &gimple_assign_set_rhs3;
112814 + break;
112815 +#endif
112816 + default:
112817 + gcc_unreachable();
112818 + }
112819 +
112820 + set_rhs(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
112821 + break;
112822 + default:
112823 + debug_gimple_stmt(stmt);
112824 + gcc_unreachable();
112825 + }
112826 +
112827 + update_stmt(stmt);
112828 +}
112829 +
112830 +static struct visited *create_visited(void)
112831 +{
112832 + struct visited *new_node;
112833 +
112834 + new_node = (struct visited *)xmalloc(sizeof(*new_node));
112835 + new_node->stmts = pointer_set_create();
112836 + new_node->my_stmts = pointer_set_create();
112837 + new_node->skip_expr_casts = pointer_set_create();
112838 + new_node->no_cast_check = pointer_set_create();
112839 + return new_node;
112840 +}
112841 +
112842 +static void free_visited(struct visited *visited)
112843 +{
112844 + pointer_set_destroy(visited->stmts);
112845 + pointer_set_destroy(visited->my_stmts);
112846 + pointer_set_destroy(visited->skip_expr_casts);
112847 + pointer_set_destroy(visited->no_cast_check);
112848 +
112849 + free(visited);
112850 +}
112851 +
112852 +/* This function calls the main recursion function (expand) that duplicates the stmts. Before that it checks the intentional_overflow attribute and asm stmts,
112853 + * 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
112854 + * in the original stmt (first stmt) and it inserts the overflow check for the arg of the callee or for the return value.
112855 + */
112856 +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)
112857 +{
112858 + enum precond ret;
112859 + tree new_node, orig_node = cur_node->node;
112860 +
112861 + ret = check_preconditions(cur_node);
112862 + if (ret == NO_ATTRIBUTE_SEARCH)
112863 + return cnodes;
112864 +
112865 + cnodes = search_overflow_attribute(cnodes, cur_node);
112866 +
112867 + if (ret == NO_CHECK_INSERT)
112868 + return cnodes;
112869 +
112870 + new_node = expand(visited, caller_node, orig_node);
112871 + if (new_node == NULL_TREE)
112872 + return cnodes;
112873 +
112874 + change_orig_node(visited, cur_node, new_node);
112875 + check_size_overflow(caller_node, cur_node->first_stmt, TREE_TYPE(new_node), new_node, orig_node, BEFORE_STMT);
112876 +
112877 + return cnodes;
112878 +}
112879 +
112880 +// Check visited_fns interesting nodes.
112881 +static bool is_in_interesting_node(struct interesting_node *head, const_gimple first_stmt, const_tree node, unsigned int num)
112882 +{
112883 + struct interesting_node *cur;
112884 +
112885 + for (cur = head; cur; cur = cur->next) {
112886 + if (!operand_equal_p(node, cur->node, 0))
112887 + continue;
112888 + if (num != cur->num)
112889 + continue;
112890 + if (first_stmt == cur->first_stmt)
112891 + return true;
112892 + }
112893 + return false;
112894 +}
112895 +
112896 +/* Create an interesting node. The ipa pass starts to duplicate from these stmts.
112897 + 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
112898 + 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
112899 + the intentional_overflow attribute check. They are collected by set_last_nodes().
112900 + num: arg count of a call stmt or 0 when it is a ret
112901 + node: the recursion starts from here, it is a call arg or a return value
112902 + 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.
112903 + intentional_attr_decl: intentional_overflow attribute of the callee function
112904 + intentional_attr_cur_fndecl: intentional_overflow attribute of the caller function
112905 + intentional_mark_from_gimple: the intentional overflow type of size_overflow asm stmt from gimple if it exists
112906 + */
112907 +static struct interesting_node *create_new_interesting_node(struct interesting_node *head, gimple first_stmt, tree node, unsigned int num, gimple asm_stmt)
112908 +{
112909 + struct interesting_node *new_node;
112910 + tree fndecl;
112911 + enum gimple_code code;
112912 +
112913 + gcc_assert(node != NULL_TREE);
112914 + code = gimple_code(first_stmt);
112915 + gcc_assert(code == GIMPLE_CALL || code == GIMPLE_ASM || code == GIMPLE_ASSIGN || code == GIMPLE_RETURN);
112916 +
112917 + if (num == CANNOT_FIND_ARG)
112918 + return head;
112919 +
112920 + if (skip_types(node))
112921 + return head;
112922 +
112923 + if (skip_asm(node))
112924 + return head;
112925 +
112926 + if (is_gimple_call(first_stmt))
112927 + fndecl = gimple_call_fndecl(first_stmt);
112928 + else
112929 + fndecl = current_function_decl;
112930 +
112931 + if (fndecl == NULL_TREE)
112932 + return head;
112933 +
112934 + if (is_in_interesting_node(head, first_stmt, node, num))
112935 + return head;
112936 +
112937 + new_node = (struct interesting_node *)xmalloc(sizeof(*new_node));
112938 +
112939 + new_node->next = NULL;
112940 + new_node->first_stmt = first_stmt;
112941 +#if BUILDING_GCC_VERSION <= 4007
112942 + new_node->last_nodes = VEC_alloc(tree, gc, VEC_LEN);
112943 +#else
112944 + vec_alloc(new_node->last_nodes, VEC_LEN);
112945 +#endif
112946 + new_node->num = num;
112947 + new_node->node = node;
112948 + new_node->fndecl = fndecl;
112949 + new_node->intentional_attr_decl = MARK_NO;
112950 + new_node->intentional_attr_cur_fndecl = MARK_NO;
112951 + new_node->intentional_mark_from_gimple = asm_stmt;
112952 +
112953 + if (!head)
112954 + return new_node;
112955 +
112956 + new_node->next = head;
112957 + return new_node;
112958 +}
112959 +
112960 +/* 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).
112961 + * If the ret stmt is in the next cgraph node list then it's an interesting ret.
112962 + */
112963 +static struct interesting_node *handle_stmt_by_cgraph_nodes_ret(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
112964 +{
112965 + struct next_cgraph_node *cur_node;
112966 + tree ret = gimple_return_retval(stmt);
112967 +
112968 + if (ret == NULL_TREE)
112969 + return head;
112970 +
112971 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
112972 + if (!operand_equal_p(cur_node->callee_fndecl, DECL_ORIGIN(current_function_decl), 0))
112973 + continue;
112974 + if (cur_node->num == 0)
112975 + head = create_new_interesting_node(head, stmt, ret, 0, NOT_INTENTIONAL_ASM);
112976 + }
112977 +
112978 + return head;
112979 +}
112980 +
112981 +/* 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).
112982 + * If the call stmt is in the next cgraph node list then it's an interesting call.
112983 + */
112984 +static struct interesting_node *handle_stmt_by_cgraph_nodes_call(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
112985 +{
112986 + unsigned int argnum;
112987 + tree arg;
112988 + const_tree fndecl;
112989 + struct next_cgraph_node *cur_node;
112990 +
112991 + fndecl = gimple_call_fndecl(stmt);
112992 + if (fndecl == NULL_TREE)
112993 + return head;
112994 +
112995 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
112996 + if (!operand_equal_p(cur_node->callee_fndecl, fndecl, 0))
112997 + continue;
112998 + argnum = get_correct_arg_count(cur_node->num, fndecl);
112999 + gcc_assert(argnum != CANNOT_FIND_ARG);
113000 + if (argnum == 0)
113001 + continue;
113002 +
113003 + arg = gimple_call_arg(stmt, argnum - 1);
113004 + head = create_new_interesting_node(head, stmt, arg, argnum, NOT_INTENTIONAL_ASM);
113005 + }
113006 +
113007 + return head;
113008 +}
113009 +
113010 +static unsigned int check_ops(const_tree orig_node, const_tree node, unsigned int ret_count)
113011 +{
113012 + if (!operand_equal_p(orig_node, node, 0))
113013 + return WRONG_NODE;
113014 + if (skip_types(node))
113015 + return WRONG_NODE;
113016 + return ret_count;
113017 +}
113018 +
113019 +// Get the index of the rhs node in an assignment
113020 +static unsigned int get_assign_ops_count(const_gimple stmt, tree node)
113021 +{
113022 + const_tree rhs1, rhs2;
113023 + unsigned int ret;
113024 +
113025 + gcc_assert(stmt);
113026 + gcc_assert(is_gimple_assign(stmt));
113027 +
113028 + rhs1 = gimple_assign_rhs1(stmt);
113029 + gcc_assert(rhs1 != NULL_TREE);
113030 +
113031 + switch (gimple_num_ops(stmt)) {
113032 + case 2:
113033 + return check_ops(node, rhs1, 1);
113034 + case 3:
113035 + ret = check_ops(node, rhs1, 1);
113036 + if (ret != WRONG_NODE)
113037 + return ret;
113038 +
113039 + rhs2 = gimple_assign_rhs2(stmt);
113040 + gcc_assert(rhs2 != NULL_TREE);
113041 + return check_ops(node, rhs2, 2);
113042 + default:
113043 + gcc_unreachable();
113044 + }
113045 +}
113046 +
113047 +// Find the correct arg number of a call stmt. It is needed when the interesting function is a cloned function.
113048 +static unsigned int find_arg_number_gimple(const_tree arg, const_gimple stmt)
113049 +{
113050 + unsigned int i;
113051 +
113052 + if (gimple_call_fndecl(stmt) == NULL_TREE)
113053 + return CANNOT_FIND_ARG;
113054 +
113055 + for (i = 0; i < gimple_call_num_args(stmt); i++) {
113056 + tree node;
113057 +
113058 + node = gimple_call_arg(stmt, i);
113059 + if (!operand_equal_p(arg, node, 0))
113060 + continue;
113061 + if (!skip_types(node))
113062 + return i + 1;
113063 + }
113064 +
113065 + return CANNOT_FIND_ARG;
113066 +}
113067 +
113068 +/* starting from the size_overflow asm stmt collect interesting stmts. They can be
113069 + * any of return, call or assignment stmts (because of inlining).
113070 + */
113071 +static struct interesting_node *get_interesting_ret_or_call(struct pointer_set_t *visited, struct interesting_node *head, tree node, gimple intentional_asm)
113072 +{
113073 + use_operand_p use_p;
113074 + imm_use_iterator imm_iter;
113075 + unsigned int argnum;
113076 +
113077 + gcc_assert(TREE_CODE(node) == SSA_NAME);
113078 +
113079 + if (pointer_set_insert(visited, node))
113080 + return head;
113081 +
113082 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
113083 + gimple stmt = USE_STMT(use_p);
113084 +
113085 + if (stmt == NULL)
113086 + return head;
113087 + if (is_gimple_debug(stmt))
113088 + continue;
113089 +
113090 + switch (gimple_code(stmt)) {
113091 + case GIMPLE_CALL:
113092 + argnum = find_arg_number_gimple(node, stmt);
113093 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
113094 + break;
113095 + case GIMPLE_RETURN:
113096 + head = create_new_interesting_node(head, stmt, node, 0, intentional_asm);
113097 + break;
113098 + case GIMPLE_ASSIGN:
113099 + argnum = get_assign_ops_count(stmt, node);
113100 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
113101 + break;
113102 + case GIMPLE_PHI: {
113103 + tree result = gimple_phi_result(stmt);
113104 + head = get_interesting_ret_or_call(visited, head, result, intentional_asm);
113105 + break;
113106 + }
113107 + case GIMPLE_ASM:
113108 + if (gimple_asm_noutputs(stmt) != 0)
113109 + break;
113110 + if (!is_size_overflow_asm(stmt))
113111 + break;
113112 + head = create_new_interesting_node(head, stmt, node, 1, intentional_asm);
113113 + break;
113114 + case GIMPLE_COND:
113115 + case GIMPLE_SWITCH:
113116 + break;
113117 + default:
113118 + debug_gimple_stmt(stmt);
113119 + gcc_unreachable();
113120 + break;
113121 + }
113122 + }
113123 + return head;
113124 +}
113125 +
113126 +static void remove_size_overflow_asm(gimple stmt)
113127 +{
113128 + gimple_stmt_iterator gsi;
113129 + tree input, output;
113130 +
113131 + if (!is_size_overflow_asm(stmt))
113132 + return;
113133 +
113134 + if (gimple_asm_noutputs(stmt) == 0) {
113135 + gsi = gsi_for_stmt(stmt);
113136 + ipa_remove_stmt_references(cgraph_get_create_node(current_function_decl), stmt);
113137 + gsi_remove(&gsi, true);
113138 + return;
113139 + }
113140 +
113141 + input = gimple_asm_input_op(stmt, 0);
113142 + output = gimple_asm_output_op(stmt, 0);
113143 + replace_size_overflow_asm_with_assign(stmt, TREE_VALUE(output), TREE_VALUE(input));
113144 +}
113145 +
113146 +/* handle the size_overflow asm stmts from the gimple pass and collect the interesting stmts.
113147 + * If the asm stmt is a parm_decl kind (noutputs == 0) then remove it.
113148 + * If it is a simple asm stmt then replace it with an assignment from the asm input to the asm output.
113149 + */
113150 +static struct interesting_node *handle_stmt_by_size_overflow_asm(gimple stmt, struct interesting_node *head)
113151 +{
113152 + const_tree output;
113153 + struct pointer_set_t *visited;
113154 + gimple intentional_asm = NOT_INTENTIONAL_ASM;
113155 +
113156 + if (!is_size_overflow_asm(stmt))
113157 + return head;
113158 +
113159 + if (is_size_overflow_intentional_asm_yes(stmt) || is_size_overflow_intentional_asm_turn_off(stmt))
113160 + intentional_asm = stmt;
113161 +
113162 + gcc_assert(gimple_asm_ninputs(stmt) == 1);
113163 +
113164 + if (gimple_asm_noutputs(stmt) == 0 && is_size_overflow_intentional_asm_turn_off(stmt))
113165 + return head;
113166 +
113167 + if (gimple_asm_noutputs(stmt) == 0) {
113168 + const_tree input;
113169 +
113170 + if (!is_size_overflow_intentional_asm_turn_off(stmt))
113171 + return head;
113172 +
113173 + input = gimple_asm_input_op(stmt, 0);
113174 + remove_size_overflow_asm(stmt);
113175 + if (is_gimple_constant(TREE_VALUE(input)))
113176 + return head;
113177 + visited = pointer_set_create();
113178 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(input), intentional_asm);
113179 + pointer_set_destroy(visited);
113180 + return head;
113181 + }
113182 +
113183 + if (!is_size_overflow_intentional_asm_yes(stmt) && !is_size_overflow_intentional_asm_turn_off(stmt))
113184 + remove_size_overflow_asm(stmt);
113185 +
113186 + visited = pointer_set_create();
113187 + output = gimple_asm_output_op(stmt, 0);
113188 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(output), intentional_asm);
113189 + pointer_set_destroy(visited);
113190 + return head;
113191 +}
113192 +
113193 +/* Iterate over all the stmts of a function and look for the size_overflow asm stmts (they were created in the gimple pass)
113194 + * or a call stmt or a return stmt and store them in the interesting_node list
113195 + */
113196 +static struct interesting_node *collect_interesting_stmts(struct next_cgraph_node *next_node)
113197 +{
113198 + basic_block bb;
113199 + struct interesting_node *head = NULL;
113200 +
113201 + FOR_ALL_BB_FN(bb, cfun) {
113202 + gimple_stmt_iterator gsi;
113203 +
113204 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
113205 + enum gimple_code code;
113206 + gimple stmt = gsi_stmt(gsi);
113207 +
113208 + code = gimple_code(stmt);
113209 +
113210 + if (code == GIMPLE_ASM)
113211 + head = handle_stmt_by_size_overflow_asm(stmt, head);
113212 +
113213 + if (!next_node)
113214 + continue;
113215 + if (code == GIMPLE_CALL)
113216 + head = handle_stmt_by_cgraph_nodes_call(head, stmt, next_node);
113217 + if (code == GIMPLE_RETURN)
113218 + head = handle_stmt_by_cgraph_nodes_ret(head, stmt, next_node);
113219 + }
113220 + }
113221 + return head;
113222 +}
113223 +
113224 +static void free_interesting_node(struct interesting_node *head)
113225 +{
113226 + struct interesting_node *cur;
113227 +
113228 + while (head) {
113229 + cur = head->next;
113230 +#if BUILDING_GCC_VERSION <= 4007
113231 + VEC_free(tree, gc, head->last_nodes);
113232 +#else
113233 + vec_free(head->last_nodes);
113234 +#endif
113235 + free(head);
113236 + head = cur;
113237 + }
113238 +}
113239 +
113240 +static struct visited_fns *insert_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
113241 +{
113242 + struct visited_fns *new_visited_fns;
113243 +
113244 + new_visited_fns = (struct visited_fns *)xmalloc(sizeof(*new_visited_fns));
113245 + new_visited_fns->fndecl = cur_node->fndecl;
113246 + new_visited_fns->num = cur_node->num;
113247 + new_visited_fns->first_stmt = cur_node->first_stmt;
113248 + new_visited_fns->next = NULL;
113249 +
113250 + if (!head)
113251 + return new_visited_fns;
113252 +
113253 + new_visited_fns->next = head;
113254 + return new_visited_fns;
113255 +}
113256 +
113257 +/* 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
113258 + * it is a visited_fns function.
113259 + */
113260 +static bool is_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
113261 +{
113262 + struct visited_fns *cur;
113263 +
113264 + if (!head)
113265 + return false;
113266 +
113267 + for (cur = head; cur; cur = cur->next) {
113268 + if (cur_node->first_stmt != cur->first_stmt)
113269 + continue;
113270 + if (!operand_equal_p(cur_node->fndecl, cur->fndecl, 0))
113271 + continue;
113272 + if (cur_node->num == cur->num)
113273 + return true;
113274 + }
113275 + return false;
113276 +}
113277 +
113278 +static void free_next_cgraph_node(struct next_cgraph_node *head)
113279 +{
113280 + struct next_cgraph_node *cur;
113281 +
113282 + while (head) {
113283 + cur = head->next;
113284 + free(head);
113285 + head = cur;
113286 + }
113287 +}
113288 +
113289 +static void remove_all_size_overflow_asm(void)
113290 +{
113291 + basic_block bb;
113292 +
113293 + FOR_ALL_BB_FN(bb, cfun) {
113294 + gimple_stmt_iterator si;
113295 +
113296 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
113297 + remove_size_overflow_asm(gsi_stmt(si));
113298 + }
113299 +}
113300 +
113301 +/* Main recursive walk of the ipa pass: iterate over the collected interesting stmts in a function
113302 + * (they are interesting if they have an associated size_overflow asm stmt) and recursively walk
113303 + * the newly collected interesting functions (they are interesting if there is control flow between
113304 + * the interesting stmts and them).
113305 + */
113306 +static struct visited_fns *handle_function(struct cgraph_node *node, struct next_cgraph_node *next_node, struct visited_fns *visited_fns)
113307 +{
113308 + struct visited *visited;
113309 + struct interesting_node *head, *cur_node;
113310 + struct next_cgraph_node *cur_cnodes, *cnodes_head = NULL;
113311 +
113312 + set_current_function_decl(NODE_DECL(node));
113313 + call_count = 0;
113314 +
113315 + head = collect_interesting_stmts(next_node);
113316 +
113317 + visited = create_visited();
113318 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
113319 + if (is_visited_fns_function(visited_fns, cur_node))
113320 + continue;
113321 + cnodes_head = handle_interesting_stmt(visited, cnodes_head, cur_node, node);
113322 + visited_fns = insert_visited_fns_function(visited_fns, cur_node);
113323 + }
113324 +
113325 + free_visited(visited);
113326 + free_interesting_node(head);
113327 + remove_all_size_overflow_asm();
113328 + unset_current_function_decl();
113329 +
113330 + for (cur_cnodes = cnodes_head; cur_cnodes; cur_cnodes = cur_cnodes->next)
113331 + visited_fns = handle_function(cur_cnodes->current_function, cur_cnodes, visited_fns);
113332 +
113333 + free_next_cgraph_node(cnodes_head);
113334 + return visited_fns;
113335 +}
113336 +
113337 +static void free_visited_fns(struct visited_fns *head)
113338 +{
113339 + struct visited_fns *cur;
113340 +
113341 + while (head) {
113342 + cur = head->next;
113343 + free(head);
113344 + head = cur;
113345 + }
113346 +}
113347 +
113348 +// Main entry point of the ipa pass: erases the plf flag of all stmts and iterates over all the functions
113349 +unsigned int search_function(void)
113350 +{
113351 + struct cgraph_node *node;
113352 + struct visited_fns *visited_fns = NULL;
113353 +
113354 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
113355 + gcc_assert(cgraph_function_flags_ready);
113356 +#if BUILDING_GCC_VERSION <= 4007
113357 + gcc_assert(node->reachable);
113358 +#endif
113359 +
113360 + visited_fns = handle_function(node, NULL, visited_fns);
113361 + }
113362 +
113363 + free_visited_fns(visited_fns);
113364 + return 0;
113365 +}
113366 +
113367 +#if BUILDING_GCC_VERSION >= 4009
113368 +static const struct pass_data insert_size_overflow_check_data = {
113369 +#else
113370 +static struct ipa_opt_pass_d insert_size_overflow_check = {
113371 + .pass = {
113372 +#endif
113373 + .type = SIMPLE_IPA_PASS,
113374 + .name = "size_overflow",
113375 +#if BUILDING_GCC_VERSION >= 4008
113376 + .optinfo_flags = OPTGROUP_NONE,
113377 +#endif
113378 +#if BUILDING_GCC_VERSION >= 4009
113379 + .has_gate = false,
113380 + .has_execute = true,
113381 +#else
113382 + .gate = NULL,
113383 + .execute = search_function,
113384 + .sub = NULL,
113385 + .next = NULL,
113386 + .static_pass_number = 0,
113387 +#endif
113388 + .tv_id = TV_NONE,
113389 + .properties_required = 0,
113390 + .properties_provided = 0,
113391 + .properties_destroyed = 0,
113392 + .todo_flags_start = 0,
113393 + .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,
113394 +#if BUILDING_GCC_VERSION < 4009
113395 + },
113396 + .generate_summary = NULL,
113397 + .write_summary = NULL,
113398 + .read_summary = NULL,
113399 +#if BUILDING_GCC_VERSION >= 4006
113400 + .write_optimization_summary = NULL,
113401 + .read_optimization_summary = NULL,
113402 +#endif
113403 + .stmt_fixup = NULL,
113404 + .function_transform_todo_flags_start = 0,
113405 + .function_transform = NULL,
113406 + .variable_transform = NULL,
113407 +#endif
113408 +};
113409 +
113410 +#if BUILDING_GCC_VERSION >= 4009
113411 +namespace {
113412 +class insert_size_overflow_check : public ipa_opt_pass_d {
113413 +public:
113414 + insert_size_overflow_check() : ipa_opt_pass_d(insert_size_overflow_check_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
113415 + unsigned int execute() { return search_function(); }
113416 +};
113417 +}
113418 +#endif
113419 +
113420 +struct opt_pass *make_insert_size_overflow_check(void)
113421 +{
113422 +#if BUILDING_GCC_VERSION >= 4009
113423 + return new insert_size_overflow_check();
113424 +#else
113425 + return &insert_size_overflow_check.pass;
113426 +#endif
113427 +}
113428 +
113429 diff --git a/tools/gcc/size_overflow_plugin/intentional_overflow.c b/tools/gcc/size_overflow_plugin/intentional_overflow.c
113430 new file mode 100644
113431 index 0000000..d71d72a
113432 --- /dev/null
113433 +++ b/tools/gcc/size_overflow_plugin/intentional_overflow.c
113434 @@ -0,0 +1,736 @@
113435 +/*
113436 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
113437 + * Licensed under the GPL v2, or (at your option) v3
113438 + *
113439 + * Homepage:
113440 + * http://www.grsecurity.net/~ephox/overflow_plugin/
113441 + *
113442 + * Documentation:
113443 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
113444 + *
113445 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
113446 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
113447 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
113448 + *
113449 + * Usage:
113450 + * $ make
113451 + * $ make run
113452 + */
113453 +
113454 +#include "gcc-common.h"
113455 +#include "size_overflow.h"
113456 +
113457 +/* Get the param of the intentional_overflow attribute.
113458 + * * 0: MARK_NOT_INTENTIONAL
113459 + * * 1..MAX_PARAM: MARK_YES
113460 + * * -1: MARK_TURN_OFF
113461 + */
113462 +static tree get_attribute_param(const_tree decl)
113463 +{
113464 + const_tree attr;
113465 +
113466 + if (decl == NULL_TREE)
113467 + return NULL_TREE;
113468 +
113469 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(decl));
113470 + if (!attr || !TREE_VALUE(attr))
113471 + return NULL_TREE;
113472 +
113473 + return TREE_VALUE(attr);
113474 +}
113475 +
113476 +// MARK_TURN_OFF
113477 +bool is_turn_off_intentional_attr(const_tree decl)
113478 +{
113479 + const_tree param_head;
113480 +
113481 + param_head = get_attribute_param(decl);
113482 + if (param_head == NULL_TREE)
113483 + return false;
113484 +
113485 + if (TREE_INT_CST_HIGH(TREE_VALUE(param_head)) == -1)
113486 + return true;
113487 + return false;
113488 +}
113489 +
113490 +// MARK_NOT_INTENTIONAL
113491 +bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum)
113492 +{
113493 + const_tree param_head;
113494 +
113495 + if (argnum == 0)
113496 + return false;
113497 +
113498 + param_head = get_attribute_param(decl);
113499 + if (param_head == NULL_TREE)
113500 + return false;
113501 +
113502 + if (!TREE_INT_CST_LOW(TREE_VALUE(param_head)))
113503 + return true;
113504 + return false;
113505 +}
113506 +
113507 +// MARK_YES
113508 +bool is_yes_intentional_attr(const_tree decl, unsigned int argnum)
113509 +{
113510 + tree param, param_head;
113511 +
113512 + if (argnum == 0)
113513 + return false;
113514 +
113515 + param_head = get_attribute_param(decl);
113516 + for (param = param_head; param; param = TREE_CHAIN(param))
113517 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(param)))
113518 + return true;
113519 + return false;
113520 +}
113521 +
113522 +void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum)
113523 +{
113524 + location_t loc;
113525 +
113526 + if (caller_attr == MARK_NO || caller_attr == MARK_NOT_INTENTIONAL || caller_attr == MARK_TURN_OFF)
113527 + return;
113528 +
113529 + if (callee_attr == MARK_NOT_INTENTIONAL || callee_attr == MARK_YES)
113530 + return;
113531 +
113532 + loc = DECL_SOURCE_LOCATION(decl);
113533 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", DECL_NAME_POINTER(decl), argnum);
113534 +}
113535 +
113536 +// Get the field decl of a component ref for intentional_overflow checking
113537 +static const_tree search_field_decl(const_tree comp_ref)
113538 +{
113539 + const_tree field = NULL_TREE;
113540 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
113541 +
113542 + for (i = 0; i < len; i++) {
113543 + field = TREE_OPERAND(comp_ref, i);
113544 + if (TREE_CODE(field) == FIELD_DECL)
113545 + break;
113546 + }
113547 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
113548 + return field;
113549 +}
113550 +
113551 +/* Get the type of the intentional_overflow attribute of a node
113552 + * * MARK_TURN_OFF
113553 + * * MARK_YES
113554 + * * MARK_NO
113555 + * * MARK_NOT_INTENTIONAL
113556 + */
113557 +enum mark get_intentional_attr_type(const_tree node)
113558 +{
113559 + const_tree cur_decl;
113560 +
113561 + if (node == NULL_TREE)
113562 + return MARK_NO;
113563 +
113564 + switch (TREE_CODE(node)) {
113565 + case COMPONENT_REF:
113566 + cur_decl = search_field_decl(node);
113567 + if (is_turn_off_intentional_attr(cur_decl))
113568 + return MARK_TURN_OFF;
113569 + if (is_end_intentional_intentional_attr(cur_decl, 1))
113570 + return MARK_YES;
113571 + break;
113572 + case PARM_DECL: {
113573 + unsigned int argnum;
113574 +
113575 + cur_decl = DECL_ORIGIN(current_function_decl);
113576 + argnum = find_arg_number_tree(node, cur_decl);
113577 + if (argnum == CANNOT_FIND_ARG)
113578 + return MARK_NO;
113579 + if (is_yes_intentional_attr(cur_decl, argnum))
113580 + return MARK_YES;
113581 + if (is_end_intentional_intentional_attr(cur_decl, argnum))
113582 + return MARK_NOT_INTENTIONAL;
113583 + break;
113584 + }
113585 + case FUNCTION_DECL:
113586 + if (is_turn_off_intentional_attr(DECL_ORIGIN(node)))
113587 + return MARK_TURN_OFF;
113588 + break;
113589 + default:
113590 + break;
113591 + }
113592 + return MARK_NO;
113593 +}
113594 +
113595 +// Search for the intentional_overflow attribute on the last nodes
113596 +static enum mark search_last_nodes_intentional(struct interesting_node *cur_node)
113597 +{
113598 + unsigned int i;
113599 + tree last_node;
113600 + enum mark mark = MARK_NO;
113601 +
113602 +#if BUILDING_GCC_VERSION <= 4007
113603 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, last_node) {
113604 +#else
113605 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, last_node) {
113606 +#endif
113607 + mark = get_intentional_attr_type(last_node);
113608 + if (mark != MARK_NO)
113609 + break;
113610 + }
113611 + return mark;
113612 +}
113613 +
113614 +/* Check the intentional kind of size_overflow asm stmt (created by the gimple pass) and
113615 + * set the appropriate intentional_overflow type. Delete the asm stmt in the end.
113616 + */
113617 +static bool is_intentional_attribute_from_gimple(struct interesting_node *cur_node)
113618 +{
113619 + if (!cur_node->intentional_mark_from_gimple)
113620 + return false;
113621 +
113622 + if (is_size_overflow_intentional_asm_yes(cur_node->intentional_mark_from_gimple))
113623 + cur_node->intentional_attr_cur_fndecl = MARK_YES;
113624 + else
113625 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
113626 +
113627 + // skip param decls
113628 + if (gimple_asm_noutputs(cur_node->intentional_mark_from_gimple) == 0)
113629 + return true;
113630 + return true;
113631 +}
113632 +
113633 +/* Search intentional_overflow attribute on caller and on callee too.
113634 + * 0</MARK_YES: no dup, search size_overflow and intentional_overflow attributes
113635 + * 0/MARK_NOT_INTENTIONAL: no dup, search size_overflow attribute (int)
113636 + * -1/MARK_TURN_OFF: no dup, no search, current_function_decl -> no dup
113637 +*/
113638 +void check_intentional_attribute_ipa(struct interesting_node *cur_node)
113639 +{
113640 + const_tree fndecl;
113641 +
113642 + if (is_intentional_attribute_from_gimple(cur_node))
113643 + return;
113644 +
113645 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
113646 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
113647 + return;
113648 + }
113649 +
113650 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASM) {
113651 + cur_node->intentional_attr_cur_fndecl = MARK_NOT_INTENTIONAL;
113652 + return;
113653 + }
113654 +
113655 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASSIGN)
113656 + return;
113657 +
113658 + fndecl = get_interesting_orig_fndecl(cur_node->first_stmt, cur_node->num);
113659 + if (is_turn_off_intentional_attr(fndecl)) {
113660 + cur_node->intentional_attr_decl = MARK_TURN_OFF;
113661 + return;
113662 + }
113663 +
113664 + if (is_end_intentional_intentional_attr(fndecl, cur_node->num))
113665 + cur_node->intentional_attr_decl = MARK_NOT_INTENTIONAL;
113666 + else if (is_yes_intentional_attr(fndecl, cur_node->num))
113667 + cur_node->intentional_attr_decl = MARK_YES;
113668 +
113669 + cur_node->intentional_attr_cur_fndecl = search_last_nodes_intentional(cur_node);
113670 + print_missing_intentional(cur_node->intentional_attr_decl, cur_node->intentional_attr_cur_fndecl, cur_node->fndecl, cur_node->num);
113671 +}
113672 +
113673 +bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
113674 +{
113675 + const_tree rhs1, lhs, rhs1_type, lhs_type;
113676 + enum machine_mode lhs_mode, rhs_mode;
113677 + gimple def_stmt = get_def_stmt(no_const_rhs);
113678 +
113679 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
113680 + return false;
113681 +
113682 + rhs1 = gimple_assign_rhs1(def_stmt);
113683 + lhs = gimple_assign_lhs(def_stmt);
113684 + rhs1_type = TREE_TYPE(rhs1);
113685 + lhs_type = TREE_TYPE(lhs);
113686 + rhs_mode = TYPE_MODE(rhs1_type);
113687 + lhs_mode = TYPE_MODE(lhs_type);
113688 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
113689 + return false;
113690 +
113691 + return true;
113692 +}
113693 +
113694 +static unsigned int uses_num(tree node)
113695 +{
113696 + imm_use_iterator imm_iter;
113697 + use_operand_p use_p;
113698 + unsigned int num = 0;
113699 +
113700 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
113701 + gimple use_stmt = USE_STMT(use_p);
113702 +
113703 + if (use_stmt == NULL)
113704 + return num;
113705 + if (is_gimple_debug(use_stmt))
113706 + continue;
113707 + if (gimple_assign_cast_p(use_stmt) && is_size_overflow_type(gimple_assign_lhs(use_stmt)))
113708 + continue;
113709 + num++;
113710 + }
113711 + return num;
113712 +}
113713 +
113714 +static bool no_uses(tree node)
113715 +{
113716 + return !uses_num(node);
113717 +}
113718 +
113719 +// 3.8.5 mm/page-writeback.c __ilog2_u64(): ret, uint + uintmax; uint -> int; int max
113720 +bool is_const_plus_unsigned_signed_truncation(const_tree lhs)
113721 +{
113722 + tree rhs1, lhs_type, rhs_type, rhs2, not_const_rhs;
113723 + gimple def_stmt = get_def_stmt(lhs);
113724 +
113725 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
113726 + return false;
113727 +
113728 + rhs1 = gimple_assign_rhs1(def_stmt);
113729 + rhs_type = TREE_TYPE(rhs1);
113730 + lhs_type = TREE_TYPE(lhs);
113731 + if (TYPE_UNSIGNED(lhs_type) || !TYPE_UNSIGNED(rhs_type))
113732 + return false;
113733 + if (TYPE_MODE(lhs_type) != TYPE_MODE(rhs_type))
113734 + return false;
113735 +
113736 + def_stmt = get_def_stmt(rhs1);
113737 + if (!def_stmt || !is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 3)
113738 + return false;
113739 +
113740 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR)
113741 + return false;
113742 +
113743 + rhs1 = gimple_assign_rhs1(def_stmt);
113744 + rhs2 = gimple_assign_rhs2(def_stmt);
113745 + if (!is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
113746 + return false;
113747 +
113748 + if (is_gimple_constant(rhs2))
113749 + not_const_rhs = rhs1;
113750 + else
113751 + not_const_rhs = rhs2;
113752 +
113753 + return no_uses(not_const_rhs);
113754 +}
113755 +
113756 +static bool is_lt_signed_type_max(const_tree rhs)
113757 +{
113758 + const_tree new_type, type_max, type = TREE_TYPE(rhs);
113759 +
113760 + if (!TYPE_UNSIGNED(type))
113761 + return true;
113762 +
113763 + switch (TYPE_MODE(type)) {
113764 + case QImode:
113765 + new_type = intQI_type_node;
113766 + break;
113767 + case HImode:
113768 + new_type = intHI_type_node;
113769 + break;
113770 + case SImode:
113771 + new_type = intSI_type_node;
113772 + break;
113773 + case DImode:
113774 + new_type = intDI_type_node;
113775 + break;
113776 + default:
113777 + debug_tree((tree)type);
113778 + gcc_unreachable();
113779 + }
113780 +
113781 + type_max = TYPE_MAX_VALUE(new_type);
113782 + if (!tree_int_cst_lt(type_max, rhs))
113783 + return true;
113784 +
113785 + return false;
113786 +}
113787 +
113788 +static bool is_gt_zero(const_tree rhs)
113789 +{
113790 + const_tree type = TREE_TYPE(rhs);
113791 +
113792 + if (TYPE_UNSIGNED(type))
113793 + return true;
113794 +
113795 + if (!tree_int_cst_lt(rhs, integer_zero_node))
113796 + return true;
113797 +
113798 + return false;
113799 +}
113800 +
113801 +bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
113802 +{
113803 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
113804 + return false;
113805 + if (!is_gimple_constant(rhs))
113806 + return false;
113807 +
113808 + // If the const is between 0 and the max value of the signed type of the same bitsize then there is no intentional overflow
113809 + if (is_lt_signed_type_max(rhs) && is_gt_zero(rhs))
113810 + return false;
113811 +
113812 + return true;
113813 +}
113814 +
113815 +static tree change_assign_rhs(struct visited *visited, gimple stmt, const_tree orig_rhs, tree new_rhs)
113816 +{
113817 + gimple assign;
113818 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
113819 + tree origtype = TREE_TYPE(orig_rhs);
113820 +
113821 + gcc_assert(is_gimple_assign(stmt));
113822 +
113823 + assign = build_cast_stmt(visited, origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
113824 + pointer_set_insert(visited->my_stmts, assign);
113825 + return gimple_assign_lhs(assign);
113826 +}
113827 +
113828 +tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2)
113829 +{
113830 + tree new_rhs, orig_rhs;
113831 + void (*gimple_assign_set_rhs)(gimple, tree);
113832 + tree rhs1 = gimple_assign_rhs1(stmt);
113833 + tree rhs2 = gimple_assign_rhs2(stmt);
113834 + tree lhs = gimple_assign_lhs(stmt);
113835 +
113836 + if (!check_overflow)
113837 + return create_assign(visited, stmt, lhs, AFTER_STMT);
113838 +
113839 + if (change_rhs == NULL_TREE)
113840 + return create_assign(visited, stmt, lhs, AFTER_STMT);
113841 +
113842 + if (new_rhs2 == NULL_TREE) {
113843 + orig_rhs = rhs1;
113844 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
113845 + } else {
113846 + orig_rhs = rhs2;
113847 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
113848 + }
113849 +
113850 + check_size_overflow(caller_node, stmt, TREE_TYPE(change_rhs), change_rhs, orig_rhs, BEFORE_STMT);
113851 +
113852 + new_rhs = change_assign_rhs(visited, stmt, orig_rhs, change_rhs);
113853 + gimple_assign_set_rhs(stmt, new_rhs);
113854 + update_stmt(stmt);
113855 +
113856 + return create_assign(visited, stmt, lhs, AFTER_STMT);
113857 +}
113858 +
113859 +static bool is_subtraction_special(struct visited *visited, const_gimple stmt)
113860 +{
113861 + gimple rhs1_def_stmt, rhs2_def_stmt;
113862 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
113863 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
113864 + const_tree rhs1 = gimple_assign_rhs1(stmt);
113865 + const_tree rhs2 = gimple_assign_rhs2(stmt);
113866 +
113867 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
113868 + return false;
113869 +
113870 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
113871 +
113872 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
113873 + return false;
113874 +
113875 + rhs1_def_stmt = get_def_stmt(rhs1);
113876 + rhs2_def_stmt = get_def_stmt(rhs2);
113877 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
113878 + return false;
113879 +
113880 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
113881 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
113882 + rhs1_def_stmt_lhs = gimple_assign_lhs(rhs1_def_stmt);
113883 + rhs2_def_stmt_lhs = gimple_assign_lhs(rhs2_def_stmt);
113884 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
113885 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
113886 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
113887 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
113888 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
113889 + return false;
113890 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
113891 + return false;
113892 +
113893 + pointer_set_insert(visited->no_cast_check, rhs1_def_stmt);
113894 + pointer_set_insert(visited->no_cast_check, rhs2_def_stmt);
113895 + return true;
113896 +}
113897 +
113898 +static gimple create_binary_assign(struct visited *visited, enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
113899 +{
113900 + gimple assign;
113901 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
113902 + tree type = TREE_TYPE(rhs1);
113903 + tree lhs = create_new_var(type);
113904 +
113905 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
113906 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
113907 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
113908 +
113909 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
113910 + update_stmt(assign);
113911 + pointer_set_insert(visited->my_stmts, assign);
113912 + return assign;
113913 +}
113914 +
113915 +static tree cast_to_TI_type(struct visited *visited, gimple stmt, tree node)
113916 +{
113917 + gimple_stmt_iterator gsi;
113918 + gimple cast_stmt;
113919 + tree type = TREE_TYPE(node);
113920 +
113921 + if (types_compatible_p(type, intTI_type_node))
113922 + return node;
113923 +
113924 + gsi = gsi_for_stmt(stmt);
113925 + cast_stmt = build_cast_stmt(visited, intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
113926 + pointer_set_insert(visited->my_stmts, cast_stmt);
113927 + return gimple_assign_lhs(cast_stmt);
113928 +}
113929 +
113930 +static tree get_def_stmt_rhs(struct visited *visited, const_tree var)
113931 +{
113932 + tree rhs1, def_stmt_rhs1;
113933 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
113934 +
113935 + def_stmt = get_def_stmt(var);
113936 + if (!gimple_assign_cast_p(def_stmt))
113937 + return NULL_TREE;
113938 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && pointer_set_contains(visited->my_stmts, def_stmt) && gimple_assign_cast_p(def_stmt));
113939 +
113940 + rhs1 = gimple_assign_rhs1(def_stmt);
113941 + rhs1_def_stmt = get_def_stmt(rhs1);
113942 + if (!gimple_assign_cast_p(rhs1_def_stmt))
113943 + return rhs1;
113944 +
113945 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
113946 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
113947 +
113948 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
113949 + case GIMPLE_CALL:
113950 + case GIMPLE_NOP:
113951 + case GIMPLE_ASM:
113952 + case GIMPLE_PHI:
113953 + return def_stmt_rhs1;
113954 + case GIMPLE_ASSIGN:
113955 + return rhs1;
113956 + default:
113957 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
113958 + gcc_unreachable();
113959 + }
113960 +}
113961 +
113962 +tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs)
113963 +{
113964 + tree new_rhs1, new_rhs2;
113965 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
113966 + gimple assign, stmt = get_def_stmt(lhs);
113967 + tree rhs1 = gimple_assign_rhs1(stmt);
113968 + tree rhs2 = gimple_assign_rhs2(stmt);
113969 +
113970 + if (!is_subtraction_special(visited, stmt))
113971 + return NULL_TREE;
113972 +
113973 + new_rhs1 = expand(visited, caller_node, rhs1);
113974 + new_rhs2 = expand(visited, caller_node, rhs2);
113975 +
113976 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs1);
113977 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs2);
113978 +
113979 + if (new_rhs1_def_stmt_rhs1 == NULL_TREE || new_rhs2_def_stmt_rhs1 == NULL_TREE)
113980 + return NULL_TREE;
113981 +
113982 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
113983 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs1_def_stmt_rhs1);
113984 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs2_def_stmt_rhs1);
113985 + }
113986 +
113987 + assign = create_binary_assign(visited, MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
113988 + new_lhs = gimple_assign_lhs(assign);
113989 + check_size_overflow(caller_node, assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
113990 +
113991 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
113992 +}
113993 +
113994 +bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
113995 +{
113996 + const_gimple def_stmt;
113997 +
113998 + if (TREE_CODE(rhs) != SSA_NAME)
113999 + return false;
114000 +
114001 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
114002 + return false;
114003 +
114004 + def_stmt = get_def_stmt(rhs);
114005 + if (!is_gimple_assign(def_stmt) || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
114006 + return false;
114007 +
114008 + return true;
114009 +}
114010 +
114011 +/* e.g., drivers/acpi/acpica/utids.c acpi_ut_execute_CID()
114012 + * ((count - 1) * sizeof(struct acpi_pnp_dee_id_list) -> (count + fffffff) * 16
114013 + * fffffff * 16 > signed max -> truncate
114014 + */
114015 +static bool look_for_mult_and_add(const_gimple stmt)
114016 +{
114017 + const_tree res;
114018 + tree rhs1, rhs2, def_rhs1, def_rhs2, const_rhs, def_const_rhs;
114019 + const_gimple def_stmt;
114020 +
114021 + if (!stmt || gimple_code(stmt) == GIMPLE_NOP)
114022 + return false;
114023 + if (!is_gimple_assign(stmt))
114024 + return false;
114025 + if (gimple_assign_rhs_code(stmt) != MULT_EXPR)
114026 + return false;
114027 +
114028 + rhs1 = gimple_assign_rhs1(stmt);
114029 + rhs2 = gimple_assign_rhs2(stmt);
114030 + if (is_gimple_constant(rhs1)) {
114031 + const_rhs = rhs1;
114032 + def_stmt = get_def_stmt(rhs2);
114033 + } else if (is_gimple_constant(rhs2)) {
114034 + const_rhs = rhs2;
114035 + def_stmt = get_def_stmt(rhs1);
114036 + } else
114037 + return false;
114038 +
114039 + if (!is_gimple_assign(def_stmt))
114040 + return false;
114041 +
114042 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR && gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
114043 + return false;
114044 +
114045 + def_rhs1 = gimple_assign_rhs1(def_stmt);
114046 + def_rhs2 = gimple_assign_rhs2(def_stmt);
114047 + if (is_gimple_constant(def_rhs1))
114048 + def_const_rhs = def_rhs1;
114049 + else if (is_gimple_constant(def_rhs2))
114050 + def_const_rhs = def_rhs2;
114051 + else
114052 + return false;
114053 +
114054 + res = fold_binary_loc(gimple_location(def_stmt), MULT_EXPR, TREE_TYPE(const_rhs), const_rhs, def_const_rhs);
114055 + if (is_lt_signed_type_max(res) && is_gt_zero(res))
114056 + return false;
114057 + return true;
114058 +}
114059 +
114060 +enum intentional_overflow_type add_mul_intentional_overflow(const_gimple stmt)
114061 +{
114062 + const_gimple def_stmt_1, def_stmt_2;
114063 + const_tree rhs1, rhs2;
114064 + bool add_mul_rhs1, add_mul_rhs2;
114065 +
114066 + rhs1 = gimple_assign_rhs1(stmt);
114067 + def_stmt_1 = get_def_stmt(rhs1);
114068 + add_mul_rhs1 = look_for_mult_and_add(def_stmt_1);
114069 +
114070 + rhs2 = gimple_assign_rhs2(stmt);
114071 + def_stmt_2 = get_def_stmt(rhs2);
114072 + add_mul_rhs2 = look_for_mult_and_add(def_stmt_2);
114073 +
114074 + if (add_mul_rhs1)
114075 + return RHS1_INTENTIONAL_OVERFLOW;
114076 + if (add_mul_rhs2)
114077 + return RHS2_INTENTIONAL_OVERFLOW;
114078 + return NO_INTENTIONAL_OVERFLOW;
114079 +}
114080 +
114081 +static gimple get_dup_stmt(struct visited *visited, gimple stmt)
114082 +{
114083 + gimple my_stmt;
114084 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
114085 +
114086 + gsi_next(&gsi);
114087 + my_stmt = gsi_stmt(gsi);
114088 +
114089 + gcc_assert(pointer_set_contains(visited->my_stmts, my_stmt));
114090 + gcc_assert(gimple_assign_rhs_code(stmt) == gimple_assign_rhs_code(my_stmt));
114091 +
114092 + return my_stmt;
114093 +}
114094 +
114095 +/* unsigned type -> unary or binary assign (rhs1 or rhs2 is constant)
114096 + * unsigned type cast to signed type, unsigned type: no more uses
114097 + * e.g., lib/vsprintf.c:simple_strtol()
114098 + * _10 = (unsigned long int) _9
114099 + * _11 = -_10;
114100 + * _12 = (long int) _11; (_11_ no more uses)
114101 + */
114102 +static bool is_call_or_cast(gimple stmt)
114103 +{
114104 + return gimple_assign_cast_p(stmt) || is_gimple_call(stmt);
114105 +}
114106 +
114107 +static bool is_unsigned_cast_or_call_def_stmt(const_tree node)
114108 +{
114109 + const_tree rhs;
114110 + gimple def_stmt;
114111 +
114112 + if (node == NULL_TREE)
114113 + return true;
114114 + if (is_gimple_constant(node))
114115 + return true;
114116 +
114117 + def_stmt = get_def_stmt(node);
114118 + if (!def_stmt)
114119 + return false;
114120 +
114121 + if (is_call_or_cast(def_stmt))
114122 + return true;
114123 +
114124 + if (!is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 2)
114125 + return false;
114126 + rhs = gimple_assign_rhs1(def_stmt);
114127 + def_stmt = get_def_stmt(rhs);
114128 + if (!def_stmt)
114129 + return false;
114130 + return is_call_or_cast(def_stmt);
114131 +}
114132 +
114133 +void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt)
114134 +{
114135 + unsigned int use_num;
114136 + gimple so_stmt;
114137 + const_gimple def_stmt;
114138 + const_tree rhs1, rhs2;
114139 + tree rhs = gimple_assign_rhs1(stmt);
114140 + tree lhs_type = TREE_TYPE(gimple_assign_lhs(stmt));
114141 + const_tree rhs_type = TREE_TYPE(rhs);
114142 +
114143 + if (!(TYPE_UNSIGNED(rhs_type) && !TYPE_UNSIGNED(lhs_type)))
114144 + return;
114145 + if (GET_MODE_BITSIZE(TYPE_MODE(rhs_type)) != GET_MODE_BITSIZE(TYPE_MODE(lhs_type)))
114146 + return;
114147 + use_num = uses_num(rhs);
114148 + if (use_num != 1)
114149 + return;
114150 +
114151 + def_stmt = get_def_stmt(rhs);
114152 + if (!def_stmt)
114153 + return;
114154 + if (!is_gimple_assign(def_stmt))
114155 + return;
114156 +
114157 + rhs1 = gimple_assign_rhs1(def_stmt);
114158 + if (!is_unsigned_cast_or_call_def_stmt(rhs1))
114159 + return;
114160 +
114161 + rhs2 = gimple_assign_rhs2(def_stmt);
114162 + if (!is_unsigned_cast_or_call_def_stmt(rhs2))
114163 + return;
114164 + if (gimple_num_ops(def_stmt) == 3 && !is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
114165 + return;
114166 +
114167 + so_stmt = get_dup_stmt(visited, stmt);
114168 + create_up_and_down_cast(visited, so_stmt, lhs_type, gimple_assign_rhs1(so_stmt));
114169 +}
114170 +
114171 diff --git a/tools/gcc/size_overflow_plugin/misc.c b/tools/gcc/size_overflow_plugin/misc.c
114172 new file mode 100644
114173 index 0000000..4bddad2
114174 --- /dev/null
114175 +++ b/tools/gcc/size_overflow_plugin/misc.c
114176 @@ -0,0 +1,203 @@
114177 +/*
114178 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
114179 + * Licensed under the GPL v2, or (at your option) v3
114180 + *
114181 + * Homepage:
114182 + * http://www.grsecurity.net/~ephox/overflow_plugin/
114183 + *
114184 + * Documentation:
114185 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
114186 + *
114187 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
114188 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
114189 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
114190 + *
114191 + * Usage:
114192 + * $ make
114193 + * $ make run
114194 + */
114195 +
114196 +#include "gcc-common.h"
114197 +#include "size_overflow.h"
114198 +
114199 +void set_current_function_decl(tree fndecl)
114200 +{
114201 + gcc_assert(fndecl != NULL_TREE);
114202 +
114203 + push_cfun(DECL_STRUCT_FUNCTION(fndecl));
114204 + calculate_dominance_info(CDI_DOMINATORS);
114205 + current_function_decl = fndecl;
114206 +}
114207 +
114208 +void unset_current_function_decl(void)
114209 +{
114210 + free_dominance_info(CDI_DOMINATORS);
114211 + pop_cfun();
114212 + current_function_decl = NULL_TREE;
114213 +}
114214 +
114215 +static bool is_bool(const_tree node)
114216 +{
114217 + const_tree type;
114218 +
114219 + if (node == NULL_TREE)
114220 + return false;
114221 +
114222 + type = TREE_TYPE(node);
114223 + if (!INTEGRAL_TYPE_P(type))
114224 + return false;
114225 + if (TREE_CODE(type) == BOOLEAN_TYPE)
114226 + return true;
114227 + if (TYPE_PRECISION(type) == 1)
114228 + return true;
114229 + return false;
114230 +}
114231 +
114232 +bool skip_types(const_tree var)
114233 +{
114234 + tree type;
114235 + enum tree_code code;
114236 +
114237 + if (is_gimple_constant(var))
114238 + return true;
114239 +
114240 + switch (TREE_CODE(var)) {
114241 + case ADDR_EXPR:
114242 +#if BUILDING_GCC_VERSION >= 4006
114243 + case MEM_REF:
114244 +#endif
114245 + case ARRAY_REF:
114246 + case BIT_FIELD_REF:
114247 + case INDIRECT_REF:
114248 + case TARGET_MEM_REF:
114249 + case COMPONENT_REF:
114250 + case VAR_DECL:
114251 + case VIEW_CONVERT_EXPR:
114252 + return true;
114253 + default:
114254 + break;
114255 + }
114256 +
114257 + code = TREE_CODE(var);
114258 + gcc_assert(code == SSA_NAME || code == PARM_DECL);
114259 +
114260 + type = TREE_TYPE(var);
114261 + switch (TREE_CODE(type)) {
114262 + case INTEGER_TYPE:
114263 + case ENUMERAL_TYPE:
114264 + return false;
114265 + case BOOLEAN_TYPE:
114266 + return is_bool(var);
114267 + default:
114268 + return true;
114269 + }
114270 +}
114271 +
114272 +gimple get_def_stmt(const_tree node)
114273 +{
114274 + gcc_assert(node != NULL_TREE);
114275 +
114276 + if (skip_types(node))
114277 + return NULL;
114278 +
114279 + if (TREE_CODE(node) != SSA_NAME)
114280 + return NULL;
114281 + return SSA_NAME_DEF_STMT(node);
114282 +}
114283 +
114284 +tree create_new_var(tree type)
114285 +{
114286 + tree new_var = create_tmp_var(type, "cicus");
114287 +
114288 + add_referenced_var(new_var);
114289 + return new_var;
114290 +}
114291 +
114292 +static bool skip_cast(tree dst_type, const_tree rhs, bool force)
114293 +{
114294 + const_gimple def_stmt = get_def_stmt(rhs);
114295 +
114296 + if (force)
114297 + return false;
114298 +
114299 + if (is_gimple_constant(rhs))
114300 + return false;
114301 +
114302 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
114303 + return false;
114304 +
114305 + if (!types_compatible_p(dst_type, TREE_TYPE(rhs)))
114306 + return false;
114307 +
114308 + // DI type can be on 32 bit (from create_assign) but overflow type stays DI
114309 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
114310 + return false;
114311 +
114312 + return true;
114313 +}
114314 +
114315 +tree cast_a_tree(tree type, tree var)
114316 +{
114317 + gcc_assert(type != NULL_TREE);
114318 + gcc_assert(var != NULL_TREE);
114319 + gcc_assert(fold_convertible_p(type, var));
114320 +
114321 + return fold_convert(type, var);
114322 +}
114323 +
114324 +gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force)
114325 +{
114326 + gimple assign, def_stmt;
114327 +
114328 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
114329 + gcc_assert(!is_gimple_constant(rhs));
114330 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
114331 + gcc_unreachable();
114332 +
114333 + def_stmt = get_def_stmt(rhs);
114334 + if (def_stmt && gimple_code(def_stmt) != GIMPLE_NOP && skip_cast(dst_type, rhs, force) && pointer_set_contains(visited->my_stmts, def_stmt))
114335 + return def_stmt;
114336 +
114337 + if (lhs == CREATE_NEW_VAR)
114338 + lhs = create_new_var(dst_type);
114339 +
114340 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
114341 +
114342 + if (!gsi_end_p(*gsi)) {
114343 + location_t loc = gimple_location(gsi_stmt(*gsi));
114344 + gimple_set_location(assign, loc);
114345 + }
114346 +
114347 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
114348 +
114349 + if (before)
114350 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
114351 + else
114352 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
114353 + update_stmt(assign);
114354 + return assign;
114355 +}
114356 +
114357 +bool is_size_overflow_type(const_tree var)
114358 +{
114359 + const char *name;
114360 + const_tree type_name, type;
114361 +
114362 + if (var == NULL_TREE)
114363 + return false;
114364 +
114365 + type = TREE_TYPE(var);
114366 + type_name = TYPE_NAME(type);
114367 + if (type_name == NULL_TREE)
114368 + return false;
114369 +
114370 + if (DECL_P(type_name))
114371 + name = DECL_NAME_POINTER(type_name);
114372 + else
114373 + name = IDENTIFIER_POINTER(type_name);
114374 +
114375 + if (!strncmp(name, "size_overflow_type", 18))
114376 + return true;
114377 + return false;
114378 +}
114379 +
114380 diff --git a/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
114381 new file mode 100644
114382 index 0000000..7c9e6d1
114383 --- /dev/null
114384 +++ b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
114385 @@ -0,0 +1,138 @@
114386 +/*
114387 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
114388 + * Licensed under the GPL v2, or (at your option) v3
114389 + *
114390 + * Homepage:
114391 + * http://www.grsecurity.net/~ephox/overflow_plugin/
114392 + *
114393 + * Documentation:
114394 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
114395 + *
114396 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
114397 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
114398 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
114399 + *
114400 + * Usage:
114401 + * $ make
114402 + * $ make run
114403 + */
114404 +
114405 +#include "gcc-common.h"
114406 +#include "size_overflow.h"
114407 +
114408 +bool skip_expr_on_double_type(const_gimple stmt)
114409 +{
114410 + enum tree_code code = gimple_assign_rhs_code(stmt);
114411 +
114412 + switch (code) {
114413 + case RSHIFT_EXPR:
114414 + case TRUNC_DIV_EXPR:
114415 + case CEIL_DIV_EXPR:
114416 + case FLOOR_DIV_EXPR:
114417 + case ROUND_DIV_EXPR:
114418 + case EXACT_DIV_EXPR:
114419 + case RDIV_EXPR:
114420 + case TRUNC_MOD_EXPR:
114421 + case CEIL_MOD_EXPR:
114422 + case FLOOR_MOD_EXPR:
114423 + case ROUND_MOD_EXPR:
114424 + return true;
114425 + default:
114426 + return false;
114427 + }
114428 +}
114429 +
114430 +void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs)
114431 +{
114432 + const_tree orig_rhs1;
114433 + tree down_lhs, new_lhs, dup_type = TREE_TYPE(rhs);
114434 + gimple down_cast, up_cast;
114435 + gimple_stmt_iterator gsi = gsi_for_stmt(use_stmt);
114436 +
114437 + down_cast = build_cast_stmt(visited, orig_type, rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
114438 + down_lhs = gimple_assign_lhs(down_cast);
114439 +
114440 + gsi = gsi_for_stmt(use_stmt);
114441 + up_cast = build_cast_stmt(visited, dup_type, down_lhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
114442 + new_lhs = gimple_assign_lhs(up_cast);
114443 +
114444 + orig_rhs1 = gimple_assign_rhs1(use_stmt);
114445 + if (operand_equal_p(orig_rhs1, rhs, 0))
114446 + gimple_assign_set_rhs1(use_stmt, new_lhs);
114447 + else
114448 + gimple_assign_set_rhs2(use_stmt, new_lhs);
114449 + update_stmt(use_stmt);
114450 +
114451 + pointer_set_insert(visited->my_stmts, up_cast);
114452 + pointer_set_insert(visited->my_stmts, down_cast);
114453 + pointer_set_insert(visited->skip_expr_casts, up_cast);
114454 + pointer_set_insert(visited->skip_expr_casts, down_cast);
114455 +}
114456 +
114457 +static tree get_proper_unsigned_half_type(const_tree node)
114458 +{
114459 + tree new_type, type;
114460 +
114461 + gcc_assert(is_size_overflow_type(node));
114462 +
114463 + type = TREE_TYPE(node);
114464 + switch (TYPE_MODE(type)) {
114465 + case HImode:
114466 + new_type = unsigned_intQI_type_node;
114467 + break;
114468 + case SImode:
114469 + new_type = unsigned_intHI_type_node;
114470 + break;
114471 + case DImode:
114472 + new_type = unsigned_intSI_type_node;
114473 + break;
114474 + case TImode:
114475 + new_type = unsigned_intDI_type_node;
114476 + break;
114477 + default:
114478 + gcc_unreachable();
114479 + }
114480 +
114481 + if (TYPE_QUALS(type) != 0)
114482 + return build_qualified_type(new_type, TYPE_QUALS(type));
114483 + return new_type;
114484 +}
114485 +
114486 +static void insert_cast_rhs(struct visited *visited, gimple stmt, tree rhs)
114487 +{
114488 + tree type;
114489 +
114490 + if (rhs == NULL_TREE)
114491 + return;
114492 + if (!is_size_overflow_type(rhs))
114493 + return;
114494 +
114495 + type = get_proper_unsigned_half_type(rhs);
114496 + if (is_gimple_constant(rhs))
114497 + return;
114498 + create_up_and_down_cast(visited, stmt, type, rhs);
114499 +}
114500 +
114501 +static void insert_cast(struct visited *visited, gimple stmt, tree rhs)
114502 +{
114503 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && !is_size_overflow_type(rhs))
114504 + return;
114505 + gcc_assert(is_size_overflow_type(rhs));
114506 + insert_cast_rhs(visited, stmt, rhs);
114507 +}
114508 +
114509 +void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type)
114510 +{
114511 + tree rhs1, rhs2;
114512 +
114513 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS1_INTENTIONAL_OVERFLOW) {
114514 + rhs1 = gimple_assign_rhs1(stmt);
114515 + insert_cast(visited, stmt, rhs1);
114516 + }
114517 +
114518 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS2_INTENTIONAL_OVERFLOW) {
114519 + rhs2 = gimple_assign_rhs2(stmt);
114520 + insert_cast(visited, stmt, rhs2);
114521 + }
114522 +}
114523 +
114524 diff --git a/tools/gcc/size_overflow_plugin/size_overflow.h b/tools/gcc/size_overflow_plugin/size_overflow.h
114525 new file mode 100644
114526 index 0000000..e5b4e50
114527 --- /dev/null
114528 +++ b/tools/gcc/size_overflow_plugin/size_overflow.h
114529 @@ -0,0 +1,127 @@
114530 +#ifndef SIZE_OVERFLOW_H
114531 +#define SIZE_OVERFLOW_H
114532 +
114533 +#define CREATE_NEW_VAR NULL_TREE
114534 +#define CANNOT_FIND_ARG 32
114535 +#define MAX_PARAM 31
114536 +#define BEFORE_STMT true
114537 +#define AFTER_STMT false
114538 +
114539 +#define TURN_OFF_ASM_STR "# size_overflow MARK_TURN_OFF "
114540 +#define YES_ASM_STR "# size_overflow MARK_YES "
114541 +#define OK_ASM_STR "# size_overflow "
114542 +
114543 +enum mark {
114544 + MARK_NO, MARK_YES, MARK_NOT_INTENTIONAL, MARK_TURN_OFF
114545 +};
114546 +
114547 +enum intentional_overflow_type {
114548 + NO_INTENTIONAL_OVERFLOW, RHS1_INTENTIONAL_OVERFLOW, RHS2_INTENTIONAL_OVERFLOW
114549 +};
114550 +
114551 +struct visited {
114552 + struct pointer_set_t *stmts;
114553 + struct pointer_set_t *my_stmts;
114554 + struct pointer_set_t *skip_expr_casts;
114555 + struct pointer_set_t *no_cast_check;
114556 +};
114557 +
114558 +// size_overflow_plugin.c
114559 +extern tree report_size_overflow_decl;
114560 +extern tree size_overflow_type_HI;
114561 +extern tree size_overflow_type_SI;
114562 +extern tree size_overflow_type_DI;
114563 +extern tree size_overflow_type_TI;
114564 +
114565 +
114566 +// size_overflow_plugin_hash.c
114567 +struct size_overflow_hash {
114568 + const struct size_overflow_hash * const next;
114569 + const char * const name;
114570 + const unsigned int param;
114571 +};
114572 +
114573 +struct interesting_node {
114574 + struct interesting_node *next;
114575 + gimple first_stmt;
114576 + const_tree fndecl;
114577 + tree node;
114578 +#if BUILDING_GCC_VERSION <= 4007
114579 + VEC(tree, gc) *last_nodes;
114580 +#else
114581 + vec<tree, va_gc> *last_nodes;
114582 +#endif
114583 + unsigned int num;
114584 + enum mark intentional_attr_decl;
114585 + enum mark intentional_attr_cur_fndecl;
114586 + gimple intentional_mark_from_gimple;
114587 +};
114588 +
114589 +extern bool is_size_overflow_asm(const_gimple stmt);
114590 +extern unsigned int get_function_num(const_tree node, const_tree orig_fndecl);
114591 +extern unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl);
114592 +extern bool is_missing_function(const_tree orig_fndecl, unsigned int num);
114593 +extern bool is_a_return_check(const_tree node);
114594 +extern const struct size_overflow_hash *get_function_hash(const_tree fndecl);
114595 +extern unsigned int find_arg_number_tree(const_tree arg, const_tree func);
114596 +
114597 +
114598 +// size_overflow_debug.c
114599 +extern struct opt_pass *make_dump_pass(void);
114600 +
114601 +
114602 +// intentional_overflow.c
114603 +extern enum mark get_intentional_attr_type(const_tree node);
114604 +extern bool is_size_overflow_intentional_asm_yes(const_gimple stmt);
114605 +extern bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt);
114606 +extern bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum);
114607 +extern bool is_yes_intentional_attr(const_tree decl, unsigned int argnum);
114608 +extern bool is_turn_off_intentional_attr(const_tree decl);
114609 +extern void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum);
114610 +extern void check_intentional_attribute_ipa(struct interesting_node *cur_node);
114611 +extern bool is_a_cast_and_const_overflow(const_tree no_const_rhs);
114612 +extern bool is_const_plus_unsigned_signed_truncation(const_tree lhs);
114613 +extern bool is_a_constant_overflow(const_gimple stmt, const_tree rhs);
114614 +extern tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2);
114615 +extern tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs);
114616 +extern bool is_a_neg_overflow(const_gimple stmt, const_tree rhs);
114617 +extern enum intentional_overflow_type add_mul_intentional_overflow(const_gimple def_stmt);
114618 +extern void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt);
114619 +
114620 +
114621 +// insert_size_overflow_check_ipa.c
114622 +extern unsigned int search_function(void);
114623 +extern unsigned int call_count;
114624 +extern struct opt_pass *make_insert_size_overflow_check(void);
114625 +extern const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum);
114626 +
114627 +
114628 +// insert_size_overflow_asm.c
114629 +extern struct opt_pass *make_insert_size_overflow_asm_pass(void);
114630 +
114631 +
114632 +// misc.c
114633 +extern void set_current_function_decl(tree fndecl);
114634 +extern void unset_current_function_decl(void);
114635 +extern gimple get_def_stmt(const_tree node);
114636 +extern tree create_new_var(tree type);
114637 +extern gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force);
114638 +extern bool skip_types(const_tree var);
114639 +extern tree cast_a_tree(tree type, tree var);
114640 +extern bool is_size_overflow_type(const_tree var);
114641 +
114642 +
114643 +// insert_size_overflow_check_core.c
114644 +extern tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs);
114645 +extern void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
114646 +extern tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
114647 +extern tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before);
114648 +
114649 +
114650 +// remove_unnecessary_dup.c
114651 +extern struct opt_pass *make_remove_unnecessary_dup_pass(void);
114652 +extern void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type);
114653 +extern bool skip_expr_on_double_type(const_gimple stmt);
114654 +extern void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs);
114655 +
114656 +#endif
114657 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_debug.c b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
114658 new file mode 100644
114659 index 0000000..4378111
114660 --- /dev/null
114661 +++ b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
114662 @@ -0,0 +1,116 @@
114663 +/*
114664 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
114665 + * Licensed under the GPL v2, or (at your option) v3
114666 + *
114667 + * Homepage:
114668 + * http://www.grsecurity.net/~ephox/overflow_plugin/
114669 + *
114670 + * Documentation:
114671 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
114672 + *
114673 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
114674 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
114675 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
114676 + *
114677 + * Usage:
114678 + * $ make
114679 + * $ make run
114680 + */
114681 +
114682 +#include "gcc-common.h"
114683 +
114684 +static unsigned int dump_functions(void)
114685 +{
114686 + struct cgraph_node *node;
114687 +
114688 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
114689 + basic_block bb;
114690 +
114691 + push_cfun(DECL_STRUCT_FUNCTION(NODE_DECL(node)));
114692 + current_function_decl = NODE_DECL(node);
114693 +
114694 + fprintf(stderr, "-----------------------------------------\n%s\n-----------------------------------------\n", DECL_NAME_POINTER(current_function_decl));
114695 +
114696 + FOR_ALL_BB_FN(bb, cfun) {
114697 + gimple_stmt_iterator si;
114698 +
114699 + fprintf(stderr, "<bb %u>:\n", bb->index);
114700 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
114701 + debug_gimple_stmt(gsi_stmt(si));
114702 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
114703 + debug_gimple_stmt(gsi_stmt(si));
114704 + fprintf(stderr, "\n");
114705 + }
114706 +
114707 + fprintf(stderr, "-------------------------------------------------------------------------\n");
114708 +
114709 + pop_cfun();
114710 + current_function_decl = NULL_TREE;
114711 + }
114712 +
114713 + fprintf(stderr, "###############################################################################\n");
114714 +
114715 + return 0;
114716 +}
114717 +
114718 +#if BUILDING_GCC_VERSION >= 4009
114719 +static const struct pass_data dump_pass_data = {
114720 +#else
114721 +static struct ipa_opt_pass_d dump_pass = {
114722 + .pass = {
114723 +#endif
114724 + .type = SIMPLE_IPA_PASS,
114725 + .name = "dump",
114726 +#if BUILDING_GCC_VERSION >= 4008
114727 + .optinfo_flags = OPTGROUP_NONE,
114728 +#endif
114729 +#if BUILDING_GCC_VERSION >= 4009
114730 + .has_gate = false,
114731 + .has_execute = true,
114732 +#else
114733 + .gate = NULL,
114734 + .execute = dump_functions,
114735 + .sub = NULL,
114736 + .next = NULL,
114737 + .static_pass_number = 0,
114738 +#endif
114739 + .tv_id = TV_NONE,
114740 + .properties_required = 0,
114741 + .properties_provided = 0,
114742 + .properties_destroyed = 0,
114743 + .todo_flags_start = 0,
114744 + .todo_flags_finish = 0,
114745 +#if BUILDING_GCC_VERSION < 4009
114746 + },
114747 + .generate_summary = NULL,
114748 + .write_summary = NULL,
114749 + .read_summary = NULL,
114750 +#if BUILDING_GCC_VERSION >= 4006
114751 + .write_optimization_summary = NULL,
114752 + .read_optimization_summary = NULL,
114753 +#endif
114754 + .stmt_fixup = NULL,
114755 + .function_transform_todo_flags_start = 0,
114756 + .function_transform = NULL,
114757 + .variable_transform = NULL,
114758 +#endif
114759 +};
114760 +
114761 +#if BUILDING_GCC_VERSION >= 4009
114762 +namespace {
114763 +class dump_pass : public ipa_opt_pass_d {
114764 +public:
114765 + dump_pass() : ipa_opt_pass_d(dump_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
114766 + unsigned int execute() { return dump_functions(); }
114767 +};
114768 +}
114769 +#endif
114770 +
114771 +struct opt_pass *make_dump_pass(void)
114772 +{
114773 +#if BUILDING_GCC_VERSION >= 4009
114774 + return new dump_pass();
114775 +#else
114776 + return &dump_pass.pass;
114777 +#endif
114778 +}
114779 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash.data b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
114780 new file mode 100644
114781 index 0000000..386792a
114782 --- /dev/null
114783 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
114784 @@ -0,0 +1,5808 @@
114785 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
114786 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
114787 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
114788 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
114789 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
114790 +padzero_55 padzero 1 55 &sel_read_policyvers_55
114791 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
114792 +__skb_to_sgvec_72 __skb_to_sgvec 0 72 NULL
114793 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
114794 +load_msg_95 load_msg 2 95 NULL
114795 +ipath_verbs_send_117 ipath_verbs_send 5-3 117 NULL
114796 +init_q_132 init_q 4 132 NULL
114797 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
114798 +hva_to_gfn_memslot_149 hva_to_gfn_memslot 0-1 149 NULL
114799 +ping_v6_sendmsg_152 ping_v6_sendmsg 4 152 NULL
114800 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 NULL nohasharray
114801 +ext4_ext_get_actual_len_153 ext4_ext_get_actual_len 0 153 &tracing_trace_options_write_153
114802 +pci_request_selected_regions_169 pci_request_selected_regions 0 169 NULL
114803 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
114804 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
114805 +ll_xattr_cache_seq_write_250 ll_xattr_cache_seq_write 3 250 NULL
114806 +br_port_info_size_268 br_port_info_size 0 268 NULL
114807 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
114808 +SYSC_connect_304 SYSC_connect 3 304 NULL
114809 +syslog_print_307 syslog_print 2 307 NULL
114810 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
114811 +mlx5_core_access_reg_361 mlx5_core_access_reg 3-5 361 NULL
114812 +aio_read_events_ring_410 aio_read_events_ring 3 410 NULL
114813 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
114814 +snd_ca0106_ptr_read_467 snd_ca0106_ptr_read 0 467 NULL
114815 +cfs_trace_set_debug_mb_usrstr_486 cfs_trace_set_debug_mb_usrstr 2 486 NULL
114816 +nvme_trans_modesel_data_488 nvme_trans_modesel_data 4 488 NULL
114817 +iwl_dbgfs_protection_mode_write_502 iwl_dbgfs_protection_mode_write 3 502 NULL
114818 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
114819 +ocfs2_validate_meta_ecc_bhs_527 ocfs2_validate_meta_ecc_bhs 0 527 NULL
114820 +zlib_deflate_workspacesize_537 zlib_deflate_workspacesize 0-1-2 537 NULL
114821 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
114822 +sco_sock_setsockopt_552 sco_sock_setsockopt 5 552 NULL
114823 +lpfc_nlp_state_name_556 lpfc_nlp_state_name 2 556 NULL
114824 +snd_aw2_saa7146_get_hw_ptr_playback_558 snd_aw2_saa7146_get_hw_ptr_playback 0 558 NULL
114825 +start_isoc_chain_565 start_isoc_chain 2 565 NULL nohasharray
114826 +dev_hard_header_565 dev_hard_header 0 565 &start_isoc_chain_565
114827 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
114828 +btrfs_stack_file_extent_offset_607 btrfs_stack_file_extent_offset 0 607 NULL
114829 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
114830 +fuse_request_alloc_nofs_617 fuse_request_alloc_nofs 1 617 NULL
114831 +ptlrpc_lprocfs_nrs_seq_write_621 ptlrpc_lprocfs_nrs_seq_write 3 621 NULL
114832 +viafb_dfpl_proc_write_627 viafb_dfpl_proc_write 3 627 NULL
114833 +ceph_osdc_new_request_635 ceph_osdc_new_request 6 635 NULL
114834 +cfs_hash_bkt_size_643 cfs_hash_bkt_size 0 643 NULL
114835 +unlink_queued_645 unlink_queued 4 645 NULL
114836 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
114837 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
114838 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
114839 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
114840 +dvb_video_write_754 dvb_video_write 3 754 NULL
114841 +cfs_trace_allocate_string_buffer_781 cfs_trace_allocate_string_buffer 2 781 NULL
114842 +ath6kl_disconnect_timeout_write_794 ath6kl_disconnect_timeout_write 3 794 NULL
114843 +snd_pcm_drain_811 snd_pcm_drain 0 811 NULL
114844 +if_writecmd_815 if_writecmd 2 815 NULL
114845 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
114846 +error_state_read_859 error_state_read 6 859 NULL
114847 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
114848 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
114849 +snd_pcm_action_single_905 snd_pcm_action_single 0 905 NULL
114850 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
114851 +__nodes_weight_956 __nodes_weight 0 956 NULL
114852 +bnx2x_fill_fw_str_968 bnx2x_fill_fw_str 3 968 NULL
114853 +mnt_want_write_975 mnt_want_write 0 975 NULL
114854 +usnic_ib_qp_grp_dump_hdr_989 usnic_ib_qp_grp_dump_hdr 2 989 NULL
114855 +memcmp_990 memcmp 0 990 NULL
114856 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
114857 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
114858 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
114859 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
114860 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
114861 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
114862 +nfs4_init_nonuniform_client_string_1097 nfs4_init_nonuniform_client_string 3 1097 NULL
114863 +cfg80211_report_obss_beacon_1133 cfg80211_report_obss_beacon 3 1133 NULL
114864 +i2400m_rx_ctl_1157 i2400m_rx_ctl 4 1157 NULL
114865 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
114866 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
114867 +pstore_ftrace_knob_write_1198 pstore_ftrace_knob_write 3 1198 NULL
114868 +i2400m_rx_ctl_ack_1199 i2400m_rx_ctl_ack 3 1199 NULL
114869 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
114870 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
114871 +lov_ost_pool_init_1215 lov_ost_pool_init 2 1215 NULL
114872 +fsync_buffers_list_1219 fsync_buffers_list 0 1219 NULL
114873 +kernfs_file_direct_read_1238 kernfs_file_direct_read 3 1238 NULL
114874 +acpi_battery_write_alarm_1240 acpi_battery_write_alarm 3 1240 NULL
114875 +drm_primary_helper_create_plane_1262 drm_primary_helper_create_plane 3 1262 NULL
114876 +ocfs2_extend_file_1266 ocfs2_extend_file 3 1266 NULL
114877 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
114878 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
114879 +SyS_flistxattr_1287 SyS_flistxattr 3 1287 NULL
114880 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
114881 +posix_acl_xattr_set_1301 posix_acl_xattr_set 4 1301 NULL
114882 +ffs_1322 ffs 0 1322 NULL
114883 +qlcnic_pci_sriov_configure_1327 qlcnic_pci_sriov_configure 2 1327 NULL
114884 +btrfs_submit_compressed_write_1347 btrfs_submit_compressed_write 5 1347 NULL
114885 +snd_pcm_lib_write1_1358 snd_pcm_lib_write1 0-3 1358 NULL
114886 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
114887 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
114888 +ocfs2_prepare_inode_for_write_1372 ocfs2_prepare_inode_for_write 3 1372 NULL
114889 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
114890 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
114891 +SYSC_io_getevents_1392 SYSC_io_getevents 3 1392 NULL
114892 +cfs_trace_copyout_string_1416 cfs_trace_copyout_string 2 1416 NULL
114893 +init_rs_internal_1436 init_rs_internal 1 1436 NULL
114894 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
114895 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
114896 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
114897 +SYSC_syslog_1477 SYSC_syslog 3 1477 NULL
114898 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
114899 +fpregs_set_1497 fpregs_set 4 1497 NULL
114900 +tomoyo_round2_1518 tomoyo_round2 0 1518 NULL
114901 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
114902 +ath6kl_init_get_fwcaps_1557 ath6kl_init_get_fwcaps 3 1557 NULL
114903 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
114904 +ipath_ht_handle_hwerrors_1592 ipath_ht_handle_hwerrors 3 1592 NULL
114905 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
114906 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
114907 +v9fs_fid_xattr_get_1618 v9fs_fid_xattr_get 0 1618 NULL
114908 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
114909 +mei_cl_recv_1665 mei_cl_recv 3 1665 NULL
114910 +rmap_add_1677 rmap_add 3 1677 NULL
114911 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
114912 +iwl_dbgfs_d0i3_refs_read_1705 iwl_dbgfs_d0i3_refs_read 3 1705 NULL
114913 +pdu_write_u_1710 pdu_write_u 3 1710 NULL
114914 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
114915 +btrfs_dir_data_len_1714 btrfs_dir_data_len 0 1714 NULL
114916 +internal_create_group_1733 internal_create_group 0 1733 NULL
114917 +dev_irnet_read_1741 dev_irnet_read 3 1741 NULL
114918 +usb_ep_align_maybe_1743 usb_ep_align_maybe 0-3 1743 NULL
114919 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
114920 +cosa_write_1774 cosa_write 3 1774 NULL
114921 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
114922 +__nodelist_scnprintf_1815 __nodelist_scnprintf 2-0 1815 NULL
114923 +sb_issue_zeroout_1884 sb_issue_zeroout 3 1884 NULL
114924 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
114925 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
114926 +SyS_add_key_1900 SyS_add_key 4 1900 NULL
114927 +uhid_char_read_1920 uhid_char_read 3 1920 NULL
114928 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
114929 +bdev_erase_1933 bdev_erase 3 1933 NULL
114930 +ext3_fiemap_1936 ext3_fiemap 4 1936 NULL
114931 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL
114932 +ieee80211_if_fmt_dot11MeshConfirmTimeout_1945 ieee80211_if_fmt_dot11MeshConfirmTimeout 3 1945 NULL
114933 +__assign_irq_vector_1961 __assign_irq_vector 0 1961 NULL
114934 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
114935 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
114936 +gpio_power_write_1991 gpio_power_write 3 1991 NULL
114937 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
114938 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
114939 +ocfs2_global_qinit_alloc_2018 ocfs2_global_qinit_alloc 0 2018 NULL
114940 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
114941 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
114942 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
114943 +ocfs2_expand_inline_dir_2063 ocfs2_expand_inline_dir 3 2063 NULL
114944 +__generic_copy_from_user_intel_2073 __generic_copy_from_user_intel 0-3 2073 NULL
114945 +diva_set_driver_dbg_mask_2077 diva_set_driver_dbg_mask 0 2077 NULL
114946 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
114947 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
114948 +__set_print_fmt_2106 __set_print_fmt 0 2106 NULL
114949 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
114950 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
114951 +btrfs_file_extent_inline_len_2116 btrfs_file_extent_inline_len 0 2116 NULL
114952 +enable_read_2117 enable_read 3 2117 NULL
114953 +pcf50633_write_block_2124 pcf50633_write_block 2-3 2124 NULL
114954 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
114955 +iov_iter_count_2152 iov_iter_count 0 2152 NULL
114956 +__copy_to_user_ll_2157 __copy_to_user_ll 0-3 2157 NULL
114957 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
114958 +bio_integrity_alloc_2194 bio_integrity_alloc 3 2194 NULL
114959 +picolcd_debug_reset_write_2195 picolcd_debug_reset_write 3 2195 NULL
114960 +u32_array_read_2219 u32_array_read 3 2219 NULL nohasharray
114961 +mei_dbgfs_read_meclients_2219 mei_dbgfs_read_meclients 3 2219 &u32_array_read_2219
114962 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
114963 +netlbl_secattr_catmap_walk_2255 netlbl_secattr_catmap_walk 0-2 2255 NULL
114964 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
114965 +do_update_counters_2259 do_update_counters 4 2259 NULL
114966 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
114967 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
114968 +sr_read_cmd_2299 sr_read_cmd 5 2299 NULL
114969 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
114970 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
114971 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 NULL nohasharray
114972 +hfsplus_find_init_2318 hfsplus_find_init 0 2318 &picolcd_fb_write_2318
114973 +dice_hwdep_read_2326 dice_hwdep_read 3 2326 NULL
114974 +__erst_read_to_erange_2341 __erst_read_to_erange 0 2341 NULL
114975 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
114976 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
114977 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
114978 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
114979 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
114980 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
114981 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
114982 +raid1_size_2419 raid1_size 0-2 2419 NULL
114983 +arch_msi_check_device_2449 arch_msi_check_device 0 2449 NULL
114984 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
114985 +wiphy_new_2482 wiphy_new 2 2482 NULL
114986 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
114987 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
114988 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
114989 +ext4_get_inode_loc_2516 ext4_get_inode_loc 0 2516 NULL
114990 +batadv_tvlv_container_list_size_2524 batadv_tvlv_container_list_size 0 2524 NULL
114991 +smk_write_syslog_2529 smk_write_syslog 3 2529 NULL
114992 +__ceph_setxattr_2532 __ceph_setxattr 4 2532 NULL
114993 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
114994 +pcm_sanity_check_2574 pcm_sanity_check 0 2574 NULL
114995 +mdc_max_rpcs_in_flight_seq_write_2594 mdc_max_rpcs_in_flight_seq_write 3 2594 NULL
114996 +slot_bytes_2609 slot_bytes 0 2609 NULL
114997 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
114998 +switch_status_2629 switch_status 5 2629 NULL
114999 +tcp_xmit_size_goal_2661 tcp_xmit_size_goal 2 2661 NULL
115000 +osc_build_ppga_2670 osc_build_ppga 2 2670 NULL
115001 +ffs_ep0_read_2672 ffs_ep0_read 3 2672 NULL
115002 +oti6858_write_2692 oti6858_write 4 2692 NULL
115003 +nfc_llcp_send_ui_frame_2702 nfc_llcp_send_ui_frame 5 2702 NULL
115004 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
115005 +lprocfs_stats_counter_size_2708 lprocfs_stats_counter_size 0 2708 NULL
115006 +xfs_readdir_2767 xfs_readdir 3 2767 NULL
115007 +fsl_edma_alloc_desc_2769 fsl_edma_alloc_desc 2 2769 NULL
115008 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
115009 +set_msr_hyperv_pw_2785 set_msr_hyperv_pw 3 2785 NULL
115010 +device_add_attrs_2789 device_add_attrs 0 2789 NULL
115011 +iwl_dbgfs_clear_ucode_statistics_write_2804 iwl_dbgfs_clear_ucode_statistics_write 3 2804 NULL
115012 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
115013 +vb2_dc_get_userptr_2829 vb2_dc_get_userptr 2-3 2829 NULL nohasharray
115014 +snd_pcm_reset_2829 snd_pcm_reset 0 2829 &vb2_dc_get_userptr_2829
115015 +wait_for_avail_2847 wait_for_avail 0 2847 NULL
115016 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
115017 +irnet_ctrl_read_2863 irnet_ctrl_read 4 2863 NULL
115018 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
115019 +nla_padlen_2883 nla_padlen 1 2883 NULL
115020 +cmm_write_2896 cmm_write 3 2896 NULL
115021 +osc_import_seq_write_2923 osc_import_seq_write 3 2923 NULL
115022 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
115023 +nes_read_indexed_2946 nes_read_indexed 0 2946 NULL
115024 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
115025 +i40e_dbg_prep_dump_buf_2951 i40e_dbg_prep_dump_buf 2 2951 NULL
115026 +set_fast_connectable_2952 set_fast_connectable 4 2952 NULL
115027 +free_area_init_core_2962 free_area_init_core 2-3 2962 NULL
115028 +bio_setup_sector_2970 bio_setup_sector 3 2970 NULL
115029 +do_strnlen_user_2976 do_strnlen_user 0-2 2976 NULL
115030 +p9_nr_pages_2992 p9_nr_pages 0-2 2992 NULL
115031 +lov_stripetype_seq_write_3013 lov_stripetype_seq_write 3 3013 NULL
115032 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
115033 +depth_write_3021 depth_write 3 3021 NULL
115034 +snd_azf3328_codec_inl_3022 snd_azf3328_codec_inl 0 3022 NULL
115035 +nvme_split_and_submit_3027 nvme_split_and_submit 3 3027 NULL
115036 +kvm_unmap_hva_3028 kvm_unmap_hva 2 3028 NULL
115037 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
115038 +lpfc_idiag_mbxacc_write_3038 lpfc_idiag_mbxacc_write 3 3038 NULL nohasharray
115039 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 &lpfc_idiag_mbxacc_write_3038
115040 +nr_free_buffer_pages_3044 nr_free_buffer_pages 0 3044 NULL
115041 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
115042 +qp_alloc_ppn_set_3068 qp_alloc_ppn_set 2-4 3068 NULL
115043 +__blk_end_bidi_request_3070 __blk_end_bidi_request 3-4 3070 NULL
115044 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 NULL
115045 +read_file_antenna_diversity_3077 read_file_antenna_diversity 3 3077 NULL
115046 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
115047 +rb_alloc_3102 rb_alloc 1 3102 NULL
115048 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
115049 +print_time_3132 print_time 0 3132 NULL
115050 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
115051 +CIFSSMBSetPosixACL_3154 CIFSSMBSetPosixACL 5 3154 NULL
115052 +uv_num_possible_blades_3177 uv_num_possible_blades 0 3177 NULL
115053 +uinput_ioctl_handler_3181 uinput_ioctl_handler 2 3181 NULL nohasharray
115054 +uvc_video_stats_dump_3181 uvc_video_stats_dump 3 3181 &uinput_ioctl_handler_3181
115055 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
115056 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
115057 +alloc_context_3194 alloc_context 1 3194 NULL
115058 +shmem_pread_slow_3198 shmem_pread_slow 3-2 3198 NULL
115059 +codec_reg_write_file_3204 codec_reg_write_file 3 3204 NULL
115060 +SyS_sendto_3219 SyS_sendto 6 3219 NULL
115061 +btrfs_prealloc_file_range_3227 btrfs_prealloc_file_range 3 3227 NULL
115062 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
115063 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
115064 +ext3_xattr_find_entry_3237 ext3_xattr_find_entry 0 3237 NULL
115065 +key_key_read_3241 key_key_read 3 3241 NULL
115066 +__ilog2_u64_3284 __ilog2_u64 0 3284 NULL
115067 +ieee80211_if_write_beacon_loss_3296 ieee80211_if_write_beacon_loss 3 3296 NULL
115068 +cgroup_name_3300 cgroup_name 3 3300 NULL
115069 +__set_extent_bit_3305 __set_extent_bit 0 3305 NULL
115070 +__iovec_copy_from_user_inatomic_3314 __iovec_copy_from_user_inatomic 4-3-0 3314 NULL
115071 +_iwl_dbgfs_d3_sram_write_3315 _iwl_dbgfs_d3_sram_write 3 3315 NULL
115072 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
115073 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
115074 +sysfs_create_group_3339 sysfs_create_group 0 3339 NULL
115075 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
115076 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
115077 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
115078 +scnprintf_3360 scnprintf 0-2 3360 NULL
115079 +sr_read_3366 sr_read 3 3366 NULL
115080 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
115081 +isdn_readbchan_3401 isdn_readbchan 0-5 3401 NULL
115082 +mei_io_cb_alloc_resp_buf_3414 mei_io_cb_alloc_resp_buf 2 3414 NULL
115083 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
115084 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
115085 +SyS_msgsnd_3436 SyS_msgsnd 3 3436 NULL
115086 +softsynth_write_3455 softsynth_write 3 3455 NULL
115087 +snd_pcm_lib_readv_transfer_3464 snd_pcm_lib_readv_transfer 5-4-2 3464 NULL
115088 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
115089 +xfrm_migrate_msgsize_3496 xfrm_migrate_msgsize 1 3496 NULL
115090 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL
115091 +SyS_semtimedop_3532 SyS_semtimedop 3 3532 NULL
115092 +SyS_readv_3539 SyS_readv 3 3539 NULL
115093 +btrfs_dir_name_len_3549 btrfs_dir_name_len 0 3549 NULL
115094 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
115095 +evtchn_read_3569 evtchn_read 3 3569 NULL
115096 +ll_track_ppid_seq_write_3582 ll_track_ppid_seq_write 3 3582 NULL
115097 +vc_resize_3585 vc_resize 3-2 3585 NULL
115098 +kvm_mmu_notifier_change_pte_3596 kvm_mmu_notifier_change_pte 3 3596 NULL
115099 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
115100 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
115101 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
115102 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
115103 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
115104 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
115105 +_iwl_dbgfs_tx_flush_write_3675 _iwl_dbgfs_tx_flush_write 3 3675 NULL
115106 +snd_m3_assp_read_3703 snd_m3_assp_read 0 3703 NULL
115107 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
115108 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
115109 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
115110 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
115111 +hfsplus_direct_IO_3835 hfsplus_direct_IO 4 3835 NULL
115112 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
115113 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
115114 +get_fd_set_3866 get_fd_set 1 3866 NULL
115115 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
115116 +efivarfs_file_read_3893 efivarfs_file_read 3 3893 NULL
115117 +nvram_write_3894 nvram_write 3 3894 NULL
115118 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
115119 +comedi_buf_read_n_available_3899 comedi_buf_read_n_available 0 3899 NULL
115120 +vcs_write_3910 vcs_write 3 3910 NULL
115121 +SyS_move_pages_3920 SyS_move_pages 2 3920 NULL
115122 +brcmf_debugfs_fws_stats_read_3947 brcmf_debugfs_fws_stats_read 3 3947 NULL
115123 +mite_bytes_written_to_memory_lb_3987 mite_bytes_written_to_memory_lb 0 3987 NULL
115124 +do_add_counters_3992 do_add_counters 3 3992 NULL
115125 +obd_alloc_memmd_4002 obd_alloc_memmd 0 4002 NULL
115126 +userspace_status_4004 userspace_status 4 4004 NULL
115127 +mei_write_4005 mei_write 3 4005 NULL nohasharray
115128 +xfs_check_block_4005 xfs_check_block 4 4005 &mei_write_4005
115129 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
115130 +blk_end_request_4024 blk_end_request 3 4024 NULL
115131 +ext4_xattr_find_entry_4025 ext4_xattr_find_entry 0 4025 NULL
115132 +mtip_hw_read_registers_4037 mtip_hw_read_registers 3 4037 NULL
115133 +read_file_queues_4078 read_file_queues 3 4078 NULL
115134 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
115135 +tm6000_read_4151 tm6000_read 3 4151 NULL
115136 +mpt_raid_phys_disk_get_num_paths_4155 mpt_raid_phys_disk_get_num_paths 0 4155 NULL
115137 +msg_bits_4158 msg_bits 0-3-4 4158 NULL
115138 +get_alua_req_4166 get_alua_req 3 4166 NULL
115139 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
115140 +read_file_bool_4180 read_file_bool 3 4180 NULL
115141 +vring_new_virtqueue_4199 vring_new_virtqueue 2 4199 NULL
115142 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
115143 +__snd_gf1_read_addr_4210 __snd_gf1_read_addr 0 4210 NULL
115144 +ath6kl_force_roam_write_4282 ath6kl_force_roam_write 3 4282 NULL
115145 +goldfish_audio_write_4284 goldfish_audio_write 3 4284 NULL
115146 +get_connectors_for_crtc_4291 get_connectors_for_crtc 0 4291 NULL
115147 +__usbnet_read_cmd_4299 __usbnet_read_cmd 7 4299 NULL
115148 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
115149 +count_strings_4315 count_strings 0 4315 NULL
115150 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
115151 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
115152 +ima_eventdigest_init_common_4338 ima_eventdigest_init_common 2 4338 NULL
115153 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 3-0 4365 NULL
115154 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
115155 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 NULL nohasharray
115156 +access_process_vm_4412 access_process_vm 0 4412 &cxacru_cm_get_array_4412
115157 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
115158 +rtw_android_get_rssi_4421 rtw_android_get_rssi 0 4421 NULL
115159 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
115160 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
115161 +snd_seq_expand_var_event_4481 snd_seq_expand_var_event 0-5 4481 NULL
115162 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
115163 +set_link_security_4502 set_link_security 4 4502 NULL
115164 +ll_max_readahead_per_file_mb_seq_write_4531 ll_max_readahead_per_file_mb_seq_write 3 4531 NULL
115165 +tty_register_device_4544 tty_register_device 2 4544 NULL
115166 +fsl_edma_prep_slave_sg_4555 fsl_edma_prep_slave_sg 3 4555 NULL
115167 +btrfs_file_extent_inline_item_len_4575 btrfs_file_extent_inline_item_len 0 4575 NULL
115168 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
115169 +bch_alloc_4593 bch_alloc 1 4593 NULL
115170 +ll_rw_extents_stats_seq_write_4633 ll_rw_extents_stats_seq_write 3 4633 NULL
115171 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
115172 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
115173 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
115174 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
115175 +kone_receive_4690 kone_receive 4 4690 NULL
115176 +hash_netportnet6_expire_4702 hash_netportnet6_expire 4 4702 NULL
115177 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
115178 +show_header_4722 show_header 3 4722 NULL nohasharray
115179 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 &show_header_4722
115180 +ll_rw_offset_stats_seq_write_4736 ll_rw_offset_stats_seq_write 3 4736 NULL nohasharray
115181 +bitmap_startwrite_4736 bitmap_startwrite 2 4736 &ll_rw_offset_stats_seq_write_4736
115182 +lu_buf_alloc_4753 lu_buf_alloc 2 4753 NULL
115183 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
115184 +create_subvol_4791 create_subvol 4 4791 NULL
115185 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
115186 +C_SYSC_setsockopt_4806 C_SYSC_setsockopt 5 4806 NULL
115187 +repair_io_failure_4815 repair_io_failure 4-3 4815 NULL
115188 +comedi_buf_write_free_4847 comedi_buf_write_free 2 4847 NULL
115189 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
115190 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
115191 +ocfs2_defrag_extent_4873 ocfs2_defrag_extent 2 4873 NULL
115192 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
115193 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
115194 +ieee80211_if_fmt_ave_beacon_4941 ieee80211_if_fmt_ave_beacon 3 4941 NULL
115195 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
115196 +ath10k_read_chip_id_4969 ath10k_read_chip_id 3 4969 NULL
115197 +skb_network_header_len_4971 skb_network_header_len 0 4971 NULL
115198 +ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval_4976 ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval 3 4976 NULL
115199 +compat_SyS_ipc_5000 compat_SyS_ipc 3 5000 NULL
115200 +do_mincore_5018 do_mincore 0-2-1 5018 NULL
115201 +btrfs_punch_hole_5041 btrfs_punch_hole 2 5041 NULL
115202 +cfg80211_rx_mgmt_5056 cfg80211_rx_mgmt 5 5056 NULL
115203 +ocfs2_check_range_for_holes_5066 ocfs2_check_range_for_holes 2-3 5066 NULL
115204 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
115205 +snd_emu10k1_ptr20_read_5087 snd_emu10k1_ptr20_read 0 5087 NULL
115206 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3-4-0 5091 NULL nohasharray
115207 +get_random_bytes_5091 get_random_bytes 2 5091 &kfifo_copy_from_user_5091 nohasharray
115208 +blk_rq_sectors_5091 blk_rq_sectors 0 5091 &get_random_bytes_5091
115209 +sound_write_5102 sound_write 3 5102 NULL
115210 +i40e_dbg_netdev_ops_write_5117 i40e_dbg_netdev_ops_write 3 5117 NULL
115211 +qib_7220_handle_hwerrors_5142 qib_7220_handle_hwerrors 3 5142 NULL
115212 +__uwb_addr_print_5161 __uwb_addr_print 2 5161 NULL
115213 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
115214 +acpi_pcc_get_sqty_5176 acpi_pcc_get_sqty 0 5176 NULL
115215 +trf7970a_read_cont_5179 trf7970a_read_cont 4 5179 NULL
115216 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
115217 +dwc2_hcd_urb_alloc_5217 dwc2_hcd_urb_alloc 2 5217 NULL
115218 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
115219 +r592_write_fifo_pio_5315 r592_write_fifo_pio 3 5315 NULL
115220 +sbc_get_write_same_sectors_5317 sbc_get_write_same_sectors 0 5317 NULL
115221 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
115222 +uinput_ioctl_5342 uinput_ioctl 2 5342 NULL
115223 +cq_free_res_5355 cq_free_res 5 5355 NULL
115224 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
115225 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
115226 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
115227 +ll_xattr_cache_refill_5468 ll_xattr_cache_refill 0 5468 NULL
115228 +kernfs_fop_write_5471 kernfs_fop_write 3 5471 NULL
115229 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
115230 +pci_enable_msix_exact_5482 pci_enable_msix_exact 3-0 5482 NULL
115231 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
115232 +tty_write_5494 tty_write 3 5494 NULL
115233 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL nohasharray
115234 +ieee80211_if_fmt_last_beacon_5498 ieee80211_if_fmt_last_beacon 3 5498 &tomoyo_update_domain_5498
115235 +__max_nr_grant_frames_5505 __max_nr_grant_frames 0 5505 NULL
115236 +ieee80211_if_fmt_auto_open_plinks_5534 ieee80211_if_fmt_auto_open_plinks 3 5534 NULL
115237 +get_entry_msg_len_5552 get_entry_msg_len 0 5552 NULL
115238 +le_readq_5557 le_readq 0 5557 NULL
115239 +inw_5558 inw 0 5558 NULL
115240 +bioset_create_5580 bioset_create 1 5580 NULL
115241 +oz_ep_alloc_5587 oz_ep_alloc 1 5587 NULL
115242 +__remove_suid_5618 __remove_suid 0 5618 NULL
115243 +SYSC_fsetxattr_5639 SYSC_fsetxattr 4 5639 NULL
115244 +ext4_xattr_get_5661 ext4_xattr_get 0 5661 NULL
115245 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
115246 +get_arg_5694 get_arg 3 5694 NULL
115247 +subbuf_read_actor_5708 subbuf_read_actor 3 5708 NULL
115248 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
115249 +rts51x_transfer_data_partial_5735 rts51x_transfer_data_partial 6 5735 NULL
115250 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
115251 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
115252 +nvme_trans_bdev_char_page_5797 nvme_trans_bdev_char_page 3 5797 NULL
115253 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
115254 +nv50_disp_pioc_create__5812 nv50_disp_pioc_create_ 5 5812 NULL
115255 +ceph_x_encrypt_buflen_5829 ceph_x_encrypt_buflen 0-1 5829 NULL
115256 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
115257 +setup_req_5848 setup_req 3 5848 NULL
115258 +ria_page_count_5849 ria_page_count 0 5849 NULL
115259 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
115260 +uinput_compat_ioctl_5861 uinput_compat_ioctl 2 5861 NULL
115261 +lprocfs_fid_width_seq_write_5889 lprocfs_fid_width_seq_write 3 5889 NULL
115262 +port_show_regs_5904 port_show_regs 3 5904 NULL
115263 +rbd_segment_length_5907 rbd_segment_length 0-3-2 5907 NULL
115264 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
115265 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
115266 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
115267 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
115268 +ll_statahead_one_5962 ll_statahead_one 3 5962 NULL
115269 +__apu_get_register_5967 __apu_get_register 0 5967 NULL
115270 +ieee80211_if_fmt_rc_rateidx_mask_5ghz_5971 ieee80211_if_fmt_rc_rateidx_mask_5ghz 3 5971 NULL
115271 +SyS_semop_5980 SyS_semop 3 5980 NULL
115272 +alloc_msg_6072 alloc_msg 1 6072 NULL
115273 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
115274 +rts51x_ms_rw_multi_sector_6076 rts51x_ms_rw_multi_sector 3-4 6076 NULL
115275 +__mnt_want_write_6091 __mnt_want_write 0 6091 NULL
115276 +ipmi_addr_length_6110 ipmi_addr_length 0 6110 NULL nohasharray
115277 +force_static_address_read_6110 force_static_address_read 3 6110 &ipmi_addr_length_6110
115278 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
115279 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
115280 +ieee80211_if_fmt_beacon_timeout_6153 ieee80211_if_fmt_beacon_timeout 3 6153 NULL
115281 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
115282 +maybe_insert_hole_6167 maybe_insert_hole 3 6167 NULL
115283 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
115284 +SyS_setgroups_6182 SyS_setgroups 1 6182 NULL
115285 +mxt_show_instance_6207 mxt_show_instance 2-0 6207 NULL
115286 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
115287 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
115288 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
115289 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
115290 +of_gpio_count_6270 of_gpio_count 0 6270 NULL
115291 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
115292 +snd_hda_override_conn_list_6282 snd_hda_override_conn_list 3-0 6282 NULL nohasharray
115293 +xenbus_file_write_6282 xenbus_file_write 3 6282 &snd_hda_override_conn_list_6282
115294 +posix_acl_fix_xattr_to_user_6283 posix_acl_fix_xattr_to_user 2 6283 NULL
115295 +serial_port_in_6291 serial_port_in 0 6291 NULL
115296 +qlcnic_sriov_alloc_bc_msg_6309 qlcnic_sriov_alloc_bc_msg 2 6309 NULL
115297 +hfa384x_inw_6329 hfa384x_inw 0 6329 NULL nohasharray
115298 +SyS_mincore_6329 SyS_mincore 1-2 6329 &hfa384x_inw_6329
115299 +fuse_get_req_for_background_6337 fuse_get_req_for_background 2 6337 NULL
115300 +ucs2_strnlen_6342 ucs2_strnlen 0 6342 NULL
115301 +regcache_sync_block_raw_6350 regcache_sync_block_raw 5-4 6350 NULL
115302 +mei_dbgfs_read_devstate_6352 mei_dbgfs_read_devstate 3 6352 NULL
115303 +_proc_do_string_6376 _proc_do_string 2 6376 NULL
115304 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL
115305 +posix_acl_fix_xattr_userns_6420 posix_acl_fix_xattr_userns 4 6420 NULL
115306 +add_transaction_credits_6422 add_transaction_credits 2-3 6422 NULL
115307 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
115308 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
115309 +ieee80211_if_fmt_dot11MeshMaxRetries_6476 ieee80211_if_fmt_dot11MeshMaxRetries 3 6476 NULL
115310 +qp_memcpy_from_queue_6479 qp_memcpy_from_queue 5-4 6479 NULL
115311 +cipso_v4_map_lvl_hton_6490 cipso_v4_map_lvl_hton 0 6490 NULL
115312 +dbg_intr_buf_6501 dbg_intr_buf 2 6501 NULL
115313 +mei_read_6507 mei_read 3 6507 NULL
115314 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
115315 +wdm_read_6549 wdm_read 3 6549 NULL
115316 +dm_stats_create_6551 dm_stats_create 4-2-3 6551 NULL
115317 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
115318 +SyS_semtimedop_6563 SyS_semtimedop 3 6563 NULL
115319 +snd_pcm_hw_refine_old_user_6586 snd_pcm_hw_refine_old_user 0 6586 NULL
115320 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
115321 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
115322 +pvscsi_allocate_rings_6689 pvscsi_allocate_rings 0 6689 NULL
115323 +btrfs_lookup_csums_range_6696 btrfs_lookup_csums_range 2-3 6696 NULL
115324 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
115325 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
115326 +mpeg_read_6708 mpeg_read 3 6708 NULL
115327 +ibmpex_query_sensor_count_6709 ibmpex_query_sensor_count 0 6709 NULL
115328 +video_proc_write_6724 video_proc_write 3 6724 NULL
115329 +posix_acl_xattr_count_6725 posix_acl_xattr_count 0-1 6725 NULL
115330 +kobject_add_varg_6781 kobject_add_varg 0 6781 NULL
115331 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
115332 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
115333 +zone_spanned_pages_in_node_6787 zone_spanned_pages_in_node 0-3-4 6787 NULL
115334 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
115335 +ll_xattr_cache_find_6798 ll_xattr_cache_find 0 6798 NULL
115336 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
115337 +lbs_rdrf_write_6826 lbs_rdrf_write 3 6826 NULL
115338 +calc_pages_for_6838 calc_pages_for 0-2-1 6838 NULL
115339 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
115340 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
115341 +perf_output_sample_ustack_6868 perf_output_sample_ustack 2 6868 NULL
115342 +dio_complete_6879 dio_complete 0-3-2 6879 NULL
115343 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL nohasharray
115344 +ieee80211_if_fmt_path_refresh_time_6888 ieee80211_if_fmt_path_refresh_time 3 6888 &raw_seticmpfilter_6888
115345 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
115346 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 NULL nohasharray
115347 +spi_show_regs_6911 spi_show_regs 3 6911 &proc_sessionid_read_6911 nohasharray
115348 +acm_alloc_minor_6911 acm_alloc_minor 0 6911 &spi_show_regs_6911
115349 +__kfifo_dma_in_finish_r_6913 __kfifo_dma_in_finish_r 2-3 6913 NULL
115350 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
115351 +ipath_verbs_send_dma_6929 ipath_verbs_send_dma 6 6929 NULL
115352 +qsfp_cks_6945 qsfp_cks 2-0 6945 NULL
115353 +tg3_nvram_write_block_unbuffered_6955 tg3_nvram_write_block_unbuffered 3 6955 NULL
115354 +pch_uart_hal_read_6961 pch_uart_hal_read 0 6961 NULL
115355 +i40e_dbg_dump_write_6973 i40e_dbg_dump_write 3 6973 NULL nohasharray
115356 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 &i40e_dbg_dump_write_6973
115357 +request_key_async_6990 request_key_async 4 6990 NULL
115358 +tpl_write_6998 tpl_write 3 6998 NULL
115359 +r871x_set_wpa_ie_7000 r871x_set_wpa_ie 3 7000 NULL
115360 +cipso_v4_gentag_enum_7006 cipso_v4_gentag_enum 0 7006 NULL
115361 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
115362 +ld_usb_write_7022 ld_usb_write 3 7022 NULL
115363 +wimax_msg_7030 wimax_msg 4 7030 NULL
115364 +ceph_kvmalloc_7033 ceph_kvmalloc 1 7033 NULL
115365 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
115366 +snd_pcm_oss_bytes_7051 snd_pcm_oss_bytes 2 7051 NULL
115367 +nouveau_device_create__7063 nouveau_device_create_ 7 7063 NULL
115368 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
115369 +event_enable_read_7074 event_enable_read 3 7074 NULL
115370 +tipc_send_packet_7091 tipc_send_packet 4 7091 NULL nohasharray
115371 +beacon_interval_read_7091 beacon_interval_read 3 7091 &tipc_send_packet_7091
115372 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
115373 +osc_resend_count_seq_write_7120 osc_resend_count_seq_write 3 7120 NULL
115374 +qib_format_hwerrors_7133 qib_format_hwerrors 5 7133 NULL
115375 +kvm_mmu_notifier_test_young_7139 kvm_mmu_notifier_test_young 3 7139 NULL
115376 +qlcnic_enable_msix_7144 qlcnic_enable_msix 2 7144 NULL
115377 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
115378 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
115379 +security_inode_need_killpriv_7322 security_inode_need_killpriv 0 7322 NULL
115380 +pci_vpd_info_field_size_7324 pci_vpd_info_field_size 0 7324 NULL
115381 +mgmt_control_7349 mgmt_control 3 7349 NULL
115382 +at_est2timeout_7365 at_est2timeout 0-1 7365 NULL
115383 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
115384 +ath10k_read_fw_stats_7387 ath10k_read_fw_stats 3 7387 NULL
115385 +hweight_long_7388 hweight_long 0 7388 NULL
115386 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
115387 +_ore_add_stripe_unit_7399 _ore_add_stripe_unit 6-3 7399 NULL
115388 +audmux_read_file_7400 audmux_read_file 3 7400 NULL
115389 +readb_7401 readb 0 7401 NULL
115390 +tipc_recvmsg_7402 tipc_recvmsg 4 7402 NULL
115391 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
115392 +__copy_to_user_nocheck_7443 __copy_to_user_nocheck 0-3 7443 NULL
115393 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
115394 +SYSC_setgroups_7454 SYSC_setgroups 1 7454 NULL
115395 +rt2x00debug_read_queue_stats_7455 rt2x00debug_read_queue_stats 3 7455 NULL
115396 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
115397 +garp_request_join_7471 garp_request_join 4 7471 NULL
115398 +snd_pcm_lib_read1_7491 snd_pcm_lib_read1 0-3 7491 NULL
115399 +ahash_instance_headroom_7509 ahash_instance_headroom 0 7509 NULL nohasharray
115400 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 &ahash_instance_headroom_7509
115401 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
115402 +sk_convert_filter_7541 sk_convert_filter 2 7541 NULL
115403 +ath10k_read_htt_stats_mask_7557 ath10k_read_htt_stats_mask 3 7557 NULL
115404 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
115405 +netvsc_get_slots_7565 netvsc_get_slots 0 7565 NULL
115406 +cfs_cpt_num_estimate_7571 cfs_cpt_num_estimate 0 7571 NULL
115407 +groups_alloc_7614 groups_alloc 1 7614 NULL nohasharray
115408 +create_dir_7614 create_dir 0 7614 &groups_alloc_7614
115409 +_rtw_zmalloc_7636 _rtw_zmalloc 1 7636 NULL
115410 +fault_inject_write_7662 fault_inject_write 3 7662 NULL
115411 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 NULL
115412 +acpi_ns_get_pathname_length_7699 acpi_ns_get_pathname_length 0 7699 NULL
115413 +dev_write_7708 dev_write 3 7708 NULL
115414 +pci_raw_set_power_state_7729 pci_raw_set_power_state 0 7729 NULL
115415 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
115416 +ubi_io_read_vid_hdr_7766 ubi_io_read_vid_hdr 0 7766 NULL
115417 +iwl_dbgfs_bt_cmd_read_7770 iwl_dbgfs_bt_cmd_read 3 7770 NULL
115418 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
115419 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
115420 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
115421 +lustre_packed_msg_size_7792 lustre_packed_msg_size 0 7792 NULL nohasharray
115422 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 &lustre_packed_msg_size_7792
115423 +cfs_trace_dump_debug_buffer_usrstr_7861 cfs_trace_dump_debug_buffer_usrstr 2 7861 NULL
115424 +tipc_alloc_entry_7875 tipc_alloc_entry 2 7875 NULL
115425 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
115426 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
115427 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
115428 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
115429 +integrity_digsig_verify_7956 integrity_digsig_verify 3-0 7956 NULL
115430 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
115431 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
115432 +vcs_read_8017 vcs_read 3 8017 NULL
115433 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
115434 +ms_read_multiple_pages_8052 ms_read_multiple_pages 5-4 8052 NULL
115435 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
115436 +spi_write_then_read_8073 spi_write_then_read 5-3 8073 NULL
115437 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 NULL
115438 +venus_lookup_8121 venus_lookup 4 8121 NULL
115439 +ieee80211_if_fmt_num_buffered_multicast_8127 ieee80211_if_fmt_num_buffered_multicast 3 8127 NULL
115440 +__sk_mem_schedule_8185 __sk_mem_schedule 2 8185 NULL
115441 +ieee80211_if_fmt_dot11MeshHoldingTimeout_8187 ieee80211_if_fmt_dot11MeshHoldingTimeout 3 8187 NULL
115442 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
115443 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
115444 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
115445 +play_iframe_8219 play_iframe 3 8219 NULL
115446 +kvm_mmu_page_set_gfn_8225 kvm_mmu_page_set_gfn 2 8225 NULL
115447 +sctp_ssnmap_size_8228 sctp_ssnmap_size 0-1-2 8228 NULL
115448 +check_xattr_ref_inode_8244 check_xattr_ref_inode 0 8244 NULL
115449 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
115450 +init_cdev_8274 init_cdev 1 8274 NULL
115451 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
115452 +qib_decode_7220_err_8315 qib_decode_7220_err 3 8315 NULL
115453 +snd_pcm_update_state_8320 snd_pcm_update_state 0 8320 NULL
115454 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
115455 +rtw_cfg80211_rx_action_8329 rtw_cfg80211_rx_action 3 8329 NULL
115456 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
115457 +ieee80211_if_fmt_ht_opmode_8347 ieee80211_if_fmt_ht_opmode 3 8347 NULL
115458 +generic_write_sync_8358 generic_write_sync 0 8358 NULL
115459 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
115460 +ath6kl_lrssi_roam_write_8362 ath6kl_lrssi_roam_write 3 8362 NULL
115461 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
115462 +zd_rf_scnprint_id_8406 zd_rf_scnprint_id 0-3 8406 NULL
115463 +smk_write_change_rule_8411 smk_write_change_rule 3 8411 NULL nohasharray
115464 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 &smk_write_change_rule_8411
115465 +roccat_common2_sysfs_read_8431 roccat_common2_sysfs_read 6 8431 NULL
115466 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
115467 +fore200e_chunk_alloc_8501 fore200e_chunk_alloc 4-3 8501 NULL
115468 +batadv_tt_len_8502 batadv_tt_len 0-1 8502 NULL
115469 +dev_config_8506 dev_config 3 8506 NULL
115470 +ACL_to_cifs_posix_8509 ACL_to_cifs_posix 3 8509 NULL
115471 +opticon_process_data_packet_8524 opticon_process_data_packet 3 8524 NULL
115472 +user_on_off_8552 user_on_off 2 8552 NULL
115473 +profile_remove_8556 profile_remove 3 8556 NULL
115474 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL nohasharray
115475 +pci_msi_check_device_8570 pci_msi_check_device 0 8570 &cache_slow_downcall_8570
115476 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
115477 +tower_write_8580 tower_write 3 8580 NULL
115478 +cfs_cpt_number_8618 cfs_cpt_number 0 8618 NULL
115479 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
115480 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
115481 +scsi_dma_map_8632 scsi_dma_map 0 8632 NULL
115482 +fuse_send_write_pages_8636 fuse_send_write_pages 0-5 8636 NULL
115483 +mlx5_vzalloc_8663 mlx5_vzalloc 1 8663 NULL
115484 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
115485 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
115486 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
115487 +skb_frag_size_8695 skb_frag_size 0 8695 NULL
115488 +arcfb_write_8702 arcfb_write 3 8702 NULL
115489 +i_size_read_8703 i_size_read 0 8703 NULL nohasharray
115490 +init_header_8703 init_header 0 8703 &i_size_read_8703
115491 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
115492 +tracing_max_lat_write_8728 tracing_max_lat_write 3 8728 NULL
115493 +jffs2_acl_count_8729 jffs2_acl_count 0-1 8729 NULL
115494 +__create_irqs_8733 __create_irqs 2 8733 NULL
115495 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
115496 +compound_order_8750 compound_order 0 8750 NULL
115497 +yurex_write_8761 yurex_write 3 8761 NULL
115498 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
115499 +kstrtoint_from_user_8778 kstrtoint_from_user 2 8778 NULL
115500 +paging32_prefetch_gpte_8783 paging32_prefetch_gpte 4 8783 NULL
115501 +ext4_try_to_write_inline_data_8785 ext4_try_to_write_inline_data 3-4 8785 NULL
115502 +__bitmap_weight_8796 __bitmap_weight 0 8796 NULL
115503 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
115504 +SyS_llistxattr_8824 SyS_llistxattr 3 8824 NULL
115505 +extent_read_full_page_8826 extent_read_full_page 0 8826 NULL
115506 +ll_xattr_cache_get_8829 ll_xattr_cache_get 0 8829 NULL
115507 +get_queue_depth_8833 get_queue_depth 0 8833 NULL
115508 +dvb_ringbuffer_pkt_next_8834 dvb_ringbuffer_pkt_next 0-2 8834 NULL
115509 +usb_ep_queue_8839 usb_ep_queue 0 8839 NULL
115510 +iwl_rx_packet_len_8854 iwl_rx_packet_len 0 8854 NULL
115511 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
115512 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
115513 +radeon_drm_ioctl_8875 radeon_drm_ioctl 2 8875 NULL
115514 +compressed_bio_size_8887 compressed_bio_size 0-2 8887 NULL
115515 +ab3100_get_set_reg_8890 ab3100_get_set_reg 3 8890 NULL nohasharray
115516 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 &ab3100_get_set_reg_8890
115517 +sdio_max_byte_size_8907 sdio_max_byte_size 0 8907 NULL
115518 +sysfs_merge_group_8917 sysfs_merge_group 0 8917 NULL
115519 +write_file_ani_8918 write_file_ani 3 8918 NULL
115520 +layout_commit_8926 layout_commit 3 8926 NULL
115521 +cp2112_hid_get_8933 cp2112_hid_get 4 8933 NULL
115522 +adjust_priv_size_8935 adjust_priv_size 0-1 8935 NULL
115523 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
115524 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
115525 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
115526 +qib_qsfp_dump_8966 qib_qsfp_dump 0-3 8966 NULL
115527 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
115528 +seq_open_net_8968 seq_open_net 4 8968 NULL nohasharray
115529 +vol_cdev_read_8968 vol_cdev_read 3 8968 &seq_open_net_8968
115530 +bio_integrity_get_tag_8974 bio_integrity_get_tag 3 8974 NULL
115531 +sony_register_touchpad_8981 sony_register_touchpad 2 8981 NULL
115532 +jbd2_journal_blocks_per_page_9004 jbd2_journal_blocks_per_page 0 9004 NULL
115533 +il_dbgfs_clear_ucode_stats_write_9016 il_dbgfs_clear_ucode_stats_write 3 9016 NULL
115534 +snd_emu10k1_ptr_read_9026 snd_emu10k1_ptr_read 0-2 9026 NULL
115535 +nla_put_9042 nla_put 3 9042 NULL
115536 +sta_tx_latency_stat_header_9050 sta_tx_latency_stat_header 0-3-4 9050 NULL
115537 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
115538 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
115539 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
115540 +create_queues_9088 create_queues 2-3 9088 NULL
115541 +ftdi_prepare_write_buffer_9093 ftdi_prepare_write_buffer 3 9093 NULL
115542 +adxl34x_spi_read_block_9108 adxl34x_spi_read_block 3 9108 NULL
115543 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 NULL nohasharray
115544 +gfn_to_rmap_9110 gfn_to_rmap 2-3 9110 &caif_stream_sendmsg_9110
115545 +udf_direct_IO_9111 udf_direct_IO 4 9111 NULL
115546 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
115547 +vb2_dma_sg_alloc_9157 vb2_dma_sg_alloc 2 9157 NULL
115548 +dbg_command_buf_9165 dbg_command_buf 2 9165 NULL
115549 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
115550 +count_leading_zeros_9183 count_leading_zeros 0 9183 NULL
115551 +altera_swap_ir_9194 altera_swap_ir 2 9194 NULL
115552 +snd_m3_get_pointer_9206 snd_m3_get_pointer 0 9206 NULL
115553 +iwl_dbgfs_frame_stats_read_9211 iwl_dbgfs_frame_stats_read 3 9211 NULL
115554 +virtqueue_add_9217 virtqueue_add 4-5 9217 NULL
115555 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
115556 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
115557 +hfsplus_bnode_read_u16_9262 hfsplus_bnode_read_u16 0 9262 NULL
115558 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
115559 +flakey_status_9274 flakey_status 5 9274 NULL
115560 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
115561 +ceph_sync_setxattr_9310 ceph_sync_setxattr 4 9310 NULL
115562 +ieee80211_if_fmt_txpower_9334 ieee80211_if_fmt_txpower 3 9334 NULL
115563 +nvme_trans_fmt_get_parm_header_9340 nvme_trans_fmt_get_parm_header 2 9340 NULL
115564 +ocfs2_orphan_for_truncate_9342 ocfs2_orphan_for_truncate 4 9342 NULL
115565 +ll_direct_rw_pages_9361 ll_direct_rw_pages 0 9361 NULL
115566 +sta_beacon_loss_count_read_9370 sta_beacon_loss_count_read 3 9370 NULL
115567 +virtqueue_add_outbuf_9395 virtqueue_add_outbuf 3 9395 NULL
115568 +read_9397 read 3 9397 NULL
115569 +hash_ipportip4_expire_9415 hash_ipportip4_expire 4 9415 NULL
115570 +btrfs_drop_extents_9423 btrfs_drop_extents 4 9423 NULL
115571 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
115572 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
115573 +ieee80211_if_fmt_fwded_unicast_9454 ieee80211_if_fmt_fwded_unicast 3 9454 NULL
115574 +get_registers_9470 get_registers 4 9470 NULL nohasharray
115575 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 &get_registers_9470
115576 +crypt_status_9492 crypt_status 5 9492 NULL
115577 +lbs_threshold_write_9502 lbs_threshold_write 5 9502 NULL
115578 +lp_write_9511 lp_write 3 9511 NULL
115579 +mext_calc_swap_extents_9517 mext_calc_swap_extents 4 9517 NULL
115580 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
115581 +ll_max_read_ahead_whole_mb_seq_write_9528 ll_max_read_ahead_whole_mb_seq_write 3 9528 NULL
115582 +read_file_dma_9530 read_file_dma 3 9530 NULL
115583 +iwl_dbgfs_bf_params_read_9542 iwl_dbgfs_bf_params_read 3 9542 NULL
115584 +il_dbgfs_missed_beacon_write_9546 il_dbgfs_missed_beacon_write 3 9546 NULL
115585 +compat_SyS_pwritev64_9548 compat_SyS_pwritev64 3 9548 NULL
115586 +fw_node_create_9559 fw_node_create 2 9559 NULL
115587 +kobj_map_9566 kobj_map 2-3 9566 NULL
115588 +f2fs_read_data_pages_9574 f2fs_read_data_pages 4 9574 NULL
115589 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5-6 9605 NULL
115590 +lov_ost_pool_add_9626 lov_ost_pool_add 3 9626 NULL
115591 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
115592 +ceph_copy_user_to_page_vector_9635 ceph_copy_user_to_page_vector 4-3 9635 NULL
115593 +acpi_ex_insert_into_field_9638 acpi_ex_insert_into_field 3 9638 NULL
115594 +ll_checksum_seq_write_9648 ll_checksum_seq_write 3 9648 NULL
115595 +ocfs2_xattr_get_rec_9652 ocfs2_xattr_get_rec 0 9652 NULL
115596 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
115597 +tipc_port_mcast_xmit_9663 tipc_port_mcast_xmit 4 9663 NULL
115598 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
115599 +dns_query_9676 dns_query 3 9676 NULL
115600 +qib_7322_handle_hwerrors_9678 qib_7322_handle_hwerrors 3 9678 NULL
115601 +__erst_read_from_storage_9690 __erst_read_from_storage 0 9690 NULL
115602 +vx_transfer_end_9701 vx_transfer_end 0 9701 NULL
115603 +fuse_iter_npages_9705 fuse_iter_npages 0 9705 NULL nohasharray
115604 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 &fuse_iter_npages_9705
115605 +cfg80211_tx_mlme_mgmt_9715 cfg80211_tx_mlme_mgmt 3 9715 NULL
115606 +parse_uac2_sample_rate_range_9718 parse_uac2_sample_rate_range 0 9718 NULL
115607 +btrfs_stack_file_extent_num_bytes_9720 btrfs_stack_file_extent_num_bytes 0 9720 NULL
115608 +SYSC_ppoll_9721 SYSC_ppoll 2 9721 NULL
115609 +nla_get_u8_9736 nla_get_u8 0 9736 NULL
115610 +ieee80211_if_fmt_num_mcast_sta_9738 ieee80211_if_fmt_num_mcast_sta 3 9738 NULL
115611 +ddb_input_read_9743 ddb_input_read 3-0 9743 NULL
115612 +regmap_multi_reg_write_bypassed_9751 regmap_multi_reg_write_bypassed 3 9751 NULL nohasharray
115613 +sta_last_ack_signal_read_9751 sta_last_ack_signal_read 3 9751 &regmap_multi_reg_write_bypassed_9751
115614 +btrfs_super_root_9763 btrfs_super_root 0 9763 NULL
115615 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
115616 +kvm_age_hva_9795 kvm_age_hva 2 9795 NULL
115617 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 NULL nohasharray
115618 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 &udpv6_recvmsg_9813
115619 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
115620 +btrfs_free_reserved_extent_9867 btrfs_free_reserved_extent 2 9867 NULL
115621 +wil_read_file_ioblob_9878 wil_read_file_ioblob 3 9878 NULL
115622 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 NULL nohasharray
115623 +bm_register_write_9893 bm_register_write 3 9893 &snd_midi_event_new_9893
115624 +snd_gf1_pcm_playback_copy_9895 snd_gf1_pcm_playback_copy 3-5 9895 NULL
115625 +nonpaging_page_fault_9908 nonpaging_page_fault 2 9908 NULL
115626 +iwl_dbgfs_prph_reg_read_9928 iwl_dbgfs_prph_reg_read 3 9928 NULL
115627 +root_nfs_parse_options_9937 root_nfs_parse_options 3 9937 NULL
115628 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
115629 +read_file_misc_9948 read_file_misc 3 9948 NULL
115630 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
115631 +SyS_gethostname_9964 SyS_gethostname 2 9964 NULL
115632 +get_free_serial_index_9969 get_free_serial_index 0 9969 NULL
115633 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
115634 +SYSC_move_pages_9986 SYSC_move_pages 2 9986 NULL
115635 +aat2870_dump_reg_10019 aat2870_dump_reg 0 10019 NULL
115636 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
115637 +get_elem_size_10110 get_elem_size 0-2 10110 NULL nohasharray
115638 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 &get_elem_size_10110
115639 +gfs2_meta_read_10112 gfs2_meta_read 0 10112 NULL
115640 +SyS_migrate_pages_10134 SyS_migrate_pages 2 10134 NULL
115641 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
115642 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL
115643 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
115644 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
115645 +kstrtol_from_user_10168 kstrtol_from_user 2 10168 NULL
115646 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
115647 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
115648 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
115649 +__qlcnic_pci_sriov_enable_10281 __qlcnic_pci_sriov_enable 2 10281 NULL
115650 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
115651 +ubi_leb_change_10289 ubi_leb_change 0 10289 NULL
115652 +read_emulate_10310 read_emulate 2-4 10310 NULL
115653 +read_file_spectral_count_10320 read_file_spectral_count 3 10320 NULL
115654 +compat_SyS_writev_10327 compat_SyS_writev 3 10327 NULL
115655 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
115656 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
115657 +dbAllocAny_10354 dbAllocAny 0 10354 NULL
115658 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
115659 +ms_write_multiple_pages_10362 ms_write_multiple_pages 6-5 10362 NULL
115660 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
115661 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
115662 +led_classdev_register_10384 led_classdev_register 0 10384 NULL
115663 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
115664 +fwtty_rx_10434 fwtty_rx 3 10434 NULL
115665 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
115666 +hash_ipportip6_expire_10478 hash_ipportip6_expire 4 10478 NULL
115667 +nouveau_pwr_create__10483 nouveau_pwr_create_ 4 10483 NULL
115668 +ext4_itable_unused_count_10501 ext4_itable_unused_count 0 10501 NULL
115669 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
115670 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
115671 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
115672 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
115673 +qlcnic_pci_sriov_enable_10519 qlcnic_pci_sriov_enable 2 10519 NULL
115674 +snd_pcm_hw_params_user_10520 snd_pcm_hw_params_user 0 10520 NULL
115675 +kstrtouint_from_user_10536 kstrtouint_from_user 2 10536 NULL nohasharray
115676 +snd_pcm_lib_read_10536 snd_pcm_lib_read 0-3 10536 &kstrtouint_from_user_10536
115677 +ext4_write_begin_10576 ext4_write_begin 3-4 10576 NULL
115678 +scrub_remap_extent_10588 scrub_remap_extent 2 10588 NULL
115679 +otp_read_10594 otp_read 2-4-5 10594 NULL
115680 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
115681 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
115682 +fq_alloc_node_10633 fq_alloc_node 1 10633 NULL
115683 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL nohasharray
115684 +ubi_io_write_vid_hdr_10660 ubi_io_write_vid_hdr 0 10660 &nfs_idmap_lookup_id_10660
115685 +efx_max_tx_len_10662 efx_max_tx_len 0-2 10662 NULL
115686 +parport_write_10669 parport_write 0 10669 NULL
115687 +edge_write_10692 edge_write 4 10692 NULL
115688 +ubi_wl_get_peb_10699 ubi_wl_get_peb 0 10699 NULL
115689 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL nohasharray
115690 +inl_10708 inl 0 10708 &selinux_inode_setxattr_10708
115691 +shash_async_setkey_10720 shash_async_setkey 3 10720 NULL nohasharray
115692 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 &shash_async_setkey_10720
115693 +spi_sync_10731 spi_sync 0 10731 NULL
115694 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL nohasharray
115695 +apu_get_register_10737 apu_get_register 0 10737 &sctp_getsockopt_maxseg_10737
115696 +SyS_io_getevents_10756 SyS_io_getevents 3 10756 NULL
115697 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
115698 +rd_build_prot_space_10761 rd_build_prot_space 2-3 10761 NULL
115699 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
115700 +__qp_memcpy_to_queue_10779 __qp_memcpy_to_queue 2-4 10779 NULL
115701 +diva_set_trace_filter_10820 diva_set_trace_filter 0-1 10820 NULL
115702 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
115703 +ida_get_new_above_10853 ida_get_new_above 0 10853 NULL
115704 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
115705 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
115706 +wiidebug_drm_write_10879 wiidebug_drm_write 3 10879 NULL
115707 +get_scq_10897 get_scq 2 10897 NULL
115708 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
115709 +lprocfs_wr_atomic_10912 lprocfs_wr_atomic 3 10912 NULL
115710 +__copy_from_user_10918 __copy_from_user 0-3 10918 NULL
115711 +kobject_add_10919 kobject_add 0 10919 NULL
115712 +ar9003_dump_modal_eeprom_10959 ar9003_dump_modal_eeprom 3-2-0 10959 NULL
115713 +ci_port_test_write_10962 ci_port_test_write 3 10962 NULL
115714 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
115715 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
115716 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
115717 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
115718 +SetLineNumber_11023 SetLineNumber 0 11023 NULL
115719 +pci_msi_vec_count_11046 pci_msi_vec_count 0 11046 NULL
115720 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
115721 +qlcnic_83xx_calculate_msix_vector_11063 qlcnic_83xx_calculate_msix_vector 0 11063 NULL nohasharray
115722 +insert_inline_extent_backref_11063 insert_inline_extent_backref 8 11063 &qlcnic_83xx_calculate_msix_vector_11063
115723 +tcp_send_mss_11079 tcp_send_mss 0 11079 NULL
115724 +snd_pcm_delay_11081 snd_pcm_delay 0 11081 NULL
115725 +count_argc_11083 count_argc 0 11083 NULL
115726 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
115727 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
115728 +page_offset_11120 page_offset 0 11120 NULL
115729 +cea_db_payload_len_11124 cea_db_payload_len 0 11124 NULL nohasharray
115730 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 &cea_db_payload_len_11124
115731 +alloc_alien_cache_11127 alloc_alien_cache 2 11127 NULL
115732 +snd_gf1_pcm_playback_silence_11172 snd_gf1_pcm_playback_silence 3-4 11172 NULL
115733 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
115734 +comedi_alloc_spriv_11234 comedi_alloc_spriv 2 11234 NULL
115735 +of_irq_count_11253 of_irq_count 0 11253 NULL
115736 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
115737 +ath6kl_power_params_write_11274 ath6kl_power_params_write 3 11274 NULL
115738 +__proc_daemon_file_11305 __proc_daemon_file 5 11305 NULL
115739 +ext4_xattr_check_names_11314 ext4_xattr_check_names 0 11314 NULL
115740 +bcache_dev_sectors_dirty_add_11315 bcache_dev_sectors_dirty_add 3-4 11315 NULL
115741 +sk_filter_size_11316 sk_filter_size 0 11316 NULL nohasharray
115742 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 &sk_filter_size_11316
115743 +construct_key_11329 construct_key 3 11329 NULL nohasharray
115744 +__kfifo_out_peek_11329 __kfifo_out_peek 0-3 11329 &construct_key_11329
115745 +next_segment_11330 next_segment 0-2-1 11330 NULL
115746 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
115747 +ext4_get_inline_size_11349 ext4_get_inline_size 0 11349 NULL
115748 +sel_write_create_11353 sel_write_create 3 11353 NULL nohasharray
115749 +nl80211_send_mgmt_11353 nl80211_send_mgmt 7 11353 &sel_write_create_11353
115750 +of_get_available_child_count_11361 of_get_available_child_count 0 11361 NULL
115751 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
115752 +tcf_register_action_11381 tcf_register_action 2 11381 NULL nohasharray
115753 +nft_value_dump_11381 nft_value_dump 3 11381 &tcf_register_action_11381
115754 +isku_sysfs_read_keys_capslock_11392 isku_sysfs_read_keys_capslock 6 11392 NULL
115755 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
115756 +lprocfs_wr_evict_client_11402 lprocfs_wr_evict_client 3 11402 NULL
115757 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
115758 +str_to_user_11411 str_to_user 2 11411 NULL
115759 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
115760 +ath6kl_wmi_test_rx_11414 ath6kl_wmi_test_rx 3 11414 NULL
115761 +adis16480_show_firmware_revision_11417 adis16480_show_firmware_revision 3 11417 NULL
115762 +trace_options_read_11419 trace_options_read 3 11419 NULL
115763 +i40e_dbg_command_write_11421 i40e_dbg_command_write 3 11421 NULL
115764 +xd_read_multiple_pages_11422 xd_read_multiple_pages 5-4 11422 NULL
115765 +bttv_read_11432 bttv_read 3 11432 NULL
115766 +create_zero_mask_11453 create_zero_mask 0-1 11453 NULL
115767 +do_blockdev_direct_IO_11455 do_blockdev_direct_IO 0-6 11455 NULL
115768 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 NULL nohasharray
115769 +pci_set_power_state_11479 pci_set_power_state 0 11479 &sca3000_read_first_n_hw_rb_11479
115770 +xfs_file_buffered_aio_write_11492 xfs_file_buffered_aio_write 4 11492 NULL
115771 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
115772 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
115773 +ll_direct_IO_26_seg_11518 ll_direct_IO_26_seg 0 11518 NULL
115774 +twl_direction_in_11527 twl_direction_in 2 11527 NULL
115775 +skb_cow_data_11565 skb_cow_data 0 11565 NULL
115776 +lpfc_idiag_ctlacc_write_11576 lpfc_idiag_ctlacc_write 3 11576 NULL
115777 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
115778 +batadv_iv_ogm_orig_add_if_11586 batadv_iv_ogm_orig_add_if 2 11586 NULL
115779 +snd_pcm_action_11589 snd_pcm_action 0 11589 NULL
115780 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
115781 +batadv_iv_ogm_orig_del_if_11604 batadv_iv_ogm_orig_del_if 2 11604 NULL
115782 +SYSC_mq_timedsend_11607 SYSC_mq_timedsend 3 11607 NULL
115783 +C_SYSC_migrate_pages_11618 C_SYSC_migrate_pages 2 11618 NULL
115784 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
115785 +nla_total_size_11658 nla_total_size 1-0 11658 NULL
115786 +slab_ksize_11664 slab_ksize 0 11664 NULL
115787 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
115788 +compat_SyS_msgsnd_11675 compat_SyS_msgsnd 3 11675 NULL
115789 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
115790 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
115791 +split_11691 split 2 11691 NULL
115792 +compat_SyS_keyctl_11695 compat_SyS_keyctl 4 11695 NULL nohasharray
115793 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 &compat_SyS_keyctl_11695
115794 +blk_rq_cur_bytes_11723 blk_rq_cur_bytes 0 11723 NULL
115795 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
115796 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
115797 +ieee80211_get_num_supported_channels_11768 ieee80211_get_num_supported_channels 0 11768 NULL
115798 +tipc_sendmsg_11769 tipc_sendmsg 4 11769 NULL
115799 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
115800 +btrfs_key_blockptr_11786 btrfs_key_blockptr 0 11786 NULL
115801 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
115802 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
115803 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
115804 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
115805 +unix_stream_connect_11844 unix_stream_connect 3 11844 NULL
115806 +pci_enable_msix_range_11852 pci_enable_msix_range 0-4 11852 NULL
115807 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
115808 +ieee80211_rx_bss_info_11887 ieee80211_rx_bss_info 3 11887 NULL
115809 +mdc_rename_11899 mdc_rename 4-6 11899 NULL
115810 +xstateregs_get_11906 xstateregs_get 4 11906 NULL
115811 +ti_write_11916 ti_write 4 11916 NULL
115812 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
115813 +atomic_sub_return_11939 atomic_sub_return 0-1 11939 NULL
115814 +r1_sync_page_io_11963 r1_sync_page_io 3 11963 NULL
115815 +read_and_add_raw_conns_11987 read_and_add_raw_conns 0 11987 NULL
115816 +ftdi_elan_total_command_size_12045 ftdi_elan_total_command_size 0 12045 NULL
115817 +ieee80211_if_read_user_power_level_12050 ieee80211_if_read_user_power_level 3 12050 NULL
115818 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
115819 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
115820 +batadv_tt_global_size_mod_12085 batadv_tt_global_size_mod 3 12085 NULL
115821 +rtw_malloc2d_12102 rtw_malloc2d 1-2-3 12102 NULL
115822 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
115823 +set_powered_12129 set_powered 4 12129 NULL
115824 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
115825 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
115826 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
115827 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
115828 +get_idx_gc_leb_12148 get_idx_gc_leb 0 12148 NULL
115829 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
115830 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
115831 +fnic_reset_stats_write_12177 fnic_reset_stats_write 3 12177 NULL
115832 +LNetEQAlloc_12178 LNetEQAlloc 1 12178 NULL
115833 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
115834 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
115835 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
115836 +snd_pcm_kernel_ioctl_12219 snd_pcm_kernel_ioctl 0 12219 NULL
115837 +fuse_get_req_12221 fuse_get_req 2 12221 NULL nohasharray
115838 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 &fuse_get_req_12221
115839 +__alloc_bootmem_low_nopanic_12235 __alloc_bootmem_low_nopanic 1 12235 NULL
115840 +usnic_ib_qp_grp_dump_rows_12239 usnic_ib_qp_grp_dump_rows 3 12239 NULL
115841 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
115842 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
115843 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
115844 +SYSC_vm86_12279 SYSC_vm86 2 12279 NULL
115845 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
115846 +roundup_to_multiple_of_64_12288 roundup_to_multiple_of_64 0-1 12288 NULL nohasharray
115847 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 &roundup_to_multiple_of_64_12288
115848 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
115849 +usnic_transport_sock_to_str_12322 usnic_transport_sock_to_str 2-0 12322 NULL
115850 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
115851 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
115852 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
115853 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
115854 +write_file_dump_12391 write_file_dump 3 12391 NULL nohasharray
115855 +populate_dir_12391 populate_dir 0 12391 &write_file_dump_12391
115856 +hbucket_elem_add_12416 hbucket_elem_add 3 12416 NULL
115857 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
115858 +cfs_array_alloc_12441 cfs_array_alloc 2 12441 NULL
115859 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
115860 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
115861 +fnic_trace_ctrl_read_12497 fnic_trace_ctrl_read 3 12497 NULL
115862 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
115863 +write_inode_now_12565 write_inode_now 0 12565 NULL
115864 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
115865 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
115866 +_iwl_dbgfs_prph_reg_write_12597 _iwl_dbgfs_prph_reg_write 3 12597 NULL
115867 +tlbflush_write_file_12598 tlbflush_write_file 3 12598 NULL
115868 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
115869 +sdhci_pltfm_init_12627 sdhci_pltfm_init 3 12627 NULL
115870 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
115871 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
115872 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
115873 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
115874 +rtw_android_get_link_speed_12655 rtw_android_get_link_speed 0 12655 NULL
115875 +ocfs2_read_block_12659 ocfs2_read_block 0 12659 NULL
115876 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
115877 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
115878 +ext4_writepage_trans_blocks_12674 ext4_writepage_trans_blocks 0 12674 NULL
115879 +iwl_dbgfs_calib_disabled_write_12707 iwl_dbgfs_calib_disabled_write 3 12707 NULL
115880 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
115881 +ivtv_write_12721 ivtv_write 3 12721 NULL
115882 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
115883 +__mei_cl_async_send_12737 __mei_cl_async_send 3 12737 NULL
115884 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
115885 +listxattr_12769 listxattr 3 12769 NULL
115886 +sctp_ssnmap_init_12772 sctp_ssnmap_init 3-2 12772 NULL
115887 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
115888 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
115889 +SyS_add_key_12834 SyS_add_key 4 12834 NULL
115890 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
115891 +spidev_sync_12842 spidev_sync 0 12842 NULL
115892 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
115893 +ath9k_dump_4k_modal_eeprom_12883 ath9k_dump_4k_modal_eeprom 3-2 12883 NULL
115894 +get_leb_cnt_12892 get_leb_cnt 0-2 12892 NULL
115895 +get_virtual_node_size_12908 get_virtual_node_size 0 12908 NULL
115896 +rds_pages_in_vec_12922 rds_pages_in_vec 0 12922 NULL
115897 +do_inode_permission_12946 do_inode_permission 0 12946 NULL
115898 +bm_status_write_12964 bm_status_write 3 12964 NULL
115899 +raid56_parity_recover_12987 raid56_parity_recover 5 12987 NULL
115900 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
115901 +sk_peek_offset_12991 sk_peek_offset 0 12991 NULL
115902 +__btrfs_direct_write_13007 __btrfs_direct_write 4-0 13007 NULL
115903 +bset_prev_bytes_13020 bset_prev_bytes 0 13020 NULL
115904 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
115905 +generic_segment_checks_13041 generic_segment_checks 0 13041 NULL
115906 +ocfs2_write_begin_13045 ocfs2_write_begin 3-4 13045 NULL
115907 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL nohasharray
115908 +ptlrpc_lprocfs_threads_min_seq_write_13060 ptlrpc_lprocfs_threads_min_seq_write 3 13060 &__dn_setsockopt_13060
115909 +biovec_create_pool_13079 biovec_create_pool 2 13079 NULL
115910 +xattr_getsecurity_13090 xattr_getsecurity 0 13090 NULL
115911 +ttm_dma_pool_alloc_new_pages_13105 ttm_dma_pool_alloc_new_pages 3 13105 NULL
115912 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
115913 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
115914 +blk_update_request_13146 blk_update_request 3 13146 NULL
115915 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
115916 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
115917 +ucs2_strlen_13178 ucs2_strlen 0 13178 NULL
115918 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
115919 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
115920 +comedi_read_13199 comedi_read 3 13199 NULL
115921 +hash_ipport4_expire_13201 hash_ipport4_expire 4 13201 NULL
115922 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
115923 +svm_msrpm_offset_13220 svm_msrpm_offset 0-1 13220 NULL
115924 +fnic_trace_ctrl_write_13229 fnic_trace_ctrl_write 3 13229 NULL
115925 +_iwl_dbgfs_disable_power_off_write_13243 _iwl_dbgfs_disable_power_off_write 3 13243 NULL
115926 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
115927 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
115928 +bio_integrity_trim_13259 bio_integrity_trim 3-2 13259 NULL
115929 +simple_attr_write_13260 simple_attr_write 3 13260 NULL
115930 +pmcraid_notify_aen_13274 pmcraid_notify_aen 3 13274 NULL
115931 +il4965_stats_flag_13281 il4965_stats_flag 0-3 13281 NULL
115932 +lpfc_idiag_mbxacc_get_setup_13282 lpfc_idiag_mbxacc_get_setup 0 13282 NULL
115933 +sd_major_13294 sd_major 0-1 13294 NULL
115934 +read_file_phy_err_13318 read_file_phy_err 3 13318 NULL
115935 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
115936 +round_event_name_len_13348 round_event_name_len 0 13348 NULL
115937 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
115938 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
115939 +ext4_meta_trans_blocks_13380 ext4_meta_trans_blocks 0-3-2 13380 NULL
115940 +lov_mds_md_size_13388 lov_mds_md_size 0-1 13388 NULL nohasharray
115941 +dis_bypass_write_13388 dis_bypass_write 3 13388 &lov_mds_md_size_13388
115942 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
115943 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL
115944 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 7-8-9 13443 NULL
115945 +sb_init_dio_done_wq_13482 sb_init_dio_done_wq 0 13482 NULL
115946 +data_read_13494 data_read 3 13494 NULL
115947 +core_status_13515 core_status 4 13515 NULL
115948 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
115949 +bm_init_13529 bm_init 2 13529 NULL
115950 +request_any_context_irq_13530 request_any_context_irq 0 13530 NULL
115951 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
115952 +SyS_vm86_13557 SyS_vm86 2 13557 NULL
115953 +ieee80211_if_read_ap_power_level_13558 ieee80211_if_read_ap_power_level 3 13558 NULL
115954 +hash_net4_expire_13559 hash_net4_expire 4 13559 NULL
115955 +ubifs_get_idx_gc_leb_13566 ubifs_get_idx_gc_leb 0 13566 NULL
115956 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
115957 +cache_write_13589 cache_write 3 13589 NULL
115958 +Rd_Indx_13602 Rd_Indx 3-2 13602 NULL
115959 +wm8994_bulk_write_13615 wm8994_bulk_write 2-3 13615 NULL
115960 +pmcraid_get_minor_13619 pmcraid_get_minor 0 13619 NULL
115961 +packet_snd_13634 packet_snd 3 13634 NULL
115962 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
115963 +cache_downcall_13666 cache_downcall 3 13666 NULL
115964 +ext3_xattr_list_entries_13682 ext3_xattr_list_entries 0 13682 NULL
115965 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
115966 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
115967 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
115968 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
115969 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
115970 +random_read_13815 random_read 3 13815 NULL
115971 +mutex_lock_interruptible_nested_13817 mutex_lock_interruptible_nested 0 13817 NULL
115972 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
115973 +___mei_cl_send_13821 ___mei_cl_send 3 13821 NULL
115974 +enc_pools_insert_13849 enc_pools_insert 3 13849 NULL
115975 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
115976 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL
115977 +qp_memcpy_to_queue_13886 qp_memcpy_to_queue 5-2 13886 NULL
115978 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
115979 +cfg80211_inform_bss_width_13933 cfg80211_inform_bss_width 9 13933 NULL
115980 +ext3_xattr_block_get_13936 ext3_xattr_block_get 0 13936 NULL
115981 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL nohasharray
115982 +ocfs2_xa_value_truncate_13940 ocfs2_xa_value_truncate 2 13940 &ieee80211_if_read_dot11MeshForwarding_13940
115983 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
115984 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
115985 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL nohasharray
115986 +pagecache_write_end_13950 pagecache_write_end 0 13950 &lpfc_idiag_queacc_read_13950
115987 +osc_grant_shrink_interval_seq_write_13952 osc_grant_shrink_interval_seq_write 3 13952 NULL
115988 +snd_pcm_plug_slave_size_13967 snd_pcm_plug_slave_size 0-2 13967 NULL
115989 +qcam_read_13977 qcam_read 3 13977 NULL
115990 +dsp_read_13980 dsp_read 2 13980 NULL
115991 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
115992 +sddr09_write_data_14014 sddr09_write_data 3 14014 NULL
115993 +btrfs_get_blocks_direct_14016 btrfs_get_blocks_direct 2 14016 NULL
115994 +dmi_format_ids_14018 dmi_format_ids 2 14018 NULL
115995 +iscsi_create_flashnode_conn_14022 iscsi_create_flashnode_conn 4 14022 NULL
115996 +pci_add_ext_cap_save_buffer_14032 pci_add_ext_cap_save_buffer 3 14032 NULL
115997 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
115998 +read_def_modal_eeprom_14041 read_def_modal_eeprom 3 14041 NULL
115999 +ieee80211_if_fmt_aid_14055 ieee80211_if_fmt_aid 3 14055 NULL
116000 +ovs_nla_alloc_flow_actions_14056 ovs_nla_alloc_flow_actions 1 14056 NULL
116001 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
116002 +lov_stripeoffset_seq_write_14078 lov_stripeoffset_seq_write 3 14078 NULL
116003 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
116004 +ext4_journal_blocks_per_page_14127 ext4_journal_blocks_per_page 0 14127 NULL
116005 +isku_sysfs_read_light_14140 isku_sysfs_read_light 6 14140 NULL
116006 +em_canid_change_14150 em_canid_change 3 14150 NULL
116007 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
116008 +midi_alloc_ep_req_14159 midi_alloc_ep_req 2 14159 NULL
116009 +print_input_mask_14168 print_input_mask 3-0 14168 NULL
116010 +ocfs2_xattr_value_truncate_14183 ocfs2_xattr_value_truncate 3 14183 NULL
116011 +datafab_read_data_14186 datafab_read_data 4 14186 NULL
116012 +hfsplus_brec_find_14200 hfsplus_brec_find 0 14200 NULL
116013 +alloc_async_14208 alloc_async 1 14208 NULL
116014 +ath6kl_regread_write_14220 ath6kl_regread_write 3 14220 NULL
116015 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
116016 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4 14244 NULL
116017 +btrfs_token_file_extent_ram_bytes_14247 btrfs_token_file_extent_ram_bytes 0 14247 NULL
116018 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
116019 +rr_status_14293 rr_status 5 14293 NULL
116020 +read_default_ldt_14302 read_default_ldt 2 14302 NULL
116021 +oo_objects_14319 oo_objects 0 14319 NULL
116022 +ll_get_user_pages_14328 ll_get_user_pages 3-2-0 14328 NULL
116023 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
116024 +alloc_tx_struct_14349 alloc_tx_struct 1 14349 NULL
116025 +hash_ipportnet4_expire_14354 hash_ipportnet4_expire 4 14354 NULL
116026 +snd_pcm_lib_readv_14363 snd_pcm_lib_readv 0-3 14363 NULL
116027 +lowpan_read_14369 lowpan_read 3 14369 NULL
116028 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
116029 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
116030 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
116031 +get_kcore_size_14425 get_kcore_size 0 14425 NULL
116032 +_iwl_dbgfs_sram_write_14439 _iwl_dbgfs_sram_write 3 14439 NULL
116033 +block_size_14443 block_size 0 14443 NULL
116034 +lmv_user_md_size_14456 lmv_user_md_size 0-1 14456 NULL
116035 +snd_emu10k1_proc_spdif_status_14457 snd_emu10k1_proc_spdif_status 4-5 14457 NULL
116036 +ath10k_write_htt_stats_mask_14458 ath10k_write_htt_stats_mask 3 14458 NULL
116037 +lustre_msg_size_v2_14470 lustre_msg_size_v2 0 14470 NULL
116038 +dma_transfer_size_14473 dma_transfer_size 0 14473 NULL
116039 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
116040 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
116041 +split_state_14491 split_state 0 14491 NULL
116042 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
116043 +dataflash_read_user_otp_14536 dataflash_read_user_otp 3-2 14536 NULL nohasharray
116044 +ep0_write_14536 ep0_write 3 14536 &dataflash_read_user_otp_14536
116045 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
116046 +qp_host_alloc_queue_14566 qp_host_alloc_queue 1 14566 NULL
116047 +SyS_setdomainname_14569 SyS_setdomainname 2 14569 NULL
116048 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
116049 +ceph_osdc_alloc_request_14597 ceph_osdc_alloc_request 3 14597 NULL
116050 +dbJoin_14644 dbJoin 0 14644 NULL
116051 +profile_replace_14652 profile_replace 3 14652 NULL
116052 +usnic_vnic_dump_14662 usnic_vnic_dump 3 14662 NULL
116053 +min_bytes_needed_14675 min_bytes_needed 0 14675 NULL
116054 +nvme_trans_log_info_exceptions_14677 nvme_trans_log_info_exceptions 3 14677 NULL
116055 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
116056 +ieee80211_if_fmt_rc_rateidx_mask_2ghz_14683 ieee80211_if_fmt_rc_rateidx_mask_2ghz 3 14683 NULL
116057 +SyS_fsetxattr_14702 SyS_fsetxattr 4 14702 NULL
116058 +persistent_ram_ecc_string_14704 persistent_ram_ecc_string 0 14704 NULL
116059 +u_audio_playback_14709 u_audio_playback 3 14709 NULL
116060 +rtw_cbuf_alloc_14710 rtw_cbuf_alloc 1 14710 NULL
116061 +vfd_write_14717 vfd_write 3 14717 NULL
116062 +__blk_end_request_14729 __blk_end_request 3 14729 NULL
116063 +raid1_resize_14740 raid1_resize 2 14740 NULL
116064 +i915_error_state_buf_init_14742 i915_error_state_buf_init 2 14742 NULL
116065 +btrfs_inode_extref_name_len_14752 btrfs_inode_extref_name_len 0 14752 NULL
116066 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
116067 +regmap_range_read_file_14775 regmap_range_read_file 3 14775 NULL
116068 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
116069 +keys_proc_write_14792 keys_proc_write 3 14792 NULL
116070 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
116071 +__kfifo_in_14797 __kfifo_in 3-0 14797 NULL
116072 +hpet_readl_14801 hpet_readl 0 14801 NULL nohasharray
116073 +snd_als300_gcr_read_14801 snd_als300_gcr_read 0 14801 &hpet_readl_14801
116074 +do_tune_cpucache_14828 do_tune_cpucache 2 14828 NULL
116075 +mrp_attr_create_14853 mrp_attr_create 3 14853 NULL
116076 +lcd_write_14857 lcd_write 3 14857 NULL
116077 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
116078 +gmux_index_read8_14890 gmux_index_read8 0 14890 NULL
116079 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
116080 +SYSC_readv_14901 SYSC_readv 3 14901 NULL
116081 +__arch_hweight64_14923 __arch_hweight64 0 14923 NULL nohasharray
116082 +qp_memcpy_to_queue_iov_14923 qp_memcpy_to_queue_iov 5-2 14923 &__arch_hweight64_14923
116083 +ocfs2_expand_nonsparse_inode_14936 ocfs2_expand_nonsparse_inode 3-4 14936 NULL
116084 +queue_cnt_14951 queue_cnt 0 14951 NULL
116085 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
116086 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
116087 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
116088 +setkey_14987 setkey 3 14987 NULL nohasharray
116089 +gpio_twl4030_write_14987 gpio_twl4030_write 1 14987 &setkey_14987
116090 +blk_integrity_tuple_size_15027 blk_integrity_tuple_size 0 15027 NULL
116091 +read_file_node_aggr_15040 read_file_node_aggr 3 15040 NULL
116092 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
116093 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
116094 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
116095 +ntfs_copy_from_user_15072 ntfs_copy_from_user 0-5-3 15072 NULL
116096 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
116097 +smscore_load_firmware_family2_15086 smscore_load_firmware_family2 3 15086 NULL
116098 +btrfs_readpage_15094 btrfs_readpage 0 15094 NULL
116099 +compat_SyS_pwritev_15118 compat_SyS_pwritev 3 15118 NULL
116100 +hex_dump_to_buffer_15121 hex_dump_to_buffer 6 15121 NULL
116101 +start_port_15124 start_port 0 15124 NULL
116102 +ipwireless_ppp_mru_15153 ipwireless_ppp_mru 0 15153 NULL
116103 +self_check_not_bad_15175 self_check_not_bad 0 15175 NULL
116104 +SYSC_setdomainname_15180 SYSC_setdomainname 2 15180 NULL
116105 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
116106 +mtt_alloc_res_15211 mtt_alloc_res 5 15211 NULL
116107 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
116108 +iwl_dbgfs_sram_write_15239 iwl_dbgfs_sram_write 3 15239 NULL
116109 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
116110 +simple_strtol_15273 simple_strtol 0 15273 NULL
116111 +fw_realloc_buffer_15280 fw_realloc_buffer 2 15280 NULL
116112 +kovaplus_sysfs_read_15337 kovaplus_sysfs_read 6 15337 NULL
116113 +ioread16_15342 ioread16 0 15342 NULL
116114 +ept_prefetch_gpte_15348 ept_prefetch_gpte 4 15348 NULL
116115 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
116116 +ext4_direct_IO_15369 ext4_direct_IO 4 15369 NULL
116117 +graph_depth_read_15371 graph_depth_read 3 15371 NULL
116118 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
116119 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
116120 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
116121 +get_modalias_15406 get_modalias 2 15406 NULL
116122 +blockdev_direct_IO_15408 blockdev_direct_IO 5 15408 NULL
116123 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4-0 15423 NULL
116124 +rtw_cfg80211_rx_action_p2p_15432 rtw_cfg80211_rx_action_p2p 3 15432 NULL
116125 +tcp_mtu_to_mss_15438 tcp_mtu_to_mss 2-0 15438 NULL
116126 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
116127 +insert_old_idx_znode_15500 insert_old_idx_znode 0 15500 NULL
116128 +zd_chip_is_zd1211b_15518 zd_chip_is_zd1211b 0 15518 NULL
116129 +ifx_spi_write_15531 ifx_spi_write 3 15531 NULL
116130 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
116131 +xfrm_state_mtu_15548 xfrm_state_mtu 0-2 15548 NULL
116132 +snd_pcm_channel_info_15572 snd_pcm_channel_info 0 15572 NULL
116133 +persistent_status_15574 persistent_status 4 15574 NULL
116134 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
116135 +vme_user_write_15587 vme_user_write 3 15587 NULL
116136 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
116137 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
116138 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
116139 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &tomoyo_scan_bprm_15642 nohasharray
116140 +sk_memory_allocated_add_15642 sk_memory_allocated_add 2 15642 &pipeline_hs_tx_stat_fifo_int_read_15642
116141 +joydev_handle_JSIOCSBTNMAP_15643 joydev_handle_JSIOCSBTNMAP 3 15643 NULL
116142 +fs_path_add_15648 fs_path_add 3 15648 NULL
116143 +__do_readpage_15652 __do_readpage 0 15652 NULL
116144 +xsd_read_15653 xsd_read 3 15653 NULL
116145 +unix_bind_15668 unix_bind 3 15668 NULL
116146 +dm_read_15674 dm_read 3 15674 NULL nohasharray
116147 +SyS_connect_15674 SyS_connect 3 15674 &dm_read_15674
116148 +uinput_str_to_user_15695 uinput_str_to_user 3 15695 NULL
116149 +__sk_migrate_realloc_15709 __sk_migrate_realloc 3 15709 NULL
116150 +tracing_snapshot_write_15719 tracing_snapshot_write 3 15719 NULL
116151 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
116152 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
116153 +gnttab_expand_15817 gnttab_expand 1 15817 NULL nohasharray
116154 +nameseq_list_15817 nameseq_list 3-0 15817 &gnttab_expand_15817
116155 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
116156 +table_size_15851 table_size 0-1-2 15851 NULL
116157 +write_file_tx99_15856 write_file_tx99 3 15856 NULL
116158 +media_entity_init_15870 media_entity_init 2-4 15870 NULL nohasharray
116159 +ubi_io_write_15870 ubi_io_write 0 15870 &media_entity_init_15870
116160 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
116161 +parse_audio_stream_data_15937 parse_audio_stream_data 3 15937 NULL
116162 +power_read_15939 power_read 3 15939 NULL
116163 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
116164 +snd_pcm_lib_read_transfer_15952 snd_pcm_lib_read_transfer 5-2-4 15952 NULL
116165 +memblock_virt_alloc_try_nid_15954 memblock_virt_alloc_try_nid 1 15954 NULL
116166 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
116167 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
116168 +read_file_spectral_period_16057 read_file_spectral_period 3 16057 NULL
116169 +si5351_msynth_params_address_16062 si5351_msynth_params_address 0-1 16062 NULL
116170 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
116171 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 NULL nohasharray
116172 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 &isr_hw_pm_mode_changes_read_16110
116173 +snd_dma_pointer_16126 snd_dma_pointer 0-2 16126 NULL
116174 +fsm_init_16134 fsm_init 2 16134 NULL
116175 +ext4_xattr_block_get_16148 ext4_xattr_block_get 0 16148 NULL
116176 +optimal_reclaimed_pages_16172 optimal_reclaimed_pages 0 16172 NULL
116177 +mapping_level_16188 mapping_level 2-0 16188 NULL
116178 +i40e_allocate_virt_mem_d_16191 i40e_allocate_virt_mem_d 3 16191 NULL
116179 +ath10k_htt_rx_ring_size_16201 ath10k_htt_rx_ring_size 0 16201 NULL
116180 +cipso_v4_map_cat_rng_hton_16203 cipso_v4_map_cat_rng_hton 0 16203 NULL
116181 +SyS_pselect6_16210 SyS_pselect6 1 16210 NULL
116182 +create_table_16213 create_table 2 16213 NULL
116183 +ath9k_hw_ar9287_dump_eeprom_16224 ath9k_hw_ar9287_dump_eeprom 5-4 16224 NULL
116184 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
116185 +BcmGetSectionValStartOffset_16235 BcmGetSectionValStartOffset 0 16235 NULL
116186 +lov_prep_brw_set_16246 lov_prep_brw_set 3 16246 NULL
116187 +i40e_dbg_dump_read_16247 i40e_dbg_dump_read 3 16247 NULL
116188 +il_dbgfs_disable_ht40_write_16249 il_dbgfs_disable_ht40_write 3 16249 NULL
116189 +SyS_fgetxattr_16254 SyS_fgetxattr 4 16254 NULL
116190 +reiserfs_acl_count_16265 reiserfs_acl_count 0-1 16265 NULL
116191 +ocfs2_xattr_bucket_value_truncate_16279 ocfs2_xattr_bucket_value_truncate 4 16279 NULL
116192 +nand_bch_init_16280 nand_bch_init 3-2 16280 NULL nohasharray
116193 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 &nand_bch_init_16280
116194 +account_16283 account 0-4-2 16283 NULL nohasharray
116195 +mirror_status_16283 mirror_status 5 16283 &account_16283
116196 +jumpshot_read_data_16287 jumpshot_read_data 4 16287 NULL
116197 +mo_xattr_get_16288 mo_xattr_get 0 16288 NULL
116198 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
116199 +rbd_segment_offset_16293 rbd_segment_offset 0-2 16293 NULL
116200 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
116201 +kvm_handle_hva_range_16312 kvm_handle_hva_range 3-2 16312 NULL
116202 +sysfs_create_groups_16360 sysfs_create_groups 0 16360 NULL
116203 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
116204 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
116205 +i8042_create_kbd_port_16379 i8042_create_kbd_port 0 16379 NULL
116206 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
116207 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
116208 +__bio_add_page_16435 __bio_add_page 0-4 16435 NULL
116209 +cmdline_store_16442 cmdline_store 4 16442 NULL
116210 +btrfs_truncate_inode_items_16452 btrfs_truncate_inode_items 4 16452 NULL
116211 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
116212 +req_capsule_get_size_16467 req_capsule_get_size 0 16467 NULL
116213 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
116214 +KEY_OFFSET_16504 KEY_OFFSET 0 16504 NULL
116215 +snd_interval_max_16529 snd_interval_max 0 16529 NULL
116216 +raid10_resize_16537 raid10_resize 2 16537 NULL
116217 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
116218 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
116219 +lustre_msg_hdr_size_v2_16589 lustre_msg_hdr_size_v2 0 16589 NULL
116220 +gmux_index_read32_16604 gmux_index_read32 0 16604 NULL
116221 +compat_SyS_migrate_pages_16618 compat_SyS_migrate_pages 2 16618 NULL
116222 +rtw_set_wpa_ie_16633 rtw_set_wpa_ie 3 16633 NULL
116223 +btrfs_get_token_32_16651 btrfs_get_token_32 0 16651 NULL
116224 +__wa_populate_dto_urb_16699 __wa_populate_dto_urb 3-4 16699 NULL
116225 +__proc_lnet_buffers_16717 __proc_lnet_buffers 5 16717 NULL
116226 +__copy_to_user_swizzled_16748 __copy_to_user_swizzled 3-4 16748 NULL
116227 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
116228 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
116229 +i2o_parm_issue_16790 i2o_parm_issue 0 16790 NULL
116230 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
116231 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
116232 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
116233 +hfsplus_min_io_size_16859 hfsplus_min_io_size 0 16859 NULL
116234 +alloc_idx_lebs_16872 alloc_idx_lebs 2 16872 NULL
116235 +carl9170_debugfs_ampdu_state_read_16873 carl9170_debugfs_ampdu_state_read 3 16873 NULL
116236 +st_write_16874 st_write 3 16874 NULL
116237 +__kfifo_peek_n_16877 __kfifo_peek_n 0 16877 NULL
116238 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 NULL nohasharray
116239 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 &psb_unlocked_ioctl_16926
116240 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
116241 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
116242 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
116243 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
116244 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
116245 +C_SYSC_keyctl_17041 C_SYSC_keyctl 4 17041 NULL
116246 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
116247 +__arch_hweight32_17060 __arch_hweight32 0 17060 NULL
116248 +sddr55_read_data_17072 sddr55_read_data 4 17072 NULL
116249 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
116250 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
116251 +carl9170_debugfs_mem_usage_read_17084 carl9170_debugfs_mem_usage_read 3 17084 NULL
116252 +entry_length_17093 entry_length 0 17093 NULL
116253 +write_mem_17114 write_mem 3 17114 NULL
116254 +pvr2_hdw_state_report_17121 pvr2_hdw_state_report 3 17121 NULL
116255 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
116256 +jumpshot_write_data_17151 jumpshot_write_data 4 17151 NULL
116257 +sep_read_17161 sep_read 3 17161 NULL
116258 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
116259 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
116260 +UniStrnlen_17169 UniStrnlen 0 17169 NULL
116261 +access_remote_vm_17189 access_remote_vm 0 17189 NULL nohasharray
116262 +iwl_dbgfs_txfifo_flush_write_17189 iwl_dbgfs_txfifo_flush_write 3 17189 &access_remote_vm_17189
116263 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 NULL nohasharray
116264 +driver_state_read_17194 driver_state_read 3 17194 &iscsit_find_cmd_from_itt_or_dump_17194
116265 +sync_request_17208 sync_request 2 17208 NULL
116266 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
116267 +lprocfs_read_frac_helper_17261 lprocfs_read_frac_helper 0 17261 NULL
116268 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
116269 +alloc_ep_17269 alloc_ep 1 17269 NULL
116270 +pg_read_17276 pg_read 3 17276 NULL
116271 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
116272 +hmac_sha256_17278 hmac_sha256 2 17278 NULL
116273 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
116274 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
116275 +ieee80211_if_fmt_dot11MeshForwarding_17301 ieee80211_if_fmt_dot11MeshForwarding 3 17301 NULL
116276 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
116277 +gnttab_map_frames_v2_17314 gnttab_map_frames_v2 2 17314 NULL
116278 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
116279 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
116280 +mdc_import_seq_write_17409 mdc_import_seq_write 3 17409 NULL
116281 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
116282 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
116283 +libcfs_ipif_enumerate_17445 libcfs_ipif_enumerate 0 17445 NULL
116284 +nla_get_u32_17455 nla_get_u32 0 17455 NULL
116285 +__ref_totlen_17461 __ref_totlen 0 17461 NULL
116286 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
116287 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
116288 +lbs_highrssi_write_17515 lbs_highrssi_write 3 17515 NULL
116289 +qp_free_res_17541 qp_free_res 5 17541 NULL
116290 +__copy_to_user_17551 __copy_to_user 0-3 17551 NULL
116291 +copy_from_user_17559 copy_from_user 3-0 17559 NULL
116292 +snd_pcm_action_lock_irq_17569 snd_pcm_action_lock_irq 0 17569 NULL
116293 +hash_netport4_expire_17573 hash_netport4_expire 4 17573 NULL
116294 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
116295 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
116296 +osst_execute_17607 osst_execute 7-6 17607 NULL
116297 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
116298 +dma_map_page_17628 dma_map_page 0 17628 NULL
116299 +twl4030_set_gpio_direction_17645 twl4030_set_gpio_direction 1 17645 NULL
116300 +SYSC_migrate_pages_17657 SYSC_migrate_pages 2 17657 NULL
116301 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL nohasharray
116302 +ubi_io_read_data_17662 ubi_io_read_data 0 17662 &packet_setsockopt_17662
116303 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
116304 +filemap_fdatawait_17688 filemap_fdatawait 0 17688 NULL
116305 +venus_rename_17707 venus_rename 4-5 17707 NULL
116306 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
116307 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
116308 +ubifs_leb_change_17789 ubifs_leb_change 0 17789 NULL
116309 +shrink_slab_node_17794 shrink_slab_node 3 17794 NULL
116310 +lpuart_copy_rx_to_tty_17801 lpuart_copy_rx_to_tty 3 17801 NULL
116311 +gnet_stats_copy_app_17821 gnet_stats_copy_app 3 17821 NULL
116312 +cipso_v4_gentag_rbm_17836 cipso_v4_gentag_rbm 0 17836 NULL
116313 +em28xx_audio_ep_packet_size_17844 em28xx_audio_ep_packet_size 0 17844 NULL
116314 +dm_stats_message_17863 dm_stats_message 5 17863 NULL
116315 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
116316 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
116317 +virtio_cread32_17873 virtio_cread32 0 17873 NULL
116318 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
116319 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL nohasharray
116320 +i40e_align_l2obj_base_17878 i40e_align_l2obj_base 0-1 17878 &orinoco_set_key_17878
116321 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
116322 +ieee80211_if_fmt_dot11MeshMaxPeerLinks_17883 ieee80211_if_fmt_dot11MeshMaxPeerLinks 3 17883 NULL
116323 +ieee80211_if_fmt_dot11MeshHWMPRootMode_17890 ieee80211_if_fmt_dot11MeshHWMPRootMode 3 17890 NULL
116324 +dev_pm_opp_get_opp_count_17911 dev_pm_opp_get_opp_count 0 17911 NULL
116325 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
116326 +tipc_port_iovec_rcv_17921 tipc_port_iovec_rcv 3 17921 NULL
116327 +scsi_bufflen_17933 scsi_bufflen 0 17933 NULL
116328 +__mutex_lock_check_stamp_17947 __mutex_lock_check_stamp 0 17947 NULL
116329 +beacon_interval_write_17952 beacon_interval_write 3 17952 NULL
116330 +calc_nr_buckets_17976 calc_nr_buckets 0 17976 NULL
116331 +ext4_ext_calc_credits_for_single_extent_17983 ext4_ext_calc_credits_for_single_extent 0-2 17983 NULL
116332 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
116333 +gnttab_max_grant_frames_17993 gnttab_max_grant_frames 0 17993 NULL
116334 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
116335 +cpufreq_add_dev_symlink_18028 cpufreq_add_dev_symlink 0 18028 NULL
116336 +o2hb_highest_node_18034 o2hb_highest_node 0 18034 NULL
116337 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
116338 +__btrfs_drop_extents_18049 __btrfs_drop_extents 5 18049 NULL
116339 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
116340 +lua_sysfs_read_18062 lua_sysfs_read 6 18062 NULL
116341 +fpregs_get_18066 fpregs_get 4 18066 NULL
116342 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
116343 +SYSC_pselect6_18076 SYSC_pselect6 1 18076 NULL
116344 +SYSC_semtimedop_18091 SYSC_semtimedop 3 18091 NULL
116345 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
116346 +hfs_direct_IO_18104 hfs_direct_IO 4 18104 NULL
116347 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
116348 +svc_getnl_18120 svc_getnl 0 18120 NULL
116349 +paging32_gpte_to_gfn_lvl_18131 paging32_gpte_to_gfn_lvl 0-2-1 18131 NULL
116350 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
116351 +is_idx_node_in_use_18165 is_idx_node_in_use 0 18165 NULL
116352 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
116353 +snd_pcm_hw_refine_user_18204 snd_pcm_hw_refine_user 0 18204 NULL
116354 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
116355 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
116356 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
116357 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
116358 +alloc_trace_uprobe_18247 alloc_trace_uprobe 3 18247 NULL
116359 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
116360 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
116361 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
116362 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
116363 +find_dirty_idx_leb_18280 find_dirty_idx_leb 0 18280 NULL
116364 +bio_phys_segments_18281 bio_phys_segments 0 18281 NULL nohasharray
116365 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 &bio_phys_segments_18281
116366 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
116367 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
116368 +um_idi_write_18293 um_idi_write 3 18293 NULL
116369 +nouveau_disp_create__18305 nouveau_disp_create_ 4-7 18305 NULL
116370 +vga_r_18310 vga_r 0 18310 NULL
116371 +class_add_profile_18315 class_add_profile 1-3-5 18315 NULL
116372 +csio_mem_read_18319 csio_mem_read 3 18319 NULL
116373 +alloc_and_copy_string_18321 alloc_and_copy_string 2 18321 NULL
116374 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
116375 +bio_integrity_advance_18324 bio_integrity_advance 2 18324 NULL
116376 +copy_page_to_iter_18345 copy_page_to_iter 3-0 18345 NULL
116377 +lcd_proc_write_18351 lcd_proc_write 3 18351 NULL
116378 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
116379 +SyS_process_vm_readv_18366 SyS_process_vm_readv 3-5 18366 NULL
116380 +ep_io_18367 ep_io 0 18367 NULL
116381 +qib_user_sdma_num_pages_18371 qib_user_sdma_num_pages 0 18371 NULL
116382 +__ceph_getxattr_18386 __ceph_getxattr 0 18386 NULL
116383 +ci_role_write_18388 ci_role_write 3 18388 NULL
116384 +adis16136_show_serial_18402 adis16136_show_serial 3 18402 NULL
116385 +rtl8169_rx_fill_18416 rtl8169_rx_fill 0 18416 NULL
116386 +memblock_virt_alloc_node_nopanic_18431 memblock_virt_alloc_node_nopanic 1 18431 NULL
116387 +iscsi_create_flashnode_sess_18433 iscsi_create_flashnode_sess 4 18433 NULL
116388 +snd_hda_get_connections_18437 snd_hda_get_connections 0 18437 NULL
116389 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
116390 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
116391 +pci_vpd_lrdt_size_18479 pci_vpd_lrdt_size 0 18479 NULL nohasharray
116392 +mite_bytes_in_transit_18479 mite_bytes_in_transit 0 18479 &pci_vpd_lrdt_size_18479
116393 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
116394 +btrfs_fiemap_18501 btrfs_fiemap 3 18501 NULL
116395 +__copy_user_zeroing_intel_18510 __copy_user_zeroing_intel 0-3 18510 NULL
116396 +snd_vx_inb_18514 snd_vx_inb 0 18514 NULL
116397 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
116398 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 9 18530 NULL
116399 +tipc_send2port_18531 tipc_send2port 4 18531 NULL
116400 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
116401 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
116402 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
116403 +debug_output_18575 debug_output 3 18575 NULL
116404 +filemap_fdatawait_range_18600 filemap_fdatawait_range 0 18600 NULL nohasharray
116405 +slabinfo_write_18600 slabinfo_write 3 18600 &filemap_fdatawait_range_18600
116406 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
116407 +from_buffer_18625 from_buffer 3 18625 NULL
116408 +snd_pcm_oss_write3_18657 snd_pcm_oss_write3 0-3 18657 NULL
116409 +ieee80211_if_fmt_rssi_threshold_18664 ieee80211_if_fmt_rssi_threshold 3 18664 NULL
116410 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 NULL
116411 +fnic_stats_debugfs_read_18688 fnic_stats_debugfs_read 3 18688 NULL
116412 +echo_client_prep_commit_18693 echo_client_prep_commit 8 18693 NULL
116413 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
116414 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
116415 +blk_rq_bytes_18715 blk_rq_bytes 0 18715 NULL
116416 +nfs4_init_callback_netid_18717 nfs4_init_callback_netid 3 18717 NULL
116417 +snd_als4k_gcr_read_addr_18741 snd_als4k_gcr_read_addr 0 18741 NULL
116418 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
116419 +__erst_read_to_erange_from_nvram_18748 __erst_read_to_erange_from_nvram 0 18748 NULL
116420 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
116421 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
116422 +SyS_lsetxattr_18776 SyS_lsetxattr 4 18776 NULL
116423 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
116424 +dm_stats_print_18815 dm_stats_print 7 18815 NULL
116425 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
116426 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
116427 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
116428 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
116429 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
116430 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
116431 +ieee80211_rx_mgmt_disassoc_18927 ieee80211_rx_mgmt_disassoc 3 18927 NULL
116432 +snapshot_write_next_18937 snapshot_write_next 0 18937 NULL
116433 +__nla_reserve_18974 __nla_reserve 3 18974 NULL
116434 +__blockdev_direct_IO_18977 __blockdev_direct_IO 0-6 18977 NULL
116435 +find_dirtiest_idx_leb_19001 find_dirtiest_idx_leb 0 19001 NULL
116436 +layout_in_gaps_19006 layout_in_gaps 2 19006 NULL
116437 +huge_page_size_19008 huge_page_size 0 19008 NULL
116438 +hash_netport6_expire_19013 hash_netport6_expire 4 19013 NULL
116439 +sysfs_create_dir_ns_19033 sysfs_create_dir_ns 0 19033 NULL
116440 +revalidate_19043 revalidate 2 19043 NULL
116441 +afs_vnode_store_data_19048 afs_vnode_store_data 2-3-4-5 19048 NULL
116442 +osc_pinger_recov_seq_write_19056 osc_pinger_recov_seq_write 3 19056 NULL nohasharray
116443 +do_vm86_irq_handling_19056 do_vm86_irq_handling 2 19056 &osc_pinger_recov_seq_write_19056
116444 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
116445 +ceph_create_snap_context_19082 ceph_create_snap_context 1 19082 NULL
116446 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
116447 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
116448 +skb_gro_offset_19123 skb_gro_offset 0 19123 NULL
116449 +snd_als4k_iobase_readl_19136 snd_als4k_iobase_readl 0 19136 NULL
116450 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
116451 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
116452 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
116453 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
116454 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 3-0 19214 NULL
116455 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
116456 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
116457 +snd_mask_max_19224 snd_mask_max 0 19224 NULL
116458 +snd_pcm_capture_rewind_19229 snd_pcm_capture_rewind 0-2 19229 NULL
116459 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
116460 +ucma_query_19260 ucma_query 4 19260 NULL
116461 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
116462 +batadv_tt_save_orig_buffer_19288 batadv_tt_save_orig_buffer 4 19288 NULL nohasharray
116463 +cfg80211_rx_unprot_mlme_mgmt_19288 cfg80211_rx_unprot_mlme_mgmt 3 19288 &batadv_tt_save_orig_buffer_19288
116464 +qc_capture_19298 qc_capture 3 19298 NULL
116465 +ocfs2_prepare_inode_for_refcount_19303 ocfs2_prepare_inode_for_refcount 3-4 19303 NULL
116466 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
116467 +debug_read_19322 debug_read 3 19322 NULL
116468 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 NULL nohasharray
116469 +lbs_host_sleep_write_19332 lbs_host_sleep_write 3 19332 &cfg80211_inform_bss_19332
116470 +closure_sub_19359 closure_sub 2 19359 NULL
116471 +firmware_data_write_19360 firmware_data_write 6-5 19360 NULL
116472 +read_zero_19366 read_zero 3 19366 NULL
116473 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
116474 +sync_fill_pt_info_19397 sync_fill_pt_info 0 19397 NULL
116475 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
116476 +hid_hw_raw_request_19408 hid_hw_raw_request 0 19408 NULL
116477 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
116478 +SyS_sched_getaffinity_19444 SyS_sched_getaffinity 2 19444 NULL
116479 +xfrm_alg_auth_len_19454 xfrm_alg_auth_len 0 19454 NULL
116480 +gnet_stats_copy_19458 gnet_stats_copy 4 19458 NULL
116481 +gp2ap020a00f_get_thresh_reg_19468 gp2ap020a00f_get_thresh_reg 0 19468 NULL
116482 +sky2_read16_19475 sky2_read16 0 19475 NULL
116483 +kstrtoll_from_user_19500 kstrtoll_from_user 2 19500 NULL
116484 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
116485 +batadv_tvlv_container_register_19520 batadv_tvlv_container_register 5 19520 NULL
116486 +cfc_write_array_to_buffer_19529 cfc_write_array_to_buffer 3 19529 NULL
116487 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
116488 +gfn_to_index_19558 gfn_to_index 0-1-3-2 19558 NULL
116489 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
116490 +nfsd_read_19568 nfsd_read 5 19568 NULL
116491 +ieee80211_key_alloc_19575 ieee80211_key_alloc 3 19575 NULL
116492 +mnt_want_write_file_19579 mnt_want_write_file 0 19579 NULL
116493 +bm_status_read_19583 bm_status_read 3 19583 NULL
116494 +load_xattr_datum_19594 load_xattr_datum 0 19594 NULL
116495 +__mei_cl_recv_19636 __mei_cl_recv 3 19636 NULL
116496 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
116497 +memblock_virt_alloc_low_nopanic_19714 memblock_virt_alloc_low_nopanic 1 19714 NULL
116498 +ocfs2_control_get_this_node_19721 ocfs2_control_get_this_node 0 19721 NULL
116499 +read_reg_19723 read_reg 0 19723 NULL
116500 +wm8350_block_write_19727 wm8350_block_write 2-3 19727 NULL
116501 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
116502 +snd_es1968_get_dma_ptr_19747 snd_es1968_get_dma_ptr 0 19747 NULL
116503 +p9_client_read_19750 p9_client_read 5-0 19750 NULL
116504 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
116505 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
116506 +jffs2_acl_from_medium_19762 jffs2_acl_from_medium 2 19762 NULL
116507 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
116508 +vfs_getxattr_19832 vfs_getxattr 0 19832 NULL
116509 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
116510 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
116511 +__nla_put_19857 __nla_put 3 19857 NULL
116512 +mrp_request_join_19882 mrp_request_join 4 19882 NULL
116513 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
116514 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
116515 +mangle_name_19923 mangle_name 0 19923 NULL
116516 +cgroup_task_count_19930 cgroup_task_count 0 19930 NULL
116517 +guest_read_tsc_19931 guest_read_tsc 0 19931 NULL
116518 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
116519 +cfg80211_rx_assoc_resp_19944 cfg80211_rx_assoc_resp 4 19944 NULL
116520 +ll_xattr_cache_list_19954 ll_xattr_cache_list 0 19954 NULL
116521 +get_jack_mode_name_19976 get_jack_mode_name 4 19976 NULL
116522 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
116523 +rtw_set_wps_probe_resp_19989 rtw_set_wps_probe_resp 3 19989 NULL nohasharray
116524 +i40e_reserve_msix_vectors_19989 i40e_reserve_msix_vectors 2 19989 &rtw_set_wps_probe_resp_19989
116525 +diva_um_idi_read_20003 diva_um_idi_read 0 20003 NULL
116526 +lov_stripe_md_size_20009 lov_stripe_md_size 0-1 20009 NULL nohasharray
116527 +event_trigger_write_20009 event_trigger_write 3 20009 &lov_stripe_md_size_20009
116528 +tree_mod_log_eb_move_20011 tree_mod_log_eb_move 5 20011 NULL
116529 +SYSC_fgetxattr_20027 SYSC_fgetxattr 4 20027 NULL
116530 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
116531 +iwl_mvm_power_mac_dbgfs_read_20067 iwl_mvm_power_mac_dbgfs_read 0-4 20067 NULL
116532 +target_message_20072 target_message 2 20072 NULL
116533 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
116534 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
116535 +aat2870_reg_write_file_20086 aat2870_reg_write_file 3 20086 NULL
116536 +team_options_register_20091 team_options_register 3 20091 NULL
116537 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
116538 +root_nfs_copy_20111 root_nfs_copy 3 20111 NULL
116539 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
116540 +self_check_vid_hdr_20131 self_check_vid_hdr 0 20131 NULL
116541 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
116542 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
116543 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
116544 +crystalhd_map_dio_20181 crystalhd_map_dio 3 20181 NULL
116545 +pvr2_ctrl_value_to_sym_20229 pvr2_ctrl_value_to_sym 5 20229 NULL
116546 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
116547 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
116548 +btrfs_header_nritems_20296 btrfs_header_nritems 0 20296 NULL
116549 +r10_sync_page_io_20307 r10_sync_page_io 3 20307 NULL
116550 +dm_get_reserved_bio_based_ios_20315 dm_get_reserved_bio_based_ios 0 20315 NULL
116551 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
116552 +vx_send_msg_nolock_20322 vx_send_msg_nolock 0 20322 NULL
116553 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
116554 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
116555 +handle_arr_calc_size_20355 handle_arr_calc_size 0-1 20355 NULL
116556 +snd_pcm_stop_20376 snd_pcm_stop 0 20376 NULL
116557 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
116558 +snd_nm256_readl_20394 snd_nm256_readl 0 20394 NULL
116559 +SyS_get_mempolicy_20399 SyS_get_mempolicy 3 20399 NULL nohasharray
116560 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 &SyS_get_mempolicy_20399
116561 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
116562 +read_buf_20469 read_buf 2 20469 NULL
116563 +bio_trim_20472 bio_trim 2 20472 NULL
116564 +btrfs_get_32_20476 btrfs_get_32 0 20476 NULL
116565 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
116566 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
116567 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
116568 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
116569 +venus_create_20555 venus_create 4 20555 NULL
116570 +btrfs_super_log_root_20565 btrfs_super_log_root 0 20565 NULL
116571 +crypto_ahash_reqsize_20569 crypto_ahash_reqsize 0 20569 NULL
116572 +kvm_test_age_hva_20593 kvm_test_age_hva 2 20593 NULL
116573 +set_secure_conn_20596 set_secure_conn 4 20596 NULL
116574 +sync_timeline_create_20601 sync_timeline_create 2 20601 NULL
116575 +lirc_write_20604 lirc_write 3 20604 NULL
116576 +qib_qsfp_write_20614 qib_qsfp_write 0-2-4 20614 NULL
116577 +snd_pcm_oss_prepare_20641 snd_pcm_oss_prepare 0 20641 NULL
116578 +get_extent_skip_holes_20642 get_extent_skip_holes 2 20642 NULL
116579 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3-4 20646 NULL
116580 +cpulist_scnprintf_20648 cpulist_scnprintf 2-0 20648 NULL
116581 +oz_add_farewell_20652 oz_add_farewell 5 20652 NULL
116582 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
116583 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL nohasharray
116584 +btrfs_qgroup_reserve_20676 btrfs_qgroup_reserve 0 20676 &snd_hdsp_playback_copy_20676
116585 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 0-4 20682 NULL
116586 +cpumask_size_20683 cpumask_size 0 20683 NULL
116587 +btrfs_node_blockptr_20685 btrfs_node_blockptr 0 20685 NULL
116588 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
116589 +__maestro_read_20700 __maestro_read 0 20700 NULL
116590 +cipso_v4_gentag_rng_20703 cipso_v4_gentag_rng 0 20703 NULL
116591 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
116592 +ocfs2_read_xattr_bucket_20722 ocfs2_read_xattr_bucket 0 20722 NULL
116593 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
116594 +fb_prepare_logo_20743 fb_prepare_logo 0 20743 NULL
116595 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
116596 +ocfs2_align_bytes_to_clusters_20754 ocfs2_align_bytes_to_clusters 2 20754 NULL
116597 +brcmf_p2p_escan_20763 brcmf_p2p_escan 2 20763 NULL nohasharray
116598 +mnt_clone_write_20763 mnt_clone_write 0 20763 &brcmf_p2p_escan_20763
116599 +ubi_io_read_20767 ubi_io_read 0 20767 NULL
116600 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
116601 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
116602 +lowpan_write_20800 lowpan_write 3 20800 NULL
116603 +strndup_user_20819 strndup_user 2 20819 NULL
116604 +tipc_msg_build_20825 tipc_msg_build 3 20825 NULL
116605 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
116606 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
116607 +p9_tag_alloc_20845 p9_tag_alloc 3 20845 NULL
116608 +nvme_trans_supported_vpd_pages_20847 nvme_trans_supported_vpd_pages 4 20847 NULL
116609 +get_name_20855 get_name 4 20855 NULL
116610 +iwl_dbgfs_pm_params_read_20866 iwl_dbgfs_pm_params_read 3 20866 NULL
116611 +snd_pcm_capture_avail_20867 snd_pcm_capture_avail 0 20867 NULL
116612 +srq_free_res_20868 srq_free_res 5 20868 NULL
116613 +cfs_cpt_table_create_20884 cfs_cpt_table_create 1 20884 NULL
116614 +rb_simple_write_20890 rb_simple_write 3 20890 NULL
116615 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
116616 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
116617 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
116618 +lbs_rdbbp_write_20918 lbs_rdbbp_write 3 20918 NULL
116619 +htable_bits_20933 htable_bits 0 20933 NULL
116620 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
116621 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
116622 +rsxx_cram_read_20957 rsxx_cram_read 3 20957 NULL
116623 +nfs_map_name_to_uid_20962 nfs_map_name_to_uid 3 20962 NULL
116624 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
116625 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
116626 +qib_verbs_send_20999 qib_verbs_send 5-3 20999 NULL
116627 +btrfs_dirty_pages_21019 btrfs_dirty_pages 0 21019 NULL
116628 +btrfs_inode_ref_name_len_21024 btrfs_inode_ref_name_len 0 21024 NULL
116629 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
116630 +srp_change_queue_depth_21038 srp_change_queue_depth 2 21038 NULL
116631 +fsl_edma_prep_dma_cyclic_21042 fsl_edma_prep_dma_cyclic 4-3 21042 NULL
116632 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
116633 +reiserfs_direct_IO_21051 reiserfs_direct_IO 4 21051 NULL
116634 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
116635 +qdisc_get_default_21072 qdisc_get_default 2 21072 NULL
116636 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
116637 +bl_add_page_to_bio_21094 bl_add_page_to_bio 2 21094 NULL nohasharray
116638 +multipath_status_21094 multipath_status 5 21094 &bl_add_page_to_bio_21094
116639 +rate_control_pid_events_read_21099 rate_control_pid_events_read 3 21099 NULL
116640 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
116641 +_efx_mcdi_rpc_async_21119 _efx_mcdi_rpc_async 4-5 21119 NULL
116642 +i2400m_rx_trace_21127 i2400m_rx_trace 3 21127 NULL
116643 +mei_dbgfs_read_active_21172 mei_dbgfs_read_active 3 21172 NULL
116644 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
116645 +__generic_file_aio_write_21201 __generic_file_aio_write 0 21201 NULL
116646 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
116647 +scsi_execute_req_flags_21215 scsi_execute_req_flags 5 21215 NULL
116648 +get_numpages_21227 get_numpages 0-2-1 21227 NULL
116649 +input_ff_create_21240 input_ff_create 2 21240 NULL
116650 +cfg80211_notify_new_peer_candidate_21242 cfg80211_notify_new_peer_candidate 4 21242 NULL
116651 +fru_length_21257 fru_length 0 21257 NULL
116652 +rtw_set_wps_beacon_21262 rtw_set_wps_beacon 3 21262 NULL
116653 +drm_universal_plane_init_21296 drm_universal_plane_init 6 21296 NULL
116654 +do_msg_fill_21307 do_msg_fill 3 21307 NULL
116655 +add_res_range_21310 add_res_range 4 21310 NULL
116656 +get_zeroed_page_21322 get_zeroed_page 0 21322 NULL
116657 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
116658 +read_file_bool_bmps_21344 read_file_bool_bmps 3 21344 NULL
116659 +gfs2_ea_get_copy_21353 gfs2_ea_get_copy 0 21353 NULL
116660 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
116661 +SYSC_rt_sigpending_21379 SYSC_rt_sigpending 2 21379 NULL
116662 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
116663 +insert_ptr_21386 insert_ptr 6 21386 NULL
116664 +diva_get_driver_dbg_mask_21399 diva_get_driver_dbg_mask 0 21399 NULL
116665 +__clone_and_map_simple_bio_21404 __clone_and_map_simple_bio 4 21404 NULL
116666 +snd_m3_inw_21406 snd_m3_inw 0 21406 NULL
116667 +usnic_ib_dump_vf_hdr_21423 usnic_ib_dump_vf_hdr 3 21423 NULL
116668 +snapshot_read_next_21426 snapshot_read_next 0 21426 NULL
116669 +tcp_bound_to_half_wnd_21429 tcp_bound_to_half_wnd 0-2 21429 NULL
116670 +tracing_saved_cmdlines_read_21434 tracing_saved_cmdlines_read 3 21434 NULL
116671 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
116672 +__ertm_hdr_size_21450 __ertm_hdr_size 0 21450 NULL
116673 +mei_nfc_send_21477 mei_nfc_send 3 21477 NULL
116674 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
116675 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
116676 +btrfs_file_aio_write_21520 btrfs_file_aio_write 4 21520 NULL
116677 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
116678 +cipso_v4_map_cat_enum_hton_21540 cipso_v4_map_cat_enum_hton 0 21540 NULL
116679 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
116680 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
116681 +xfs_buf_read_uncached_21585 xfs_buf_read_uncached 3 21585 NULL
116682 +snd_es18xx_mixer_read_21586 snd_es18xx_mixer_read 0 21586 NULL
116683 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
116684 +filemap_get_page_21606 filemap_get_page 2 21606 NULL
116685 +__jfs_getxattr_21631 __jfs_getxattr 0 21631 NULL
116686 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
116687 +ocfs2_xattr_get_nolock_21678 ocfs2_xattr_get_nolock 0 21678 NULL
116688 +regmap_register_patch_21681 regmap_register_patch 3 21681 NULL
116689 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1 21687 NULL
116690 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
116691 +update_time_21719 update_time 0 21719 NULL
116692 +unix_skb_len_21722 unix_skb_len 0 21722 NULL
116693 +lprocfs_wr_import_21728 lprocfs_wr_import 3 21728 NULL
116694 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
116695 +usbat_flash_read_data_21762 usbat_flash_read_data 4 21762 NULL
116696 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
116697 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
116698 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
116699 +_iwl_dbgfs_sta_drain_write_21837 _iwl_dbgfs_sta_drain_write 3 21837 NULL
116700 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
116701 +lpfc_idiag_extacc_avail_get_21865 lpfc_idiag_extacc_avail_get 0-3 21865 NULL
116702 +brcms_debugfs_hardware_read_21867 brcms_debugfs_hardware_read 3 21867 NULL
116703 +msix_capability_init_21870 msix_capability_init 0 21870 NULL
116704 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
116705 +ldlm_lock_create_21888 ldlm_lock_create 7 21888 NULL
116706 +dbAllocCtl_21911 dbAllocCtl 0 21911 NULL
116707 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
116708 +twl_i2c_write_u16_21953 twl_i2c_write_u16 3 21953 NULL
116709 +__build_xattrs_21979 __build_xattrs 0 21979 NULL
116710 +SYSC_prctl_21980 SYSC_prctl 4 21980 NULL
116711 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 3-0 22001 NULL nohasharray
116712 +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
116713 +regcache_sync_block_raw_flush_22021 regcache_sync_block_raw_flush 3-4 22021 NULL
116714 +btrfs_get_16_22023 btrfs_get_16 0 22023 NULL
116715 +_sp2d_min_pg_22032 _sp2d_min_pg 0 22032 NULL
116716 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
116717 +ieee80211_if_fmt_dropped_frames_ttl_22054 ieee80211_if_fmt_dropped_frames_ttl 3 22054 NULL
116718 +btrfs_reloc_clone_csums_22077 btrfs_reloc_clone_csums 2-3 22077 NULL
116719 +mem_rw_22085 mem_rw 3 22085 NULL
116720 +kstrtos32_from_user_22087 kstrtos32_from_user 2 22087 NULL
116721 +snd_pcm_xrun_22088 snd_pcm_xrun 0 22088 NULL
116722 +rt2x00debug_read_crypto_stats_22109 rt2x00debug_read_crypto_stats 3 22109 NULL
116723 +snd_hda_codec_read_22130 snd_hda_codec_read 0 22130 NULL
116724 +SyS_sched_setaffinity_22148 SyS_sched_setaffinity 2 22148 NULL
116725 +do_tcp_sendpages_22155 do_tcp_sendpages 4 22155 NULL
116726 +pci_request_region_22164 pci_request_region 0 22164 NULL
116727 +__kfifo_alloc_22173 __kfifo_alloc 3 22173 NULL
116728 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
116729 +mem_write_22232 mem_write 3 22232 NULL
116730 +p9_virtio_zc_request_22240 p9_virtio_zc_request 6-5 22240 NULL
116731 +prepare_to_wait_event_22247 prepare_to_wait_event 0 22247 NULL
116732 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
116733 +ping_common_sendmsg_22261 ping_common_sendmsg 5 22261 NULL
116734 +add_res_tree_22263 add_res_tree 7 22263 NULL
116735 +queue_max_sectors_22280 queue_max_sectors 0 22280 NULL
116736 +pci_vpd_srdt_size_22300 pci_vpd_srdt_size 0 22300 NULL nohasharray
116737 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 &pci_vpd_srdt_size_22300
116738 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
116739 +lov_setstripe_22307 lov_setstripe 2 22307 NULL
116740 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
116741 +atomic_read_22342 atomic_read 0 22342 NULL
116742 +ll_lazystatfs_seq_write_22353 ll_lazystatfs_seq_write 3 22353 NULL
116743 +snd_pcm_alsa_frames_22363 snd_pcm_alsa_frames 2 22363 NULL
116744 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
116745 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
116746 +zoran_write_22404 zoran_write 3 22404 NULL
116747 +queue_reply_22416 queue_reply 3 22416 NULL
116748 +__set_enter_print_fmt_22431 __set_enter_print_fmt 0 22431 NULL
116749 +queue_max_segments_22441 queue_max_segments 0 22441 NULL
116750 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
116751 +ecryptfs_write_22488 ecryptfs_write 4-3 22488 NULL
116752 +qib_user_sdma_alloc_header_22490 qib_user_sdma_alloc_header 2 22490 NULL
116753 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
116754 +trim_no_bitmap_22524 trim_no_bitmap 4-3 22524 NULL
116755 +ntb_setup_bwd_msix_22549 ntb_setup_bwd_msix 2-0 22549 NULL
116756 +ocfs2_read_extent_block_22550 ocfs2_read_extent_block 0 22550 NULL
116757 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
116758 +dbFindCtl_22587 dbFindCtl 0 22587 NULL
116759 +snapshot_read_22601 snapshot_read 3 22601 NULL
116760 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
116761 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
116762 +wl1271_rx_filter_get_fields_size_22638 wl1271_rx_filter_get_fields_size 0 22638 NULL
116763 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
116764 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
116765 +ext4_ext_direct_IO_22679 ext4_ext_direct_IO 4 22679 NULL
116766 +fill_gap_22681 fill_gap 0 22681 NULL nohasharray
116767 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 &fill_gap_22681
116768 +bch_dump_read_22685 bch_dump_read 3 22685 NULL
116769 +reg_umr_22686 reg_umr 5 22686 NULL
116770 +SYSC_vmsplice_22697 SYSC_vmsplice 3 22697 NULL
116771 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
116772 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4-0 22735 NULL
116773 +ceph_decode_32_22738 ceph_decode_32 0 22738 NULL nohasharray
116774 +__mei_cl_send_22738 __mei_cl_send 3 22738 &ceph_decode_32_22738
116775 +__writeback_single_inode_22739 __writeback_single_inode 0 22739 NULL
116776 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
116777 +qlcnic_sriov_init_22762 qlcnic_sriov_init 2 22762 NULL
116778 +print_frame_22769 print_frame 0 22769 NULL
116779 +ftrace_arch_read_dyn_info_22773 ftrace_arch_read_dyn_info 0 22773 NULL
116780 +__break_lease_22777 __break_lease 0 22777 NULL
116781 +vnic_dev_get_res_count_22791 vnic_dev_get_res_count 0 22791 NULL
116782 +pla_ocp_write_22802 pla_ocp_write 4 22802 NULL
116783 +__generic_copy_to_user_intel_22806 __generic_copy_to_user_intel 0-3 22806 NULL
116784 +create_attr_set_22861 create_attr_set 1 22861 NULL
116785 +hash_ip6_expire_22867 hash_ip6_expire 4 22867 NULL
116786 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
116787 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
116788 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
116789 +ion_handle_test_kernel_22900 ion_handle_test_kernel 4-3 22900 NULL nohasharray
116790 +policy_emit_config_values_22900 policy_emit_config_values 3 22900 &ion_handle_test_kernel_22900
116791 +__set_xattr_22923 __set_xattr 0 22923 NULL
116792 +xstateregs_set_22932 xstateregs_set 4 22932 NULL
116793 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
116794 +alloc_sglist_22960 alloc_sglist 2-3 22960 NULL
116795 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
116796 +vme_get_size_22964 vme_get_size 0 22964 NULL
116797 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
116798 +cached_dev_cache_miss_22979 cached_dev_cache_miss 4 22979 NULL
116799 +usb_get_langid_22983 usb_get_langid 0 22983 NULL
116800 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
116801 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
116802 +cifs_local_to_utf16_bytes_23025 cifs_local_to_utf16_bytes 0 23025 NULL
116803 +st_status_23032 st_status 5 23032 NULL
116804 +nv50_disp_chan_create__23056 nv50_disp_chan_create_ 5 23056 NULL
116805 +comedi_buf_write_n_available_23057 comedi_buf_write_n_available 0 23057 NULL
116806 +security_inode_killpriv_23060 security_inode_killpriv 0 23060 NULL
116807 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
116808 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
116809 +mei_cl_send_23068 mei_cl_send 3 23068 NULL
116810 +raw_sendmsg_23078 raw_sendmsg 4 23078 NULL
116811 +get_user_hdr_len_23079 get_user_hdr_len 0 23079 NULL
116812 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
116813 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
116814 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
116815 +pipe_iov_copy_from_user_23102 pipe_iov_copy_from_user 3 23102 NULL
116816 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
116817 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
116818 +bset_tree_bytes_23111 bset_tree_bytes 0 23111 NULL nohasharray
116819 +nl80211_send_rx_auth_23111 nl80211_send_rx_auth 4 23111 &bset_tree_bytes_23111
116820 +__clear_user_23118 __clear_user 0-2 23118 NULL
116821 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
116822 +ata_scsi_change_queue_depth_23126 ata_scsi_change_queue_depth 2 23126 NULL
116823 +read_file_ani_23161 read_file_ani 3 23161 NULL
116824 +usblp_write_23178 usblp_write 3 23178 NULL
116825 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
116826 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
116827 +nft_hash_tbl_alloc_23224 nft_hash_tbl_alloc 1 23224 NULL
116828 +tty_buffer_request_room_23228 tty_buffer_request_room 2-0 23228 NULL
116829 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL
116830 +ft1000_read_dpram_mag_32_23232 ft1000_read_dpram_mag_32 0 23232 NULL
116831 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
116832 +__gfn_to_rmap_23240 __gfn_to_rmap 1-2 23240 NULL
116833 +nv50_ram_create__23241 nv50_ram_create_ 4 23241 NULL
116834 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
116835 +uwb_dev_addr_print_23282 uwb_dev_addr_print 2 23282 NULL
116836 +diva_get_trace_filter_23286 diva_get_trace_filter 0 23286 NULL
116837 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
116838 +__aa_kvmalloc_23320 __aa_kvmalloc 1 23320 NULL
116839 +page_readlink_23346 page_readlink 3 23346 NULL
116840 +kmem_zalloc_large_23351 kmem_zalloc_large 1 23351 NULL
116841 +get_dst_timing_23358 get_dst_timing 0 23358 NULL nohasharray
116842 +write_inode_23358 write_inode 0 23358 &get_dst_timing_23358
116843 +fd_setup_write_same_buf_23369 fd_setup_write_same_buf 3 23369 NULL
116844 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
116845 +vga_mm_r_23419 vga_mm_r 0 23419 NULL
116846 +ocfs2_zero_tail_23447 ocfs2_zero_tail 3 23447 NULL
116847 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
116848 +__ata_change_queue_depth_23484 __ata_change_queue_depth 3 23484 NULL
116849 +linear_conf_23485 linear_conf 2 23485 NULL nohasharray
116850 +sync_mapping_buffers_23485 sync_mapping_buffers 0 23485 &linear_conf_23485
116851 +event_filter_read_23494 event_filter_read 3 23494 NULL
116852 +lustre_acl_xattr_merge2ext_23502 lustre_acl_xattr_merge2ext 2 23502 NULL
116853 +devm_iio_device_alloc_23511 devm_iio_device_alloc 2 23511 NULL
116854 +__proc_cpt_table_23516 __proc_cpt_table 5 23516 NULL
116855 +hash_ipmark6_expire_23518 hash_ipmark6_expire 4 23518 NULL
116856 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
116857 +tcp_current_mss_23552 tcp_current_mss 0 23552 NULL
116858 +dbg_leb_change_23555 dbg_leb_change 0 23555 NULL
116859 +btrfs_super_bytenr_23561 btrfs_super_bytenr 0 23561 NULL
116860 +venus_symlink_23570 venus_symlink 6-4 23570 NULL
116861 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
116862 +xfpregs_get_23586 xfpregs_get 4 23586 NULL
116863 +snd_interval_min_23590 snd_interval_min 0 23590 NULL
116864 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
116865 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
116866 +sInW_23663 sInW 0 23663 NULL
116867 +SyS_connect_23669 SyS_connect 3 23669 NULL
116868 +cx18_read_23699 cx18_read 3 23699 NULL
116869 +at_get_23708 at_get 0 23708 NULL
116870 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
116871 +__kfifo_max_r_23768 __kfifo_max_r 0-2-1 23768 NULL
116872 +__build_packet_message_23778 __build_packet_message 4-10 23778 NULL
116873 +security_inode_getxattr_23781 security_inode_getxattr 0 23781 NULL
116874 +cfg80211_inform_bss_width_frame_23782 cfg80211_inform_bss_width_frame 5 23782 NULL
116875 +mpt_free_res_23793 mpt_free_res 5 23793 NULL
116876 +map_write_23795 map_write 3 23795 NULL
116877 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
116878 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
116879 +lustre_msg_buflen_23827 lustre_msg_buflen 0 23827 NULL
116880 +ceph_copy_page_vector_to_user_23829 ceph_copy_page_vector_to_user 0-3-4 23829 NULL
116881 +pgdat_end_pfn_23842 pgdat_end_pfn 0 23842 NULL
116882 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
116883 +p54_init_common_23850 p54_init_common 1 23850 NULL
116884 +bin_to_hex_dup_23853 bin_to_hex_dup 2 23853 NULL
116885 +ocfs2_xattr_get_clusters_23857 ocfs2_xattr_get_clusters 0 23857 NULL
116886 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
116887 +nouveau_clock_create__23881 nouveau_clock_create_ 5 23881 NULL nohasharray
116888 +writeback_single_inode_23881 writeback_single_inode 0 23881 &nouveau_clock_create__23881
116889 +tipc_snprintf_23893 tipc_snprintf 2-0 23893 NULL
116890 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL nohasharray
116891 +ieee80211_if_read_hw_queues_23911 ieee80211_if_read_hw_queues 3 23911 &add_new_gdb_meta_bg_23911
116892 +f2fs_getxattr_23917 f2fs_getxattr 0 23917 NULL
116893 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 NULL nohasharray
116894 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 &ipath_reg_phys_mr_23918
116895 +kvm_read_guest_23928 kvm_read_guest 4-2 23928 NULL
116896 +uvc_endpoint_max_bpi_23944 uvc_endpoint_max_bpi 0 23944 NULL
116897 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
116898 +size_roundup_power2_23958 size_roundup_power2 0-1 23958 NULL
116899 +sddr55_write_data_23983 sddr55_write_data 4 23983 NULL
116900 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
116901 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
116902 +give_pages_24021 give_pages 3 24021 NULL
116903 +adis16400_show_serial_number_24037 adis16400_show_serial_number 3 24037 NULL
116904 +hmac_setkey_24043 hmac_setkey 3 24043 NULL
116905 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
116906 +iwl_dbgfs_low_latency_read_24062 iwl_dbgfs_low_latency_read 3 24062 NULL
116907 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
116908 +C_SYSC_process_vm_writev_24102 C_SYSC_process_vm_writev 3-5 24102 NULL
116909 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
116910 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
116911 +lov_brw_24122 lov_brw 4 24122 NULL
116912 +mpu401_read_24126 mpu401_read 3 24126 NULL
116913 +_picolcd_flash_write_24134 _picolcd_flash_write 4 24134 NULL
116914 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
116915 +SyS_sethostname_24150 SyS_sethostname 2 24150 NULL
116916 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
116917 +adu_read_24177 adu_read 3 24177 NULL
116918 +safe_prepare_write_buffer_24187 safe_prepare_write_buffer 3 24187 NULL
116919 +irq_remapping_setup_msi_irqs_24194 irq_remapping_setup_msi_irqs 2 24194 NULL
116920 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
116921 +efx_vf_size_24213 efx_vf_size 0 24213 NULL
116922 +tcpprobe_sprint_24222 tcpprobe_sprint 0-2 24222 NULL
116923 +mei_amthif_read_24224 mei_amthif_read 4 24224 NULL nohasharray
116924 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 3-2-1 24224 &mei_amthif_read_24224
116925 +pci_num_vf_24235 pci_num_vf 0 24235 NULL
116926 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
116927 +em28xx_alloc_urbs_24260 em28xx_alloc_urbs 4-6 24260 NULL
116928 +calculate_sizes_24273 calculate_sizes 2 24273 NULL
116929 +thin_status_24278 thin_status 5 24278 NULL
116930 +msg_size_24288 msg_size 0 24288 NULL
116931 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
116932 +reserve_metadata_bytes_24313 reserve_metadata_bytes 0 24313 NULL
116933 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
116934 +si476x_radio_read_acf_blob_24336 si476x_radio_read_acf_blob 3 24336 NULL
116935 +C_SYSC_pwritev_24345 C_SYSC_pwritev 3 24345 NULL
116936 +prepare_pages_24349 prepare_pages 0 24349 NULL
116937 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
116938 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
116939 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
116940 +btrfs_item_size_nr_24367 btrfs_item_size_nr 0 24367 NULL
116941 +igetword_24373 igetword 0 24373 NULL nohasharray
116942 +break_deleg_24373 break_deleg 0 24373 &igetword_24373
116943 +max_io_len_24384 max_io_len 0-1 24384 NULL
116944 +mpt_alloc_res_24387 mpt_alloc_res 5 24387 NULL
116945 +osc_cur_grant_bytes_seq_write_24396 osc_cur_grant_bytes_seq_write 3 24396 NULL
116946 +getxattr_24398 getxattr 4 24398 NULL nohasharray
116947 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 &getxattr_24398
116948 +populate_msi_sysfs_24399 populate_msi_sysfs 0 24399 NULL
116949 +blk_update_bidi_request_24415 blk_update_bidi_request 3-4 24415 NULL
116950 +nvme_trans_log_supp_pages_24418 nvme_trans_log_supp_pages 3 24418 NULL
116951 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
116952 +xenbus_file_read_24427 xenbus_file_read 3 24427 NULL
116953 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
116954 +copy_and_ioctl_24434 copy_and_ioctl 4 24434 NULL
116955 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
116956 +rtw_set_wps_assoc_resp_24440 rtw_set_wps_assoc_resp 3 24440 NULL nohasharray
116957 +smk_user_access_24440 smk_user_access 3 24440 &rtw_set_wps_assoc_resp_24440
116958 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
116959 +lbs_highsnr_write_24460 lbs_highsnr_write 3 24460 NULL
116960 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
116961 +dut_mode_read_24489 dut_mode_read 3 24489 NULL
116962 +read_file_spec_scan_ctl_24491 read_file_spec_scan_ctl 3 24491 NULL
116963 +pd_video_read_24510 pd_video_read 3 24510 NULL
116964 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
116965 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
116966 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
116967 +write_cache_pages_24562 write_cache_pages 0 24562 NULL
116968 +SyS_pselect6_24582 SyS_pselect6 1 24582 NULL
116969 +udf_compute_nr_groups_24594 udf_compute_nr_groups 0 24594 NULL
116970 +sensor_hub_get_physical_device_count_24605 sensor_hub_get_physical_device_count 0 24605 NULL nohasharray
116971 +lov_alloc_memmd_24605 lov_alloc_memmd 2 24605 &sensor_hub_get_physical_device_count_24605
116972 +SyS_poll_24620 SyS_poll 2 24620 NULL
116973 +context_alloc_24645 context_alloc 3 24645 NULL
116974 +blk_rq_err_bytes_24650 blk_rq_err_bytes 0 24650 NULL
116975 +btrfs_check_data_free_space_24692 btrfs_check_data_free_space 0 24692 NULL
116976 +datafab_write_data_24696 datafab_write_data 4 24696 NULL
116977 +intelfbhw_get_p1p2_24703 intelfbhw_get_p1p2 2 24703 NULL
116978 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
116979 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
116980 +get_dma_residue_24749 get_dma_residue 0 24749 NULL
116981 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
116982 +ocfs2_read_blocks_24777 ocfs2_read_blocks 0 24777 NULL
116983 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
116984 +cache_read_24790 cache_read 3 24790 NULL
116985 +user_regset_copyout_24796 user_regset_copyout 7 24796 NULL
116986 +kvm_read_guest_virt_helper_24804 kvm_read_guest_virt_helper 3-1 24804 NULL
116987 +ath6kl_fwlog_mask_write_24810 ath6kl_fwlog_mask_write 3 24810 NULL
116988 +snd_als4k_gcr_read_24840 snd_als4k_gcr_read 0 24840 NULL
116989 +snd_pcm_lib_buffer_bytes_24865 snd_pcm_lib_buffer_bytes 0 24865 NULL
116990 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
116991 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
116992 +queues_read_24877 queues_read 3 24877 NULL
116993 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
116994 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL nohasharray
116995 +__btrfs_free_extent_24927 __btrfs_free_extent 7 24927 &v4l2_ctrl_new_24927
116996 +ocfs2_fiemap_24949 ocfs2_fiemap 3-4 24949 NULL
116997 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
116998 +security_inode_rename_24971 security_inode_rename 0 24971 NULL
116999 +twl_i2c_write_u8_24976 twl_i2c_write_u8 3 24976 NULL
117000 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
117001 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
117002 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
117003 +ni_660x_num_counters_25031 ni_660x_num_counters 0 25031 NULL
117004 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
117005 +btrfs_stack_key_blockptr_25058 btrfs_stack_key_blockptr 0 25058 NULL
117006 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
117007 +ll_track_pid_seq_write_25068 ll_track_pid_seq_write 3 25068 NULL
117008 +SYSC_listxattr_25072 SYSC_listxattr 3 25072 NULL
117009 +ima_appraise_measurement_25093 ima_appraise_measurement 6 25093 NULL
117010 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
117011 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
117012 +_iwl_dbgfs_reduced_txp_write_25169 _iwl_dbgfs_reduced_txp_write 3 25169 NULL nohasharray
117013 +kvm_mmu_notifier_change_pte_25169 kvm_mmu_notifier_change_pte 3 25169 &_iwl_dbgfs_reduced_txp_write_25169
117014 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
117015 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
117016 +stripe_status_25259 stripe_status 5 25259 NULL
117017 +snd_pcm_start_25273 snd_pcm_start 0 25273 NULL
117018 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
117019 +vfs_writev_25278 vfs_writev 3 25278 NULL
117020 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
117021 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 NULL
117022 +rng_buffer_size_25348 rng_buffer_size 0 25348 NULL
117023 +SYSC_kexec_load_25361 SYSC_kexec_load 2 25361 NULL
117024 +unix_mkname_25368 unix_mkname 0-2 25368 NULL
117025 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
117026 +vsp1_entity_init_25407 vsp1_entity_init 3 25407 NULL
117027 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
117028 +ipath_decode_err_25468 ipath_decode_err 3 25468 NULL
117029 +crypto_hash_digestsize_25469 crypto_hash_digestsize 0 25469 NULL
117030 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4-0 25502 NULL
117031 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
117032 +sb_permission_25523 sb_permission 0 25523 NULL
117033 +ext3_get_inode_loc_25542 ext3_get_inode_loc 0 25542 NULL
117034 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
117035 +wimax_addr_scnprint_25548 wimax_addr_scnprint 2 25548 NULL
117036 +ht_print_chan_25556 ht_print_chan 0-3-4 25556 NULL
117037 +skb_tailroom_25567 skb_tailroom 0 25567 NULL
117038 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
117039 +copy_user_generic_25611 copy_user_generic 0 25611 NULL
117040 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
117041 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL nohasharray
117042 +__get_user_pages_25628 __get_user_pages 0 25628 &befs_utf2nls_25628
117043 +__direct_map_25647 __direct_map 5-6 25647 NULL
117044 +aircable_prepare_write_buffer_25669 aircable_prepare_write_buffer 3 25669 NULL
117045 +lpfc_idiag_cmd_get_25672 lpfc_idiag_cmd_get 2 25672 NULL
117046 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
117047 +prom_early_alloc_25692 prom_early_alloc 1 25692 NULL
117048 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
117049 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
117050 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 NULL nohasharray
117051 +sel_write_context_25726 sel_write_context 3 25726 &__alloc_bootmem_low_node_25726
117052 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
117053 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
117054 +sg_read_25799 sg_read 3 25799 NULL
117055 +system_enable_read_25815 system_enable_read 3 25815 NULL
117056 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
117057 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
117058 +parport_read_25855 parport_read 0 25855 NULL
117059 +xfs_dir2_sf_hdr_size_25858 xfs_dir2_sf_hdr_size 0 25858 NULL
117060 +key_attr_size_25865 key_attr_size 0 25865 NULL
117061 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
117062 +run_delalloc_nocow_25896 run_delalloc_nocow 3-4 25896 NULL
117063 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
117064 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
117065 +nvme_trans_mode_page_create_25908 nvme_trans_mode_page_create 7-4 25908 NULL
117066 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
117067 +rcname_read_25919 rcname_read 3 25919 NULL
117068 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
117069 +key_flags_read_25931 key_flags_read 3 25931 NULL
117070 +copy_play_buf_25932 copy_play_buf 3 25932 NULL
117071 +flush_25957 flush 2 25957 NULL
117072 +_regmap_multi_reg_write_25967 _regmap_multi_reg_write 3 25967 NULL
117073 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
117074 +lustre_msg_buflen_v2_25997 lustre_msg_buflen_v2 0 25997 NULL
117075 +SyS_process_vm_readv_26019 SyS_process_vm_readv 3-5 26019 NULL
117076 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
117077 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
117078 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
117079 +pri_wm_latency_write_26063 pri_wm_latency_write 3 26063 NULL
117080 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
117081 +i8042_pnp_id_to_string_26108 i8042_pnp_id_to_string 3 26108 NULL
117082 +read_sb_page_26119 read_sb_page 5 26119 NULL
117083 +ath9k_hw_name_26146 ath9k_hw_name 3 26146 NULL
117084 +copy_oldmem_page_26164 copy_oldmem_page 3 26164 NULL
117085 +gfs2_xattr_acl_get_26166 gfs2_xattr_acl_get 0 26166 NULL nohasharray
117086 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 &gfs2_xattr_acl_get_26166
117087 +disk_devt_26180 disk_devt 0 26180 NULL
117088 +ieee80211_if_fmt_dot11MeshTTL_26198 ieee80211_if_fmt_dot11MeshTTL 3 26198 NULL
117089 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
117090 +mce_write_26201 mce_write 3 26201 NULL
117091 +mwifiex_regrdwr_write_26225 mwifiex_regrdwr_write 3 26225 NULL
117092 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
117093 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
117094 +simple_setattr_26234 simple_setattr 0 26234 NULL
117095 +genwqe_ffdc_buff_size_26263 genwqe_ffdc_buff_size 0 26263 NULL
117096 +crypto_ctxsize_26278 crypto_ctxsize 0 26278 NULL
117097 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
117098 +snd_pcm_plug_client_channels_buf_26309 snd_pcm_plug_client_channels_buf 0-3 26309 NULL
117099 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
117100 +check_can_nocow_26336 check_can_nocow 2 26336 NULL
117101 +snd_vx_check_reg_bit_26344 snd_vx_check_reg_bit 0 26344 NULL
117102 +ocfs2_duplicate_clusters_by_page_26357 ocfs2_duplicate_clusters_by_page 6-3 26357 NULL
117103 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
117104 +invalidate_inode_pages2_range_26403 invalidate_inode_pages2_range 0 26403 NULL
117105 +ntty_write_26404 ntty_write 3 26404 NULL
117106 +firmware_store_26408 firmware_store 4 26408 NULL
117107 +pagemap_read_26441 pagemap_read 3 26441 NULL
117108 +enc_pools_add_pages_26461 enc_pools_add_pages 1 26461 NULL nohasharray
117109 +tower_read_26461 tower_read 3 26461 &enc_pools_add_pages_26461
117110 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
117111 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
117112 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
117113 +read_vmcore_26501 read_vmcore 3 26501 NULL
117114 +uhid_char_write_26502 uhid_char_write 3 26502 NULL
117115 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 4-3 26507 NULL
117116 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
117117 +alloc_ep_req_26521 alloc_ep_req 3-2 26521 NULL
117118 +SyS_rt_sigpending_26538 SyS_rt_sigpending 2 26538 NULL
117119 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
117120 +dio_new_bio_26562 dio_new_bio 0 26562 NULL
117121 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL
117122 +kernfs_name_locked_26617 kernfs_name_locked 3 26617 NULL
117123 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
117124 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL nohasharray
117125 +inb_p_26650 inb_p 0 26650 &irq_alloc_generic_chip_26650
117126 +nouveau_volt_create__26654 nouveau_volt_create_ 4 26654 NULL
117127 +cipso_v4_map_cat_rbm_hton_26680 cipso_v4_map_cat_rbm_hton 0 26680 NULL
117128 +flowinfo_read_26683 flowinfo_read 3 26683 NULL
117129 +sysfs_add_file_26716 sysfs_add_file 0 26716 NULL
117130 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
117131 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
117132 +snd_hda_get_raw_connections_26762 snd_hda_get_raw_connections 0 26762 NULL
117133 +dma_map_single_attrs_26779 dma_map_single_attrs 0 26779 NULL
117134 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
117135 +cipso_v4_genopt_26812 cipso_v4_genopt 0 26812 NULL
117136 +iwl_trans_read_mem32_26825 iwl_trans_read_mem32 0 26825 NULL
117137 +smk_write_load_26829 smk_write_load 3 26829 NULL
117138 +scnprint_id_26842 scnprint_id 3-0 26842 NULL
117139 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
117140 +ss_alloc_ep_req_26848 ss_alloc_ep_req 2 26848 NULL
117141 +tipc_conn_sendmsg_26867 tipc_conn_sendmsg 5 26867 NULL
117142 +ath6kl_create_qos_write_26879 ath6kl_create_qos_write 3 26879 NULL
117143 +svc_print_xprts_26881 svc_print_xprts 0 26881 NULL
117144 +skb_zerocopy_headlen_26910 skb_zerocopy_headlen 0 26910 NULL
117145 +hhf_zalloc_26912 hhf_zalloc 1 26912 NULL
117146 +cfg80211_process_auth_26916 cfg80211_process_auth 3 26916 NULL
117147 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
117148 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
117149 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 NULL nohasharray
117150 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 &sctp_setsockopt_adaptation_layer_26935
117151 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
117152 +extract_entropy_user_26952 extract_entropy_user 3 26952 NULL nohasharray
117153 +do_trimming_26952 do_trimming 3 26952 &extract_entropy_user_26952
117154 +do_direct_IO_26979 do_direct_IO 0 26979 NULL
117155 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
117156 +ext4_convert_unwritten_extents_27064 ext4_convert_unwritten_extents 4-3-0 27064 NULL
117157 +snd_pcm_lib_period_bytes_27071 snd_pcm_lib_period_bytes 0 27071 NULL
117158 +paravirt_read_msr_27077 paravirt_read_msr 0 27077 NULL
117159 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
117160 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL nohasharray
117161 +ath9k_hw_4k_dump_eeprom_27089 ath9k_hw_4k_dump_eeprom 5-4 27089 &btmrvl_hscmd_write_27089
117162 +__devcgroup_inode_permission_27108 __devcgroup_inode_permission 0 27108 NULL
117163 +get_kernel_page_27133 get_kernel_page 0 27133 NULL
117164 +drbd_get_capacity_27141 drbd_get_capacity 0 27141 NULL
117165 +pms_capture_27142 pms_capture 4 27142 NULL
117166 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
117167 +snd_compr_calc_avail_27165 snd_compr_calc_avail 0 27165 NULL
117168 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
117169 +write_kmem_27225 write_kmem 3 27225 NULL
117170 +dbAllocAG_27228 dbAllocAG 0 27228 NULL
117171 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
117172 +ll_track_gid_seq_write_27267 ll_track_gid_seq_write 3 27267 NULL
117173 +comedi_alloc_devpriv_27272 comedi_alloc_devpriv 2 27272 NULL
117174 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
117175 +virtqueue_add_inbuf_27312 virtqueue_add_inbuf 3 27312 NULL
117176 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3-0 27332 NULL
117177 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
117178 +iwl_dbgfs_csr_write_27363 iwl_dbgfs_csr_write 3 27363 NULL
117179 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
117180 +seq_read_27411 seq_read 3 27411 NULL
117181 +ib_dma_map_sg_27413 ib_dma_map_sg 0 27413 NULL
117182 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
117183 +cypress_write_27423 cypress_write 4 27423 NULL
117184 +sddr09_read_data_27447 sddr09_read_data 3 27447 NULL
117185 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
117186 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
117187 +ip_set_get_h32_27498 ip_set_get_h32 0 27498 NULL
117188 +btrfs_get_64_27499 btrfs_get_64 0 27499 NULL
117189 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
117190 +oti_alloc_cookies_27510 oti_alloc_cookies 2 27510 NULL
117191 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
117192 +snd_sonicvibes_getdmaa_27552 snd_sonicvibes_getdmaa 0 27552 NULL
117193 +SyS_fgetxattr_27571 SyS_fgetxattr 4 27571 NULL
117194 +sco_sock_recvmsg_27572 sco_sock_recvmsg 4 27572 NULL
117195 +libipw_alloc_txb_27579 libipw_alloc_txb 1 27579 NULL
117196 +C_SYSC_mbind_27636 C_SYSC_mbind 5 27636 NULL
117197 +ocfs2_xattr_ibody_get_27642 ocfs2_xattr_ibody_get 0 27642 NULL nohasharray
117198 +read_flush_procfs_27642 read_flush_procfs 3 27642 &ocfs2_xattr_ibody_get_27642 nohasharray
117199 +nl80211_send_connect_result_27642 nl80211_send_connect_result 5-7 27642 &read_flush_procfs_27642 nohasharray
117200 +ocfs2_direct_IO_27642 ocfs2_direct_IO 4 27642 &nl80211_send_connect_result_27642
117201 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
117202 +btrfs_fallocate_27647 btrfs_fallocate 3-4 27647 NULL
117203 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
117204 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
117205 +ocfs2_extend_dir_27695 ocfs2_extend_dir 4 27695 NULL
117206 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
117207 +evm_write_key_27715 evm_write_key 3 27715 NULL
117208 +ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol_27722 ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol 3 27722 NULL
117209 +xfs_dir2_block_sfsize_27727 xfs_dir2_block_sfsize 0 27727 NULL
117210 +SyS_setsockopt_27759 SyS_setsockopt 5 27759 NULL
117211 +transport_init_session_tags_27776 transport_init_session_tags 1-2 27776 NULL
117212 +__lov_setstripe_27782 __lov_setstripe 2 27782 NULL
117213 +twl4030_set_gpio_dataout_27792 twl4030_set_gpio_dataout 1 27792 NULL
117214 +SyS_readv_27804 SyS_readv 3 27804 NULL
117215 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
117216 +hpt374_read_freq_27828 hpt374_read_freq 0 27828 NULL
117217 +init_header_complete_27833 init_header_complete 0 27833 NULL
117218 +read_profile_27859 read_profile 3 27859 NULL
117219 +sky2_pci_read16_27863 sky2_pci_read16 0 27863 NULL
117220 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
117221 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
117222 +i915_error_object_create_sized_27919 i915_error_object_create_sized 4 27919 NULL
117223 +check_mapped_name_27943 check_mapped_name 3 27943 NULL
117224 +tracing_clock_write_27961 tracing_clock_write 3 27961 NULL nohasharray
117225 +bio_next_split_27961 bio_next_split 2 27961 &tracing_clock_write_27961
117226 +security_path_chown_27966 security_path_chown 0 27966 NULL
117227 +tipc_media_addr_printf_27971 tipc_media_addr_printf 2 27971 NULL
117228 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 NULL nohasharray
117229 +device_register_27972 device_register 0 27972 &mic_rx_pkts_read_27972
117230 +compat_SyS_set_mempolicy_27975 compat_SyS_set_mempolicy 3 27975 NULL
117231 +pci_enable_device_flags_27977 pci_enable_device_flags 0 27977 NULL
117232 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
117233 +seq_get_buf_28006 seq_get_buf 0 28006 NULL
117234 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
117235 +powercap_register_zone_28028 powercap_register_zone 6 28028 NULL
117236 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
117237 +rts51x_xd_rw_28046 rts51x_xd_rw 3-4 28046 NULL
117238 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2-4 28053 NULL
117239 +pool_status_28055 pool_status 5 28055 NULL
117240 +init_rs_non_canonical_28059 init_rs_non_canonical 1 28059 NULL
117241 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
117242 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
117243 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
117244 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
117245 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
117246 +video_read_28148 video_read 3 28148 NULL
117247 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
117248 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
117249 +vread_28173 vread 0-3 28173 NULL
117250 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
117251 +counter_free_res_28187 counter_free_res 5 28187 NULL
117252 +read_disk_sb_28188 read_disk_sb 2 28188 NULL
117253 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
117254 +__qp_memcpy_from_queue_28220 __qp_memcpy_from_queue 3-4 28220 NULL
117255 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL
117256 +amd_nb_num_28228 amd_nb_num 0 28228 NULL
117257 +fuse_direct_IO_28275 fuse_direct_IO 4 28275 NULL
117258 +usemap_size_28281 usemap_size 0 28281 NULL
117259 +inline_xattr_size_28285 inline_xattr_size 0 28285 NULL
117260 +dma_map_sg_attrs_28289 dma_map_sg_attrs 0 28289 NULL
117261 +SyS_ppoll_28290 SyS_ppoll 2 28290 NULL
117262 +kstrtos16_from_user_28300 kstrtos16_from_user 2 28300 NULL
117263 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
117264 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
117265 +security_inode_link_28327 security_inode_link 0 28327 NULL
117266 +generic_write_checks_28329 generic_write_checks 0 28329 NULL
117267 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
117268 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
117269 +snapshot_write_28351 snapshot_write 3 28351 NULL
117270 +xfs_iomap_write_unwritten_28365 xfs_iomap_write_unwritten 3-2 28365 NULL
117271 +batadv_handle_tt_response_28370 batadv_handle_tt_response 4 28370 NULL
117272 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
117273 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
117274 +bypass_pwup_write_28416 bypass_pwup_write 3 28416 NULL
117275 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
117276 +ksocknal_alloc_tx_28426 ksocknal_alloc_tx 2 28426 NULL
117277 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
117278 +snd_emu10k1_efx_read_28452 snd_emu10k1_efx_read 2 28452 NULL
117279 +key_mic_failures_read_28457 key_mic_failures_read 3 28457 NULL
117280 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
117281 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
117282 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 NULL
117283 +early_init_dt_alloc_memory_arch_28528 early_init_dt_alloc_memory_arch 1 28528 NULL
117284 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
117285 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 NULL nohasharray
117286 +aio_read_events_28545 aio_read_events 3 28545 &mptctl_getiocinfo_28545 nohasharray
117287 +run_delalloc_range_28545 run_delalloc_range 3-4 28545 &aio_read_events_28545
117288 +sysfs_create_bin_file_28551 sysfs_create_bin_file 0 28551 NULL
117289 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
117290 +asymmetric_verify_28567 asymmetric_verify 3 28567 NULL
117291 +oxygen_read32_28582 oxygen_read32 0 28582 NULL
117292 +task_cgroup_path_28599 task_cgroup_path 3 28599 NULL
117293 +extract_entropy_28604 extract_entropy 5-3 28604 NULL
117294 +kfifo_unused_28612 kfifo_unused 0 28612 NULL
117295 +snd_nm256_capture_copy_28622 snd_nm256_capture_copy 3-5 28622 NULL
117296 +setup_usemap_28636 setup_usemap 3-4 28636 NULL
117297 +qib_handle_6120_hwerrors_28642 qib_handle_6120_hwerrors 3 28642 NULL
117298 +p9_fcall_alloc_28652 p9_fcall_alloc 1 28652 NULL
117299 +read_nic_io_byte_28654 read_nic_io_byte 0 28654 NULL
117300 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
117301 +SyS_setgroups16_28686 SyS_setgroups16 1 28686 NULL
117302 +kvm_mmu_get_page_28692 kvm_mmu_get_page 2 28692 NULL
117303 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
117304 +spi_execute_28736 spi_execute 5 28736 NULL
117305 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
117306 +read_file_btcoex_28743 read_file_btcoex 3 28743 NULL
117307 +max_hw_blocks_28748 max_hw_blocks 0 28748 NULL
117308 +rpc_pipe_generic_upcall_28766 rpc_pipe_generic_upcall 4 28766 NULL
117309 +ath6kl_get_num_reg_28780 ath6kl_get_num_reg 0 28780 NULL
117310 +sel_write_member_28800 sel_write_member 3 28800 NULL
117311 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
117312 +kernel_tree_alloc_28833 kernel_tree_alloc 1 28833 NULL
117313 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
117314 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
117315 +max_io_len_target_boundary_28879 max_io_len_target_boundary 0-1 28879 NULL
117316 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
117317 +da9055_group_write_28904 da9055_group_write 2-3 28904 NULL
117318 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
117319 +iwl_dbgfs_sleep_level_override_write_28925 iwl_dbgfs_sleep_level_override_write 3 28925 NULL
117320 +push_rx_28939 push_rx 3 28939 NULL
117321 +mxuport_prepare_write_buffer_28943 mxuport_prepare_write_buffer 3 28943 NULL
117322 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3-4 28963 NULL
117323 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
117324 +hash_net6_expire_28979 hash_net6_expire 4 28979 NULL
117325 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
117326 +bin_uuid_28999 bin_uuid 3 28999 NULL
117327 +fd_execute_rw_29004 fd_execute_rw 3 29004 NULL
117328 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
117329 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
117330 +btrfs_root_bytenr_29058 btrfs_root_bytenr 0 29058 NULL
117331 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
117332 +lpfc_idiag_extacc_drivr_get_29067 lpfc_idiag_extacc_drivr_get 0-3 29067 NULL
117333 +sctp_getsockopt_assoc_stats_29074 sctp_getsockopt_assoc_stats 2 29074 NULL
117334 +iwl_dbgfs_log_event_write_29088 iwl_dbgfs_log_event_write 3 29088 NULL
117335 +ccp_init_dm_workarea_29097 ccp_init_dm_workarea 3 29097 NULL
117336 +__compat_sys_preadv64_29103 __compat_sys_preadv64 3 29103 NULL
117337 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
117338 +snprintf_29125 snprintf 0 29125 NULL
117339 +iov_shorten_29130 iov_shorten 0 29130 NULL
117340 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
117341 +kvm_mmu_notifier_clear_flush_young_29154 kvm_mmu_notifier_clear_flush_young 3 29154 NULL
117342 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
117343 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL
117344 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
117345 +nvme_trans_copy_from_user_29227 nvme_trans_copy_from_user 3 29227 NULL
117346 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
117347 +recover_peb_29238 recover_peb 0 29238 NULL
117348 +evdev_handle_get_val_29242 evdev_handle_get_val 5-6 29242 NULL
117349 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
117350 +rbd_osd_req_create_29260 rbd_osd_req_create 3 29260 NULL
117351 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
117352 +ext4_fiemap_29296 ext4_fiemap 4 29296 NULL
117353 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
117354 +__fuse_get_req_29315 __fuse_get_req 2 29315 NULL
117355 +lprocfs_write_helper_29323 lprocfs_write_helper 2 29323 NULL
117356 +kvm_handle_hva_29326 kvm_handle_hva 2 29326 NULL
117357 +tun_put_user_29337 tun_put_user 5 29337 NULL
117358 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
117359 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
117360 +read_file_tx99_power_29405 read_file_tx99_power 3 29405 NULL
117361 +mempool_create_29437 mempool_create 1 29437 NULL
117362 +crypto_ahash_alignmask_29445 crypto_ahash_alignmask 0 29445 NULL
117363 +p9_client_prepare_req_29448 p9_client_prepare_req 3 29448 NULL
117364 +validate_scan_freqs_29462 validate_scan_freqs 0 29462 NULL
117365 +SyS_flistxattr_29474 SyS_flistxattr 3 29474 NULL
117366 +do_register_entry_29478 do_register_entry 4 29478 NULL
117367 +simple_strtoul_29480 simple_strtoul 0 29480 NULL
117368 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
117369 +btrfs_file_extent_disk_bytenr_29505 btrfs_file_extent_disk_bytenr 0 29505 NULL
117370 +i2c_add_adapter_29507 i2c_add_adapter 0 29507 NULL
117371 +usnic_vnic_spec_dump_29508 usnic_vnic_spec_dump 2 29508 NULL
117372 +write_file_regidx_29517 write_file_regidx 3 29517 NULL
117373 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
117374 +pci_enable_msix_29524 pci_enable_msix 0 29524 NULL
117375 +ftrace_write_29551 ftrace_write 3 29551 NULL
117376 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
117377 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
117378 +kvm_read_guest_virt_system_29569 kvm_read_guest_virt_system 4-2 29569 NULL
117379 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
117380 +security_path_chmod_29578 security_path_chmod 0 29578 NULL
117381 +iwl_dbgfs_missed_beacon_write_29586 iwl_dbgfs_missed_beacon_write 3 29586 NULL
117382 +pvr2_hdw_report_unlocked_29589 pvr2_hdw_report_unlocked 4-0 29589 NULL
117383 +dio_set_defer_completion_29599 dio_set_defer_completion 0 29599 NULL
117384 +slots_per_page_29601 slots_per_page 0 29601 NULL
117385 +osc_cached_mb_seq_write_29610 osc_cached_mb_seq_write 3 29610 NULL
117386 +nla_get_u16_29624 nla_get_u16 0 29624 NULL
117387 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
117388 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL nohasharray
117389 +spmi_controller_alloc_29654 spmi_controller_alloc 2 29654 &sctp_make_abort_user_29654
117390 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
117391 +lustre_posix_acl_xattr_2ext_29693 lustre_posix_acl_xattr_2ext 2 29693 NULL
117392 +posix_acl_from_xattr_29708 posix_acl_from_xattr 3 29708 NULL
117393 +probes_write_29711 probes_write 3 29711 NULL
117394 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
117395 +xfs_new_eof_29737 xfs_new_eof 2 29737 NULL
117396 +std_nic_write_29752 std_nic_write 3 29752 NULL
117397 +tg3_irq_count_29786 tg3_irq_count 0 29786 NULL
117398 +dbAlloc_29794 dbAlloc 0 29794 NULL
117399 +tcp_sendpage_29829 tcp_sendpage 4 29829 NULL
117400 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
117401 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
117402 +count_partial_29850 count_partial 0 29850 NULL
117403 +write_file_bool_bmps_29870 write_file_bool_bmps 3 29870 NULL
117404 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
117405 +scsi_end_request_29876 scsi_end_request 3 29876 NULL
117406 +crypto_aead_alignmask_29885 crypto_aead_alignmask 0 29885 NULL
117407 +rtw_cfg80211_indicate_sta_assoc_29897 rtw_cfg80211_indicate_sta_assoc 3 29897 NULL
117408 +lov_ost_pool_extend_29914 lov_ost_pool_extend 2 29914 NULL
117409 +write_file_queue_29922 write_file_queue 3 29922 NULL
117410 +__btrfs_getxattr_29947 __btrfs_getxattr 0 29947 NULL nohasharray
117411 +ipv6_recv_error_29947 ipv6_recv_error 3 29947 &__btrfs_getxattr_29947
117412 +arch_setup_dmar_msi_29992 arch_setup_dmar_msi 0 29992 NULL
117413 +dev_mem_write_30028 dev_mem_write 3 30028 NULL
117414 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
117415 +sysfs_add_file_mode_ns_30038 sysfs_add_file_mode_ns 0 30038 NULL
117416 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 0-4 30040 NULL
117417 +drp_wmove_30043 drp_wmove 4 30043 NULL
117418 +__pci_request_selected_regions_30058 __pci_request_selected_regions 0 30058 NULL
117419 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
117420 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
117421 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
117422 +defragment_dma_buffer_30113 defragment_dma_buffer 0 30113 NULL
117423 +spi_async_locked_30117 spi_async_locked 0 30117 NULL
117424 +u_memcpya_30139 u_memcpya 3-2 30139 NULL
117425 +dbg_port_buf_30145 dbg_port_buf 2 30145 NULL
117426 +elfcorehdr_read_30159 elfcorehdr_read 2 30159 NULL
117427 +alloc_switch_ctx_30165 alloc_switch_ctx 2 30165 NULL
117428 +expand_inode_data_30169 expand_inode_data 3-2 30169 NULL
117429 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
117430 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
117431 +__genwqe_readq_30197 __genwqe_readq 0 30197 NULL
117432 +snd_pcm_playback_forward_30201 snd_pcm_playback_forward 0-2 30201 NULL
117433 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
117434 +read_4k_modal_eeprom_30212 read_4k_modal_eeprom 3 30212 NULL
117435 +SyS_semop_30227 SyS_semop 3 30227 NULL
117436 +bitmap_file_set_bit_30228 bitmap_file_set_bit 2 30228 NULL
117437 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
117438 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL nohasharray
117439 +try_break_deleg_30271 try_break_deleg 0 30271 &isr_pci_pm_read_30271
117440 +compat_readv_30273 compat_readv 3 30273 NULL
117441 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
117442 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
117443 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
117444 +osc_contention_seconds_seq_write_30305 osc_contention_seconds_seq_write 3 30305 NULL
117445 +ext4_acl_from_disk_30320 ext4_acl_from_disk 2 30320 NULL
117446 +i8254_read_30330 i8254_read 0 30330 NULL
117447 +resource_from_user_30341 resource_from_user 3 30341 NULL
117448 +o2nm_this_node_30342 o2nm_this_node 0 30342 NULL
117449 +kstrtou32_from_user_30361 kstrtou32_from_user 2 30361 NULL
117450 +pagecache_write_begin_30364 pagecache_write_begin 0 30364 NULL
117451 +pvscsi_change_queue_depth_30365 pvscsi_change_queue_depth 2 30365 NULL
117452 +C_SYSC_readv_30369 C_SYSC_readv 3 30369 NULL
117453 +blkdev_issue_zeroout_30392 blkdev_issue_zeroout 3 30392 NULL
117454 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
117455 +get_kernel_pages_30397 get_kernel_pages 0 30397 NULL
117456 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
117457 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
117458 +lstcon_session_info_30425 lstcon_session_info 6 30425 NULL
117459 +enable_write_30456 enable_write 3 30456 NULL
117460 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
117461 +urandom_read_30462 urandom_read 3 30462 NULL
117462 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
117463 +i2c_ctrl_read_30467 i2c_ctrl_read 0 30467 NULL
117464 +adu_write_30487 adu_write 3 30487 NULL
117465 +dtim_interval_write_30489 dtim_interval_write 3 30489 NULL
117466 +batadv_send_tt_request_30493 batadv_send_tt_request 5 30493 NULL
117467 +__send_duplicate_bios_30498 __send_duplicate_bios 4 30498 NULL
117468 +memblock_virt_alloc_node_30515 memblock_virt_alloc_node 1 30515 NULL
117469 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
117470 +debug_debug2_read_30526 debug_debug2_read 3 30526 NULL
117471 +ixgbevf_acquire_msix_vectors_30559 ixgbevf_acquire_msix_vectors 2 30559 NULL
117472 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
117473 +set_le_30581 set_le 4 30581 NULL
117474 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
117475 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
117476 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
117477 +ieee80211_if_read_dot11MeshAwakeWindowDuration_30631 ieee80211_if_read_dot11MeshAwakeWindowDuration 3 30631 NULL
117478 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
117479 +mlx5_ib_alloc_fast_reg_page_list_30638 mlx5_ib_alloc_fast_reg_page_list 2 30638 NULL
117480 +SyS_listxattr_30647 SyS_listxattr 3 30647 NULL
117481 +jffs2_flash_read_30667 jffs2_flash_read 0 30667 NULL
117482 +ni_ai_fifo_read_30681 ni_ai_fifo_read 3 30681 NULL
117483 +sst_hsw_get_dsp_position_30691 sst_hsw_get_dsp_position 0 30691 NULL
117484 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
117485 +lbs_wrbbp_write_30712 lbs_wrbbp_write 3 30712 NULL
117486 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
117487 +snd_nm256_playback_silence_30727 snd_nm256_playback_silence 3-4 30727 NULL
117488 +snapshot_status_30744 snapshot_status 5 30744 NULL
117489 +fuse_conn_limit_write_30777 fuse_conn_limit_write 3 30777 NULL
117490 +__bio_alloc_30787 __bio_alloc 3 30787 NULL
117491 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
117492 +get_kobj_path_length_30831 get_kobj_path_length 0 30831 NULL
117493 +ath10k_write_fw_dbglog_30835 ath10k_write_fw_dbglog 3 30835 NULL
117494 +of_gpio_named_count_30841 of_gpio_named_count 0 30841 NULL
117495 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
117496 +wd_autoreset_write_30862 wd_autoreset_write 3 30862 NULL
117497 +ieee80211_if_fmt_dropped_frames_no_route_30884 ieee80211_if_fmt_dropped_frames_no_route 3 30884 NULL
117498 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
117499 +usnic_debugfs_buildinfo_read_30928 usnic_debugfs_buildinfo_read 3 30928 NULL
117500 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
117501 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
117502 +huge_page_mask_30981 huge_page_mask 0 30981 NULL
117503 +read_file_bt_ant_diversity_30983 read_file_bt_ant_diversity 3 30983 NULL
117504 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
117505 +ima_eventsig_init_31022 ima_eventsig_init 5 31022 NULL
117506 +template_fmt_size_31033 template_fmt_size 0 31033 NULL
117507 +do_setup_msi_irqs_31043 do_setup_msi_irqs 2 31043 NULL
117508 +stride_pg_count_31053 stride_pg_count 0-3-2-1-4-5 31053 NULL
117509 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
117510 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
117511 +proc_gid_map_write_31093 proc_gid_map_write 3 31093 NULL
117512 +depth_read_31112 depth_read 3 31112 NULL
117513 +hash_ipportnet6_expire_31118 hash_ipportnet6_expire 4 31118 NULL
117514 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
117515 +size_inside_page_31141 size_inside_page 0 31141 NULL
117516 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
117517 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
117518 +r592_read_fifo_pio_31198 r592_read_fifo_pio 3 31198 NULL
117519 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
117520 +__btrfs_free_reserved_extent_31207 __btrfs_free_reserved_extent 2 31207 NULL
117521 +cpumask_weight_31215 cpumask_weight 0 31215 NULL
117522 +__read_reg_31216 __read_reg 0 31216 NULL
117523 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
117524 +tcp_recvmsg_31238 tcp_recvmsg 4 31238 NULL
117525 +cyy_readb_31240 cyy_readb 0 31240 NULL
117526 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
117527 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
117528 +hash_netportnet4_expire_31290 hash_netportnet4_expire 4 31290 NULL
117529 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
117530 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
117531 +command_file_write_31318 command_file_write 3 31318 NULL
117532 +hwerr_crcbits_31334 hwerr_crcbits 4 31334 NULL
117533 +_regmap_raw_multi_reg_write_31336 _regmap_raw_multi_reg_write 3 31336 NULL
117534 +em28xx_init_usb_xfer_31337 em28xx_init_usb_xfer 4-6 31337 NULL
117535 +outlen_write_31358 outlen_write 3 31358 NULL
117536 +ieee80211_rx_mgmt_auth_31366 ieee80211_rx_mgmt_auth 3 31366 NULL
117537 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
117538 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3-2 31374 NULL
117539 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
117540 +inb_31388 inb 0 31388 NULL
117541 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
117542 +_sp2d_max_pg_31422 _sp2d_max_pg 0 31422 NULL
117543 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
117544 +snd_aw2_saa7146_get_hw_ptr_capture_31431 snd_aw2_saa7146_get_hw_ptr_capture 0 31431 NULL
117545 +transport_alloc_session_tags_31449 transport_alloc_session_tags 2-3 31449 NULL
117546 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
117547 +xfs_btree_get_numrecs_31477 xfs_btree_get_numrecs 0 31477 NULL
117548 +alg_setkey_31485 alg_setkey 3 31485 NULL
117549 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
117550 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
117551 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
117552 +hidraw_write_31536 hidraw_write 3 31536 NULL
117553 +usbvision_read_31555 usbvision_read 3 31555 NULL
117554 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
117555 +get_max_inline_xattr_value_size_31578 get_max_inline_xattr_value_size 0 31578 NULL
117556 +osst_write_31581 osst_write 3 31581 NULL
117557 +snd_compr_get_avail_31584 snd_compr_get_avail 0 31584 NULL
117558 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
117559 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 NULL nohasharray
117560 +memblock_virt_alloc_nopanic_31617 memblock_virt_alloc_nopanic 1 31617 &arvo_sysfs_read_31617
117561 +usnic_ib_dump_vf_31623 usnic_ib_dump_vf 3 31623 NULL
117562 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
117563 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
117564 +xfer_secondary_pool_31661 xfer_secondary_pool 2 31661 NULL
117565 +__lgread_31668 __lgread 4 31668 NULL
117566 +copy_from_user_nmi_31672 copy_from_user_nmi 3-0 31672 NULL
117567 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
117568 +fst_recover_rx_error_31687 fst_recover_rx_error 3 31687 NULL
117569 +rs_pretty_print_rate_31727 rs_pretty_print_rate 0 31727 NULL
117570 +lu_buf_check_and_grow_31735 lu_buf_check_and_grow 2 31735 NULL nohasharray
117571 +utf16s_to_utf8s_31735 utf16s_to_utf8s 0 31735 &lu_buf_check_and_grow_31735
117572 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3-2 31741 NULL
117573 +input_abs_get_max_31742 input_abs_get_max 0 31742 NULL nohasharray
117574 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 &input_abs_get_max_31742
117575 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
117576 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
117577 +SyS_lsetxattr_31766 SyS_lsetxattr 4 31766 NULL
117578 +osync_buffers_list_31789 osync_buffers_list 0 31789 NULL
117579 +usblp_cache_device_id_string_31790 usblp_cache_device_id_string 0 31790 NULL
117580 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
117581 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
117582 +data_write_31805 data_write 3 31805 NULL
117583 +SyS_msgsnd_31814 SyS_msgsnd 3 31814 NULL
117584 +strnlen_user_31815 strnlen_user 0-2 31815 NULL
117585 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
117586 +clone_bio_31854 clone_bio 4-3 31854 NULL
117587 +SyS_ppoll_31855 SyS_ppoll 2 31855 NULL
117588 +iwl_dbgfs_disable_ht40_write_31876 iwl_dbgfs_disable_ht40_write 3 31876 NULL
117589 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
117590 +ddb_output_write_31902 ddb_output_write 3-0 31902 NULL
117591 +xattr_permission_31907 xattr_permission 0 31907 NULL
117592 +lu_buf_realloc_31915 lu_buf_realloc 2 31915 NULL
117593 +new_dir_31919 new_dir 3 31919 NULL
117594 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
117595 +era_status_31934 era_status 5 31934 NULL
117596 +SYSC_sethostname_31940 SYSC_sethostname 2 31940 NULL
117597 +read_mem_31942 read_mem 3 31942 NULL nohasharray
117598 +iov_iter_copy_from_user_31942 iov_iter_copy_from_user 4-0 31942 &read_mem_31942
117599 +ext4_zero_range_31944 ext4_zero_range 3-2 31944 NULL
117600 +vb2_write_31948 vb2_write 3 31948 NULL
117601 +pvr2_ctrl_get_valname_31951 pvr2_ctrl_get_valname 4 31951 NULL
117602 +regcache_rbtree_sync_31964 regcache_rbtree_sync 2 31964 NULL
117603 +iwl_rx_packet_payload_len_31965 iwl_rx_packet_payload_len 0 31965 NULL
117604 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
117605 +iblock_execute_rw_31982 iblock_execute_rw 3 31982 NULL nohasharray
117606 +vx_read_status_31982 vx_read_status 0 31982 &iblock_execute_rw_31982
117607 +find_next_zero_bit_31990 find_next_zero_bit 0 31990 NULL
117608 +lustre_acl_xattr_merge2posix_31992 lustre_acl_xattr_merge2posix 2 31992 NULL
117609 +sysfs_create_file_31996 sysfs_create_file 0 31996 NULL
117610 +calc_hmac_32010 calc_hmac 3 32010 NULL
117611 +aead_len_32021 aead_len 0 32021 NULL nohasharray
117612 +aer_init_32021 aer_init 0 32021 &aead_len_32021
117613 +stk_read_32038 stk_read 3 32038 NULL
117614 +SYSC_llistxattr_32061 SYSC_llistxattr 3 32061 NULL
117615 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
117616 +cow_file_range_inline_32091 cow_file_range_inline 3 32091 NULL
117617 +bio_alloc_32095 bio_alloc 2 32095 NULL
117618 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
117619 +disk_status_32120 disk_status 4 32120 NULL
117620 +kobject_add_internal_32133 kobject_add_internal 0 32133 NULL
117621 +venus_link_32165 venus_link 5 32165 NULL
117622 +do_writepages_32173 do_writepages 0 32173 NULL
117623 +del_ptr_32197 del_ptr 4 32197 NULL
117624 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
117625 +riva_get_cmap_len_32218 riva_get_cmap_len 0 32218 NULL
117626 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
117627 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
117628 +ocfs2_xattr_find_entry_32260 ocfs2_xattr_find_entry 0 32260 NULL
117629 +kvm_set_spte_hva_32312 kvm_set_spte_hva 2 32312 NULL
117630 +cas_calc_tabort_32316 cas_calc_tabort 0 32316 NULL
117631 +SyS_select_32319 SyS_select 1 32319 NULL
117632 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
117633 +nl80211_send_mlme_event_32337 nl80211_send_mlme_event 4 32337 NULL
117634 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
117635 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL nohasharray
117636 +rx_streaming_always_write_32357 rx_streaming_always_write 3 32357 &dispatch_ioctl_32357
117637 +sel_read_initcon_32362 sel_read_initcon 3 32362 NULL
117638 +ll_setxattr_common_32398 ll_setxattr_common 4 32398 NULL
117639 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
117640 +vmci_qp_alloc_32405 vmci_qp_alloc 5-3 32405 NULL
117641 +snd_pcm_sync_ptr_32461 snd_pcm_sync_ptr 0 32461 NULL
117642 +cache_status_32462 cache_status 5 32462 NULL
117643 +fill_readbuf_32464 fill_readbuf 3 32464 NULL
117644 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
117645 +bypass_pwoff_write_32499 bypass_pwoff_write 3 32499 NULL
117646 +mdc_pinger_recov_seq_write_32510 mdc_pinger_recov_seq_write 3 32510 NULL
117647 +ctrl_std_val_to_sym_32516 ctrl_std_val_to_sym 5 32516 NULL
117648 +disconnect_32521 disconnect 4 32521 NULL
117649 +qsfp_read_32522 qsfp_read 0-2-4 32522 NULL
117650 +ilo_read_32531 ilo_read 3 32531 NULL
117651 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
117652 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
117653 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
117654 +osc_iocontrol_32565 osc_iocontrol 3 32565 NULL
117655 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
117656 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
117657 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
117658 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
117659 +__pci_request_region_32618 __pci_request_region 0 32618 NULL
117660 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
117661 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
117662 +kvmalloc_32646 kvmalloc 1 32646 NULL
117663 +ib_sg_dma_len_32649 ib_sg_dma_len 0 32649 NULL
117664 +generic_readlink_32654 generic_readlink 3 32654 NULL
117665 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
117666 +compat_SyS_preadv_32679 compat_SyS_preadv 3 32679 NULL
117667 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
117668 +rt2x00debug_read_queue_dump_32712 rt2x00debug_read_queue_dump 3 32712 NULL
117669 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
117670 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
117671 +vmci_transport_dgram_dequeue_32775 vmci_transport_dgram_dequeue 4 32775 NULL
117672 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
117673 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
117674 +sta_tx_latency_stat_read_32862 sta_tx_latency_stat_read 3 32862 NULL
117675 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
117676 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 NULL nohasharray
117677 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 &ath6kl_usb_submit_ctrl_in_32880
117678 +vp702x_usb_inout_cmd_32884 vp702x_usb_inout_cmd 4-6 32884 NULL
117679 +tipc_link_iovec_xmit_fast_32913 tipc_link_iovec_xmit_fast 3 32913 NULL nohasharray
117680 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 &tipc_link_iovec_xmit_fast_32913
117681 +zlib_inflate_workspacesize_32927 zlib_inflate_workspacesize 0 32927 NULL
117682 +rmap_recycle_32938 rmap_recycle 3 32938 NULL
117683 +compat_filldir_32999 compat_filldir 3 32999 NULL
117684 +SyS_syslog_33007 SyS_syslog 3 33007 NULL
117685 +br_multicast_set_hash_max_33012 br_multicast_set_hash_max 2 33012 NULL
117686 +write_file_bt_ant_diversity_33019 write_file_bt_ant_diversity 3 33019 NULL
117687 +snd_pcm_prepare_33036 snd_pcm_prepare 0 33036 NULL
117688 +mic_virtio_copy_to_user_33048 mic_virtio_copy_to_user 3 33048 NULL
117689 +SYSC_lgetxattr_33049 SYSC_lgetxattr 4 33049 NULL
117690 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
117691 +ebt_compat_match_offset_33053 ebt_compat_match_offset 0-2 33053 NULL
117692 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
117693 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
117694 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
117695 +alloc_tio_33077 alloc_tio 3 33077 NULL
117696 +acl_permission_check_33083 acl_permission_check 0 33083 NULL
117697 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
117698 +notify_change_33143 notify_change 0 33143 NULL
117699 +SyS_poll_33152 SyS_poll 2 33152 NULL
117700 +_pci_add_cap_save_buffer_33153 _pci_add_cap_save_buffer 4 33153 NULL
117701 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
117702 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 3-2 33204 NULL
117703 +pp_read_33210 pp_read 3 33210 NULL
117704 +xfs_file_aio_write_33234 xfs_file_aio_write 4 33234 NULL
117705 +snd_pcm_plug_client_size_33267 snd_pcm_plug_client_size 0-2 33267 NULL
117706 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
117707 +sync_pt_create_33282 sync_pt_create 2 33282 NULL
117708 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
117709 +isku_sysfs_read_keys_easyzone_33318 isku_sysfs_read_keys_easyzone 6 33318 NULL
117710 +vx_send_irq_dsp_33329 vx_send_irq_dsp 0 33329 NULL
117711 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
117712 +lov_stripesize_seq_write_33353 lov_stripesize_seq_write 3 33353 NULL
117713 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
117714 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
117715 +pvscsi_allocate_sg_33357 pvscsi_allocate_sg 0 33357 NULL
117716 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
117717 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
117718 +scsi_varlen_cdb_length_33385 scsi_varlen_cdb_length 0 33385 NULL
117719 +nvc0_ram_create__33391 nvc0_ram_create_ 5 33391 NULL
117720 +ocfs2_allocate_unwritten_extents_33394 ocfs2_allocate_unwritten_extents 2-3 33394 NULL
117721 +cfs_trace_copyin_string_33396 cfs_trace_copyin_string 4 33396 NULL
117722 +snd_pcm_capture_ioctl1_33408 snd_pcm_capture_ioctl1 0 33408 NULL
117723 +hash_netiface6_expire_33421 hash_netiface6_expire 4 33421 NULL
117724 +dis_tap_write_33426 dis_tap_write 3 33426 NULL
117725 +message_stats_list_33440 message_stats_list 5 33440 NULL
117726 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
117727 +create_entry_33479 create_entry 2 33479 NULL
117728 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
117729 +res_counter_read_33499 res_counter_read 4 33499 NULL
117730 +hash_netnet4_expire_33500 hash_netnet4_expire 4 33500 NULL
117731 +fb_read_33506 fb_read 3 33506 NULL
117732 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
117733 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
117734 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
117735 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
117736 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL nohasharray
117737 +osc_max_rpcs_in_flight_seq_write_33539 osc_max_rpcs_in_flight_seq_write 3 33539 &tomoyo_read_self_33539
117738 +count_subheaders_33591 count_subheaders 0 33591 NULL
117739 +scsi_execute_33596 scsi_execute 5 33596 NULL
117740 +comedi_buf_write_n_allocated_33604 comedi_buf_write_n_allocated 0 33604 NULL
117741 +xt_compat_target_offset_33608 xt_compat_target_offset 0 33608 NULL
117742 +usb_gstrings_attach_33615 usb_gstrings_attach 3 33615 NULL nohasharray
117743 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 &usb_gstrings_attach_33615
117744 +stride_page_count_33641 stride_page_count 2 33641 NULL
117745 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
117746 +inw_p_33668 inw_p 0 33668 NULL
117747 +arp_hdr_len_33671 arp_hdr_len 0 33671 NULL
117748 +i2c_hid_alloc_buffers_33673 i2c_hid_alloc_buffers 2 33673 NULL
117749 +submit_one_bio_33683 submit_one_bio 0 33683 NULL
117750 +nv50_disp_dmac_create__33696 nv50_disp_dmac_create_ 6 33696 NULL
117751 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 NULL
117752 +tipc_link_stats_33716 tipc_link_stats 3 33716 NULL
117753 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
117754 +write_file_spectral_count_33723 write_file_spectral_count 3 33723 NULL
117755 +read_file_node_recv_33729 read_file_node_recv 3 33729 NULL
117756 +rtw_cbuf_alloc23a_33740 rtw_cbuf_alloc23a 1 33740 NULL
117757 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
117758 +hashtab_create_33769 hashtab_create 3 33769 NULL
117759 +i8042_create_aux_port_33777 i8042_create_aux_port 0 33777 NULL
117760 +if_sdio_read_rx_len_33800 if_sdio_read_rx_len 0 33800 NULL
117761 +filter_write_33819 filter_write 3 33819 NULL
117762 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
117763 +scrub_setup_recheck_block_33831 scrub_setup_recheck_block 5-4 33831 NULL
117764 +ext4_journal_extend_33835 ext4_journal_extend 2 33835 NULL
117765 +snd_pcm_action_nonatomic_33844 snd_pcm_action_nonatomic 0 33844 NULL
117766 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
117767 +get_user_pages_33908 get_user_pages 0 33908 NULL
117768 +sg_nents_33909 sg_nents 0 33909 NULL
117769 +ath6kl_roam_mode_write_33912 ath6kl_roam_mode_write 3 33912 NULL
117770 +queue_logical_block_size_33918 queue_logical_block_size 0 33918 NULL
117771 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
117772 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
117773 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
117774 +__proc_dump_kernel_33954 __proc_dump_kernel 5 33954 NULL
117775 +btrfs_delalloc_reserve_metadata_33963 btrfs_delalloc_reserve_metadata 0 33963 NULL
117776 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
117777 +lbs_lowrssi_write_34025 lbs_lowrssi_write 3 34025 NULL
117778 +ppp_write_34034 ppp_write 3 34034 NULL
117779 +tty_insert_flip_string_34042 tty_insert_flip_string 3-0 34042 NULL
117780 +calc_linear_pos_34067 calc_linear_pos 0-4 34067 NULL
117781 +memcg_update_all_caches_34068 memcg_update_all_caches 1 34068 NULL
117782 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
117783 +__irq_domain_add_34101 __irq_domain_add 2 34101 NULL
117784 +proc_scsi_host_write_34107 proc_scsi_host_write 3 34107 NULL
117785 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
117786 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2-0 34135 NULL
117787 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
117788 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
117789 +skb_to_sgvec_34171 skb_to_sgvec 0 34171 NULL
117790 +rsi_debug_zone_write_34206 rsi_debug_zone_write 3 34206 NULL
117791 +ext4_da_write_begin_34215 ext4_da_write_begin 3-4 34215 NULL
117792 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
117793 +device_private_init_34279 device_private_init 0 34279 NULL
117794 +ext4_get_groups_count_34324 ext4_get_groups_count 0 34324 NULL
117795 +pcpu_need_to_extend_34326 pcpu_need_to_extend 0 34326 NULL nohasharray
117796 +iov_iter_single_seg_count_34326 iov_iter_single_seg_count 0 34326 &pcpu_need_to_extend_34326
117797 +crypto_ablkcipher_ivsize_34363 crypto_ablkcipher_ivsize 0 34363 NULL nohasharray
117798 +sync_page_io_34363 sync_page_io 3 34363 &crypto_ablkcipher_ivsize_34363
117799 +rngapi_reset_34366 rngapi_reset 3 34366 NULL
117800 +_iwl_dbgfs_low_latency_write_34378 _iwl_dbgfs_low_latency_write 3 34378 NULL nohasharray
117801 +ea_read_34378 ea_read 0 34378 &_iwl_dbgfs_low_latency_write_34378
117802 +fuse_send_read_34379 fuse_send_read 4 34379 NULL
117803 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
117804 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
117805 +read_rbu_image_type_34387 read_rbu_image_type 6 34387 NULL
117806 +iwl_calib_set_34400 iwl_calib_set 3 34400 NULL nohasharray
117807 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 &iwl_calib_set_34400
117808 +wd_exp_mode_write_34407 wd_exp_mode_write 3 34407 NULL
117809 +nl80211_send_disassoc_34424 nl80211_send_disassoc 4 34424 NULL
117810 +__extent_read_full_page_34437 __extent_read_full_page 0 34437 NULL
117811 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
117812 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
117813 +skcipher_sndbuf_34476 skcipher_sndbuf 0 34476 NULL
117814 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
117815 +security_inode_permission_34488 security_inode_permission 0 34488 NULL
117816 +SyS_pwritev_34494 SyS_pwritev 3 34494 NULL
117817 +qp_alloc_res_34496 qp_alloc_res 5 34496 NULL
117818 +lu_buf_check_and_alloc_34505 lu_buf_check_and_alloc 2 34505 NULL
117819 +tracing_stats_read_34537 tracing_stats_read 3 34537 NULL nohasharray
117820 +ext4_fallocate_34537 ext4_fallocate 4-3 34537 &tracing_stats_read_34537
117821 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4-0 34547 NULL
117822 +dbBackSplit_34561 dbBackSplit 0 34561 NULL
117823 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL nohasharray
117824 +self_check_peb_ec_hdr_34564 self_check_peb_ec_hdr 0 34564 &alloc_ieee80211_rsl_34564
117825 +lov_stripecount_seq_write_34582 lov_stripecount_seq_write 3 34582 NULL
117826 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
117827 +inet6_ifla6_size_34591 inet6_ifla6_size 0 34591 NULL
117828 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL nohasharray
117829 +cw1200_queue_init_34599 cw1200_queue_init 4 34599 &ceph_msgpool_init_34599
117830 +bio_integrity_bytes_34602 bio_integrity_bytes 2 34602 NULL
117831 +__jffs2_ref_totlen_34609 __jffs2_ref_totlen 0 34609 NULL nohasharray
117832 +mtd_write_34609 mtd_write 0 34609 &__jffs2_ref_totlen_34609
117833 +__cfg80211_disconnected_34622 __cfg80211_disconnected 3 34622 NULL
117834 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
117835 +kvm_set_spte_hva_34671 kvm_set_spte_hva 2 34671 NULL
117836 +sleep_auth_write_34676 sleep_auth_write 3 34676 NULL
117837 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
117838 +batadv_tvlv_realloc_packet_buff_34688 batadv_tvlv_realloc_packet_buff 3-4 34688 NULL
117839 +port_print_34704 port_print 3 34704 NULL
117840 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
117841 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
117842 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
117843 +lsm_alloc_plain_34755 lsm_alloc_plain 1 34755 NULL
117844 +bootmode_store_34762 bootmode_store 4 34762 NULL
117845 +device_add_34766 device_add 0 34766 NULL
117846 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
117847 +SYSC_keyctl_34800 SYSC_keyctl 4 34800 NULL
117848 +can_nocow_extent_34801 can_nocow_extent 2 34801 NULL
117849 +drbd_get_max_capacity_34804 drbd_get_max_capacity 0 34804 NULL
117850 +ll_setxattr_34806 ll_setxattr 4 34806 NULL
117851 +file_page_index_34820 file_page_index 0-2 34820 NULL
117852 +bio_segments_34832 bio_segments 0 34832 NULL
117853 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
117854 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
117855 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
117856 +usb_serial_generic_prepare_write_buffer_34857 usb_serial_generic_prepare_write_buffer 3 34857 NULL
117857 +ieee80211_if_read_txpower_34871 ieee80211_if_read_txpower 3 34871 NULL
117858 +msg_print_text_34889 msg_print_text 0 34889 NULL
117859 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
117860 +si476x_radio_read_rsq_primary_blob_34916 si476x_radio_read_rsq_primary_blob 3 34916 NULL
117861 +__inode_permission_34925 __inode_permission 0 34925 NULL nohasharray
117862 +btrfs_super_chunk_root_34925 btrfs_super_chunk_root 0 34925 &__inode_permission_34925
117863 +ceph_aio_write_34930 ceph_aio_write 4 34930 NULL
117864 +sec_flags2str_34933 sec_flags2str 3 34933 NULL
117865 +snd_info_entry_read_34938 snd_info_entry_read 3 34938 NULL
117866 +do_add_page_to_bio_34974 do_add_page_to_bio 2-10 34974 NULL
117867 +schedule_erase_34996 schedule_erase 0 34996 NULL
117868 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
117869 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
117870 +rtw_cfg80211_rx_p2p_action_public_35010 rtw_cfg80211_rx_p2p_action_public 3 35010 NULL
117871 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
117872 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
117873 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
117874 +__kfifo_uint_must_check_helper_35097 __kfifo_uint_must_check_helper 0-1 35097 NULL
117875 +capi_write_35104 capi_write 3 35104 NULL nohasharray
117876 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
117877 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
117878 +message_stats_print_35158 message_stats_print 6 35158 NULL
117879 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
117880 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
117881 +compat_SyS_pselect6_35203 compat_SyS_pselect6 1 35203 NULL
117882 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
117883 +security_key_getsecurity_35218 security_key_getsecurity 0 35218 NULL nohasharray
117884 +striped_read_35218 striped_read 0-2 35218 &security_key_getsecurity_35218
117885 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
117886 +set_fd_set_35249 set_fd_set 1 35249 NULL
117887 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
117888 +dis_disc_write_35265 dis_disc_write 3 35265 NULL
117889 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
117890 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
117891 +i2o_block_end_request_35282 i2o_block_end_request 3 35282 NULL
117892 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
117893 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3-0 35311 NULL nohasharray
117894 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 &__btrfs_buffered_write_35311
117895 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
117896 +sta_tx_latency_stat_write_35323 sta_tx_latency_stat_write 3 35323 NULL
117897 +ieee80211_if_fmt_ap_power_level_35347 ieee80211_if_fmt_ap_power_level 3 35347 NULL
117898 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
117899 +ieee80211_rx_mgmt_deauth_35351 ieee80211_rx_mgmt_deauth 3 35351 NULL
117900 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
117901 +read_kmem_35372 read_kmem 3 35372 NULL
117902 +SyS_getxattr_35408 SyS_getxattr 4 35408 NULL
117903 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
117904 +iwl_dbgfs_drv_rx_stats_read_35430 iwl_dbgfs_drv_rx_stats_read 3 35430 NULL
117905 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
117906 +efx_mcdi_rpc_async_quiet_35460 efx_mcdi_rpc_async_quiet 4-5 35460 NULL
117907 +macvtap_do_read_35475 macvtap_do_read 3 35475 NULL
117908 +fiemap_prepare_and_copy_exts_35494 fiemap_prepare_and_copy_exts 5 35494 NULL
117909 +btrfs_prealloc_file_range_trans_35500 btrfs_prealloc_file_range_trans 4 35500 NULL
117910 +async_setkey_35521 async_setkey 3 35521 NULL
117911 +__filemap_fdatawrite_range_35528 __filemap_fdatawrite_range 0 35528 NULL
117912 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
117913 +pstore_mkfile_35536 pstore_mkfile 7 35536 NULL
117914 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
117915 +ocfs2_write_zero_page_35539 ocfs2_write_zero_page 3 35539 NULL
117916 +ibnl_put_attr_35541 ibnl_put_attr 3 35541 NULL
117917 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
117918 +ext4_blocks_for_truncate_35579 ext4_blocks_for_truncate 0 35579 NULL
117919 +ext2_acl_from_disk_35580 ext2_acl_from_disk 2 35580 NULL
117920 +spk_msg_set_35586 spk_msg_set 3 35586 NULL
117921 +kernel_readv_35617 kernel_readv 3 35617 NULL
117922 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
117923 +pci_request_regions_35635 pci_request_regions 0 35635 NULL
117924 +ptlrpcd_steal_rqset_35637 ptlrpcd_steal_rqset 0 35637 NULL
117925 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
117926 +rdmaltWithLock_35669 rdmaltWithLock 0 35669 NULL
117927 +SYSC_pwritev_35690 SYSC_pwritev 3 35690 NULL
117928 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
117929 +md_super_write_35703 md_super_write 4 35703 NULL
117930 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
117931 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
117932 +pvr2_hdw_cpufw_get_35824 pvr2_hdw_cpufw_get 0-4-2 35824 NULL
117933 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
117934 +vx_query_hbuffer_size_35859 vx_query_hbuffer_size 0 35859 NULL
117935 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
117936 +fls64_35862 fls64 0 35862 NULL
117937 +kvm_dirty_bitmap_bytes_35886 kvm_dirty_bitmap_bytes 0 35886 NULL
117938 +ieee80211_if_fmt_dot11MeshRetryTimeout_35890 ieee80211_if_fmt_dot11MeshRetryTimeout 3 35890 NULL
117939 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
117940 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
117941 +rbio_nr_pages_35916 rbio_nr_pages 0-1-2 35916 NULL
117942 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
117943 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
117944 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
117945 +ext_rts51x_sd_execute_write_data_35971 ext_rts51x_sd_execute_write_data 9 35971 NULL
117946 +generic_ocp_read_35974 generic_ocp_read 3 35974 NULL nohasharray
117947 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 &generic_ocp_read_35974
117948 +acl_alloc_35979 acl_alloc 1 35979 NULL
117949 +device_add_class_symlinks_35985 device_add_class_symlinks 0 35985 NULL
117950 +kuc_alloc_35998 kuc_alloc 1 35998 NULL nohasharray
117951 +write_file_antenna_35998 write_file_antenna 3 35998 &kuc_alloc_35998
117952 +scsi_transfer_length_36011 scsi_transfer_length 0 36011 NULL
117953 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
117954 +ubi_eba_write_leb_36029 ubi_eba_write_leb 0 36029 NULL
117955 +__videobuf_alloc_36031 __videobuf_alloc 1 36031 NULL
117956 +account_shadowed_36048 account_shadowed 2 36048 NULL
117957 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
117958 +snd_pcm_playback_hw_avail_36061 snd_pcm_playback_hw_avail 0 36061 NULL
117959 +write_emulate_36065 write_emulate 2-4 36065 NULL
117960 +stack_max_size_write_36068 stack_max_size_write 3 36068 NULL
117961 +radeon_vm_num_pdes_36070 radeon_vm_num_pdes 0 36070 NULL
117962 +ieee80211_if_fmt_peer_36071 ieee80211_if_fmt_peer 3 36071 NULL
117963 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
117964 +snd_pcm_plug_read_transfer_36080 snd_pcm_plug_read_transfer 0-3 36080 NULL
117965 +mtip_hw_read_device_status_36082 mtip_hw_read_device_status 3 36082 NULL
117966 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
117967 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
117968 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
117969 +twl_set_36154 twl_set 2 36154 NULL
117970 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
117971 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
117972 +SyS_kexec_load_36176 SyS_kexec_load 2 36176 NULL
117973 +ramoops_init_przs_36199 ramoops_init_przs 4 36199 NULL
117974 +SYSC_sched_getaffinity_36208 SYSC_sched_getaffinity 2 36208 NULL
117975 +SYSC_process_vm_readv_36216 SYSC_process_vm_readv 3-5 36216 NULL
117976 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
117977 +rtw_cfg80211_set_wpa_ie_36236 rtw_cfg80211_set_wpa_ie 3 36236 NULL
117978 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
117979 +SYSC_getxattr_36242 SYSC_getxattr 4 36242 NULL
117980 +vmsplice_to_user_36245 vmsplice_to_user 3 36245 NULL nohasharray
117981 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 &vmsplice_to_user_36245
117982 +cfs_hash_buckets_realloc_36276 cfs_hash_buckets_realloc 4 36276 NULL nohasharray
117983 +usb_buffer_alloc_36276 usb_buffer_alloc 2 36276 &cfs_hash_buckets_realloc_36276
117984 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
117985 +crypto_shash_digestsize_36284 crypto_shash_digestsize 0 36284 NULL
117986 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
117987 +cfg80211_rx_mlme_mgmt_36306 cfg80211_rx_mlme_mgmt 3 36306 NULL
117988 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
117989 +__compat_sys_pwritev64_36328 __compat_sys_pwritev64 3 36328 NULL nohasharray
117990 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 &__compat_sys_pwritev64_36328
117991 +lc_create_36332 lc_create 4 36332 NULL
117992 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
117993 +isku_sysfs_read_key_mask_36343 isku_sysfs_read_key_mask 6 36343 NULL
117994 +ath6kl_regwrite_write_36351 ath6kl_regwrite_write 3 36351 NULL
117995 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL
117996 +to_sector_36361 to_sector 0-1 36361 NULL
117997 +tunables_read_36385 tunables_read 3 36385 NULL
117998 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
117999 +sierra_write_36402 sierra_write 4 36402 NULL
118000 +SyS_sethostname_36417 SyS_sethostname 2 36417 NULL
118001 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
118002 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
118003 +SyS_process_vm_writev_36476 SyS_process_vm_writev 3-5 36476 NULL
118004 +lock_and_cleanup_extent_if_need_36480 lock_and_cleanup_extent_if_need 0 36480 NULL
118005 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
118006 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 NULL nohasharray
118007 +ip6_append_data_36490 ip6_append_data 4 36490 &tx_tx_checksum_result_read_36490
118008 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
118009 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
118010 +_iwl_dbgfs_fw_nmi_write_36515 _iwl_dbgfs_fw_nmi_write 3 36515 NULL
118011 +get_param_l_36518 get_param_l 0 36518 NULL
118012 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
118013 +crypto_aead_authsize_36537 crypto_aead_authsize 0 36537 NULL
118014 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
118015 +__kfifo_to_user_36555 __kfifo_to_user 3-0 36555 NULL
118016 +btrfs_get_token_64_36572 btrfs_get_token_64 0 36572 NULL
118017 +__erst_read_36579 __erst_read 0 36579 NULL
118018 +put_cmsg_36589 put_cmsg 4 36589 NULL
118019 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
118020 +vxge_config_vpaths_36636 vxge_config_vpaths 0 36636 NULL
118021 +convert_extent_item_v0_36645 convert_extent_item_v0 4 36645 NULL
118022 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
118023 +lpfc_idiag_extacc_alloc_get_36648 lpfc_idiag_extacc_alloc_get 0-3 36648 NULL
118024 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
118025 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
118026 +xillybus_read_36678 xillybus_read 3 36678 NULL
118027 +gsmtty_write_36702 gsmtty_write 3 36702 NULL
118028 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4-0 36740 NULL
118029 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
118030 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
118031 +i40e_init_lan_hmc_36796 i40e_init_lan_hmc 5-4-3-2 36796 NULL
118032 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
118033 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
118034 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
118035 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
118036 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
118037 +cm_write_36858 cm_write 3 36858 NULL
118038 +tipc_link_iovec_long_xmit_36871 tipc_link_iovec_long_xmit 3 36871 NULL nohasharray
118039 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 &tipc_link_iovec_long_xmit_36871
118040 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
118041 +raid56_parity_write_36877 raid56_parity_write 5 36877 NULL
118042 +__btrfs_map_block_36883 __btrfs_map_block 3 36883 NULL
118043 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
118044 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
118045 +OS_kmalloc_36909 OS_kmalloc 1 36909 NULL
118046 +il4965_rs_sta_dbgfs_scale_table_write_36979 il4965_rs_sta_dbgfs_scale_table_write 3 36979 NULL
118047 +drbd_new_dev_size_36998 drbd_new_dev_size 0-3 36998 NULL
118048 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
118049 +setxattr_37006 setxattr 4 37006 NULL
118050 +command_file_read_37038 command_file_read 3 37038 NULL
118051 +figure_loop_size_37051 figure_loop_size 2-3 37051 NULL
118052 +qp_broker_create_37053 qp_broker_create 6-5 37053 NULL nohasharray
118053 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 &qp_broker_create_37053
118054 +_iwl_dbgfs_bcast_filters_macs_write_37069 _iwl_dbgfs_bcast_filters_macs_write 3 37069 NULL
118055 +SYSC_setxattr_37078 SYSC_setxattr 4 37078 NULL
118056 +parse_command_37079 parse_command 2 37079 NULL
118057 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
118058 +tun_get_user_37094 tun_get_user 5 37094 NULL
118059 +has_wrprotected_page_37123 has_wrprotected_page 2-3 37123 NULL
118060 +snd_hda_get_conn_list_37132 snd_hda_get_conn_list 0 37132 NULL
118061 +mtt_free_res_37144 mtt_free_res 5 37144 NULL
118062 +msg_word_37164 msg_word 0 37164 NULL
118063 +f2fs_direct_IO_37167 f2fs_direct_IO 4 37167 NULL
118064 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
118065 +forced_ps_write_37209 forced_ps_write 3 37209 NULL
118066 +crypto_shash_descsize_37212 crypto_shash_descsize 0 37212 NULL nohasharray
118067 +ext4_ind_direct_IO_37212 ext4_ind_direct_IO 4-0 37212 &crypto_shash_descsize_37212
118068 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
118069 +__do_replace_37227 __do_replace 5 37227 NULL
118070 +iwl_dbgfs_d3_sram_read_37237 iwl_dbgfs_d3_sram_read 3 37237 NULL
118071 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL
118072 +prot_queue_del_37258 prot_queue_del 0 37258 NULL
118073 +exofs_max_io_pages_37263 exofs_max_io_pages 0-2 37263 NULL
118074 +_iwl_dbgfs_fw_restart_write_37270 _iwl_dbgfs_fw_restart_write 3 37270 NULL
118075 +request_threaded_irq_37303 request_threaded_irq 0 37303 NULL
118076 +ieee80211_if_read_power_mode_37305 ieee80211_if_read_power_mode 3 37305 NULL
118077 +ext3_direct_IO_37308 ext3_direct_IO 4 37308 NULL
118078 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
118079 +tipc_send_37315 tipc_send 3 37315 NULL
118080 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL nohasharray
118081 +bnx2x_vf_fill_fw_str_37327 bnx2x_vf_fill_fw_str 3 37327 &l2cap_create_connless_pdu_37327
118082 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
118083 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
118084 +security_inode_getsecurity_37354 security_inode_getsecurity 0 37354 NULL
118085 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
118086 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
118087 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4-0 37428 NULL
118088 +iwl_print_last_event_logs_37433 iwl_print_last_event_logs 0-7-9 37433 NULL
118089 +fru_alloc_37442 fru_alloc 1 37442 NULL
118090 +tcp_established_options_37450 tcp_established_options 0 37450 NULL
118091 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
118092 +get_est_timing_37484 get_est_timing 0 37484 NULL
118093 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
118094 +bitmap_dirty_bits_37503 bitmap_dirty_bits 2 37503 NULL
118095 +osc_active_seq_write_37514 osc_active_seq_write 3 37514 NULL
118096 +bdev_writeseg_37519 bdev_writeseg 2-3 37519 NULL
118097 +xz_dec_test_write_37527 xz_dec_test_write 3 37527 NULL
118098 +fault_inject_read_37534 fault_inject_read 3 37534 NULL
118099 +hdr_size_37536 hdr_size 0 37536 NULL
118100 +extent_map_end_37550 extent_map_end 0 37550 NULL
118101 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL
118102 +fat_cont_expand_37552 fat_cont_expand 0 37552 NULL
118103 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
118104 +qla2x00_debounce_register_37597 qla2x00_debounce_register 0 37597 NULL
118105 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
118106 +SYSC_mbind_37622 SYSC_mbind 5 37622 NULL
118107 +SyS_mbind_37638 SyS_mbind 5 37638 NULL
118108 +may_delete_37656 may_delete 0 37656 NULL
118109 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
118110 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 NULL nohasharray
118111 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 &vmw_framebuffer_dmabuf_dirty_37661
118112 +SYSC_get_mempolicy_37664 SYSC_get_mempolicy 3 37664 NULL
118113 +__wa_seg_calculate_isoc_frame_count_37672 __wa_seg_calculate_isoc_frame_count 0 37672 NULL
118114 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
118115 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
118116 +nametbl_header_37698 nametbl_header 2-0 37698 NULL
118117 +__le32_to_cpup_37702 __le32_to_cpup 0 37702 NULL
118118 +dynamic_ps_timeout_write_37713 dynamic_ps_timeout_write 3 37713 NULL
118119 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
118120 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
118121 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
118122 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
118123 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
118124 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
118125 +ocrdma_alloc_frmr_page_list_37815 ocrdma_alloc_frmr_page_list 2 37815 NULL
118126 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
118127 +android_get_p2p_addr_37832 android_get_p2p_addr 0 37832 NULL
118128 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
118129 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
118130 +set_registers_37883 set_registers 4 37883 NULL
118131 +btrfs_stack_file_extent_disk_bytenr_37888 btrfs_stack_file_extent_disk_bytenr 0 37888 NULL
118132 +_rtw_malloc_37928 _rtw_malloc 1 37928 NULL nohasharray
118133 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 &_rtw_malloc_37928
118134 +read_rbu_packet_size_37939 read_rbu_packet_size 6 37939 NULL
118135 +write_file_bool_37957 write_file_bool 3 37957 NULL
118136 +fifo_alloc_37961 fifo_alloc 1 37961 NULL
118137 +rds_rdma_extra_size_37990 rds_rdma_extra_size 0 37990 NULL
118138 +persistent_ram_old_size_37997 persistent_ram_old_size 0 37997 NULL
118139 +vfs_readv_38011 vfs_readv 3 38011 NULL
118140 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
118141 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL nohasharray
118142 +klsi_105_prepare_write_buffer_38044 klsi_105_prepare_write_buffer 3 38044 &il_dbgfs_chain_noise_read_38044
118143 +SyS_llistxattr_38048 SyS_llistxattr 3 38048 NULL
118144 +sysfs_do_create_link_38051 sysfs_do_create_link 0 38051 NULL
118145 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
118146 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
118147 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
118148 +wcn36xx_smd_rsp_process_38081 wcn36xx_smd_rsp_process 3 38081 NULL nohasharray
118149 +xfs_buf_readahead_map_38081 xfs_buf_readahead_map 3 38081 &wcn36xx_smd_rsp_process_38081
118150 +uwb_mac_addr_print_38085 uwb_mac_addr_print 2 38085 NULL
118151 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
118152 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
118153 +ep0_read_38095 ep0_read 3 38095 NULL
118154 +osc_checksum_seq_write_38096 osc_checksum_seq_write 3 38096 NULL nohasharray
118155 +sk_wmem_schedule_38096 sk_wmem_schedule 2 38096 &osc_checksum_seq_write_38096
118156 +o2hb_read_slots_38105 o2hb_read_slots 2 38105 NULL
118157 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
118158 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
118159 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 4-3-0 38153 NULL
118160 +btrfs_extent_same_38163 btrfs_extent_same 3-2 38163 NULL
118161 +kvm_clear_guest_38164 kvm_clear_guest 3-2 38164 NULL
118162 +cdev_add_38176 cdev_add 2-3 38176 NULL
118163 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
118164 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
118165 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
118166 +ceph_decode_16_38239 ceph_decode_16 0 38239 NULL
118167 +_ipw_read_reg32_38245 _ipw_read_reg32 0 38245 NULL
118168 +snd_pcm_playback_rewind_38249 snd_pcm_playback_rewind 0-2 38249 NULL
118169 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 NULL nohasharray
118170 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 &mthca_alloc_icm_table_38268
118171 +xfs_bmbt_to_bmdr_38275 xfs_bmbt_to_bmdr 3 38275 NULL nohasharray
118172 +xfs_bmdr_to_bmbt_38275 xfs_bmdr_to_bmbt 5 38275 &xfs_bmbt_to_bmdr_38275
118173 +ftdi_process_packet_38281 ftdi_process_packet 4 38281 NULL
118174 +C_SYSC_pselect6_38296 C_SYSC_pselect6 1 38296 NULL
118175 +ucma_query_path_38305 ucma_query_path 3 38305 NULL
118176 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
118177 +ida_simple_get_38326 ida_simple_get 0 38326 NULL
118178 +__snd_gf1_look8_38333 __snd_gf1_look8 0 38333 NULL
118179 +btrfs_file_extent_disk_num_bytes_38363 btrfs_file_extent_disk_num_bytes 0 38363 NULL
118180 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
118181 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
118182 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
118183 +kvm_write_guest_38454 kvm_write_guest 4-2 38454 NULL
118184 +_iwl_dbgfs_scan_ant_rxchain_write_38479 _iwl_dbgfs_scan_ant_rxchain_write 3 38479 NULL
118185 +blk_end_bidi_request_38482 blk_end_bidi_request 3-4 38482 NULL
118186 +dev_names_read_38509 dev_names_read 3 38509 NULL
118187 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
118188 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
118189 +set_queue_count_38519 set_queue_count 0 38519 NULL
118190 +ubifs_idx_node_sz_38546 ubifs_idx_node_sz 0-2 38546 NULL
118191 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
118192 +kuc_len_38557 kuc_len 0-1 38557 NULL
118193 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
118194 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
118195 +_ipw_read32_38565 _ipw_read32 0 38565 NULL
118196 +snd_nm256_playback_copy_38567 snd_nm256_playback_copy 3-5 38567 NULL
118197 +copy_ctl_value_to_user_38587 copy_ctl_value_to_user 4 38587 NULL
118198 +rd_allocate_sgl_table_38607 rd_allocate_sgl_table 3 38607 NULL
118199 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
118200 +write_enabled_file_bool_38630 write_enabled_file_bool 3 38630 NULL
118201 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
118202 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
118203 +qp_broker_alloc_38646 qp_broker_alloc 6-5 38646 NULL
118204 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
118205 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
118206 +snd_es1371_wait_src_ready_38673 snd_es1371_wait_src_ready 0 38673 NULL
118207 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
118208 +validate_vid_hdr_38699 validate_vid_hdr 0 38699 NULL
118209 +rbio_add_io_page_38700 rbio_add_io_page 6 38700 NULL
118210 +udf_readpages_38761 udf_readpages 4 38761 NULL
118211 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
118212 +bcache_device_init_38781 bcache_device_init 3 38781 NULL
118213 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
118214 +do_pci_enable_device_38802 do_pci_enable_device 0 38802 NULL
118215 +err_decode_38804 err_decode 2 38804 NULL
118216 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
118217 +direct_entry_38836 direct_entry 3 38836 NULL
118218 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
118219 +read_nic_io_word_38853 read_nic_io_word 0 38853 NULL
118220 +interfaces_38859 interfaces 2 38859 NULL
118221 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
118222 +il_dbgfs_sram_write_38942 il_dbgfs_sram_write 3 38942 NULL
118223 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
118224 +usb_maxpacket_38977 usb_maxpacket 0 38977 NULL nohasharray
118225 +C_SYSC_preadv64_38977 C_SYSC_preadv64 3 38977 &usb_maxpacket_38977
118226 +OSDSetBlock_38986 OSDSetBlock 2-4 38986 NULL
118227 +bio_clone_range_38997 bio_clone_range 2 38997 NULL
118228 +lpfc_idiag_extacc_write_38998 lpfc_idiag_extacc_write 3 38998 NULL
118229 +get_nodes_39012 get_nodes 3 39012 NULL
118230 +twl6030_interrupt_unmask_39013 twl6030_interrupt_unmask 2 39013 NULL
118231 +force_sc_support_read_39014 force_sc_support_read 3 39014 NULL
118232 +__blkdev_issue_zeroout_39020 __blkdev_issue_zeroout 3 39020 NULL
118233 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
118234 +do_write_kmem_39051 do_write_kmem 0-1-3 39051 NULL
118235 +tomoyo_truncate_39105 tomoyo_truncate 0 39105 NULL
118236 +leb_write_lock_39111 leb_write_lock 0 39111 NULL
118237 +__kfifo_to_user_r_39123 __kfifo_to_user_r 5-3 39123 NULL
118238 +ea_foreach_39133 ea_foreach 0 39133 NULL
118239 +generic_permission_39150 generic_permission 0 39150 NULL
118240 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
118241 +ath9k_hw_ar9003_dump_eeprom_39156 ath9k_hw_ar9003_dump_eeprom 5-4 39156 NULL
118242 +echo_client_kbrw_39170 echo_client_kbrw 6 39170 NULL
118243 +ext3_xattr_check_names_39174 ext3_xattr_check_names 0 39174 NULL
118244 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
118245 +qcam_read_bytes_39205 qcam_read_bytes 0 39205 NULL
118246 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
118247 +posix_acl_to_xattr_39237 posix_acl_to_xattr 0 39237 NULL
118248 +snd_pcm_capture_forward_39248 snd_pcm_capture_forward 0-2 39248 NULL
118249 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
118250 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
118251 +i915_error_state_read_39254 i915_error_state_read 3 39254 NULL
118252 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
118253 +_iwl_dbgfs_pm_params_write_39325 _iwl_dbgfs_pm_params_write 3 39325 NULL
118254 +__cfg80211_connect_result_39326 __cfg80211_connect_result 4-6 39326 NULL
118255 +insert_reserved_file_extent_39327 insert_reserved_file_extent 3 39327 NULL
118256 +wimax_msg_alloc_39343 wimax_msg_alloc 4 39343 NULL
118257 +ide_complete_rq_39354 ide_complete_rq 3 39354 NULL
118258 +do_write_log_from_user_39362 do_write_log_from_user 3-0 39362 NULL
118259 +vortex_wtdma_getlinearpos_39371 vortex_wtdma_getlinearpos 0 39371 NULL
118260 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
118261 +fnic_trace_debugfs_read_39380 fnic_trace_debugfs_read 3 39380 NULL
118262 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
118263 +__send_to_port_39386 __send_to_port 3 39386 NULL
118264 +user_power_read_39414 user_power_read 3 39414 NULL
118265 +hash_ipmark4_expire_39419 hash_ipmark4_expire 4 39419 NULL
118266 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
118267 +mic_desc_size_39464 mic_desc_size 0 39464 NULL
118268 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
118269 +ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries_39499 ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries 3 39499 NULL
118270 +cl_req_alloc_39523 cl_req_alloc 4 39523 NULL
118271 +int_proc_write_39542 int_proc_write 3 39542 NULL
118272 +ext4_alloc_file_blocks_39551 ext4_alloc_file_blocks 3 39551 NULL
118273 +pp_write_39554 pp_write 3 39554 NULL
118274 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
118275 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
118276 +memblock_virt_alloc_internal_39600 memblock_virt_alloc_internal 1 39600 NULL
118277 +ext_depth_39607 ext_depth 0 39607 NULL
118278 +batadv_tt_tvlv_generate_39615 batadv_tt_tvlv_generate 4 39615 NULL
118279 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
118280 +sdio_readb_39618 sdio_readb 0 39618 NULL
118281 +prepare_uptodate_page_39622 prepare_uptodate_page 0 39622 NULL
118282 +set_dev_class_39645 set_dev_class 4 39645 NULL
118283 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
118284 +tcp_try_rmem_schedule_39657 tcp_try_rmem_schedule 3 39657 NULL
118285 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
118286 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
118287 +hsc_msg_len_get_39673 hsc_msg_len_get 0 39673 NULL
118288 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
118289 +sd_completed_bytes_39705 sd_completed_bytes 0 39705 NULL
118290 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
118291 +adt7316_spi_multi_read_39765 adt7316_spi_multi_read 3 39765 NULL
118292 +security_inode_listsecurity_39812 security_inode_listsecurity 0 39812 NULL
118293 +snd_pcm_oss_writev3_39818 snd_pcm_oss_writev3 3 39818 NULL
118294 +get_priv_size_39828 get_priv_size 0-1 39828 NULL
118295 +pkt_add_39897 pkt_add 3 39897 NULL
118296 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
118297 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
118298 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
118299 +__mnt_want_write_file_39917 __mnt_want_write_file 0 39917 NULL
118300 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
118301 +exofs_read_kern_39921 exofs_read_kern 6 39921 NULL nohasharray
118302 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 &exofs_read_kern_39921
118303 +__spi_async_39932 __spi_async 0 39932 NULL
118304 +__get_order_39935 __get_order 0 39935 NULL
118305 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL
118306 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3-0 39955 NULL
118307 +lstcon_group_list_39958 lstcon_group_list 2 39958 NULL
118308 +bio_chain_clone_range_39967 bio_chain_clone_range 3 39967 NULL
118309 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
118310 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
118311 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
118312 +fw_device_op_read_39990 fw_device_op_read 3 39990 NULL
118313 +server_name2svname_39998 server_name2svname 4 39998 NULL
118314 +xen_hvm_config_40018 xen_hvm_config 2 40018 NULL
118315 +ivtvfb_write_40023 ivtvfb_write 3 40023 NULL
118316 +disc_pwup_write_40027 disc_pwup_write 3 40027 NULL
118317 +ea_foreach_i_40028 ea_foreach_i 0 40028 NULL
118318 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
118319 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 NULL nohasharray
118320 +add_tty_40055 add_tty 1 40055 &l2cap_create_iframe_pdu_40055
118321 +atomic_xchg_40070 atomic_xchg 0 40070 NULL
118322 +snd_pcm_sw_params_user_40095 snd_pcm_sw_params_user 0 40095 NULL
118323 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
118324 +dwc2_max_desc_num_40132 dwc2_max_desc_num 0 40132 NULL
118325 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
118326 +ath10k_write_simulate_fw_crash_40143 ath10k_write_simulate_fw_crash 3 40143 NULL
118327 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
118328 +pt_write_40159 pt_write 3 40159 NULL
118329 +scsi_sg_count_40182 scsi_sg_count 0 40182 NULL
118330 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
118331 +allocate_probes_40204 allocate_probes 1 40204 NULL
118332 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
118333 +compress_file_range_40225 compress_file_range 3-4 40225 NULL
118334 +ocrdma_dbgfs_ops_read_40232 ocrdma_dbgfs_ops_read 3 40232 NULL
118335 +osst_read_40237 osst_read 3 40237 NULL
118336 +lpage_info_slot_40243 lpage_info_slot 1-3 40243 NULL
118337 +ocfs2_zero_extend_get_range_40248 ocfs2_zero_extend_get_range 4 40248 NULL
118338 +of_get_child_count_40254 of_get_child_count 0 40254 NULL
118339 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
118340 +ext2_fiemap_40271 ext2_fiemap 4 40271 NULL
118341 +usbnet_read_cmd_40275 usbnet_read_cmd 7 40275 NULL
118342 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
118343 +SyS_bind_40303 SyS_bind 3 40303 NULL
118344 +ubi_io_write_data_40305 ubi_io_write_data 0 40305 NULL
118345 +ib_get_mad_data_offset_40336 ib_get_mad_data_offset 0 40336 NULL
118346 +mmio_read_40348 mmio_read 4 40348 NULL
118347 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
118348 +ocfs2_check_range_for_refcount_40365 ocfs2_check_range_for_refcount 2-3 40365 NULL
118349 +get_chars_40373 get_chars 3 40373 NULL
118350 +fb_prepare_extra_logos_40429 fb_prepare_extra_logos 0-2 40429 NULL
118351 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
118352 +zd_usb_scnprint_id_40459 zd_usb_scnprint_id 0-3 40459 NULL
118353 +gp2ap020a00f_write_event_threshold_40461 gp2ap020a00f_write_event_threshold 2 40461 NULL
118354 +SyS_writev_40467 SyS_writev 3 40467 NULL
118355 +SyS_select_40473 SyS_select 1 40473 NULL
118356 +afs_fs_store_data_40484 afs_fs_store_data 3-4-5-6 40484 NULL
118357 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
118358 +devcgroup_inode_permission_40492 devcgroup_inode_permission 0 40492 NULL
118359 +__ethtool_get_sset_count_40511 __ethtool_get_sset_count 0 40511 NULL
118360 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
118361 +ixgbe_dbg_reg_ops_read_40540 ixgbe_dbg_reg_ops_read 3 40540 NULL
118362 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
118363 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
118364 +get_priv_descr_and_size_40612 get_priv_descr_and_size 0 40612 NULL
118365 +i2c_register_adapter_40660 i2c_register_adapter 0 40660 NULL
118366 +twl4030_kpwrite_u8_40665 twl4030_kpwrite_u8 3 40665 NULL
118367 +__cfg80211_roamed_40668 __cfg80211_roamed 4-6 40668 NULL
118368 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
118369 +fops_read_40672 fops_read 3 40672 NULL
118370 +idr_get_empty_slot_40674 idr_get_empty_slot 0 40674 NULL
118371 +alloc_rbio_40676 alloc_rbio 4 40676 NULL
118372 +videobuf_dma_init_user_locked_40678 videobuf_dma_init_user_locked 4-3 40678 NULL
118373 +pci_enable_resources_40680 pci_enable_resources 0 40680 NULL
118374 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
118375 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
118376 +set_extent_bit_40719 set_extent_bit 0 40719 NULL
118377 +of_pdt_build_one_prop_40735 of_pdt_build_one_prop 5 40735 NULL
118378 +fuse_readpages_40737 fuse_readpages 4 40737 NULL
118379 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
118380 +security_inode_listxattr_40752 security_inode_listxattr 0 40752 NULL
118381 +card_send_command_40757 card_send_command 3 40757 NULL
118382 +ad1889_readl_40765 ad1889_readl 0 40765 NULL
118383 +pg_write_40766 pg_write 3 40766 NULL
118384 +kernfs_fop_read_40770 kernfs_fop_read 3 40770 NULL
118385 +show_list_40775 show_list 3-0 40775 NULL
118386 +kfifo_out_copy_r_40784 kfifo_out_copy_r 0-3 40784 NULL
118387 +bitmap_weight_40791 bitmap_weight 0 40791 NULL
118388 +pyra_sysfs_read_40795 pyra_sysfs_read 6 40795 NULL
118389 +rtw_add_beacon_40801 rtw_add_beacon 3-5 40801 NULL
118390 +add_action_40811 add_action 4 40811 NULL
118391 +nl80211_send_roamed_40825 nl80211_send_roamed 5-7 40825 NULL
118392 +nilfs_mdt_init_40849 nilfs_mdt_init 3 40849 NULL
118393 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
118394 +read_file_queue_40895 read_file_queue 3 40895 NULL
118395 +waiters_read_40902 waiters_read 3 40902 NULL
118396 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
118397 +gfs2_ea_find_40913 gfs2_ea_find 0 40913 NULL
118398 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
118399 +snd_vx_create_40948 snd_vx_create 4 40948 NULL
118400 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
118401 +insert_old_idx_40987 insert_old_idx 0 40987 NULL
118402 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
118403 +iwl_dbgfs_scan_ant_rxchain_read_40999 iwl_dbgfs_scan_ant_rxchain_read 3 40999 NULL
118404 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
118405 +mtd_block_isbad_41015 mtd_block_isbad 0 41015 NULL
118406 +__proc_dobitmasks_41029 __proc_dobitmasks 5 41029 NULL
118407 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
118408 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
118409 +ocfs2_xattr_index_block_find_41040 ocfs2_xattr_index_block_find 0 41040 NULL
118410 +lprocfs_write_frac_helper_41050 lprocfs_write_frac_helper 2 41050 NULL
118411 +vfs_listxattr_41062 vfs_listxattr 0 41062 NULL nohasharray
118412 +beacon_filtering_write_41062 beacon_filtering_write 3 41062 &vfs_listxattr_41062
118413 +sc_only_mode_read_41076 sc_only_mode_read 3 41076 NULL
118414 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
118415 +nvme_map_user_pages_41093 nvme_map_user_pages 4-3 41093 NULL nohasharray
118416 +roccat_read_41093 roccat_read 3 41093 &nvme_map_user_pages_41093
118417 +dma_attach_41094 dma_attach 5-6 41094 NULL
118418 +provide_user_output_41105 provide_user_output 3 41105 NULL
118419 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
118420 +ath10k_read_wmi_services_41112 ath10k_read_wmi_services 3 41112 NULL
118421 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
118422 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
118423 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
118424 +netif_get_num_default_rss_queues_41187 netif_get_num_default_rss_queues 0 41187 NULL
118425 +request_irq_41192 request_irq 0 41192 NULL
118426 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
118427 +nfs_page_array_len_41219 nfs_page_array_len 0-2-1 41219 NULL
118428 +cfg80211_process_disassoc_41231 cfg80211_process_disassoc 3 41231 NULL
118429 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
118430 +erst_read_41260 erst_read 0 41260 NULL
118431 +alloc_context_41283 alloc_context 1 41283 NULL
118432 +of_count_phandle_with_args_41291 of_count_phandle_with_args 0 41291 NULL
118433 +o2hb_setup_one_bio_41341 o2hb_setup_one_bio 4 41341 NULL
118434 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
118435 +rtw_android_set_block_41347 rtw_android_set_block 0 41347 NULL
118436 +ceph_do_getattr_41349 ceph_do_getattr 0 41349 NULL
118437 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
118438 +kmp_init_41373 kmp_init 2 41373 NULL
118439 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
118440 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
118441 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
118442 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
118443 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
118444 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
118445 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 6-4 41442 NULL
118446 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
118447 +se_io_cb_41461 se_io_cb 3 41461 NULL
118448 +layout_leb_in_gaps_41470 layout_leb_in_gaps 0 41470 NULL
118449 +snd_pcm_status_41472 snd_pcm_status 0 41472 NULL
118450 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
118451 +bl_alloc_init_bio_41478 bl_alloc_init_bio 1 41478 NULL
118452 +kvm_unmap_hva_range_41484 kvm_unmap_hva_range 3-2 41484 NULL
118453 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
118454 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
118455 +xfrm_hash_new_size_41505 xfrm_hash_new_size 0-1 41505 NULL
118456 +SyS_preadv_41523 SyS_preadv 3 41523 NULL
118457 +dm_get_reserved_rq_based_ios_41529 dm_get_reserved_rq_based_ios 0 41529 NULL
118458 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
118459 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
118460 +nr_status_frames_41559 nr_status_frames 0-1 41559 NULL nohasharray
118461 +si476x_radio_fops_read_41559 si476x_radio_fops_read 3 41559 &nr_status_frames_41559
118462 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
118463 +batadv_tvlv_container_ogm_append_41588 batadv_tvlv_container_ogm_append 4 41588 NULL
118464 +vga_io_r_41609 vga_io_r 0 41609 NULL
118465 +tcp_hdrlen_41610 tcp_hdrlen 0 41610 NULL
118466 +usb_endpoint_maxp_41613 usb_endpoint_maxp 0 41613 NULL nohasharray
118467 +lbs_bcnmiss_write_41613 lbs_bcnmiss_write 3 41613 &usb_endpoint_maxp_41613
118468 +a2mp_send_41615 a2mp_send 4 41615 NULL
118469 +lstcon_batch_list_41627 lstcon_batch_list 2 41627 NULL
118470 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
118471 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
118472 +get_std_timing_41654 get_std_timing 0 41654 NULL
118473 +ieee80211_if_fmt_bssid_41677 ieee80211_if_fmt_bssid 3 41677 NULL
118474 +fill_pcm_stream_name_41685 fill_pcm_stream_name 2 41685 NULL
118475 +lov_unpackmd_41701 lov_unpackmd 4 41701 NULL
118476 +fillonedir_41746 fillonedir 3 41746 NULL
118477 +iwl_dbgfs_bt_notif_read_41794 iwl_dbgfs_bt_notif_read 3 41794 NULL
118478 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
118479 +rtw_android_get_macaddr_41812 rtw_android_get_macaddr 0 41812 NULL
118480 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
118481 +ixgbe_dbg_netdev_ops_read_41839 ixgbe_dbg_netdev_ops_read 3 41839 NULL
118482 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
118483 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
118484 +pci_map_single_41869 pci_map_single 0 41869 NULL
118485 +v_APCI3120_InterruptDmaMoveBlock16bit_41914 v_APCI3120_InterruptDmaMoveBlock16bit 4 41914 NULL
118486 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
118487 +ext4_da_write_inline_data_begin_41935 ext4_da_write_inline_data_begin 3-4 41935 NULL
118488 +sci_rxfill_41945 sci_rxfill 0 41945 NULL
118489 +read_gssp_41947 read_gssp 3 41947 NULL
118490 +ocfs2_xattr_bucket_get_name_value_41949 ocfs2_xattr_bucket_get_name_value 0 41949 NULL
118491 +portnames_read_41958 portnames_read 3 41958 NULL
118492 +ubi_self_check_all_ff_41959 ubi_self_check_all_ff 0 41959 NULL
118493 +dst_mtu_41969 dst_mtu 0 41969 NULL
118494 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
118495 +ubi_io_is_bad_41983 ubi_io_is_bad 0 41983 NULL
118496 +pool_allocate_42012 pool_allocate 3 42012 NULL
118497 +spidev_sync_read_42014 spidev_sync_read 0 42014 NULL
118498 +rs_sta_dbgfs_scale_table_write_42017 rs_sta_dbgfs_scale_table_write 3 42017 NULL
118499 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
118500 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
118501 +alloc_trace_kprobe_42041 alloc_trace_kprobe 6 42041 NULL
118502 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
118503 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
118504 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
118505 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
118506 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
118507 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
118508 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
118509 +dw_dma_cyclic_prep_42113 dw_dma_cyclic_prep 3-4 42113 NULL
118510 +blk_ioctl_zeroout_42160 blk_ioctl_zeroout 3 42160 NULL
118511 +mmc_align_data_size_42161 mmc_align_data_size 0-2 42161 NULL
118512 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
118513 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
118514 +write_file_beacon_42185 write_file_beacon 3 42185 NULL
118515 +get_znodes_to_commit_42201 get_znodes_to_commit 0 42201 NULL
118516 +pla_ocp_read_42235 pla_ocp_read 3 42235 NULL
118517 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
118518 +find_last_bit_42260 find_last_bit 0 42260 NULL
118519 +__pcpu_size_to_slot_42271 __pcpu_size_to_slot 0 42271 NULL
118520 +__tty_buffer_request_room_42276 __tty_buffer_request_room 2-0 42276 NULL
118521 +snd_pcm_hw_param_value_max_42280 snd_pcm_hw_param_value_max 0 42280 NULL
118522 +__cpus_weight_42299 __cpus_weight 0 42299 NULL
118523 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
118524 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
118525 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
118526 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
118527 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
118528 +tcp_sync_mss_42330 tcp_sync_mss 2-0 42330 NULL
118529 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
118530 +drbd_md_last_sector_42378 drbd_md_last_sector 0 42378 NULL
118531 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
118532 +msnd_fifo_read_42406 msnd_fifo_read 0-3 42406 NULL
118533 +krng_get_random_42420 krng_get_random 3 42420 NULL
118534 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
118535 +spr_wm_latency_write_42441 spr_wm_latency_write 3 42441 NULL
118536 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
118537 +snd_pcm_action_group_42452 snd_pcm_action_group 0 42452 NULL
118538 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
118539 +kuc_free_42455 kuc_free 2 42455 NULL
118540 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
118541 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
118542 +bypass_write_42498 bypass_write 3 42498 NULL
118543 +SyS_mincore_42511 SyS_mincore 2-1 42511 NULL
118544 +kvm_write_wall_clock_42520 kvm_write_wall_clock 2 42520 NULL
118545 +dio_bio_complete_42524 dio_bio_complete 0 42524 NULL
118546 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
118547 +self_check_ec_hdr_42528 self_check_ec_hdr 0 42528 NULL
118548 +dbAllocNear_42546 dbAllocNear 0 42546 NULL
118549 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 NULL
118550 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
118551 +iwl_print_event_log_42566 iwl_print_event_log 7-5-0 42566 NULL
118552 +xfrm_new_hash_mask_42579 xfrm_new_hash_mask 0-1 42579 NULL
118553 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
118554 +ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout_42635 ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout 3 42635 NULL
118555 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
118556 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
118557 +_regmap_raw_write_42652 _regmap_raw_write 4-2 42652 NULL
118558 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
118559 +vb2_read_42703 vb2_read 3 42703 NULL
118560 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
118561 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
118562 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
118563 +dpm_sysfs_add_42756 dpm_sysfs_add 0 42756 NULL
118564 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
118565 +snd_midi_event_decode_42780 snd_midi_event_decode 0 42780 NULL
118566 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL nohasharray
118567 +isku_sysfs_read_info_42781 isku_sysfs_read_info 6 42781 &cryptd_hash_setkey_42781
118568 +elfcorehdr_read_notes_42786 elfcorehdr_read_notes 2 42786 NULL
118569 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
118570 +ntfs_attr_extend_allocation_42796 ntfs_attr_extend_allocation 0 42796 NULL
118571 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
118572 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
118573 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
118574 +set_arg_42824 set_arg 3 42824 NULL
118575 +si476x_radio_read_rsq_blob_42827 si476x_radio_read_rsq_blob 3 42827 NULL
118576 +ocfs2_clusters_for_bytes_42872 ocfs2_clusters_for_bytes 0-2 42872 NULL
118577 +nvme_trans_unit_serial_page_42879 nvme_trans_unit_serial_page 4 42879 NULL
118578 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
118579 +hd_end_request_42904 hd_end_request 2 42904 NULL
118580 +sta_last_rx_rate_read_42909 sta_last_rx_rate_read 3 42909 NULL
118581 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
118582 +vx_reset_chk_42946 vx_reset_chk 0 42946 NULL
118583 +blkdev_direct_IO_42962 blkdev_direct_IO 4 42962 NULL
118584 +ntb_setup_snb_msix_42971 ntb_setup_snb_msix 2-0 42971 NULL
118585 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
118586 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL nohasharray
118587 +rtw_os_xmit_resource_alloc_42990 rtw_os_xmit_resource_alloc 3 42990 &nfs_idmap_get_desc_42990
118588 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
118589 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
118590 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
118591 +nfs_map_group_to_gid_43082 nfs_map_group_to_gid 3 43082 NULL
118592 +_xfer_secondary_pool_43089 _xfer_secondary_pool 2 43089 NULL
118593 +sysfs_create_file_ns_43103 sysfs_create_file_ns 0 43103 NULL
118594 +ieee80211_if_fmt_drop_unencrypted_43107 ieee80211_if_fmt_drop_unencrypted 3 43107 NULL
118595 +calculate_node_totalpages_43118 calculate_node_totalpages 2-3 43118 NULL
118596 +e1000_request_msix_43134 e1000_request_msix 0 43134 NULL
118597 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
118598 +cfs_cpt_table_alloc_43159 cfs_cpt_table_alloc 1 43159 NULL
118599 +usb_string_sub_43164 usb_string_sub 0 43164 NULL
118600 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
118601 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
118602 +ext4_xattr_ibody_get_43200 ext4_xattr_ibody_get 0 43200 NULL
118603 +uio_write_43202 uio_write 3 43202 NULL
118604 +iso_callback_43208 iso_callback 3 43208 NULL
118605 +ath10k_p2p_calc_noa_ie_len_43209 ath10k_p2p_calc_noa_ie_len 0 43209 NULL
118606 +f2fs_acl_from_disk_43210 f2fs_acl_from_disk 2 43210 NULL
118607 +atomic_long_add_return_43217 atomic_long_add_return 1-0 43217 NULL
118608 +batadv_tt_tvlv_unicast_handler_v1_43239 batadv_tt_tvlv_unicast_handler_v1 5 43239 NULL
118609 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
118610 +ide_end_rq_43269 ide_end_rq 4 43269 NULL
118611 +nilfs_direct_IO_43271 nilfs_direct_IO 4 43271 NULL
118612 +evtchn_write_43278 evtchn_write 3 43278 NULL
118613 +filemap_write_and_wait_range_43279 filemap_write_and_wait_range 0 43279 NULL
118614 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
118615 +mmu_set_spte_43327 mmu_set_spte 6-7 43327 NULL
118616 +__ext4_get_inode_loc_43332 __ext4_get_inode_loc 0 43332 NULL
118617 +xenfb_write_43412 xenfb_write 3 43412 NULL
118618 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL nohasharray
118619 +msi_capability_init_43423 msi_capability_init 0 43423 &__alloc_bootmem_low_43423
118620 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
118621 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
118622 +usb_string_43443 usb_string 0 43443 NULL nohasharray
118623 +usemap_size_43443 usemap_size 0-1-2 43443 &usb_string_43443
118624 +get_vm_area_size_43444 get_vm_area_size 0 43444 NULL
118625 +fs_path_prepare_for_add_43453 fs_path_prepare_for_add 2 43453 NULL
118626 +nvme_trans_device_id_page_43466 nvme_trans_device_id_page 4 43466 NULL
118627 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
118628 +ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime_43505 ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime 3 43505 NULL
118629 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
118630 +read_events_43534 read_events 3 43534 NULL
118631 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
118632 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
118633 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
118634 +handle_frequent_errors_43599 handle_frequent_errors 4 43599 NULL
118635 +lpfc_idiag_drbacc_read_reg_43606 lpfc_idiag_drbacc_read_reg 0-3 43606 NULL
118636 +proc_read_43614 proc_read 3 43614 NULL
118637 +disable_dma_on_even_43618 disable_dma_on_even 0 43618 NULL
118638 +alloc_thread_groups_43625 alloc_thread_groups 2 43625 NULL
118639 +random_write_43656 random_write 3 43656 NULL
118640 +bio_integrity_tag_43658 bio_integrity_tag 3 43658 NULL
118641 +ext4_acl_count_43659 ext4_acl_count 0-1 43659 NULL
118642 +write_file_tx99_power_43670 write_file_tx99_power 3 43670 NULL
118643 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4 43679 NULL
118644 +max77693_bulk_write_43698 max77693_bulk_write 2-3 43698 NULL
118645 +drbd_md_first_sector_43729 drbd_md_first_sector 0 43729 NULL
118646 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
118647 +fuse_conn_congestion_threshold_write_43736 fuse_conn_congestion_threshold_write 3 43736 NULL
118648 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
118649 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
118650 +generic_file_direct_write_43770 generic_file_direct_write 0 43770 NULL
118651 +ocfs2_xattr_get_value_outside_43787 ocfs2_xattr_get_value_outside 0 43787 NULL nohasharray
118652 +byte_pos_43787 byte_pos 0 43787 &ocfs2_xattr_get_value_outside_43787
118653 +btrfs_copy_from_user_43806 btrfs_copy_from_user 3-1-0 43806 NULL
118654 +ieee80211_if_fmt_element_ttl_43825 ieee80211_if_fmt_element_ttl 3 43825 NULL
118655 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
118656 +read_flush_43851 read_flush 3 43851 NULL
118657 +pm860x_bulk_write_43875 pm860x_bulk_write 2-3 43875 NULL
118658 +ec_dbgfs_cmd_write_43895 ec_dbgfs_cmd_write 3 43895 NULL
118659 +SendString_43928 SendString 3 43928 NULL
118660 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
118661 +__get_required_blob_size_43980 __get_required_blob_size 0-3-2 43980 NULL
118662 +nla_reserve_43984 nla_reserve 3 43984 NULL
118663 +__clkdev_alloc_43990 __clkdev_alloc 1 43990 NULL
118664 +scsi_command_size_43992 scsi_command_size 0 43992 NULL nohasharray
118665 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 &scsi_command_size_43992 nohasharray
118666 +kvm_read_guest_virt_43992 kvm_read_guest_virt 4-2 43992 &bcm_recvmsg_43992
118667 +ulist_add_43994 ulist_add 0 43994 NULL
118668 +emit_flags_44006 emit_flags 4-3 44006 NULL
118669 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
118670 +fru_strlen_44046 fru_strlen 0 44046 NULL
118671 +ath9k_def_dump_modal_eeprom_44078 ath9k_def_dump_modal_eeprom 3-2-0 44078 NULL
118672 +SYSC_add_key_44079 SYSC_add_key 4 44079 NULL
118673 +pci_msix_vec_count_44093 pci_msix_vec_count 0 44093 NULL
118674 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
118675 +skb_frag_dma_map_44112 skb_frag_dma_map 0 44112 NULL
118676 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL nohasharray
118677 +file_remove_suid_44122 file_remove_suid 0 44122 &tracing_set_trace_read_44122
118678 +SyS_process_vm_writev_44129 SyS_process_vm_writev 3-5 44129 NULL
118679 +ttm_get_pages_44142 ttm_get_pages 2 44142 NULL
118680 +scsi_get_resid_44147 scsi_get_resid 0 44147 NULL
118681 +ubifs_find_dirty_idx_leb_44169 ubifs_find_dirty_idx_leb 0 44169 NULL
118682 +ocfs2_xattr_bucket_find_44174 ocfs2_xattr_bucket_find 0 44174 NULL
118683 +SYSC_set_mempolicy_44176 SYSC_set_mempolicy 3 44176 NULL
118684 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
118685 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
118686 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
118687 +sigma_action_write_regmap_44240 sigma_action_write_regmap 3 44240 NULL
118688 +device_create_file_44285 device_create_file 0 44285 NULL
118689 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
118690 +bitmap_scnprintf_44318 bitmap_scnprintf 0-2 44318 NULL
118691 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
118692 +ccp_init_data_44324 ccp_init_data 5 44324 NULL
118693 +rs_init_44327 rs_init 1 44327 NULL
118694 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 NULL nohasharray
118695 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 &blk_queue_init_tags_44355
118696 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
118697 +mtip_hw_read_flags_44396 mtip_hw_read_flags 3 44396 NULL
118698 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
118699 +strlcpy_44400 strlcpy 3 44400 NULL
118700 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
118701 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
118702 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
118703 +write_file_debug_44476 write_file_debug 3 44476 NULL
118704 +btrfs_chunk_item_size_44478 btrfs_chunk_item_size 0-1 44478 NULL
118705 +sdio_align_size_44489 sdio_align_size 0-2 44489 NULL
118706 +bio_advance_44496 bio_advance 2 44496 NULL
118707 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
118708 +ac_register_board_44504 ac_register_board 3 44504 NULL
118709 +security_getprocattr_44505 security_getprocattr 0 44505 NULL nohasharray
118710 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 &security_getprocattr_44505
118711 +spidev_write_44510 spidev_write 3 44510 NULL
118712 +SyS_io_getevents_44519 SyS_io_getevents 3 44519 NULL
118713 +ieee80211_rx_mgmt_assoc_resp_44525 ieee80211_rx_mgmt_assoc_resp 3 44525 NULL
118714 +comm_write_44537 comm_write 3 44537 NULL
118715 +snd_pcm_drop_44542 snd_pcm_drop 0 44542 NULL
118716 +dgrp_config_proc_write_44571 dgrp_config_proc_write 3 44571 NULL
118717 +btrfs_set_extent_delalloc_44587 btrfs_set_extent_delalloc 0 44587 NULL
118718 +nouveau_perfmon_create__44602 nouveau_perfmon_create_ 4 44602 NULL
118719 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
118720 +mpi_resize_44674 mpi_resize 2 44674 NULL
118721 +sysfs_create_link_44685 sysfs_create_link 0 44685 NULL
118722 +ts_read_44687 ts_read 3 44687 NULL
118723 +lov_emerg_alloc_44698 lov_emerg_alloc 1 44698 NULL
118724 +C_SYSC_select_44701 C_SYSC_select 1 44701 NULL
118725 +__generic_block_fiemap_44713 __generic_block_fiemap 4 44713 NULL nohasharray
118726 +xfer_to_user_44713 xfer_to_user 3 44713 &__generic_block_fiemap_44713
118727 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
118728 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
118729 +fib_count_nexthops_44730 fib_count_nexthops 0 44730 NULL
118730 +efx_wanted_parallelism_44732 efx_wanted_parallelism 0 44732 NULL
118731 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
118732 +bch_bio_max_sectors_44755 bch_bio_max_sectors 0 44755 NULL
118733 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
118734 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
118735 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4-0 44769 NULL
118736 +handsfree_ramp_44777 handsfree_ramp 2 44777 NULL
118737 +irq_domain_add_legacy_44781 irq_domain_add_legacy 4-2 44781 NULL
118738 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
118739 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
118740 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
118741 +force_static_address_write_44819 force_static_address_write 3 44819 NULL
118742 +mei_cl_read_start_44824 mei_cl_read_start 2 44824 NULL
118743 +rmap_write_protect_44833 rmap_write_protect 2 44833 NULL
118744 +sisusb_write_44834 sisusb_write 3 44834 NULL
118745 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
118746 +qib_verbs_send_dma_44850 qib_verbs_send_dma 6 44850 NULL
118747 +copydesc_user_44855 copydesc_user 3 44855 NULL
118748 +set_advertising_44870 set_advertising 4 44870 NULL
118749 +init_rs_44873 init_rs 1 44873 NULL
118750 +skb_availroom_44883 skb_availroom 0 44883 NULL
118751 +do_tty_write_44896 do_tty_write 5 44896 NULL
118752 +regmap_spi_read_44921 regmap_spi_read 3-5 44921 NULL
118753 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
118754 +bytepos_delta_45017 bytepos_delta 0 45017 NULL
118755 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
118756 +dm_kvzalloc_45025 dm_kvzalloc 1 45025 NULL
118757 +sysfs_do_create_link_sd_45057 sysfs_do_create_link_sd 0 45057 NULL
118758 +sel_write_user_45060 sel_write_user 3 45060 NULL
118759 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
118760 +snd_card_new_45104 snd_card_new 5 45104 NULL
118761 +kvm_mmu_page_get_gfn_45110 kvm_mmu_page_get_gfn 0-2 45110 NULL
118762 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
118763 +usbdev_read_45114 usbdev_read 3 45114 NULL
118764 +send_to_tty_45141 send_to_tty 3 45141 NULL
118765 +cfs_trace_daemon_command_usrstr_45147 cfs_trace_daemon_command_usrstr 2 45147 NULL
118766 +gen_bitmask_string_45149 gen_bitmask_string 6 45149 NULL
118767 +device_write_45156 device_write 3 45156 NULL nohasharray
118768 +ocfs2_remove_inode_range_45156 ocfs2_remove_inode_range 3 45156 &device_write_45156
118769 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
118770 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
118771 +sctp_pack_cookie_45190 sctp_pack_cookie 6 45190 NULL nohasharray
118772 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 &sctp_pack_cookie_45190
118773 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
118774 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
118775 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
118776 +event_enable_write_45238 event_enable_write 3 45238 NULL
118777 +prism2_pda_proc_read_45246 prism2_pda_proc_read 3 45246 NULL
118778 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
118779 +gfs2_fiemap_45282 gfs2_fiemap 4 45282 NULL
118780 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
118781 +e1000_tx_map_45309 e1000_tx_map 5 45309 NULL
118782 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
118783 +brcmf_sdio_died_dump_45359 brcmf_sdio_died_dump 3 45359 NULL
118784 +null_alloc_repbuf_45375 null_alloc_repbuf 3 45375 NULL
118785 +count_skb_frag_slots_45395 count_skb_frag_slots 0 45395 NULL
118786 +sock_recv_errqueue_45412 sock_recv_errqueue 3 45412 NULL
118787 +ieee80211_if_fmt_dot11MeshHWMProotInterval_45421 ieee80211_if_fmt_dot11MeshHWMProotInterval 3 45421 NULL
118788 +ll_iocontrol_register_45430 ll_iocontrol_register 2 45430 NULL
118789 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
118790 +rds_ib_set_wr_signal_state_45463 rds_ib_set_wr_signal_state 0 45463 NULL
118791 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
118792 +snd_pcm_hwsync_45479 snd_pcm_hwsync 0 45479 NULL
118793 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
118794 +copy_macs_45534 copy_macs 4 45534 NULL
118795 +nla_attr_size_45545 nla_attr_size 0-1 45545 NULL
118796 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
118797 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
118798 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
118799 +_regmap_bus_raw_write_45559 _regmap_bus_raw_write 2 45559 NULL
118800 +posix_acl_xattr_size_45561 posix_acl_xattr_size 0-1 45561 NULL
118801 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
118802 +ath6kl_keepalive_write_45600 ath6kl_keepalive_write 3 45600 NULL
118803 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
118804 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
118805 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
118806 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
118807 +bscnl_emit_45699 bscnl_emit 2-5-0 45699 NULL nohasharray
118808 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 &bscnl_emit_45699
118809 +sg_proc_write_adio_45704 sg_proc_write_adio 3 45704 NULL
118810 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
118811 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3-0 45748 NULL nohasharray
118812 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
118813 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
118814 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
118815 +osc_checksum_type_seq_write_45785 osc_checksum_type_seq_write 3 45785 NULL
118816 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
118817 +rds_tcp_inc_copy_to_user_45804 rds_tcp_inc_copy_to_user 3 45804 NULL
118818 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
118819 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
118820 +ll_max_readahead_mb_seq_write_45815 ll_max_readahead_mb_seq_write 3 45815 NULL
118821 +memcg_update_cache_size_45828 memcg_update_cache_size 2 45828 NULL
118822 +ipv6_recv_rxpmtu_45830 ipv6_recv_rxpmtu 3 45830 NULL
118823 +insert_state_45848 insert_state 0 45848 NULL
118824 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
118825 +efx_tx_queue_insert_45859 efx_tx_queue_insert 2 45859 NULL
118826 +isdn_write_45863 isdn_write 3 45863 NULL
118827 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
118828 +ocfs2_xattr_block_find_45891 ocfs2_xattr_block_find 0 45891 NULL
118829 +cfs_cpt_weight_45903 cfs_cpt_weight 0 45903 NULL
118830 +wm_adsp_region_to_reg_45915 wm_adsp_region_to_reg 0-2 45915 NULL
118831 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
118832 +btree_keys_cachelines_45928 btree_keys_cachelines 0 45928 NULL
118833 +alloc_mr_45935 alloc_mr 1 45935 NULL
118834 +copy_to_45969 copy_to 3 45969 NULL
118835 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
118836 +ioat2_dca_count_dca_slots_45984 ioat2_dca_count_dca_slots 0 45984 NULL
118837 +kobject_init_and_add_46003 kobject_init_and_add 0 46003 NULL
118838 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
118839 +get_free_entries_46030 get_free_entries 1 46030 NULL nohasharray
118840 +fnic_reset_stats_read_46030 fnic_reset_stats_read 3 46030 &get_free_entries_46030
118841 +__access_remote_vm_46031 __access_remote_vm 0 46031 NULL
118842 +snd_emu10k1x_ptr_read_46049 snd_emu10k1x_ptr_read 0 46049 NULL
118843 +__ocfs2_move_extent_46060 __ocfs2_move_extent 3-4 46060 NULL nohasharray
118844 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 &__ocfs2_move_extent_46060
118845 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
118846 +memcg_update_array_size_46111 memcg_update_array_size 1 46111 NULL nohasharray
118847 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 &memcg_update_array_size_46111
118848 +C_SYSC_writev_46113 C_SYSC_writev 3 46113 NULL
118849 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
118850 +rtw_buf_update_46138 rtw_buf_update 4 46138 NULL
118851 +vb2_dma_sg_get_userptr_46146 vb2_dma_sg_get_userptr 3-2 46146 NULL
118852 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
118853 +twl_direction_out_46182 twl_direction_out 2 46182 NULL
118854 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
118855 +fq_resize_46195 fq_resize 2 46195 NULL
118856 +add_conn_list_46197 add_conn_list 3-0 46197 NULL
118857 +i2400m_op_msg_from_user_46213 i2400m_op_msg_from_user 4 46213 NULL
118858 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
118859 +dsp_write_46218 dsp_write 2 46218 NULL
118860 +hash_netiface4_expire_46226 hash_netiface4_expire 4 46226 NULL
118861 +xen_setup_msi_irqs_46245 xen_setup_msi_irqs 2 46245 NULL
118862 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
118863 +sg_proc_write_dressz_46316 sg_proc_write_dressz 3 46316 NULL
118864 +C_SYSC_ppoll_46319 C_SYSC_ppoll 2 46319 NULL
118865 +compat_SyS_readv_46328 compat_SyS_readv 3 46328 NULL nohasharray
118866 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 &compat_SyS_readv_46328
118867 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
118868 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
118869 +fuse_file_aio_write_46399 fuse_file_aio_write 4 46399 NULL
118870 +crypto_ablkcipher_reqsize_46411 crypto_ablkcipher_reqsize 0 46411 NULL
118871 +ttm_page_pool_get_pages_46431 ttm_page_pool_get_pages 0-5 46431 NULL
118872 +cfs_power2_roundup_46433 cfs_power2_roundup 0-1 46433 NULL
118873 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
118874 +il_dbgfs_clear_traffic_stats_write_46458 il_dbgfs_clear_traffic_stats_write 3 46458 NULL
118875 +filldir64_46469 filldir64 3 46469 NULL
118876 +fill_in_write_vector_46498 fill_in_write_vector 0 46498 NULL
118877 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
118878 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
118879 +nouveau_drm_ioctl_46514 nouveau_drm_ioctl 2 46514 NULL nohasharray
118880 +kmsg_read_46514 kmsg_read 3 46514 &nouveau_drm_ioctl_46514
118881 +nl80211_send_rx_assoc_46538 nl80211_send_rx_assoc 4 46538 NULL
118882 +dn_current_mss_46574 dn_current_mss 0 46574 NULL
118883 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
118884 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
118885 +il3945_stats_flag_46606 il3945_stats_flag 0-3 46606 NULL
118886 +vscnprintf_46617 vscnprintf 0-2 46617 NULL
118887 +__kfifo_out_r_46623 __kfifo_out_r 0-3 46623 NULL
118888 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
118889 +pci_enable_device_46642 pci_enable_device 0 46642 NULL
118890 +vfs_getxattr_alloc_46649 vfs_getxattr_alloc 0 46649 NULL
118891 +e1000_tx_map_46672 e1000_tx_map 4 46672 NULL
118892 +l2cap_create_le_flowctl_pdu_46682 l2cap_create_le_flowctl_pdu 3 46682 NULL
118893 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
118894 +__ilog2_u32_46706 __ilog2_u32 0 46706 NULL
118895 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
118896 +wl1271_rx_filter_alloc_field_46721 wl1271_rx_filter_alloc_field 5 46721 NULL
118897 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
118898 +read_file_tx99_46741 read_file_tx99 3 46741 NULL
118899 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
118900 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
118901 +_xfs_buf_get_pages_46811 _xfs_buf_get_pages 2 46811 NULL
118902 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
118903 +shmem_pwrite_fast_46842 shmem_pwrite_fast 3 46842 NULL
118904 +spi_async_46857 spi_async 0 46857 NULL
118905 +vsnprintf_46863 vsnprintf 0 46863 NULL
118906 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
118907 +qp_memcpy_from_queue_iov_46874 qp_memcpy_from_queue_iov 5-4 46874 NULL
118908 +lov_iocontrol_46876 lov_iocontrol 3 46876 NULL
118909 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
118910 +sk_mem_pages_46896 sk_mem_pages 0-1 46896 NULL
118911 +ieee80211_if_fmt_power_mode_46906 ieee80211_if_fmt_power_mode 3 46906 NULL
118912 +wlcore_alloc_hw_46917 wlcore_alloc_hw 3-1 46917 NULL
118913 +fb_write_46924 fb_write 3 46924 NULL
118914 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
118915 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
118916 +SYSC_poll_46965 SYSC_poll 2 46965 NULL
118917 +crypto_tfm_alg_alignmask_46971 crypto_tfm_alg_alignmask 0 46971 NULL
118918 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
118919 +strlcat_46985 strlcat 3 46985 NULL
118920 +bitmap_file_clear_bit_46990 bitmap_file_clear_bit 2 46990 NULL
118921 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
118922 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
118923 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2-4 47024 NULL
118924 +fs_path_len_47060 fs_path_len 0 47060 NULL
118925 +event_trigger_regex_write_47067 event_trigger_regex_write 3 47067 NULL
118926 +ext4_xattr_list_entries_47070 ext4_xattr_list_entries 0 47070 NULL
118927 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
118928 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
118929 +iwl_dump_nic_event_log_47089 iwl_dump_nic_event_log 0 47089 NULL
118930 +ptlrpc_lprocfs_threads_max_seq_write_47104 ptlrpc_lprocfs_threads_max_seq_write 3 47104 NULL
118931 +mousedev_read_47123 mousedev_read 3 47123 NULL
118932 +upcall_msg_size_47141 upcall_msg_size 2 47141 NULL
118933 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 NULL nohasharray
118934 +ses_recv_diag_47143 ses_recv_diag 4 47143 &acpi_ut_initialize_buffer_47143
118935 +mxms_headerlen_47161 mxms_headerlen 0 47161 NULL
118936 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
118937 +rts51x_ms_rw_47171 rts51x_ms_rw 3-4 47171 NULL
118938 +options_write_47243 options_write 3 47243 NULL
118939 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
118940 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
118941 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
118942 +vsnprintf_47291 vsnprintf 0 47291 NULL
118943 +SYSC_semop_47292 SYSC_semop 3 47292 NULL
118944 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
118945 +nouveau_fb_create__47316 nouveau_fb_create_ 4 47316 NULL
118946 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
118947 +avc_get_hash_stats_47359 avc_get_hash_stats 0 47359 NULL
118948 +kvm_arch_create_memslot_47364 kvm_arch_create_memslot 3 47364 NULL nohasharray
118949 +__output_copy_user_47364 __output_copy_user 3 47364 &kvm_arch_create_memslot_47364
118950 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
118951 +nv_rd32_47390 nv_rd32 0 47390 NULL nohasharray
118952 +trace_options_core_read_47390 trace_options_core_read 3 47390 &nv_rd32_47390
118953 +nametbl_list_47391 nametbl_list 2 47391 NULL
118954 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
118955 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
118956 +lbs_wrmac_write_47400 lbs_wrmac_write 3 47400 NULL
118957 +sta_vht_capa_read_47409 sta_vht_capa_read 3 47409 NULL
118958 +crypto_ablkcipher_alignmask_47410 crypto_ablkcipher_alignmask 0 47410 NULL
118959 +lbs_wrrf_write_47418 lbs_wrrf_write 3 47418 NULL
118960 +C_SYSC_set_mempolicy_47466 C_SYSC_set_mempolicy 3 47466 NULL
118961 +nvme_trans_send_fw_cmd_47479 nvme_trans_send_fw_cmd 4 47479 NULL
118962 +newpart_47485 newpart 6-4 47485 NULL
118963 +mcp23s17_read_regs_47491 mcp23s17_read_regs 4 47491 NULL
118964 +core_sys_select_47494 core_sys_select 1 47494 NULL
118965 +as3722_block_write_47503 as3722_block_write 2-3 47503 NULL
118966 +alloc_arraycache_47505 alloc_arraycache 2 47505 NULL
118967 +unlink_simple_47506 unlink_simple 3 47506 NULL
118968 +pstore_decompress_47510 pstore_decompress 0 47510 NULL
118969 +__proc_lnet_portal_rotor_47529 __proc_lnet_portal_rotor 5 47529 NULL
118970 +snd_pcm_resume_47530 snd_pcm_resume 0 47530 NULL
118971 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL nohasharray
118972 +vscnprintf_47533 vscnprintf 0-2 47533 &process_vm_rw_47533
118973 +ieee80211_if_fmt_min_discovery_timeout_47539 ieee80211_if_fmt_min_discovery_timeout 3 47539 NULL
118974 +rtw_cfg80211_set_assoc_resp_wpsp2pie_47558 rtw_cfg80211_set_assoc_resp_wpsp2pie 3 47558 NULL
118975 +read_ldt_47570 read_ldt 2 47570 NULL
118976 +isku_sysfs_read_last_set_47572 isku_sysfs_read_last_set 6 47572 NULL
118977 +btrfs_stack_header_bytenr_47589 btrfs_stack_header_bytenr 0 47589 NULL
118978 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
118979 +sctp_ssnmap_new_47608 sctp_ssnmap_new 2-1 47608 NULL
118980 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
118981 +twl4030_clear_set_47624 twl4030_clear_set 4 47624 NULL
118982 +ccp_sha_setkey_47633 ccp_sha_setkey 3 47633 NULL
118983 +get_size_47644 get_size 1-2 47644 NULL
118984 +snd_pcm_info_47699 snd_pcm_info 0 47699 NULL
118985 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL nohasharray
118986 +ipath_format_hwmsg_47700 ipath_format_hwmsg 2 47700 &packet_recvmsg_47700
118987 +save_microcode_47717 save_microcode 3 47717 NULL
118988 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
118989 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
118990 +ir_prepare_write_buffer_47747 ir_prepare_write_buffer 3 47747 NULL
118991 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
118992 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
118993 +uwb_ie_dump_hex_47774 uwb_ie_dump_hex 4 47774 NULL
118994 +SyS_setgroups16_47780 SyS_setgroups16 1 47780 NULL
118995 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
118996 +posix_acl_fix_xattr_from_user_47793 posix_acl_fix_xattr_from_user 2 47793 NULL
118997 +lov_packmd_47810 lov_packmd 0 47810 NULL
118998 +tree_mod_log_insert_move_47823 tree_mod_log_insert_move 5 47823 NULL
118999 +pinconf_dbg_config_write_47835 pinconf_dbg_config_write 3 47835 NULL
119000 +KEY_SIZE_47855 KEY_SIZE 0 47855 NULL
119001 +vhci_read_47878 vhci_read 3 47878 NULL
119002 +ubi_wl_put_peb_47886 ubi_wl_put_peb 0 47886 NULL
119003 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
119004 +cfs_percpt_alloc_47918 cfs_percpt_alloc 2 47918 NULL
119005 +comedi_write_47926 comedi_write 3 47926 NULL
119006 +nvme_trans_get_blk_desc_len_47946 nvme_trans_get_blk_desc_len 0-2 47946 NULL
119007 +arch_setup_msi_irq_47959 arch_setup_msi_irq 0 47959 NULL
119008 +gether_get_ifname_47972 gether_get_ifname 3 47972 NULL
119009 +mempool_resize_47983 mempool_resize 2 47983 NULL nohasharray
119010 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 &mempool_resize_47983
119011 +dbg_port_buf_47990 dbg_port_buf 2 47990 NULL
119012 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
119013 +lustre_cfg_len_48002 lustre_cfg_len 0 48002 NULL
119014 +gdm_tty_recv_complete_48011 gdm_tty_recv_complete 2 48011 NULL
119015 +bio_integrity_set_tag_48035 bio_integrity_set_tag 3 48035 NULL
119016 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
119017 +SYSC_writev_48040 SYSC_writev 3 48040 NULL
119018 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
119019 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
119020 +palmas_bulk_write_48068 palmas_bulk_write 2-3-5 48068 NULL
119021 +disc_write_48070 disc_write 3 48070 NULL
119022 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
119023 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
119024 +wm_latency_write_48125 wm_latency_write 3 48125 NULL
119025 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
119026 +set_discoverable_48141 set_discoverable 4 48141 NULL
119027 +dn_fib_count_nhs_48145 dn_fib_count_nhs 0 48145 NULL
119028 +SyS_vmsplice_48150 SyS_vmsplice 3 48150 NULL
119029 +_add_to_r4w_48152 _add_to_r4w 4 48152 NULL
119030 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
119031 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
119032 +rbd_obj_method_sync_48170 rbd_obj_method_sync 8 48170 NULL
119033 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
119034 +cfg80211_process_deauth_48200 cfg80211_process_deauth 3 48200 NULL
119035 +ext4_index_trans_blocks_48205 ext4_index_trans_blocks 0-2 48205 NULL
119036 +snd_seq_dump_var_event_48209 snd_seq_dump_var_event 0 48209 NULL
119037 +ll_direct_IO_26_48216 ll_direct_IO_26 4 48216 NULL
119038 +uv_blade_nr_possible_cpus_48226 uv_blade_nr_possible_cpus 0 48226 NULL
119039 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
119040 +read_file_recv_48232 read_file_recv 3 48232 NULL
119041 +unaccount_shadowed_48233 unaccount_shadowed 2 48233 NULL
119042 +nouveau_i2c_port_create__48240 nouveau_i2c_port_create_ 7 48240 NULL
119043 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
119044 +batadv_socket_read_48257 batadv_socket_read 3 48257 NULL
119045 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
119046 +trace_options_write_48275 trace_options_write 3 48275 NULL
119047 +send_set_info_48288 send_set_info 7 48288 NULL
119048 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
119049 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
119050 +hash_setkey_48310 hash_setkey 3 48310 NULL
119051 +skb_add_data_48363 skb_add_data 3 48363 NULL
119052 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
119053 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
119054 +uhid_event_from_user_48417 uhid_event_from_user 2 48417 NULL
119055 +div64_u64_rem_48418 div64_u64_rem 0-1-2 48418 NULL
119056 +snd_power_wait_48422 snd_power_wait 0 48422 NULL
119057 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
119058 +print_filtered_48442 print_filtered 2-0 48442 NULL
119059 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
119060 +compat_SyS_preadv64_48469 compat_SyS_preadv64 3 48469 NULL
119061 +_iwl_dbgfs_bt_tx_prio_write_48473 _iwl_dbgfs_bt_tx_prio_write 3 48473 NULL
119062 +ipath_format_hwerrors_48487 ipath_format_hwerrors 5 48487 NULL
119063 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
119064 +send_control_msg_48498 send_control_msg 6 48498 NULL
119065 +count_masked_bytes_48507 count_masked_bytes 0-1 48507 NULL
119066 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
119067 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
119068 +phantom_get_free_48514 phantom_get_free 0 48514 NULL
119069 +drbd_bm_capacity_48530 drbd_bm_capacity 0 48530 NULL
119070 +raid10_size_48571 raid10_size 0-2-3 48571 NULL
119071 +llog_data_len_48607 llog_data_len 1 48607 NULL
119072 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
119073 +ll_rw_extents_stats_pp_seq_write_48651 ll_rw_extents_stats_pp_seq_write 3 48651 NULL
119074 +mtd_read_48655 mtd_read 0 48655 NULL
119075 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
119076 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL
119077 +ubi_eba_unmap_leb_48671 ubi_eba_unmap_leb 0 48671 NULL
119078 +security_inode_setattr_48689 security_inode_setattr 0 48689 NULL
119079 +hysdn_log_write_48694 hysdn_log_write 3 48694 NULL
119080 +altera_drscan_48698 altera_drscan 2 48698 NULL
119081 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
119082 +lpfc_idiag_drbacc_write_48712 lpfc_idiag_drbacc_write 3 48712 NULL
119083 +SyS_lgetxattr_48719 SyS_lgetxattr 4 48719 NULL
119084 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
119085 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
119086 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
119087 +gfs2_direct_IO_48774 gfs2_direct_IO 4 48774 NULL
119088 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
119089 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
119090 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
119091 +azx_get_position_48841 azx_get_position 0 48841 NULL
119092 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
119093 +comedi_buf_write_alloc_48846 comedi_buf_write_alloc 0-2 48846 NULL
119094 +suspend_dtim_interval_write_48854 suspend_dtim_interval_write 3 48854 NULL
119095 +C_SYSC_pwritev64_48864 C_SYSC_pwritev64 3 48864 NULL nohasharray
119096 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 &C_SYSC_pwritev64_48864
119097 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
119098 +crypto_cipher_ctxsize_48890 crypto_cipher_ctxsize 0 48890 NULL
119099 +joydev_handle_JSIOCSAXMAP_48898 joydev_handle_JSIOCSAXMAP 3 48898 NULL
119100 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
119101 +msg_hdr_sz_48908 msg_hdr_sz 0 48908 NULL
119102 +snd_pcm_update_hw_ptr_48925 snd_pcm_update_hw_ptr 0 48925 NULL
119103 +sep_crypto_dma_48937 sep_crypto_dma 0 48937 NULL
119104 +si5351_write_parameters_48940 si5351_write_parameters 2 48940 NULL
119105 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
119106 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
119107 +vmci_handle_arr_create_48971 vmci_handle_arr_create 1 48971 NULL
119108 +rds_rm_size_48996 rds_rm_size 0-2 48996 NULL
119109 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
119110 +null_alloc_rs_49019 null_alloc_rs 2 49019 NULL
119111 +filemap_check_errors_49022 filemap_check_errors 0 49022 NULL
119112 +transient_status_49027 transient_status 4 49027 NULL
119113 +ll_xattr_cache_add_49032 ll_xattr_cache_add 4-0 49032 NULL
119114 +scsi_register_49094 scsi_register 2 49094 NULL
119115 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
119116 +xfrm_replay_state_esn_len_49119 xfrm_replay_state_esn_len 0 49119 NULL
119117 +ll_max_cached_mb_seq_write_49122 ll_max_cached_mb_seq_write 3 49122 NULL
119118 +pt_read_49136 pt_read 3 49136 NULL nohasharray
119119 +netxen_setup_msi_interrupts_49136 netxen_setup_msi_interrupts 2 49136 &pt_read_49136
119120 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
119121 +f2fs_acl_count_49155 f2fs_acl_count 0-1 49155 NULL
119122 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
119123 +__jfs_setxattr_49175 __jfs_setxattr 5 49175 NULL
119124 +ath6kl_bgscan_int_write_49178 ath6kl_bgscan_int_write 3 49178 NULL
119125 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
119126 +print_queue_49191 print_queue 0-4 49191 NULL
119127 +root_nfs_cat_49192 root_nfs_cat 3 49192 NULL
119128 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
119129 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
119130 +do_jffs2_getxattr_49210 do_jffs2_getxattr 0 49210 NULL
119131 +nouveau_therm_create__49228 nouveau_therm_create_ 4 49228 NULL
119132 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
119133 +isku_sysfs_read_keys_media_49268 isku_sysfs_read_keys_media 6 49268 NULL
119134 +ptlrpc_check_set_49277 ptlrpc_check_set 0 49277 NULL
119135 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
119136 +viafb_dfph_proc_write_49288 viafb_dfph_proc_write 3 49288 NULL
119137 +uio_read_49300 uio_read 3 49300 NULL
119138 +isku_sysfs_read_keys_macro_49312 isku_sysfs_read_keys_macro 6 49312 NULL
119139 +SYSC_mincore_49319 SYSC_mincore 2-1 49319 NULL
119140 +fwtty_port_handler_49327 fwtty_port_handler 9 49327 NULL
119141 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-4-3 49330 NULL
119142 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
119143 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
119144 +ext4_ext_index_trans_blocks_49396 ext4_ext_index_trans_blocks 0 49396 NULL
119145 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
119146 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
119147 +samples_to_bytes_49426 samples_to_bytes 0-2 49426 NULL
119148 +compat_do_msg_fill_49440 compat_do_msg_fill 3 49440 NULL
119149 +__hfsplus_getxattr_49460 __hfsplus_getxattr 0 49460 NULL
119150 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
119151 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
119152 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
119153 +iwl_dbgfs_disable_power_off_read_49517 iwl_dbgfs_disable_power_off_read 3 49517 NULL
119154 +SyS_listxattr_49519 SyS_listxattr 3 49519 NULL
119155 +emulator_write_phys_49520 emulator_write_phys 2-4 49520 NULL
119156 +smk_write_access_49561 smk_write_access 3 49561 NULL
119157 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
119158 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
119159 +evm_inode_setattr_49594 evm_inode_setattr 0 49594 NULL
119160 +tap_write_49595 tap_write 3 49595 NULL
119161 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
119162 +btrfs_mksubvol_49616 btrfs_mksubvol 3 49616 NULL
119163 +heap_init_49617 heap_init 2 49617 NULL
119164 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
119165 +port_fops_read_49626 port_fops_read 3 49626 NULL
119166 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
119167 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 3-4 49683 NULL
119168 +SyS_pwritev_49688 SyS_pwritev 3 49688 NULL
119169 +__setup_irq_49696 __setup_irq 0 49696 NULL
119170 +__copy_from_user_nocheck_49699 __copy_from_user_nocheck 0-3 49699 NULL
119171 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
119172 +write_pool_49718 write_pool 3 49718 NULL
119173 +kvm_mmu_notifier_invalidate_page_49723 kvm_mmu_notifier_invalidate_page 3 49723 NULL
119174 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
119175 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
119176 +btrfs_chunk_num_stripes_49751 btrfs_chunk_num_stripes 0 49751 NULL
119177 +fuse_wr_pages_49753 fuse_wr_pages 0-2-1 49753 NULL
119178 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
119179 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
119180 +ceph_osdc_readpages_49789 ceph_osdc_readpages 0 49789 NULL
119181 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
119182 +__of_parse_phandle_with_args_49807 __of_parse_phandle_with_args 0 49807 NULL
119183 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 6-3-0 49829 NULL
119184 +add_uuid_49831 add_uuid 4 49831 NULL
119185 +twl4030_write_49846 twl4030_write 2 49846 NULL
119186 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
119187 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
119188 +fiemap_count_to_size_49869 fiemap_count_to_size 0-1 49869 NULL
119189 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
119190 +osc_brw_49896 osc_brw 4 49896 NULL
119191 +ieee80211_if_fmt_dtim_count_49987 ieee80211_if_fmt_dtim_count 3 49987 NULL
119192 +drm_buffer_copy_from_user_49990 drm_buffer_copy_from_user 3 49990 NULL
119193 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
119194 +dn_mss_from_pmtu_50011 dn_mss_from_pmtu 0-2 50011 NULL
119195 +security_context_to_sid_50019 security_context_to_sid 2 50019 NULL
119196 +isdn_read_50021 isdn_read 3 50021 NULL
119197 +mdc_rename_pack_50023 mdc_rename_pack 4-6 50023 NULL
119198 +brcmf_debugfs_chipinfo_read_50033 brcmf_debugfs_chipinfo_read 3 50033 NULL
119199 +ioread8_50049 ioread8 0 50049 NULL
119200 +fuse_conn_max_background_write_50061 fuse_conn_max_background_write 3 50061 NULL
119201 +__kfifo_dma_in_prepare_50081 __kfifo_dma_in_prepare 4 50081 NULL
119202 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
119203 +libcfs_ioctl_popdata_50087 libcfs_ioctl_popdata 3 50087 NULL
119204 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
119205 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
119206 +android_set_cntry_50100 android_set_cntry 0 50100 NULL
119207 +read_file_slot_50111 read_file_slot 3 50111 NULL
119208 +rx_streaming_interval_write_50120 rx_streaming_interval_write 3 50120 NULL
119209 +jfs_direct_IO_50125 jfs_direct_IO 4 50125 NULL
119210 +SYSC_preadv_50134 SYSC_preadv 3 50134 NULL
119211 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
119212 +kmalloc_node_50163 kmalloc_node 1 50163 NULL
119213 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
119214 +ahd_probe_stack_size_50168 ahd_probe_stack_size 0 50168 NULL
119215 +odev_update_50169 odev_update 2 50169 NULL
119216 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL nohasharray
119217 +ieee80211_if_fmt_dot11MeshHWMPRannInterval_50172 ieee80211_if_fmt_dot11MeshHWMPRannInterval 3 50172 &ubi_resize_volume_50172
119218 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
119219 +cyttsp4_probe_50201 cyttsp4_probe 4 50201 NULL
119220 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
119221 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
119222 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
119223 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
119224 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
119225 +soc_codec_reg_show_50302 soc_codec_reg_show 0-3 50302 NULL
119226 +SYSC_flistxattr_50307 SYSC_flistxattr 3 50307 NULL
119227 +SYSC_sched_setaffinity_50310 SYSC_sched_setaffinity 2 50310 NULL
119228 +soc_camera_read_50319 soc_camera_read 3 50319 NULL
119229 +do_launder_page_50329 do_launder_page 0 50329 NULL
119230 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
119231 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
119232 +snd_pcm_lib_writev_50337 snd_pcm_lib_writev 0-3 50337 NULL
119233 +tpm_read_50344 tpm_read 3 50344 NULL
119234 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
119235 +iwl_dbgfs_echo_test_write_50362 iwl_dbgfs_echo_test_write 3 50362 NULL
119236 +xfrm_send_migrate_50365 xfrm_send_migrate 5 50365 NULL
119237 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
119238 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
119239 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
119240 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
119241 +validate_acl_mac_addrs_50429 validate_acl_mac_addrs 0 50429 NULL
119242 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
119243 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
119244 +device_create_sys_dev_entry_50458 device_create_sys_dev_entry 0 50458 NULL
119245 +cfs_size_round_50472 cfs_size_round 0-1 50472 NULL
119246 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
119247 +mei_io_cb_alloc_req_buf_50493 mei_io_cb_alloc_req_buf 2 50493 NULL
119248 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
119249 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
119250 +usbat_flash_write_data_50553 usbat_flash_write_data 4 50553 NULL
119251 +self_check_peb_vid_hdr_50563 self_check_peb_vid_hdr 0 50563 NULL
119252 +fat_readpages_50582 fat_readpages 4 50582 NULL
119253 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
119254 +xillybus_write_50605 xillybus_write 3 50605 NULL
119255 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
119256 +sparse_early_usemaps_alloc_node_50623 sparse_early_usemaps_alloc_node 4 50623 NULL
119257 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
119258 +ath6kl_tm_rx_event_50664 ath6kl_tm_rx_event 3 50664 NULL
119259 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
119260 +prism2_read_fid_reg_50689 prism2_read_fid_reg 0 50689 NULL
119261 +xfs_growfs_get_hdr_buf_50697 xfs_growfs_get_hdr_buf 3 50697 NULL
119262 +dev_mem_read_50706 dev_mem_read 3 50706 NULL
119263 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
119264 +__ext3_get_inode_loc_50744 __ext3_get_inode_loc 0 50744 NULL
119265 +ocfs2_xattr_block_get_50773 ocfs2_xattr_block_get 0 50773 NULL
119266 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL
119267 +bio_alloc_map_data_50782 bio_alloc_map_data 2 50782 NULL
119268 +ixgbe_acquire_msix_vectors_50789 ixgbe_acquire_msix_vectors 2 50789 NULL
119269 +tpm_write_50798 tpm_write 3 50798 NULL
119270 +tun_do_read_50800 tun_do_read 4 50800 NULL
119271 +write_flush_50803 write_flush 3 50803 NULL
119272 +dvb_play_50814 dvb_play 3 50814 NULL
119273 +btrfs_stack_file_extent_disk_num_bytes_50825 btrfs_stack_file_extent_disk_num_bytes 0 50825 NULL
119274 +dpcm_show_state_50827 dpcm_show_state 0 50827 NULL
119275 +SetArea_50835 SetArea 4 50835 NULL
119276 +videobuf_dma_init_user_50839 videobuf_dma_init_user 4-3 50839 NULL
119277 +self_check_write_50856 self_check_write 0 50856 NULL
119278 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
119279 +SyS_lgetxattr_50889 SyS_lgetxattr 4 50889 NULL
119280 +netlbl_secattr_catmap_walk_rng_50894 netlbl_secattr_catmap_walk_rng 0-2 50894 NULL
119281 +__bdev_writeseg_50903 __bdev_writeseg 4 50903 NULL
119282 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
119283 +blk_rq_cur_sectors_50910 blk_rq_cur_sectors 0 50910 NULL
119284 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
119285 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
119286 +show_device_status_50947 show_device_status 0 50947 NULL
119287 +irq_timeout_write_50950 irq_timeout_write 3 50950 NULL
119288 +virtio_cread16_50951 virtio_cread16 0 50951 NULL
119289 +sdio_uart_write_50954 sdio_uart_write 3 50954 NULL
119290 +SyS_setxattr_50957 SyS_setxattr 4 50957 NULL
119291 +of_modalias_node_50975 of_modalias_node 3 50975 NULL
119292 +iwl_statistics_flag_50981 iwl_statistics_flag 0-3 50981 NULL
119293 +timeout_write_50991 timeout_write 3 50991 NULL
119294 +proc_write_51003 proc_write 3 51003 NULL
119295 +jbd2_journal_extend_51012 jbd2_journal_extend 2 51012 NULL
119296 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
119297 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
119298 +BcmGetSectionValEndOffset_51039 BcmGetSectionValEndOffset 0 51039 NULL
119299 +dump_midi_51040 dump_midi 3 51040 NULL
119300 +usb_get_descriptor_51041 usb_get_descriptor 0 51041 NULL
119301 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
119302 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
119303 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
119304 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
119305 +__ocfs2_find_path_51096 __ocfs2_find_path 0 51096 NULL
119306 +ti_recv_51110 ti_recv 3 51110 NULL
119307 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
119308 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
119309 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
119310 +snd_pcm_unlink_51210 snd_pcm_unlink 0 51210 NULL
119311 +iwl_dbgfs_bcast_filters_macs_read_51231 iwl_dbgfs_bcast_filters_macs_read 3 51231 NULL
119312 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
119313 +snd_pcm_write_51235 snd_pcm_write 3 51235 NULL
119314 +drm_property_create_51239 drm_property_create 4 51239 NULL
119315 +st_read_51251 st_read 3 51251 NULL
119316 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
119317 +target_alloc_sgl_51264 target_alloc_sgl 3 51264 NULL
119318 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
119319 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
119320 +pvr2_std_id_to_str_51288 pvr2_std_id_to_str 2 51288 NULL
119321 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
119322 +init_map_ipmac_51317 init_map_ipmac 5 51317 NULL
119323 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
119324 +ext2_xattr_get_51327 ext2_xattr_get 0 51327 NULL
119325 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
119326 +ipw_get_event_log_len_51341 ipw_get_event_log_len 0 51341 NULL
119327 +ieee80211_if_fmt_estab_plinks_51370 ieee80211_if_fmt_estab_plinks 3 51370 NULL
119328 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
119329 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
119330 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
119331 +hfsplus_brec_read_51436 hfsplus_brec_read 0 51436 NULL
119332 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
119333 +print_devstats_dot11ACKFailureCount_51443 print_devstats_dot11ACKFailureCount 3 51443 NULL
119334 +vmxnet3_acquire_msix_vectors_51462 vmxnet3_acquire_msix_vectors 2 51462 NULL
119335 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
119336 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
119337 +kvm_fetch_guest_virt_51493 kvm_fetch_guest_virt 4-2 51493 NULL
119338 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
119339 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
119340 +batadv_tt_prepare_tvlv_local_data_51568 batadv_tt_prepare_tvlv_local_data 0 51568 NULL
119341 +ixgb_get_eeprom_len_51586 ixgb_get_eeprom_len 0 51586 NULL
119342 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
119343 +table_size_to_number_of_entries_51613 table_size_to_number_of_entries 0-1 51613 NULL
119344 +extent_fiemap_51621 extent_fiemap 3 51621 NULL
119345 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
119346 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
119347 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
119348 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
119349 +rtw_os_xmit_resource_alloc23a_51693 rtw_os_xmit_resource_alloc23a 3 51693 NULL
119350 +host_mapping_level_51696 host_mapping_level 0 51696 NULL
119351 +sel_write_access_51704 sel_write_access 3 51704 NULL
119352 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
119353 +v9fs_alloc_rdir_buf_51716 v9fs_alloc_rdir_buf 2 51716 NULL
119354 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
119355 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
119356 +cm4040_read_51732 cm4040_read 3 51732 NULL
119357 +get_user_pages_fast_51751 get_user_pages_fast 0 51751 NULL
119358 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
119359 +if_write_51756 if_write 3 51756 NULL
119360 +ssd1307fb_alloc_array_51788 ssd1307fb_alloc_array 1 51788 NULL
119361 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
119362 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
119363 +ioread32_51847 ioread32 0 51847 NULL nohasharray
119364 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 &ioread32_51847
119365 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
119366 +SYSC_sendto_51852 SYSC_sendto 6 51852 NULL
119367 +bm_page_io_async_51858 bm_page_io_async 2 51858 NULL
119368 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
119369 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
119370 +user_read_51881 user_read 3 51881 NULL
119371 +dbAdjCtl_51888 dbAdjCtl 0 51888 NULL
119372 +SyS_mq_timedsend_51896 SyS_mq_timedsend 3 51896 NULL
119373 +wmi_set_ie_51919 wmi_set_ie 3 51919 NULL
119374 +dbg_status_buf_51930 dbg_status_buf 2 51930 NULL
119375 +__tcp_mtu_to_mss_51938 __tcp_mtu_to_mss 0-2 51938 NULL
119376 +xfrm_alg_len_51940 xfrm_alg_len 0 51940 NULL
119377 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
119378 +snd_mask_min_51969 snd_mask_min 0 51969 NULL
119379 +__blkdev_get_51972 __blkdev_get 0 51972 NULL
119380 +get_zone_51981 get_zone 0-1 51981 NULL
119381 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
119382 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
119383 +scsi_sysfs_add_host_52010 scsi_sysfs_add_host 0 52010 NULL
119384 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
119385 +rdmalt_52022 rdmalt 0 52022 NULL
119386 +override_release_52032 override_release 2 52032 NULL
119387 +end_port_52042 end_port 0 52042 NULL
119388 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
119389 +msnd_fifo_write_52052 msnd_fifo_write 0-3 52052 NULL
119390 +dvb_ringbuffer_avail_52057 dvb_ringbuffer_avail 0 52057 NULL
119391 +__fuse_request_alloc_52060 __fuse_request_alloc 1 52060 NULL
119392 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
119393 +mxuport_process_read_urb_data_52072 mxuport_process_read_urb_data 3 52072 NULL
119394 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
119395 +ulist_add_merge_52096 ulist_add_merge 0 52096 NULL
119396 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
119397 +split_scan_timeout_write_52128 split_scan_timeout_write 3 52128 NULL
119398 +retry_count_read_52129 retry_count_read 3 52129 NULL
119399 +snd_pcm_channel_info_user_52135 snd_pcm_channel_info_user 0 52135 NULL
119400 +gdm_usb_hci_send_52138 gdm_usb_hci_send 3 52138 NULL
119401 +sub_alloc_52140 sub_alloc 0 52140 NULL
119402 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
119403 +htable_size_52148 htable_size 0-1 52148 NULL
119404 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
119405 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
119406 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
119407 +print_prefix_52176 print_prefix 0 52176 NULL
119408 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
119409 +reiserfs_posix_acl_from_disk_52191 reiserfs_posix_acl_from_disk 2 52191 NULL
119410 +vmci_qp_broker_alloc_52216 vmci_qp_broker_alloc 6-5 52216 NULL
119411 +fuse_request_alloc_52243 fuse_request_alloc 1 52243 NULL
119412 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
119413 +shrink_slab_52261 shrink_slab 2 52261 NULL
119414 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
119415 +handle_supp_msgs_52284 handle_supp_msgs 4 52284 NULL
119416 +kobject_set_name_vargs_52309 kobject_set_name_vargs 0 52309 NULL
119417 +read_file_reset_52310 read_file_reset 3 52310 NULL
119418 +ssd1307fb_write_52315 ssd1307fb_write 3 52315 NULL
119419 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
119420 +hwflags_read_52318 hwflags_read 3 52318 NULL
119421 +snd_pcm_hw_free_52327 snd_pcm_hw_free 0 52327 NULL
119422 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
119423 +hur_len_52339 hur_len 0 52339 NULL
119424 +bytes_to_frames_52362 bytes_to_frames 0-2 52362 NULL nohasharray
119425 +cap_inode_killpriv_52362 cap_inode_killpriv 0 52362 &bytes_to_frames_52362
119426 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
119427 +iwl_dump_fh_52371 iwl_dump_fh 0 52371 NULL
119428 +hfsplus_find_attr_52374 hfsplus_find_attr 0 52374 NULL
119429 +mq_emit_config_values_52378 mq_emit_config_values 3 52378 NULL
119430 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
119431 +jfs_setxattr_52389 jfs_setxattr 4 52389 NULL
119432 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
119433 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
119434 +hso_serial_common_create_52428 hso_serial_common_create 4 52428 NULL
119435 +delay_status_52431 delay_status 5 52431 NULL
119436 +ath6kl_delete_qos_write_52435 ath6kl_delete_qos_write 3 52435 NULL
119437 +ieee80211_if_fmt_num_sta_ps_52438 ieee80211_if_fmt_num_sta_ps 3 52438 NULL
119438 +alauda_read_data_52452 alauda_read_data 3 52452 NULL
119439 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1 52477 NULL
119440 +usb_tranzport_write_52479 usb_tranzport_write 3 52479 NULL
119441 +ocfs2_extend_no_holes_52483 ocfs2_extend_no_holes 3-4 52483 NULL
119442 +fd_do_rw_52495 fd_do_rw 3 52495 NULL
119443 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
119444 +lmv_get_easize_52504 lmv_get_easize 0 52504 NULL
119445 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
119446 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
119447 +dup_variable_bug_52525 dup_variable_bug 3 52525 NULL
119448 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
119449 +SyS_vmsplice_52540 SyS_vmsplice 3 52540 NULL
119450 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
119451 +debug_level_proc_write_52572 debug_level_proc_write 3 52572 NULL
119452 +isku_sysfs_read_macro_52587 isku_sysfs_read_macro 6 52587 NULL
119453 +snd_pcm_sw_params_52594 snd_pcm_sw_params 0 52594 NULL
119454 +SyS_setsockopt_52610 SyS_setsockopt 5 52610 NULL
119455 +ll_sa_entry_alloc_52611 ll_sa_entry_alloc 4 52611 NULL
119456 +tps80031_writes_52638 tps80031_writes 3-4 52638 NULL
119457 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
119458 +nvme_queue_extra_52661 nvme_queue_extra 0-1 52661 NULL
119459 +SYSC_gethostname_52677 SYSC_gethostname 2 52677 NULL
119460 +nvd0_disp_pioc_create__52693 nvd0_disp_pioc_create_ 5 52693 NULL
119461 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
119462 +__dm_stat_bio_52722 __dm_stat_bio 3 52722 NULL
119463 +cx25840_ir_rx_read_52724 cx25840_ir_rx_read 3 52724 NULL
119464 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
119465 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
119466 +carl9170_debugfs_vif_dump_read_52755 carl9170_debugfs_vif_dump_read 3 52755 NULL
119467 +ieee80211_if_read_beacon_timeout_52756 ieee80211_if_read_beacon_timeout 3 52756 NULL
119468 +nvme_trans_ext_inq_page_52776 nvme_trans_ext_inq_page 3 52776 NULL
119469 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
119470 +lb_alloc_ep_req_52837 lb_alloc_ep_req 2 52837 NULL
119471 +mon_bin_get_event_52863 mon_bin_get_event 4-6 52863 NULL
119472 +twl6030_gpadc_write_52867 twl6030_gpadc_write 1 52867 NULL
119473 +qib_decode_6120_err_52876 qib_decode_6120_err 3 52876 NULL
119474 +twlreg_write_52880 twlreg_write 3 52880 NULL
119475 +pvr2_ctrl_value_to_sym_internal_52881 pvr2_ctrl_value_to_sym_internal 5 52881 NULL
119476 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
119477 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
119478 +dio_bio_reap_52913 dio_bio_reap 0 52913 NULL
119479 +__kfifo_out_peek_r_52919 __kfifo_out_peek_r 3 52919 NULL
119480 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
119481 +ieee80211_if_fmt_fwded_mcast_52961 ieee80211_if_fmt_fwded_mcast 3 52961 NULL
119482 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
119483 +num_node_state_52989 num_node_state 0 52989 NULL
119484 +efivarfs_file_write_53000 efivarfs_file_write 3 53000 NULL
119485 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
119486 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
119487 +bio_cur_bytes_53037 bio_cur_bytes 0 53037 NULL
119488 +regcache_lzo_block_count_53056 regcache_lzo_block_count 0 53056 NULL
119489 +cfi_read_query_53066 cfi_read_query 0 53066 NULL
119490 +iwl_dbgfs_interrupt_write_53069 iwl_dbgfs_interrupt_write 3 53069 NULL
119491 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
119492 +vmci_check_host_caps_53087 vmci_check_host_caps 0 53087 NULL
119493 +mic_virtio_copy_from_user_53107 mic_virtio_copy_from_user 3 53107 NULL
119494 +verity_status_53120 verity_status 5 53120 NULL
119495 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
119496 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL nohasharray
119497 +inode_newsize_ok_53140 inode_newsize_ok 0 53140 &ps_poll_ps_poll_max_ap_turn_read_53140
119498 +ieee80211_bss_info_update_53170 ieee80211_bss_info_update 4 53170 NULL
119499 +btrfs_io_bio_alloc_53179 btrfs_io_bio_alloc 2 53179 NULL
119500 +clear_capture_buf_53192 clear_capture_buf 2 53192 NULL
119501 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
119502 +ptlrpc_lprocfs_req_history_max_seq_write_53243 ptlrpc_lprocfs_req_history_max_seq_write 3 53243 NULL
119503 +xfs_trans_read_buf_map_53258 xfs_trans_read_buf_map 5 53258 NULL
119504 +wil_write_file_ssid_53266 wil_write_file_ssid 3 53266 NULL
119505 +btrfs_file_extent_num_bytes_53269 btrfs_file_extent_num_bytes 0 53269 NULL
119506 +ftrace_profile_write_53327 ftrace_profile_write 3 53327 NULL
119507 +find_nr_power_limit_53330 find_nr_power_limit 0 53330 NULL
119508 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
119509 +btree_keys_bytes_53348 btree_keys_bytes 0 53348 NULL
119510 +sock_setbindtodevice_53369 sock_setbindtodevice 3 53369 NULL
119511 +get_random_bytes_arch_53370 get_random_bytes_arch 2 53370 NULL
119512 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
119513 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
119514 +apei_exec_run_optional_53452 apei_exec_run_optional 0 53452 NULL
119515 +paging64_prefetch_gpte_53468 paging64_prefetch_gpte 4 53468 NULL
119516 +ima_write_template_field_data_53475 ima_write_template_field_data 2 53475 NULL nohasharray
119517 +create_trace_kprobe_53475 create_trace_kprobe 1 53475 &ima_write_template_field_data_53475
119518 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
119519 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
119520 +do_verify_xattr_datum_53499 do_verify_xattr_datum 0 53499 NULL
119521 +snd_pcm_format_physical_width_53505 snd_pcm_format_physical_width 0 53505 NULL
119522 +dbAllocNext_53506 dbAllocNext 0 53506 NULL
119523 +force_sc_support_write_53512 force_sc_support_write 3 53512 NULL nohasharray
119524 +check_acl_53512 check_acl 0 53512 &force_sc_support_write_53512
119525 +nft_data_dump_53549 nft_data_dump 5 53549 NULL
119526 +SYSC_bind_53582 SYSC_bind 3 53582 NULL
119527 +cifs_utf16_bytes_53593 cifs_utf16_bytes 0 53593 NULL
119528 +proc_uid_map_write_53596 proc_uid_map_write 3 53596 NULL
119529 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
119530 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL
119531 +xd_write_multiple_pages_53633 xd_write_multiple_pages 6-5 53633 NULL
119532 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
119533 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
119534 +fuse_fill_write_pages_53682 fuse_fill_write_pages 4-0 53682 NULL
119535 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
119536 +bdev_logical_block_size_53690 bdev_logical_block_size 0 53690 NULL nohasharray
119537 +igb_alloc_q_vector_53690 igb_alloc_q_vector 4-6 53690 &bdev_logical_block_size_53690
119538 +find_overflow_devnum_53711 find_overflow_devnum 0 53711 NULL
119539 +__proc_debug_mb_53732 __proc_debug_mb 5 53732 NULL
119540 +wdm_write_53735 wdm_write 3 53735 NULL
119541 +lpfc_idiag_queacc_read_qe_53755 lpfc_idiag_queacc_read_qe 0-2 53755 NULL nohasharray
119542 +amdtp_out_stream_get_max_payload_53755 amdtp_out_stream_get_max_payload 0 53755 &lpfc_idiag_queacc_read_qe_53755
119543 +wa_populate_buf_in_urb_53758 wa_populate_buf_in_urb 3-4 53758 NULL
119544 +ext2_acl_count_53773 ext2_acl_count 0-1 53773 NULL
119545 +__kfifo_dma_in_prepare_r_53792 __kfifo_dma_in_prepare_r 4-5 53792 NULL
119546 +qp_alloc_host_work_53798 qp_alloc_host_work 5-3 53798 NULL
119547 +regmap_raw_write_53803 regmap_raw_write 2-4 53803 NULL
119548 +lpfc_idiag_ctlacc_read_reg_53809 lpfc_idiag_ctlacc_read_reg 0-3 53809 NULL
119549 +nls_nullsize_53815 nls_nullsize 0 53815 NULL
119550 +setup_data_read_53822 setup_data_read 3 53822 NULL
119551 +pms_read_53873 pms_read 3 53873 NULL
119552 +ieee80211_if_fmt_dropped_frames_congestion_53883 ieee80211_if_fmt_dropped_frames_congestion 3 53883 NULL
119553 +SyS_setgroups_53900 SyS_setgroups 1 53900 NULL
119554 +batadv_tt_tvlv_ogm_handler_v1_53909 batadv_tt_tvlv_ogm_handler_v1 5 53909 NULL
119555 +azx_via_get_position_53916 azx_via_get_position 0 53916 NULL
119556 +usb_serial_generic_write_53927 usb_serial_generic_write 4 53927 NULL
119557 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
119558 +__ocfs2_xattr_set_value_outside_53981 __ocfs2_xattr_set_value_outside 5 53981 NULL
119559 +ieee80211_if_fmt_dot11MeshHWMPperrMinInterval_53998 ieee80211_if_fmt_dot11MeshHWMPperrMinInterval 3 53998 NULL
119560 +hfsplus_attr_build_key_54013 hfsplus_attr_build_key 0 54013 NULL
119561 +snd_pcm_lib_write_transfer_54018 snd_pcm_lib_write_transfer 5-2-4 54018 NULL
119562 +mdc_kuc_write_54019 mdc_kuc_write 3 54019 NULL
119563 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
119564 +batadv_tt_update_orig_54049 batadv_tt_update_orig 6-4 54049 NULL
119565 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
119566 +nl80211_send_disconnected_54056 nl80211_send_disconnected 5 54056 NULL
119567 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
119568 +_malloc_54077 _malloc 1 54077 NULL
119569 +lustre_posix_acl_xattr_filter_54103 lustre_posix_acl_xattr_filter 2 54103 NULL nohasharray
119570 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 &lustre_posix_acl_xattr_filter_54103
119571 +__comedi_buf_write_alloc_54112 __comedi_buf_write_alloc 0-2 54112 NULL
119572 +strn_len_54122 strn_len 0 54122 NULL
119573 +isku_receive_54130 isku_receive 4 54130 NULL
119574 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
119575 +irq_blk_threshold_write_54138 irq_blk_threshold_write 3 54138 NULL
119576 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 NULL
119577 +nouveau_falcon_create__54169 nouveau_falcon_create_ 8 54169 NULL
119578 +p9_client_prepare_req_54175 p9_client_prepare_req 3 54175 NULL
119579 +do_sys_poll_54221 do_sys_poll 2 54221 NULL
119580 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
119581 +pi_read_regr_54231 pi_read_regr 0 54231 NULL
119582 +mcp23s08_read_regs_54246 mcp23s08_read_regs 4 54246 NULL
119583 +reada_add_block_54247 reada_add_block 2 54247 NULL
119584 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
119585 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
119586 +audio_write_54261 audio_write 4 54261 NULL nohasharray
119587 +wusb_prf_54261 wusb_prf 7 54261 &audio_write_54261
119588 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
119589 +kstrtou16_from_user_54274 kstrtou16_from_user 2 54274 NULL
119590 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
119591 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
119592 +reclaim_pages_54301 reclaim_pages 3 54301 NULL
119593 +sprintf_54306 sprintf 0 54306 NULL
119594 +bio_add_pc_page_54319 bio_add_pc_page 4 54319 NULL
119595 +br_fdb_fillbuf_54339 br_fdb_fillbuf 0 54339 NULL
119596 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
119597 +__get_free_pages_54352 __get_free_pages 0 54352 NULL
119598 +readlink_copy_54366 readlink_copy 2 54366 NULL
119599 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
119600 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 NULL nohasharray
119601 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 &do_dccp_setsockopt_54377
119602 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
119603 +snd_pcm_oss_read2_54387 snd_pcm_oss_read2 0-3 54387 NULL
119604 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
119605 +ll_ra_count_get_54410 ll_ra_count_get 3 54410 NULL
119606 +copy_gadget_strings_54417 copy_gadget_strings 2-3 54417 NULL
119607 +sparse_early_mem_maps_alloc_node_54485 sparse_early_mem_maps_alloc_node 4 54485 NULL
119608 +simple_strtoull_54493 simple_strtoull 0 54493 NULL
119609 +btrfs_ordered_sum_size_54509 btrfs_ordered_sum_size 0-2 54509 NULL
119610 +sst_byt_get_dsp_position_54513 sst_byt_get_dsp_position 0-3 54513 NULL
119611 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
119612 +vmci_transport_dgram_enqueue_54525 vmci_transport_dgram_enqueue 4 54525 NULL
119613 +viacam_read_54526 viacam_read 3 54526 NULL
119614 +unix_dgram_connect_54535 unix_dgram_connect 3 54535 NULL
119615 +setsockopt_54539 setsockopt 5 54539 NULL
119616 +lbs_lowsnr_write_54549 lbs_lowsnr_write 3 54549 NULL
119617 +SYSC_setsockopt_54561 SYSC_setsockopt 5 54561 NULL
119618 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
119619 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
119620 +nvme_npages_54601 nvme_npages 0-1 54601 NULL
119621 +irq_pkt_threshold_write_54605 irq_pkt_threshold_write 3 54605 NULL
119622 +port_fops_write_54627 port_fops_write 3 54627 NULL
119623 +tipc_send_stream_54648 tipc_send_stream 4 54648 NULL
119624 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
119625 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
119626 +twl6030_interrupt_mask_54659 twl6030_interrupt_mask 2 54659 NULL
119627 +tdp_page_fault_54663 tdp_page_fault 2 54663 NULL
119628 +bus_add_device_54665 bus_add_device 0 54665 NULL
119629 +cw1200_queue_stats_init_54670 cw1200_queue_stats_init 2 54670 NULL
119630 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
119631 +evm_read_key_54674 evm_read_key 3 54674 NULL
119632 +__btrfs_inc_extent_ref_54706 __btrfs_inc_extent_ref 7 54706 NULL
119633 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
119634 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
119635 +kzalloc_54740 kzalloc 1 54740 NULL
119636 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
119637 +lpfc_idiag_pcicfg_write_54749 lpfc_idiag_pcicfg_write 3 54749 NULL
119638 +crystalhd_user_data_54754 crystalhd_user_data 3 54754 NULL
119639 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
119640 +adis16480_show_firmware_date_54762 adis16480_show_firmware_date 3 54762 NULL
119641 +ldsem_atomic_update_54774 ldsem_atomic_update 1 54774 NULL
119642 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
119643 +nfsd_write_54809 nfsd_write 6 54809 NULL
119644 +ar9287_dump_modal_eeprom_54814 ar9287_dump_modal_eeprom 3-2 54814 NULL
119645 +crypto_tfm_ctx_alignment_54815 crypto_tfm_ctx_alignment 0 54815 NULL nohasharray
119646 +kvzalloc_54815 kvzalloc 1 54815 &crypto_tfm_ctx_alignment_54815 nohasharray
119647 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 &kvzalloc_54815
119648 +generic_perform_write_54832 generic_perform_write 3-0 54832 NULL
119649 +write_rio_54837 write_rio 3 54837 NULL
119650 +ext3_acl_from_disk_54839 ext3_acl_from_disk 2 54839 NULL nohasharray
119651 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 &ext3_acl_from_disk_54839
119652 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
119653 +printer_read_54851 printer_read 3 54851 NULL
119654 +assign_irq_vector_54852 assign_irq_vector 0 54852 NULL
119655 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
119656 +prism_build_supp_rates_54865 prism_build_supp_rates 0 54865 NULL
119657 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL nohasharray
119658 +kobject_set_name_vargs_54913 kobject_set_name_vargs 0 54913 &iscsi_pool_init_54913
119659 +btrfs_stack_chunk_num_stripes_54923 btrfs_stack_chunk_num_stripes 0 54923 NULL
119660 +bio_add_page_54933 bio_add_page 0-3 54933 NULL
119661 +mxms_structlen_54939 mxms_structlen 0 54939 NULL
119662 +add_port_54941 add_port 2 54941 NULL
119663 +tipc_send2name_54946 tipc_send2name 5 54946 NULL
119664 +ath9k_dump_btcoex_54949 ath9k_dump_btcoex 0-3 54949 NULL
119665 +alauda_write_data_54967 alauda_write_data 3 54967 NULL
119666 +c4_add_card_54968 c4_add_card 3 54968 NULL
119667 +ext3_xattr_get_54989 ext3_xattr_get 0 54989 NULL
119668 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
119669 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
119670 +apei_exec_run_55075 apei_exec_run 0 55075 NULL
119671 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
119672 +snd_pcm_capture_hw_avail_55086 snd_pcm_capture_hw_avail 0 55086 NULL
119673 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
119674 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
119675 +filldir_55137 filldir 3 55137 NULL
119676 +ocfs2_truncate_file_55148 ocfs2_truncate_file 3 55148 NULL
119677 +npages_to_npools_55149 npages_to_npools 0-1 55149 NULL
119678 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
119679 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
119680 +compat_SyS_ppoll_55196 compat_SyS_ppoll 2 55196 NULL
119681 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
119682 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL
119683 +__kfifo_dma_out_prepare_r_55211 __kfifo_dma_out_prepare_r 4-5 55211 NULL
119684 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
119685 +qxl_alloc_client_monitors_config_55216 qxl_alloc_client_monitors_config 2 55216 NULL
119686 +nouveau_mc_create__55217 nouveau_mc_create_ 4 55217 NULL
119687 +dbAllocDmap_55227 dbAllocDmap 0 55227 NULL
119688 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
119689 +lbs_failcount_write_55276 lbs_failcount_write 3 55276 NULL
119690 +persistent_ram_new_55286 persistent_ram_new 1-2 55286 NULL
119691 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
119692 +lov_get_stripecnt_55297 lov_get_stripecnt 0-3 55297 NULL
119693 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
119694 +qp_alloc_guest_work_55305 qp_alloc_guest_work 5-3 55305 NULL nohasharray
119695 +compat_SyS_process_vm_readv_55305 compat_SyS_process_vm_readv 3-5 55305 &qp_alloc_guest_work_55305
119696 +compat_SyS_mbind_55329 compat_SyS_mbind 5 55329 NULL
119697 +vme_user_read_55338 vme_user_read 3 55338 NULL
119698 +__wa_xfer_setup_sizes_55342 __wa_xfer_setup_sizes 0 55342 NULL nohasharray
119699 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 &__wa_xfer_setup_sizes_55342
119700 +cw1200_sdio_align_size_55391 cw1200_sdio_align_size 2 55391 NULL
119701 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
119702 +nouveau_cli_create_55425 nouveau_cli_create 3 55425 NULL
119703 +si476x_radio_read_rds_blckcnt_blob_55427 si476x_radio_read_rds_blckcnt_blob 3 55427 NULL
119704 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
119705 +cx23888_ir_rx_read_55473 cx23888_ir_rx_read 3 55473 NULL
119706 +snd_pcm_lib_write_55483 snd_pcm_lib_write 0-3 55483 NULL
119707 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
119708 +batadv_tt_entries_55487 batadv_tt_entries 0-1 55487 NULL
119709 +ras_stride_increase_window_55501 ras_stride_increase_window 3 55501 NULL
119710 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 NULL
119711 +ea_get_55522 ea_get 3-0 55522 NULL
119712 +buffer_size_55534 buffer_size 0 55534 NULL
119713 +set_msr_interception_55538 set_msr_interception 2 55538 NULL
119714 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
119715 +hash_ipport6_expire_55549 hash_ipport6_expire 4 55549 NULL
119716 +dm_stats_list_55551 dm_stats_list 4 55551 NULL
119717 +compat_SyS_setsockopt_55581 compat_SyS_setsockopt 5 55581 NULL
119718 +add_partition_55588 add_partition 2 55588 NULL
119719 +kstrtou8_from_user_55599 kstrtou8_from_user 2 55599 NULL
119720 +SyS_keyctl_55602 SyS_keyctl 4 55602 NULL
119721 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
119722 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
119723 +edge_tty_recv_55622 edge_tty_recv 3 55622 NULL
119724 +reiserfs_xattr_get_55628 reiserfs_xattr_get 0 55628 NULL nohasharray
119725 +pktgen_if_write_55628 pktgen_if_write 3 55628 &reiserfs_xattr_get_55628
119726 +osc_obd_max_pages_per_rpc_seq_write_55636 osc_obd_max_pages_per_rpc_seq_write 3 55636 NULL
119727 +xfs_bmbt_maxrecs_55649 xfs_bmbt_maxrecs 0-2 55649 NULL
119728 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
119729 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
119730 +get_info_55681 get_info 3 55681 NULL
119731 +iwl_dbgfs_plcp_delta_write_55682 iwl_dbgfs_plcp_delta_write 3 55682 NULL
119732 +genl_allocate_reserve_groups_55705 genl_allocate_reserve_groups 1 55705 NULL
119733 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
119734 +tap_pwup_write_55723 tap_pwup_write 3 55723 NULL
119735 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 2 55738 NULL
119736 +set_local_name_55757 set_local_name 4 55757 NULL
119737 +strlen_55778 strlen 0 55778 NULL nohasharray
119738 +is_idx_node_in_tnc_55778 is_idx_node_in_tnc 0 55778 &strlen_55778
119739 +set_spte_55783 set_spte 5-4 55783 NULL
119740 +req_bio_endio_55786 req_bio_endio 3 55786 NULL nohasharray
119741 +conf_read_55786 conf_read 3 55786 &req_bio_endio_55786
119742 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
119743 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
119744 +ip_hdrlen_55849 ip_hdrlen 0 55849 NULL
119745 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
119746 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
119747 +hsc_write_55875 hsc_write 3 55875 NULL
119748 +ramdisk_store_55885 ramdisk_store 4 55885 NULL
119749 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
119750 +hash_ip4_expire_55911 hash_ip4_expire 4 55911 NULL
119751 +snd_pcm_hw_param_value_min_55917 snd_pcm_hw_param_value_min 0 55917 NULL
119752 +ext2_direct_IO_55932 ext2_direct_IO 4 55932 NULL
119753 +kvm_write_guest_virt_system_55944 kvm_write_guest_virt_system 4-2 55944 NULL
119754 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
119755 +ceph_get_direct_page_vector_55956 ceph_get_direct_page_vector 2 55956 NULL
119756 +simple_read_from_buffer_55957 simple_read_from_buffer 2-5 55957 NULL
119757 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
119758 +btrfs_clone_55977 btrfs_clone 5-3 55977 NULL
119759 +wa_xfer_create_subset_sg_55992 wa_xfer_create_subset_sg 3-2 55992 NULL
119760 +nvme_alloc_iod_56027 nvme_alloc_iod 1-2 56027 NULL
119761 +rtl8169_init_ring_56028 rtl8169_init_ring 0 56028 NULL
119762 +usb_ocp_write_56047 usb_ocp_write 4 56047 NULL
119763 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
119764 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
119765 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
119766 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
119767 +write_file_frameerrors_56145 write_file_frameerrors 3 56145 NULL
119768 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
119769 +ath9k_dump_legacy_btcoex_56194 ath9k_dump_legacy_btcoex 3-0 56194 NULL
119770 +vring_add_indirect_56222 vring_add_indirect 4 56222 NULL
119771 +ocfs2_find_xe_in_bucket_56224 ocfs2_find_xe_in_bucket 0 56224 NULL
119772 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
119773 +fd_copyin_56247 fd_copyin 3 56247 NULL
119774 +sk_rmem_schedule_56255 sk_rmem_schedule 3 56255 NULL
119775 +acpi_ex_get_serial_access_length_56275 acpi_ex_get_serial_access_length 0-2 56275 NULL
119776 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
119777 +ieee80211_if_fmt_user_power_level_56283 ieee80211_if_fmt_user_power_level 3 56283 NULL
119778 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
119779 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
119780 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
119781 +speakup_file_write_56310 speakup_file_write 3 56310 NULL
119782 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
119783 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
119784 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
119785 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
119786 +mite_device_bytes_transferred_56355 mite_device_bytes_transferred 0 56355 NULL
119787 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 4-0 56368 NULL
119788 +dev_read_56369 dev_read 3 56369 NULL
119789 +ath10k_read_simulate_fw_crash_56371 ath10k_read_simulate_fw_crash 3 56371 NULL
119790 +snd_pcm_common_ioctl1_56382 snd_pcm_common_ioctl1 0 56382 NULL
119791 +write_gssp_56404 write_gssp 3 56404 NULL
119792 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
119793 +store_msg_56417 store_msg 3 56417 NULL
119794 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
119795 +l2cap_segment_le_sdu_56426 l2cap_segment_le_sdu 4 56426 NULL
119796 +ec_dbgfs_cmd_read_56431 ec_dbgfs_cmd_read 3 56431 NULL
119797 +fl_create_56435 fl_create 5 56435 NULL
119798 +gnttab_map_56439 gnttab_map 2 56439 NULL
119799 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2-4 56453 NULL
119800 +set_connectable_56458 set_connectable 4 56458 NULL
119801 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
119802 +putused_user_56467 putused_user 3 56467 NULL
119803 +ocfs2_zero_extend_range_56468 ocfs2_zero_extend_range 3-2 56468 NULL
119804 +lbs_rdmac_write_56471 lbs_rdmac_write 3 56471 NULL
119805 +crypto_shash_alignmask_56486 crypto_shash_alignmask 0 56486 NULL
119806 +ieee80211_rx_mgmt_probe_beacon_56491 ieee80211_rx_mgmt_probe_beacon 3 56491 NULL
119807 +memblock_virt_alloc_56501 memblock_virt_alloc 1 56501 NULL
119808 +init_map_ip_56508 init_map_ip 5 56508 NULL
119809 +lustre_posix_acl_xattr_reduce_space_56512 lustre_posix_acl_xattr_reduce_space 3 56512 NULL
119810 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
119811 +ip_options_get_56538 ip_options_get 4 56538 NULL
119812 +ll_wr_track_id_56544 ll_wr_track_id 2 56544 NULL
119813 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
119814 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
119815 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
119816 +gro_pull_from_frag0_56593 gro_pull_from_frag0 2 56593 NULL
119817 +event_filter_write_56609 event_filter_write 3 56609 NULL
119818 +nvme_trans_log_temperature_56613 nvme_trans_log_temperature 3 56613 NULL
119819 +gather_array_56641 gather_array 3 56641 NULL
119820 +lookup_extent_backref_56644 lookup_extent_backref 9 56644 NULL
119821 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
119822 +tg3_nvram_write_block_56666 tg3_nvram_write_block 3 56666 NULL
119823 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
119824 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3-0 56702 NULL
119825 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
119826 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
119827 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
119828 +__copy_from_user_ll_56738 __copy_from_user_ll 0-3 56738 NULL
119829 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
119830 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
119831 +ttm_alloc_new_pages_56792 ttm_alloc_new_pages 5 56792 NULL
119832 +ion_ioctl_56806 ion_ioctl 2 56806 NULL
119833 +do_syslog_56807 do_syslog 3 56807 NULL
119834 +mtdchar_write_56831 mtdchar_write 3 56831 NULL
119835 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4-0 56847 NULL
119836 +si476x_radio_read_agc_blob_56849 si476x_radio_read_agc_blob 3 56849 NULL
119837 +ext3_xattr_ibody_get_56880 ext3_xattr_ibody_get 0 56880 NULL
119838 +pvr2_debugifc_print_status_56890 pvr2_debugifc_print_status 3 56890 NULL
119839 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
119840 +batadv_tt_update_changes_56895 batadv_tt_update_changes 3 56895 NULL nohasharray
119841 +le_auto_conn_write_56895 le_auto_conn_write 3 56895 &batadv_tt_update_changes_56895
119842 +hfsplus_find_cat_56899 hfsplus_find_cat 0 56899 NULL
119843 +strcspn_56913 strcspn 0 56913 NULL
119844 +__kfifo_out_56927 __kfifo_out 0-3 56927 NULL
119845 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
119846 +nouveau_xtensa_create__56952 nouveau_xtensa_create_ 8 56952 NULL
119847 +diva_get_driver_info_56967 diva_get_driver_info 0 56967 NULL
119848 +sptlrpc_secflags2str_56995 sptlrpc_secflags2str 3 56995 NULL
119849 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
119850 +btrfs_super_csum_size_57004 btrfs_super_csum_size 0 57004 NULL
119851 +aircable_process_packet_57027 aircable_process_packet 4 57027 NULL
119852 +ieee80211_if_fmt_state_57043 ieee80211_if_fmt_state 3 57043 NULL nohasharray
119853 +skb_network_offset_57043 skb_network_offset 0 57043 &ieee80211_if_fmt_state_57043
119854 +bytes_to_samples_57049 bytes_to_samples 0-2 57049 NULL
119855 +xfs_buf_read_map_57053 xfs_buf_read_map 3 57053 NULL
119856 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
119857 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
119858 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
119859 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
119860 +altera_get_note_57099 altera_get_note 6 57099 NULL
119861 +hpfs_readpages_57106 hpfs_readpages 4 57106 NULL
119862 +snd_pcm_hw_params_old_user_57108 snd_pcm_hw_params_old_user 0 57108 NULL
119863 +crypto_compress_ctxsize_57109 crypto_compress_ctxsize 0 57109 NULL
119864 +cipso_v4_gentag_loc_57119 cipso_v4_gentag_loc 0 57119 NULL
119865 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 NULL nohasharray
119866 +rds_ib_sub_signaled_57136 rds_ib_sub_signaled 2 57136 &ima_show_htable_value_57136 nohasharray
119867 +nl80211_send_deauth_57136 nl80211_send_deauth 4 57136 &rds_ib_sub_signaled_57136
119868 +snd_sonicvibes_getdmac_57140 snd_sonicvibes_getdmac 0 57140 NULL
119869 +_iwl_dbgfs_bf_params_write_57141 _iwl_dbgfs_bf_params_write 3 57141 NULL
119870 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
119871 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
119872 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
119873 +hash_netnet6_expire_57191 hash_netnet6_expire 4 57191 NULL
119874 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
119875 +dma_fifo_alloc_57236 dma_fifo_alloc 2-3-5 57236 NULL
119876 +flush_space_57241 flush_space 0 57241 NULL
119877 +rsxx_cram_write_57244 rsxx_cram_write 3 57244 NULL
119878 +ieee80211_if_fmt_tsf_57249 ieee80211_if_fmt_tsf 3 57249 NULL
119879 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
119880 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
119881 +lbs_sleepparams_write_57283 lbs_sleepparams_write 3 57283 NULL
119882 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
119883 +snd_pcm_read_57289 snd_pcm_read 3 57289 NULL
119884 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
119885 +write_file_regval_57313 write_file_regval 3 57313 NULL
119886 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
119887 +usblp_read_57342 usblp_read 3 57342 NULL
119888 +print_devstats_dot11RTSFailureCount_57347 print_devstats_dot11RTSFailureCount 3 57347 NULL
119889 +dio_send_cur_page_57348 dio_send_cur_page 0 57348 NULL
119890 +tipc_bclink_stats_57372 tipc_bclink_stats 2 57372 NULL
119891 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
119892 +read_file_blob_57406 read_file_blob 3 57406 NULL
119893 +enclosure_register_57412 enclosure_register 3 57412 NULL
119894 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL
119895 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
119896 +__roundup_pow_of_two_57461 __roundup_pow_of_two 0 57461 NULL
119897 +sisusb_clear_vram_57466 sisusb_clear_vram 2-3 57466 NULL
119898 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL
119899 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
119900 +skb_headlen_57501 skb_headlen 0 57501 NULL
119901 +copy_in_user_57502 copy_in_user 3 57502 NULL
119902 +ckhdid_printf_57505 ckhdid_printf 2 57505 NULL
119903 +init_tag_map_57515 init_tag_map 3 57515 NULL
119904 +wil_read_file_ssid_57517 wil_read_file_ssid 3 57517 NULL nohasharray
119905 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 &wil_read_file_ssid_57517
119906 +cmm_read_57520 cmm_read 3 57520 NULL
119907 +inode_permission_57531 inode_permission 0 57531 NULL
119908 +acpi_dev_get_resources_57534 acpi_dev_get_resources 0 57534 NULL
119909 +ptlrpc_lprocfs_hp_ratio_seq_write_57537 ptlrpc_lprocfs_hp_ratio_seq_write 3 57537 NULL
119910 +compat_SyS_process_vm_writev_57542 compat_SyS_process_vm_writev 3-5 57542 NULL
119911 +obd_unpackmd_57563 obd_unpackmd 0 57563 NULL
119912 +snd_pcm_playback_ioctl1_57569 snd_pcm_playback_ioctl1 0 57569 NULL
119913 +get_bridge_ifindices_57579 get_bridge_ifindices 0 57579 NULL
119914 +ldlm_cli_enqueue_local_57582 ldlm_cli_enqueue_local 11 57582 NULL
119915 +il_dbgfs_interrupt_write_57591 il_dbgfs_interrupt_write 3 57591 NULL
119916 +read_file_spectral_fft_period_57593 read_file_spectral_fft_period 3 57593 NULL
119917 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
119918 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 NULL
119919 +mem_read_57631 mem_read 3 57631 NULL
119920 +pci_enable_msi_block_57632 pci_enable_msi_block 0 57632 NULL
119921 +msi_compose_msg_57637 msi_compose_msg 0 57637 NULL
119922 +r3964_write_57662 r3964_write 4 57662 NULL
119923 +proc_ns_readlink_57664 proc_ns_readlink 3 57664 NULL
119924 +__lgwrite_57669 __lgwrite 4 57669 NULL
119925 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
119926 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
119927 +vm_find_vqs_57729 vm_find_vqs 0 57729 NULL
119928 +nouveau_gpio_create__57735 nouveau_gpio_create_ 4-5 57735 NULL
119929 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 NULL
119930 +ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval_57762 ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval 3 57762 NULL
119931 +SYSC_process_vm_writev_57776 SYSC_process_vm_writev 3-5 57776 NULL
119932 +security_inode_unlink_57791 security_inode_unlink 0 57791 NULL
119933 +ld2_57794 ld2 0 57794 NULL
119934 +ivtv_read_57796 ivtv_read 3 57796 NULL
119935 +ion_test_ioctl_57799 ion_test_ioctl 2 57799 NULL
119936 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
119937 +copy_to_user_57835 copy_to_user 0-3 57835 NULL
119938 +flash_read_57843 flash_read 3 57843 NULL
119939 +kiblnd_create_tx_pool_57846 kiblnd_create_tx_pool 2 57846 NULL
119940 +radeon_ttm_gtt_read_57879 radeon_ttm_gtt_read 3 57879 NULL
119941 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
119942 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
119943 +ll_xattr_find_get_lock_57912 ll_xattr_find_get_lock 0 57912 NULL
119944 +memcg_caches_array_size_57918 memcg_caches_array_size 0-1 57918 NULL
119945 +twl_i2c_write_57923 twl_i2c_write 3-4 57923 NULL
119946 +__snd_gf1_look16_57925 __snd_gf1_look16 0 57925 NULL
119947 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
119948 +xfs_mru_cache_create_57943 xfs_mru_cache_create 3 57943 NULL
119949 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
119950 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL nohasharray
119951 +ioat3_dca_count_dca_slots_57953 ioat3_dca_count_dca_slots 0 57953 &ip_set_alloc_57953
119952 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
119953 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
119954 +io_playback_transfer_58030 io_playback_transfer 4 58030 NULL
119955 +mce_async_out_58056 mce_async_out 3 58056 NULL
119956 +ocfs2_find_leaf_58065 ocfs2_find_leaf 0 58065 NULL
119957 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
119958 +cm4040_write_58079 cm4040_write 3 58079 NULL
119959 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
119960 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
119961 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
119962 +ieee80211_if_fmt_flags_58205 ieee80211_if_fmt_flags 3 58205 NULL
119963 +i40evf_allocate_virt_mem_d_58210 i40evf_allocate_virt_mem_d 3 58210 NULL
119964 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
119965 +read_file_debug_58256 read_file_debug 3 58256 NULL
119966 +osc_max_dirty_mb_seq_write_58263 osc_max_dirty_mb_seq_write 3 58263 NULL
119967 +cfg80211_mgmt_tx_status_58266 cfg80211_mgmt_tx_status 4 58266 NULL
119968 +profile_load_58267 profile_load 3 58267 NULL
119969 +kstrtos8_from_user_58268 kstrtos8_from_user 2 58268 NULL
119970 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
119971 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
119972 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
119973 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
119974 +ext4_ext_truncate_extend_restart_58331 ext4_ext_truncate_extend_restart 3 58331 NULL
119975 +__copy_from_user_swizzled_58337 __copy_from_user_swizzled 2-4 58337 NULL
119976 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
119977 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
119978 +_drbd_md_sync_page_io_58403 _drbd_md_sync_page_io 6 58403 NULL
119979 +idetape_pad_zeros_58406 idetape_pad_zeros 2 58406 NULL
119980 +i2400m_pld_size_58415 i2400m_pld_size 0 58415 NULL
119981 +capabilities_read_58457 capabilities_read 3 58457 NULL
119982 +usnic_vnic_get_resources_58462 usnic_vnic_get_resources 3 58462 NULL
119983 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 NULL nohasharray
119984 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 &compat_do_ipt_set_ctl_58466
119985 +nv_rd08_58472 nv_rd08 0 58472 NULL
119986 +acpi_tables_sysfs_init_58477 acpi_tables_sysfs_init 0 58477 NULL
119987 +snd_gf1_read_addr_58483 snd_gf1_read_addr 0 58483 NULL
119988 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
119989 +btrfs_cont_expand_58498 btrfs_cont_expand 2-3-0 58498 NULL
119990 +tcf_hash_create_58507 tcf_hash_create 4 58507 NULL
119991 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
119992 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
119993 +scnprint_mac_oui_58578 scnprint_mac_oui 3-0 58578 NULL
119994 +cur_wm_latency_write_58581 cur_wm_latency_write 3 58581 NULL
119995 +get_rhf_errstring_58582 get_rhf_errstring 3 58582 NULL
119996 +ea_read_inline_58589 ea_read_inline 0 58589 NULL
119997 +isku_sysfs_read_keys_thumbster_58590 isku_sysfs_read_keys_thumbster 6 58590 NULL
119998 +xip_file_read_58592 xip_file_read 3 58592 NULL
119999 +ecryptfs_write_end_58594 ecryptfs_write_end 5-3 58594 NULL
120000 +radeon_bo_size_58606 radeon_bo_size 0 58606 NULL
120001 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
120002 +filemap_fdatawrite_range_58630 filemap_fdatawrite_range 0 58630 NULL
120003 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
120004 +iwl_dbgfs_rx_handlers_write_58655 iwl_dbgfs_rx_handlers_write 3 58655 NULL
120005 +find_zero_58685 find_zero 0-1 58685 NULL
120006 +uwb_bce_print_IEs_58686 uwb_bce_print_IEs 4 58686 NULL
120007 +tps6586x_writes_58689 tps6586x_writes 2-3 58689 NULL
120008 +scsi_setup_command_freelist_58703 scsi_setup_command_freelist 0 58703 NULL
120009 +vx_send_msg_58711 vx_send_msg 0 58711 NULL
120010 +csum_exist_in_range_58730 csum_exist_in_range 2-3 58730 NULL
120011 +frames_to_bytes_58741 frames_to_bytes 0-2 58741 NULL
120012 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
120013 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
120014 +regmap_calc_reg_len_58795 regmap_calc_reg_len 0 58795 NULL
120015 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
120016 +isku_sysfs_read_58806 isku_sysfs_read 5 58806 NULL
120017 +ep_read_58813 ep_read 3 58813 NULL
120018 +command_write_58841 command_write 3 58841 NULL
120019 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
120020 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
120021 +esas2r_change_queue_depth_58886 esas2r_change_queue_depth 2 58886 NULL
120022 +lprocfs_wr_pinger_recov_58914 lprocfs_wr_pinger_recov 3 58914 NULL
120023 +print_devstats_dot11FCSErrorCount_58919 print_devstats_dot11FCSErrorCount 3 58919 NULL
120024 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
120025 +wait_table_hash_nr_entries_58962 wait_table_hash_nr_entries 0 58962 NULL
120026 +ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout_58965 ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout 3 58965 NULL
120027 +crypto_aead_ivsize_58970 crypto_aead_ivsize 0 58970 NULL
120028 +init_list_set_59005 init_list_set 3 59005 NULL
120029 +ep_write_59008 ep_write 3 59008 NULL
120030 +lpfc_idiag_baracc_write_59014 lpfc_idiag_baracc_write 3 59014 NULL
120031 +SyS_preadv_59029 SyS_preadv 3 59029 NULL
120032 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
120033 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
120034 +crypto_aead_reqsize_59039 crypto_aead_reqsize 0 59039 NULL
120035 +regmap_bulk_write_59049 regmap_bulk_write 2-4 59049 NULL nohasharray
120036 +i8042_enable_kbd_port_59049 i8042_enable_kbd_port 0 59049 &regmap_bulk_write_59049
120037 +mmc_sd_num_wr_blocks_59112 mmc_sd_num_wr_blocks 0 59112 NULL
120038 +sta_tx_latency_stat_table_59122 sta_tx_latency_stat_table 0-4-5 59122 NULL nohasharray
120039 +scsi_io_completion_59122 scsi_io_completion 2 59122 &sta_tx_latency_stat_table_59122
120040 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
120041 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 NULL nohasharray
120042 +print_devstats_dot11RTSSuccessCount_59145 print_devstats_dot11RTSSuccessCount 3 59145 &framebuffer_alloc_59145
120043 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
120044 +pvr2_hdw_report_clients_59152 pvr2_hdw_report_clients 3 59152 NULL
120045 +ksize_59176 ksize 0 59176 NULL
120046 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
120047 +ocfs2_move_extent_59187 ocfs2_move_extent 2-5 59187 NULL
120048 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
120049 +check_mapped_selector_name_59216 check_mapped_selector_name 5 59216 NULL
120050 +dt3155_read_59226 dt3155_read 3 59226 NULL
120051 +paging64_gpte_to_gfn_lvl_59229 paging64_gpte_to_gfn_lvl 0-2-1 59229 NULL
120052 +nla_len_59258 nla_len 0 59258 NULL
120053 +drbd_bm_write_page_59290 drbd_bm_write_page 2 59290 NULL
120054 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
120055 +fd_copyout_59323 fd_copyout 3 59323 NULL
120056 +read_9287_modal_eeprom_59327 read_9287_modal_eeprom 3 59327 NULL
120057 +set_state_private_59336 set_state_private 0 59336 NULL
120058 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
120059 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
120060 +f2fs_fallocate_59377 f2fs_fallocate 4-3 59377 NULL
120061 +pvr2_debugifc_print_info_59380 pvr2_debugifc_print_info 3 59380 NULL
120062 +journal_init_dev_59384 journal_init_dev 5 59384 NULL
120063 +__net_get_random_once_59389 __net_get_random_once 2 59389 NULL
120064 +isku_sysfs_read_keys_function_59412 isku_sysfs_read_keys_function 6 59412 NULL
120065 +pci_ctrl_read_59424 pci_ctrl_read 0 59424 NULL
120066 +vxge_hw_ring_rxds_per_block_get_59425 vxge_hw_ring_rxds_per_block_get 0 59425 NULL
120067 +snd_pcm_tstamp_59431 snd_pcm_tstamp 0 59431 NULL
120068 +SyS_sched_setaffinity_59442 SyS_sched_setaffinity 2 59442 NULL
120069 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
120070 +tipc_recv_stream_59456 tipc_recv_stream 4 59456 NULL
120071 +_iwl_dbgfs_bcast_filters_write_59491 _iwl_dbgfs_bcast_filters_write 3 59491 NULL
120072 +rtw_cfg80211_set_mgnt_wpsp2pie_59497 rtw_cfg80211_set_mgnt_wpsp2pie 3 59497 NULL
120073 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
120074 +C_SYSC_get_mempolicy_59516 C_SYSC_get_mempolicy 3 59516 NULL
120075 +mic_vringh_copy_59523 mic_vringh_copy 4 59523 NULL
120076 +msix_setup_entries_59545 msix_setup_entries 0 59545 NULL nohasharray
120077 +idr_alloc_59545 idr_alloc 0 59545 &msix_setup_entries_59545
120078 +mpi_get_nbits_59551 mpi_get_nbits 0 59551 NULL
120079 +tunables_write_59563 tunables_write 3 59563 NULL
120080 +bio_split_59564 bio_split 2 59564 NULL
120081 +__copy_from_user_ll_nozero_59571 __copy_from_user_ll_nozero 0-3 59571 NULL
120082 +memdup_user_59590 memdup_user 2 59590 NULL
120083 +xrcdn_free_res_59616 xrcdn_free_res 5 59616 NULL nohasharray
120084 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 &xrcdn_free_res_59616
120085 +ath6kl_endpoint_stats_write_59621 ath6kl_endpoint_stats_write 3 59621 NULL
120086 +mtrr_write_59622 mtrr_write 3 59622 NULL
120087 +find_first_zero_bit_59636 find_first_zero_bit 0 59636 NULL
120088 +SyS_setdomainname_59646 SyS_setdomainname 2 59646 NULL
120089 +file_update_time_59647 file_update_time 0 59647 NULL
120090 +hidraw_read_59650 hidraw_read 3 59650 NULL
120091 +v9fs_xattr_set_acl_59651 v9fs_xattr_set_acl 4 59651 NULL
120092 +__devcgroup_check_permission_59665 __devcgroup_check_permission 0 59665 NULL
120093 +iwl_dbgfs_mac_params_read_59666 iwl_dbgfs_mac_params_read 3 59666 NULL
120094 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
120095 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
120096 +ioperm_get_59701 ioperm_get 4-3 59701 NULL
120097 +snd_pcm_info_user_59711 snd_pcm_info_user 0 59711 NULL
120098 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
120099 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 NULL
120100 +fat_direct_IO_59741 fat_direct_IO 4 59741 NULL
120101 +qib_decode_7220_sdma_errs_59745 qib_decode_7220_sdma_errs 4 59745 NULL
120102 +strnlen_59746 strnlen 0 59746 NULL
120103 +ext3_acl_count_59754 ext3_acl_count 0-1 59754 NULL
120104 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL nohasharray
120105 +cap_inode_need_killpriv_59766 cap_inode_need_killpriv 0 59766 &long_retry_limit_read_59766
120106 +venus_remove_59781 venus_remove 4 59781 NULL
120107 +mei_nfc_recv_59784 mei_nfc_recv 3 59784 NULL
120108 +C_SYSC_preadv_59801 C_SYSC_preadv 3 59801 NULL
120109 +ipw_write_59807 ipw_write 3 59807 NULL
120110 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
120111 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
120112 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
120113 +regmap_raw_write_async_59849 regmap_raw_write_async 2-4 59849 NULL
120114 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
120115 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
120116 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
120117 +kvm_mmu_notifier_invalidate_range_start_59944 kvm_mmu_notifier_invalidate_range_start 3-4 59944 NULL
120118 +ath10k_read_dfs_stats_59949 ath10k_read_dfs_stats 3 59949 NULL
120119 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 NULL nohasharray
120120 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 &dapm_widget_power_read_file_59950
120121 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
120122 +__arch_hweight16_59975 __arch_hweight16 0 59975 NULL
120123 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
120124 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
120125 +ieee80211_if_fmt_dot11MeshAwakeWindowDuration_60006 ieee80211_if_fmt_dot11MeshAwakeWindowDuration 3 60006 NULL
120126 +copy_items_60009 copy_items 7 60009 NULL
120127 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
120128 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
120129 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
120130 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
120131 +bio_integrity_hw_sectors_60039 bio_integrity_hw_sectors 0-2 60039 NULL
120132 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
120133 +vcs_size_60050 vcs_size 0 60050 NULL
120134 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 NULL
120135 +compat_writev_60063 compat_writev 3 60063 NULL
120136 +ath6kl_listen_int_write_60066 ath6kl_listen_int_write 3 60066 NULL
120137 +c4iw_num_stags_60073 c4iw_num_stags 0 60073 NULL
120138 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
120139 +ieee80211_if_fmt_fwded_frames_60103 ieee80211_if_fmt_fwded_frames 3 60103 NULL
120140 +SYSC_msgsnd_60113 SYSC_msgsnd 3 60113 NULL
120141 +nfs_idmap_request_key_60124 nfs_idmap_request_key 2 60124 NULL
120142 +__mutex_lock_common_60134 __mutex_lock_common 0 60134 NULL
120143 +ld_usb_read_60156 ld_usb_read 3 60156 NULL
120144 +jmb38x_ms_count_slots_60164 jmb38x_ms_count_slots 0 60164 NULL
120145 +init_state_60165 init_state 2 60165 NULL
120146 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 NULL nohasharray
120147 +sg_build_sgat_60179 sg_build_sgat 3 60179 &jffs2_alloc_full_dirent_60179
120148 +fuse_async_req_send_60183 fuse_async_req_send 0-3 60183 NULL
120149 +arch_setup_msi_irqs_60193 arch_setup_msi_irqs 0 60193 NULL nohasharray
120150 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 &arch_setup_msi_irqs_60193
120151 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 NULL
120152 +btrfs_get_token_16_60220 btrfs_get_token_16 0 60220 NULL
120153 +irq_alloc_domain_generic_chips_60264 irq_alloc_domain_generic_chips 2-3 60264 NULL
120154 +display_crc_ctl_write_60273 display_crc_ctl_write 3 60273 NULL
120155 +printer_write_60276 printer_write 3 60276 NULL
120156 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
120157 +getDataLength_60301 getDataLength 0 60301 NULL
120158 +bch_subtract_dirty_60306 bch_subtract_dirty 3-4 60306 NULL
120159 +usb_alphatrack_write_60341 usb_alphatrack_write 3 60341 NULL
120160 +__kfifo_from_user_r_60345 __kfifo_from_user_r 5-3 60345 NULL
120161 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
120162 +ubi_eba_atomic_leb_change_60379 ubi_eba_atomic_leb_change 0 60379 NULL
120163 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
120164 +ocfs2_zero_extend_60396 ocfs2_zero_extend 3 60396 NULL
120165 +driver_names_read_60399 driver_names_read 3 60399 NULL
120166 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
120167 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
120168 +kmalloc_60432 kmalloc 1 60432 NULL nohasharray
120169 +tstats_write_60432 tstats_write 3 60432 &kmalloc_60432
120170 +snd_hda_get_num_raw_conns_60462 snd_hda_get_num_raw_conns 0 60462 NULL
120171 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
120172 +lustre_msg_early_size_60496 lustre_msg_early_size 0 60496 NULL
120173 +compat_SyS_get_mempolicy_60527 compat_SyS_get_mempolicy 3 60527 NULL
120174 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
120175 +nonpaging_map_60551 nonpaging_map 4 60551 NULL
120176 +osc_lockless_truncate_seq_write_60553 osc_lockless_truncate_seq_write 3 60553 NULL
120177 +tracing_entries_write_60563 tracing_entries_write 3 60563 NULL
120178 +memblock_virt_alloc_try_nid_nopanic_60604 memblock_virt_alloc_try_nid_nopanic 1 60604 NULL
120179 +inode_change_ok_60614 inode_change_ok 0 60614 NULL
120180 +skb_transport_offset_60619 skb_transport_offset 0 60619 NULL
120181 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
120182 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
120183 +__proc_lnet_stats_60647 __proc_lnet_stats 5 60647 NULL
120184 +if_sdio_host_to_card_60666 if_sdio_host_to_card 4 60666 NULL
120185 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
120186 +vga_rcrt_60731 vga_rcrt 0 60731 NULL
120187 +snd_ice1712_ds_read_60754 snd_ice1712_ds_read 0 60754 NULL
120188 +raid_status_60755 raid_status 5 60755 NULL
120189 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
120190 +opticon_write_60775 opticon_write 4 60775 NULL
120191 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
120192 +snd_pcm_oss_readv3_60792 snd_pcm_oss_readv3 3 60792 NULL
120193 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
120194 +__clone_and_map_data_bio_60861 __clone_and_map_data_bio 3-4 60861 NULL
120195 +alloc_buf_60864 alloc_buf 3-2 60864 NULL
120196 +generic_writepages_60871 generic_writepages 0 60871 NULL
120197 +ubifs_read_one_lp_60882 ubifs_read_one_lp 0 60882 NULL
120198 +ext4_update_inline_data_60888 ext4_update_inline_data 3 60888 NULL
120199 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
120200 +libcfs_sock_ioctl_60915 libcfs_sock_ioctl 0 60915 NULL
120201 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
120202 +submit_extent_page_60928 submit_extent_page 5 60928 NULL
120203 +pti_char_write_60960 pti_char_write 3 60960 NULL
120204 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
120205 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
120206 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
120207 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
120208 +graph_depth_write_61024 graph_depth_write 3 61024 NULL
120209 +sdhci_pltfm_register_61031 sdhci_pltfm_register 3 61031 NULL
120210 +lpfc_idiag_queacc_write_61043 lpfc_idiag_queacc_write 3 61043 NULL
120211 +symtab_init_61050 symtab_init 2 61050 NULL
120212 +fuse_send_write_61053 fuse_send_write 0-4 61053 NULL
120213 +snd_pcm_pause_61054 snd_pcm_pause 0 61054 NULL
120214 +bitmap_scnlistprintf_61062 bitmap_scnlistprintf 2-0 61062 NULL
120215 +ahash_align_buffer_size_61070 ahash_align_buffer_size 0-1-2 61070 NULL
120216 +snd_pcm_update_hw_ptr0_61084 snd_pcm_update_hw_ptr0 0 61084 NULL
120217 +get_derived_key_61100 get_derived_key 4 61100 NULL
120218 +i40e_calculate_l2fpm_size_61104 i40e_calculate_l2fpm_size 0-4-3-2-1 61104 NULL
120219 +alloc_chrdev_region_61112 alloc_chrdev_region 0 61112 NULL
120220 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
120221 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
120222 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
120223 +pair_device_61175 pair_device 4 61175 NULL nohasharray
120224 +event_oom_late_read_61175 event_oom_late_read 3 61175 &pair_device_61175
120225 +dio_bio_add_page_61178 dio_bio_add_page 0 61178 NULL
120226 +SyS_prctl_61202 SyS_prctl 4 61202 NULL
120227 +arch_hibernation_header_save_61212 arch_hibernation_header_save 0 61212 NULL
120228 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
120229 +v9fs_mmap_file_read_61262 v9fs_mmap_file_read 3 61262 NULL
120230 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 NULL nohasharray
120231 +find_get_pages_tag_61270 find_get_pages_tag 0 61270 &btrfs_bio_alloc_61270 nohasharray
120232 +ifalias_store_61270 ifalias_store 4 61270 &find_get_pages_tag_61270
120233 +vortex_adbdma_getlinearpos_61283 vortex_adbdma_getlinearpos 0 61283 NULL nohasharray
120234 +hfsplus_getxattr_finder_info_61283 hfsplus_getxattr_finder_info 0 61283 &vortex_adbdma_getlinearpos_61283
120235 +nvme_trans_copy_to_user_61288 nvme_trans_copy_to_user 3 61288 NULL
120236 +xfer_from_user_61307 xfer_from_user 3 61307 NULL
120237 +xfrm_user_sec_ctx_size_61320 xfrm_user_sec_ctx_size 0 61320 NULL
120238 +C_SYSC_msgsnd_61330 C_SYSC_msgsnd 3 61330 NULL
120239 +write_file_spectral_short_repeat_61335 write_file_spectral_short_repeat 3 61335 NULL
120240 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
120241 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
120242 +__dm_get_reserved_ios_61342 __dm_get_reserved_ios 0-3-2 61342 NULL
120243 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
120244 +system_enable_write_61396 system_enable_write 3 61396 NULL
120245 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
120246 +snd_pcm_lib_writev_transfer_61483 snd_pcm_lib_writev_transfer 5-4-2 61483 NULL
120247 +btrfs_item_size_61485 btrfs_item_size 0 61485 NULL
120248 +erst_errno_61526 erst_errno 0 61526 NULL
120249 +compat_SyS_select_61542 compat_SyS_select 1 61542 NULL
120250 +trace_options_core_write_61551 trace_options_core_write 3 61551 NULL
120251 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
120252 +fan_proc_write_61569 fan_proc_write 3 61569 NULL
120253 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
120254 +ldlm_pool_rw_atomic_seq_write_61572 ldlm_pool_rw_atomic_seq_write 3 61572 NULL
120255 +seq_open_private_61589 seq_open_private 3 61589 NULL
120256 +ept_gpte_to_gfn_lvl_61591 ept_gpte_to_gfn_lvl 0-2-1 61591 NULL
120257 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
120258 +nfs4_init_uniform_client_string_61601 nfs4_init_uniform_client_string 3 61601 NULL
120259 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
120260 +ieee80211_if_fmt_hw_queues_61629 ieee80211_if_fmt_hw_queues 3 61629 NULL
120261 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
120262 +snd_pcm_oss_read3_61643 snd_pcm_oss_read3 0-3 61643 NULL nohasharray
120263 +tcf_hashinfo_init_61643 tcf_hashinfo_init 2 61643 &snd_pcm_oss_read3_61643
120264 +resize_stripes_61650 resize_stripes 2 61650 NULL
120265 +ttm_page_pool_free_61661 ttm_page_pool_free 2-0 61661 NULL
120266 +insert_one_name_61668 insert_one_name 7 61668 NULL
120267 +snd_pcm_playback_avail_61671 snd_pcm_playback_avail 0 61671 NULL
120268 +qib_format_hwmsg_61679 qib_format_hwmsg 2 61679 NULL
120269 +lock_loop_61681 lock_loop 1 61681 NULL
120270 +__do_tune_cpucache_61684 __do_tune_cpucache 2 61684 NULL
120271 +filter_read_61692 filter_read 3 61692 NULL
120272 +iov_length_61716 iov_length 0 61716 NULL
120273 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
120274 +null_alloc_reqbuf_61719 null_alloc_reqbuf 3 61719 NULL
120275 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
120276 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
120277 +SyS_sendto_61763 SyS_sendto 6 61763 NULL
120278 +mls_compute_context_len_61812 mls_compute_context_len 0 61812 NULL
120279 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
120280 +regcache_sync_block_61846 regcache_sync_block 5-4 61846 NULL
120281 +ath9k_hw_def_dump_eeprom_61853 ath9k_hw_def_dump_eeprom 5-4 61853 NULL
120282 +evdev_compute_buffer_size_61863 evdev_compute_buffer_size 0 61863 NULL
120283 +SYSC_lsetxattr_61869 SYSC_lsetxattr 4 61869 NULL
120284 +get_fw_name_61874 get_fw_name 3 61874 NULL
120285 +btrfs_ioctl_clone_61886 btrfs_ioctl_clone 3-4-5 61886 NULL
120286 +lprocfs_write_frac_u64_helper_61897 lprocfs_write_frac_u64_helper 2 61897 NULL
120287 +lov_mds_md_stripecnt_61899 lov_mds_md_stripecnt 0-1 61899 NULL
120288 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
120289 +kernfs_name_61910 kernfs_name 3 61910 NULL
120290 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
120291 +au0828_init_isoc_61917 au0828_init_isoc 3-2-4 61917 NULL
120292 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
120293 +SyS_kexec_load_61946 SyS_kexec_load 2 61946 NULL
120294 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
120295 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
120296 +fix_read_error_61965 fix_read_error 4 61965 NULL
120297 +cow_file_range_61979 cow_file_range 3 61979 NULL
120298 +set_extent_delalloc_61982 set_extent_delalloc 0 61982 NULL
120299 +dequeue_event_62000 dequeue_event 3 62000 NULL
120300 +xt_compat_match_offset_62011 xt_compat_match_offset 0 62011 NULL
120301 +SyS_setxattr_62019 SyS_setxattr 4 62019 NULL
120302 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
120303 +SYSC_select_62024 SYSC_select 1 62024 NULL
120304 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
120305 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
120306 +do_pselect_62061 do_pselect 1 62061 NULL
120307 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
120308 +fat_setattr_62084 fat_setattr 0 62084 NULL
120309 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
120310 +btrfs_direct_IO_62114 btrfs_direct_IO 4 62114 NULL
120311 +ip_recv_error_62117 ip_recv_error 3 62117 NULL
120312 +generic_block_fiemap_62122 generic_block_fiemap 4 62122 NULL
120313 +llc_ui_header_len_62131 llc_ui_header_len 0 62131 NULL
120314 +qib_diag_write_62133 qib_diag_write 3 62133 NULL nohasharray
120315 +kobject_add_varg_62133 kobject_add_varg 0 62133 &qib_diag_write_62133
120316 +ql_status_62135 ql_status 5 62135 NULL nohasharray
120317 +device_add_attrs_62135 device_add_attrs 0 62135 &ql_status_62135
120318 +video_usercopy_62151 video_usercopy 2 62151 NULL
120319 +SyS_getxattr_62166 SyS_getxattr 4 62166 NULL
120320 +prism54_wpa_bss_ie_get_62173 prism54_wpa_bss_ie_get 0 62173 NULL
120321 +write_file_dfs_62180 write_file_dfs 3 62180 NULL
120322 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
120323 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
120324 +smk_read_syslog_62227 smk_read_syslog 3 62227 NULL
120325 +SYSC_setgroups16_62232 SYSC_setgroups16 1 62232 NULL
120326 +nfsd_read_file_62241 nfsd_read_file 6 62241 NULL
120327 +ion_handle_test_dma_62262 ion_handle_test_dma 4-5 62262 NULL
120328 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
120329 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
120330 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
120331 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
120332 +subseq_list_62332 subseq_list 3-0 62332 NULL
120333 +ll_statahead_max_seq_write_62333 ll_statahead_max_seq_write 3 62333 NULL
120334 +flash_write_62354 flash_write 3 62354 NULL
120335 +xfpregs_set_62363 xfpregs_set 4 62363 NULL
120336 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
120337 +altera_irscan_62396 altera_irscan 2 62396 NULL
120338 +set_ssp_62411 set_ssp 4 62411 NULL
120339 +udf_expand_file_adinicb_62470 udf_expand_file_adinicb 0 62470 NULL
120340 +ext_rts51x_sd_execute_read_data_62501 ext_rts51x_sd_execute_read_data 9 62501 NULL
120341 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
120342 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
120343 +debugfs_read_62535 debugfs_read 3 62535 NULL
120344 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
120345 +qib_refresh_qsfp_cache_62547 qib_refresh_qsfp_cache 0 62547 NULL
120346 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
120347 +get_subdir_62581 get_subdir 3 62581 NULL
120348 +nfsd_vfs_read_62605 nfsd_vfs_read 6 62605 NULL
120349 +dut_mode_write_62630 dut_mode_write 3 62630 NULL
120350 +vfs_fsync_range_62635 vfs_fsync_range 0 62635 NULL
120351 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
120352 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
120353 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
120354 +gfs2_log_write_62717 gfs2_log_write 3 62717 NULL
120355 +rdm_62719 rdm 0 62719 NULL
120356 +obd_ioctl_popdata_62741 obd_ioctl_popdata 3 62741 NULL
120357 +key_replays_read_62746 key_replays_read 3 62746 NULL
120358 +lov_verify_lmm_62747 lov_verify_lmm 2 62747 NULL
120359 +mwifiex_rdeeprom_write_62754 mwifiex_rdeeprom_write 3 62754 NULL
120360 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 NULL
120361 +C_SYSC_ipc_62776 C_SYSC_ipc 3 62776 NULL
120362 +SyS_sched_getaffinity_62786 SyS_sched_getaffinity 2 62786 NULL
120363 +dm_stats_account_io_62787 dm_stats_account_io 3 62787 NULL
120364 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
120365 +__rounddown_pow_of_two_62836 __rounddown_pow_of_two 0 62836 NULL
120366 +bio_get_nr_vecs_62838 bio_get_nr_vecs 0 62838 NULL
120367 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
120368 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
120369 +read_nic_io_dword_62859 read_nic_io_dword 0 62859 NULL
120370 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
120371 +aoechr_write_62883 aoechr_write 3 62883 NULL
120372 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
120373 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
120374 +getdqbuf_62908 getdqbuf 1 62908 NULL
120375 +ll_statahead_agl_seq_write_62928 ll_statahead_agl_seq_write 3 62928 NULL
120376 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
120377 +kstrtoull_from_user_63026 kstrtoull_from_user 2 63026 NULL
120378 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
120379 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
120380 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
120381 +unlink1_63059 unlink1 3 63059 NULL
120382 +xen_set_nslabs_63066 xen_set_nslabs 0 63066 NULL
120383 +iwl_dbgfs_fw_rx_stats_read_63070 iwl_dbgfs_fw_rx_stats_read 3 63070 NULL
120384 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5 63087 NULL
120385 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
120386 +ext4_chunk_trans_blocks_63123 ext4_chunk_trans_blocks 0-2 63123 NULL
120387 +snd_pcm_status_user_63140 snd_pcm_status_user 0 63140 NULL
120388 +ubifs_change_one_lp_63157 ubifs_change_one_lp 0 63157 NULL
120389 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
120390 +SyS_syslog_63178 SyS_syslog 3 63178 NULL
120391 +vme_master_read_63221 vme_master_read 0 63221 NULL
120392 +SyS_gethostname_63227 SyS_gethostname 2 63227 NULL
120393 +ptp_read_63251 ptp_read 4 63251 NULL
120394 +xfs_dir2_leaf_getdents_63262 xfs_dir2_leaf_getdents 3 63262 NULL
120395 +iwl_dbgfs_fw_error_dump_read_63263 iwl_dbgfs_fw_error_dump_read 3 63263 NULL
120396 +raid5_resize_63306 raid5_resize 2 63306 NULL
120397 +ath10k_read_fw_dbglog_63323 ath10k_read_fw_dbglog 3 63323 NULL
120398 +proc_info_read_63344 proc_info_read 3 63344 NULL
120399 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
120400 +idmouse_read_63374 idmouse_read 3 63374 NULL
120401 +usbnet_read_cmd_nopm_63388 usbnet_read_cmd_nopm 7 63388 NULL nohasharray
120402 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 &usbnet_read_cmd_nopm_63388
120403 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
120404 +nouveau_event_create_63411 nouveau_event_create 1 63411 NULL
120405 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
120406 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
120407 +si5351_bulk_write_63468 si5351_bulk_write 2-3 63468 NULL
120408 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
120409 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
120410 +read_kcore_63488 read_kcore 3 63488 NULL
120411 +iwl_dbgfs_bcast_filters_read_63489 iwl_dbgfs_bcast_filters_read 3 63489 NULL
120412 +snd_pcm_plug_write_transfer_63503 snd_pcm_plug_write_transfer 0-3 63503 NULL
120413 +efx_mcdi_rpc_async_63529 efx_mcdi_rpc_async 4-5 63529 NULL
120414 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL nohasharray
120415 +generic_cont_expand_simple_63534 generic_cont_expand_simple 0 63534 &ubi_more_leb_change_data_63534
120416 +write_file_spectral_period_63536 write_file_spectral_period 3 63536 NULL
120417 +if_sdio_read_scratch_63540 if_sdio_read_scratch 0 63540 NULL
120418 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
120419 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 NULL
120420 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
120421 +write_debug_level_63613 write_debug_level 3 63613 NULL
120422 +__spi_validate_63618 __spi_validate 0 63618 NULL
120423 +symbol_build_supp_rates_63634 symbol_build_supp_rates 0 63634 NULL
120424 +hid_report_len_63637 hid_report_len 0 63637 NULL
120425 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
120426 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
120427 +ldlm_cli_enqueue_63657 ldlm_cli_enqueue 8 63657 NULL
120428 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
120429 +vbi_read_63673 vbi_read 3 63673 NULL
120430 +write_file_spectral_fft_period_63696 write_file_spectral_fft_period 3 63696 NULL
120431 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
120432 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
120433 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
120434 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
120435 +snd_pcm_link_63772 snd_pcm_link 0 63772 NULL
120436 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
120437 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
120438 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
120439 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
120440 +C_SYSC_process_vm_readv_63811 C_SYSC_process_vm_readv 3-5 63811 NULL
120441 +regmap_multi_reg_write_63826 regmap_multi_reg_write 3 63826 NULL
120442 +sel_write_load_63830 sel_write_load 3 63830 NULL
120443 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
120444 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
120445 +uvc_alloc_urb_buffers_63922 uvc_alloc_urb_buffers 0-2-3 63922 NULL
120446 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
120447 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
120448 +__team_options_register_63941 __team_options_register 3 63941 NULL
120449 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
120450 +set_bredr_63975 set_bredr 4 63975 NULL
120451 +construct_key_and_link_63985 construct_key_and_link 3 63985 NULL
120452 +rs_extent_to_bm_page_63996 rs_extent_to_bm_page 0-1 63996 NULL
120453 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
120454 +SyS_rt_sigpending_64018 SyS_rt_sigpending 2 64018 NULL
120455 +dbAllocDmapLev_64030 dbAllocDmapLev 0 64030 NULL
120456 +SyS_fsetxattr_64039 SyS_fsetxattr 4 64039 NULL
120457 +get_u8_64076 get_u8 0 64076 NULL
120458 +xilly_malloc_64077 xilly_malloc 2 64077 NULL
120459 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
120460 +vmci_handle_arr_get_size_64088 vmci_handle_arr_get_size 0 64088 NULL
120461 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
120462 +SyS_set_mempolicy_64096 SyS_set_mempolicy 3 64096 NULL
120463 +to_bytes_64103 to_bytes 0-1 64103 NULL
120464 +SyS_mq_timedsend_64107 SyS_mq_timedsend 3 64107 NULL
120465 +rdma_addr_size_64116 rdma_addr_size 0 64116 NULL
120466 +do_load_xattr_datum_64118 do_load_xattr_datum 0 64118 NULL
120467 +bypass_wd_write_64120 bypass_wd_write 3 64120 NULL
120468 +ext4_prepare_inline_data_64124 ext4_prepare_inline_data 3 64124 NULL
120469 +init_bch_64130 init_bch 1-2 64130 NULL
120470 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
120471 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
120472 +bnx2x_vf_mcast_64166 bnx2x_vf_mcast 4 64166 NULL
120473 +cpumask_scnprintf_64170 cpumask_scnprintf 0-2 64170 NULL
120474 +kernfs_iop_setxattr_64220 kernfs_iop_setxattr 4 64220 NULL
120475 +xfs_vm_direct_IO_64223 xfs_vm_direct_IO 4 64223 NULL
120476 +read_pulse_64227 read_pulse 0-3 64227 NULL
120477 +ea_len_64229 ea_len 0 64229 NULL
120478 +io_capture_transfer_64276 io_capture_transfer 4 64276 NULL
120479 +btrfs_file_extent_offset_64278 btrfs_file_extent_offset 0 64278 NULL
120480 +sta_current_tx_rate_read_64286 sta_current_tx_rate_read 3 64286 NULL
120481 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 NULL nohasharray
120482 +event_id_read_64288 event_id_read 3 64288 &xfs_dir_cilookup_result_64288
120483 +ocfs2_block_check_validate_bhs_64302 ocfs2_block_check_validate_bhs 0 64302 NULL
120484 +snd_hda_get_sub_nodes_64304 snd_hda_get_sub_nodes 0 64304 NULL
120485 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
120486 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
120487 +ts_write_64336 ts_write 3 64336 NULL
120488 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
120489 +qlcnic_82xx_calculate_msix_vector_64354 qlcnic_82xx_calculate_msix_vector 0 64354 NULL
120490 +user_regset_copyin_64360 user_regset_copyin 7 64360 NULL
120491 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
120492 +reg_create_64372 reg_create 5 64372 NULL nohasharray
120493 +bnx2_enable_msix_64372 bnx2_enable_msix 2 64372 &reg_create_64372
120494 +ilo_write_64378 ilo_write 3 64378 NULL
120495 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
120496 +vmcs_readl_64381 vmcs_readl 0 64381 NULL
120497 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
120498 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
120499 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
120500 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
120501 +keyctl_get_security_64418 keyctl_get_security 3 64418 NULL
120502 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
120503 +read_file_spectral_short_repeat_64431 read_file_spectral_short_repeat 3 64431 NULL
120504 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
120505 +__i2c_add_numbered_adapter_64445 __i2c_add_numbered_adapter 0 64445 NULL
120506 +single_open_size_64483 single_open_size 4 64483 NULL
120507 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
120508 +msg_data_sz_64503 msg_data_sz 0 64503 NULL
120509 +remove_uuid_64505 remove_uuid 4 64505 NULL
120510 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
120511 +iwl_dbgfs_ucode_tracing_write_64524 iwl_dbgfs_ucode_tracing_write 3 64524 NULL
120512 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
120513 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
120514 +SyS_bind_64544 SyS_bind 3 64544 NULL
120515 +rbd_obj_read_sync_64554 rbd_obj_read_sync 3-4 64554 NULL
120516 +__btrfs_prealloc_file_range_64557 __btrfs_prealloc_file_range 3 64557 NULL
120517 +ll_max_rw_chunk_seq_write_64561 ll_max_rw_chunk_seq_write 3 64561 NULL nohasharray
120518 +__spi_sync_64561 __spi_sync 0 64561 &ll_max_rw_chunk_seq_write_64561
120519 +__apei_exec_run_64563 __apei_exec_run 0 64563 NULL
120520 +kstrtoul_from_user_64569 kstrtoul_from_user 2 64569 NULL
120521 +do_erase_64574 do_erase 4 64574 NULL
120522 +fanotify_write_64623 fanotify_write 3 64623 NULL
120523 +_iwl_dbgfs_d0i3_refs_write_64642 _iwl_dbgfs_d0i3_refs_write 3 64642 NULL
120524 +regmap_read_debugfs_64658 regmap_read_debugfs 5 64658 NULL
120525 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 NULL nohasharray
120526 +ocfs2_read_xattr_block_64661 ocfs2_read_xattr_block 0 64661 &tlbflush_read_file_64661
120527 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
120528 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
120529 +nr_free_zone_pages_64680 nr_free_zone_pages 0 64680 NULL
120530 +snd_pcm_oss_capture_position_fixup_64713 snd_pcm_oss_capture_position_fixup 0 64713 NULL
120531 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
120532 +atomic_add_return_64720 atomic_add_return 0-1 64720 NULL
120533 +i2400m_msg_to_dev_64722 i2400m_msg_to_dev 3 64722 NULL
120534 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
120535 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
120536 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
120537 +message_for_md_64777 message_for_md 5 64777 NULL
120538 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
120539 +regmap_reg_ranges_read_file_64798 regmap_reg_ranges_read_file 3 64798 NULL
120540 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
120541 +rfkill_fop_write_64808 rfkill_fop_write 3 64808 NULL
120542 +proc_projid_map_write_64810 proc_projid_map_write 3 64810 NULL
120543 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
120544 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
120545 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
120546 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
120547 +pci_vc_do_save_buffer_64876 pci_vc_do_save_buffer 0 64876 NULL
120548 +lprocfs_write_u64_helper_64880 lprocfs_write_u64_helper 2 64880 NULL
120549 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
120550 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL nohasharray
120551 +tipc_port_iovec_reject_64958 tipc_port_iovec_reject 4 64958 &ip_options_get_from_user_64958
120552 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
120553 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
120554 +crypto_ahash_digestsize_65014 crypto_ahash_digestsize 0 65014 NULL
120555 +insert_dent_65034 insert_dent 7 65034 NULL
120556 +snd_hda_get_pin_label_65035 snd_hda_get_pin_label 5 65035 NULL
120557 +ext4_ind_trans_blocks_65053 ext4_ind_trans_blocks 0-2 65053 NULL
120558 +pcibios_enable_device_65059 pcibios_enable_device 0 65059 NULL
120559 +make_idx_node_65068 make_idx_node 0 65068 NULL
120560 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
120561 +batadv_socket_write_65083 batadv_socket_write 3 65083 NULL
120562 +ocfs2_truncate_cluster_pages_65086 ocfs2_truncate_cluster_pages 2 65086 NULL
120563 +ath9k_dump_mci_btcoex_65090 ath9k_dump_mci_btcoex 3-0 65090 NULL
120564 +scsi_add_host_with_dma_65093 scsi_add_host_with_dma 0 65093 NULL
120565 +generic_ocp_write_65107 generic_ocp_write 4 65107 NULL
120566 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
120567 +print_endpoint_stat_65232 print_endpoint_stat 0-3-4 65232 NULL
120568 +whci_n_caps_65247 whci_n_caps 0 65247 NULL
120569 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
120570 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
120571 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
120572 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
120573 +get_var_len_65304 get_var_len 0 65304 NULL
120574 +unpack_array_65318 unpack_array 0 65318 NULL
120575 +pci_vpd_find_tag_65325 pci_vpd_find_tag 0-2 65325 NULL
120576 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
120577 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
120578 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
120579 +SyS_writev_65372 SyS_writev 3 65372 NULL
120580 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
120581 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
120582 +__read_vmcore_65402 __read_vmcore 2 65402 NULL
120583 +ocfs2_write_begin_nolock_65410 ocfs2_write_begin_nolock 3-4 65410 NULL
120584 +device_add_groups_65423 device_add_groups 0 65423 NULL
120585 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
120586 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
120587 +il_dbgfs_wd_timeout_write_65464 il_dbgfs_wd_timeout_write 3 65464 NULL
120588 +clear_user_65470 clear_user 2 65470 NULL
120589 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
120590 +lookup_inline_extent_backref_65493 lookup_inline_extent_backref 9 65493 NULL
120591 +nvme_trans_standard_inquiry_page_65526 nvme_trans_standard_inquiry_page 4 65526 NULL
120592 +tree_mod_log_eb_copy_65535 tree_mod_log_eb_copy 6 65535 NULL
120593 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
120594 new file mode 100644
120595 index 0000000..560cd7b
120596 --- /dev/null
120597 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
120598 @@ -0,0 +1,92 @@
120599 +spa_set_aux_vdevs_746 spa_set_aux_vdevs 3 746 NULL
120600 +zfs_lookup_2144 zfs_lookup 0 2144 NULL
120601 +mappedread_2627 mappedread 2 2627 NULL
120602 +vdev_disk_dio_alloc_2957 vdev_disk_dio_alloc 1 2957 NULL
120603 +nv_alloc_pushpage_spl_4286 nv_alloc_pushpage_spl 2 4286 NULL
120604 +zpl_xattr_get_4574 zpl_xattr_get 0 4574 NULL
120605 +sa_replace_all_by_template_5699 sa_replace_all_by_template 3 5699 NULL
120606 +dmu_write_6048 dmu_write 4-3 6048 NULL
120607 +dmu_buf_hold_array_6095 dmu_buf_hold_array 4-3 6095 NULL
120608 +update_pages_6225 update_pages 2-3 6225 NULL
120609 +bio_nr_pages_7117 bio_nr_pages 0-2 7117 NULL
120610 +dmu_buf_hold_array_by_bonus_8562 dmu_buf_hold_array_by_bonus 3-2 8562 NULL
120611 +zpios_dmu_write_8858 zpios_dmu_write 4-5 8858 NULL
120612 +ddi_copyout_9401 ddi_copyout 3 9401 NULL
120613 +avl_numnodes_12384 avl_numnodes 0 12384 NULL
120614 +dmu_write_uio_dnode_12473 dmu_write_uio_dnode 3 12473 NULL
120615 +dmu_xuio_init_12866 dmu_xuio_init 2 12866 NULL
120616 +zpl_read_common_14389 zpl_read_common 0 14389 NULL
120617 +dmu_snapshot_realname_14632 dmu_snapshot_realname 4 14632 NULL
120618 +kmem_alloc_debug_14852 kmem_alloc_debug 1 14852 NULL
120619 +kmalloc_node_nofail_15151 kmalloc_node_nofail 1 15151 NULL
120620 +dmu_write_uio_16351 dmu_write_uio 4 16351 NULL
120621 +zfs_log_write_16524 zfs_log_write 6-5 16524 NULL
120622 +sa_build_layouts_16910 sa_build_layouts 3 16910 NULL
120623 +dsl_dir_namelen_17053 dsl_dir_namelen 0 17053 NULL
120624 +kcopy_copy_to_user_17336 kcopy_copy_to_user 5 17336 NULL
120625 +sa_add_layout_entry_17507 sa_add_layout_entry 3 17507 NULL
120626 +sa_attr_table_setup_18029 sa_attr_table_setup 3 18029 NULL
120627 +uiocopy_18680 uiocopy 2 18680 NULL
120628 +dmu_buf_hold_array_by_dnode_19125 dmu_buf_hold_array_by_dnode 2-3 19125 NULL
120629 +zpl_acl_from_xattr_21141 zpl_acl_from_xattr 2 21141 NULL
120630 +dsl_pool_tx_assign_init_22518 dsl_pool_tx_assign_init 2 22518 NULL
120631 +nvlist_lookup_byte_array_22527 nvlist_lookup_byte_array 0 22527 NULL
120632 +sa_replace_all_by_template_locked_22533 sa_replace_all_by_template_locked 3 22533 NULL
120633 +tsd_hash_table_init_22559 tsd_hash_table_init 1 22559 NULL
120634 +spa_vdev_remove_aux_23966 spa_vdev_remove_aux 4 23966 NULL
120635 +zpl_xattr_acl_set_access_24129 zpl_xattr_acl_set_access 4 24129 NULL
120636 +dmu_assign_arcbuf_24622 dmu_assign_arcbuf 2 24622 NULL
120637 +zap_lookup_norm_25166 zap_lookup_norm 9 25166 NULL
120638 +dmu_prealloc_25456 dmu_prealloc 4-3 25456 NULL
120639 +kmalloc_nofail_26347 kmalloc_nofail 1 26347 NULL
120640 +zfsctl_snapshot_zpath_27578 zfsctl_snapshot_zpath 2 27578 NULL
120641 +zpios_dmu_read_30015 zpios_dmu_read 4-5 30015 NULL
120642 +splat_write_30943 splat_write 3 30943 NULL
120643 +zpl_xattr_get_sa_31183 zpl_xattr_get_sa 0 31183 NULL
120644 +dmu_read_uio_31467 dmu_read_uio 4 31467 NULL
120645 +zfs_replay_fuids_31479 zfs_replay_fuids 4 31479 NULL
120646 +spa_history_log_to_phys_31632 spa_history_log_to_phys 0-1 31632 NULL
120647 +__zpl_xattr_get_32601 __zpl_xattr_get 0 32601 NULL
120648 +proc_copyout_string_34049 proc_copyout_string 2 34049 NULL
120649 +nv_alloc_sleep_spl_34544 nv_alloc_sleep_spl 2 34544 NULL
120650 +nv_alloc_nosleep_spl_34761 nv_alloc_nosleep_spl 2 34761 NULL
120651 +zap_leaf_array_match_36922 zap_leaf_array_match 4 36922 NULL
120652 +copyinstr_36980 copyinstr 3 36980 NULL
120653 +zpl_xattr_acl_set_default_37864 zpl_xattr_acl_set_default 4 37864 NULL
120654 +splat_read_38116 splat_read 3 38116 NULL
120655 +sa_setup_38756 sa_setup 4 38756 NULL
120656 +vdev_disk_physio_39898 vdev_disk_physio 3 39898 NULL
120657 +arc_buf_size_39982 arc_buf_size 0 39982 NULL
120658 +kzalloc_nofail_40719 kzalloc_nofail 1 40719 NULL
120659 +fuidstr_to_sid_40777 fuidstr_to_sid 4 40777 NULL
120660 +vdev_raidz_matrix_reconstruct_40852 vdev_raidz_matrix_reconstruct 2-3 40852 NULL
120661 +sa_find_layout_40892 sa_find_layout 4 40892 NULL
120662 +zpl_xattr_get_dir_41918 zpl_xattr_get_dir 0 41918 NULL
120663 +zfs_sa_get_xattr_42600 zfs_sa_get_xattr 0 42600 NULL
120664 +zpl_xattr_acl_set_42808 zpl_xattr_acl_set 4 42808 NULL
120665 +xdr_dec_array_43091 xdr_dec_array 5 43091 NULL
120666 +dsl_dataset_namelen_43136 dsl_dataset_namelen 0 43136 NULL
120667 +kcopy_write_43683 kcopy_write 3 43683 NULL
120668 +uiomove_44355 uiomove 2 44355 NULL
120669 +dmu_read_44418 dmu_read 4-3 44418 NULL
120670 +ddi_copyin_44846 ddi_copyin 3 44846 NULL
120671 +kcopy_do_get_45061 kcopy_do_get 5 45061 NULL
120672 +copyin_45945 copyin 3 45945 NULL
120673 +zil_itx_create_46555 zil_itx_create 2 46555 NULL
120674 +dmu_write_uio_dbuf_48064 dmu_write_uio_dbuf 3 48064 NULL
120675 +blk_rq_pos_48233 blk_rq_pos 0 48233 NULL
120676 +spa_history_write_49650 spa_history_write 3 49650 NULL
120677 +kcopy_copy_pages_to_user_49823 kcopy_copy_pages_to_user 3-4 49823 NULL
120678 +zfs_log_write_50162 zfs_log_write 6-5 50162 NULL
120679 +i_fm_alloc_51038 i_fm_alloc 2 51038 NULL
120680 +copyout_51409 copyout 3 51409 NULL
120681 +zvol_log_write_54898 zvol_log_write 4-3 54898 NULL
120682 +zfs_acl_node_alloc_55641 zfs_acl_node_alloc 1 55641 NULL
120683 +get_nvlist_56685 get_nvlist 2 56685 NULL
120684 +zprop_get_numprops_56820 zprop_get_numprops 0 56820 NULL
120685 +splat_taskq_test4_common_59829 splat_taskq_test4_common 5 59829 NULL
120686 +zfs_replay_domain_cnt_61399 zfs_replay_domain_cnt 0 61399 NULL
120687 +zpios_write_61823 zpios_write 3 61823 NULL
120688 +proc_copyin_string_62019 proc_copyin_string 4 62019 NULL
120689 +random_get_pseudo_bytes_64611 random_get_pseudo_bytes 2 64611 NULL
120690 +zpios_read_64734 zpios_read 3 64734 NULL
120691 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
120692 new file mode 100644
120693 index 0000000..95f7abd
120694 --- /dev/null
120695 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
120696 @@ -0,0 +1,259 @@
120697 +/*
120698 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
120699 + * Licensed under the GPL v2, or (at your option) v3
120700 + *
120701 + * Homepage:
120702 + * http://www.grsecurity.net/~ephox/overflow_plugin/
120703 + *
120704 + * Documentation:
120705 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
120706 + *
120707 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
120708 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
120709 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
120710 + *
120711 + * Usage:
120712 + * $ make
120713 + * $ make run
120714 + */
120715 +
120716 +#include "gcc-common.h"
120717 +#include "size_overflow.h"
120718 +
120719 +int plugin_is_GPL_compatible;
120720 +
120721 +tree report_size_overflow_decl;
120722 +
120723 +tree size_overflow_type_HI;
120724 +tree size_overflow_type_SI;
120725 +tree size_overflow_type_DI;
120726 +tree size_overflow_type_TI;
120727 +
120728 +static struct plugin_info size_overflow_plugin_info = {
120729 + .version = "20140725",
120730 + .help = "no-size-overflow\tturn off size overflow checking\n",
120731 +};
120732 +
120733 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
120734 +{
120735 + unsigned int arg_count;
120736 + enum tree_code code = TREE_CODE(*node);
120737 +
120738 + switch (code) {
120739 + case FUNCTION_DECL:
120740 + arg_count = type_num_arguments(TREE_TYPE(*node));
120741 + break;
120742 + case FUNCTION_TYPE:
120743 + case METHOD_TYPE:
120744 + arg_count = type_num_arguments(*node);
120745 + break;
120746 + default:
120747 + *no_add_attrs = true;
120748 + error("%s: %qE attribute only applies to functions", __func__, name);
120749 + return NULL_TREE;
120750 + }
120751 +
120752 + for (; args; args = TREE_CHAIN(args)) {
120753 + tree position = TREE_VALUE(args);
120754 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
120755 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
120756 + *no_add_attrs = true;
120757 + }
120758 + }
120759 + return NULL_TREE;
120760 +}
120761 +
120762 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
120763 +{
120764 + unsigned int arg_count;
120765 + enum tree_code code = TREE_CODE(*node);
120766 +
120767 + switch (code) {
120768 + case FUNCTION_DECL:
120769 + arg_count = type_num_arguments(TREE_TYPE(*node));
120770 + break;
120771 + case FUNCTION_TYPE:
120772 + case METHOD_TYPE:
120773 + arg_count = type_num_arguments(*node);
120774 + break;
120775 + case FIELD_DECL:
120776 + return NULL_TREE;
120777 + default:
120778 + *no_add_attrs = true;
120779 + error("%qE attribute only applies to functions", name);
120780 + return NULL_TREE;
120781 + }
120782 +
120783 + if (TREE_INT_CST_HIGH(TREE_VALUE(args)) != 0)
120784 + return NULL_TREE;
120785 +
120786 + for (; args; args = TREE_CHAIN(args)) {
120787 + tree position = TREE_VALUE(args);
120788 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
120789 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
120790 + *no_add_attrs = true;
120791 + }
120792 + }
120793 + return NULL_TREE;
120794 +}
120795 +
120796 +static struct attribute_spec size_overflow_attr = {
120797 + .name = "size_overflow",
120798 + .min_length = 1,
120799 + .max_length = -1,
120800 + .decl_required = true,
120801 + .type_required = false,
120802 + .function_type_required = false,
120803 + .handler = handle_size_overflow_attribute,
120804 +#if BUILDING_GCC_VERSION >= 4007
120805 + .affects_type_identity = false
120806 +#endif
120807 +};
120808 +
120809 +static struct attribute_spec intentional_overflow_attr = {
120810 + .name = "intentional_overflow",
120811 + .min_length = 1,
120812 + .max_length = -1,
120813 + .decl_required = true,
120814 + .type_required = false,
120815 + .function_type_required = false,
120816 + .handler = handle_intentional_overflow_attribute,
120817 +#if BUILDING_GCC_VERSION >= 4007
120818 + .affects_type_identity = false
120819 +#endif
120820 +};
120821 +
120822 +static void register_attributes(void __unused *event_data, void __unused *data)
120823 +{
120824 + register_attribute(&size_overflow_attr);
120825 + register_attribute(&intentional_overflow_attr);
120826 +}
120827 +
120828 +static tree create_typedef(tree type, const char* ident)
120829 +{
120830 + tree new_type, decl;
120831 +
120832 + new_type = build_variant_type_copy(type);
120833 + decl = build_decl(BUILTINS_LOCATION, TYPE_DECL, get_identifier(ident), new_type);
120834 + DECL_ORIGINAL_TYPE(decl) = type;
120835 + TYPE_NAME(new_type) = decl;
120836 + return new_type;
120837 +}
120838 +
120839 +// Create the noreturn report_size_overflow() function decl.
120840 +static void size_overflow_start_unit(void __unused *gcc_data, void __unused *user_data)
120841 +{
120842 + tree const_char_ptr_type_node;
120843 + tree fntype;
120844 +
120845 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
120846 +
120847 + size_overflow_type_HI = create_typedef(intHI_type_node, "size_overflow_type_HI");
120848 + size_overflow_type_SI = create_typedef(intSI_type_node, "size_overflow_type_SI");
120849 + size_overflow_type_DI = create_typedef(intDI_type_node, "size_overflow_type_DI");
120850 + size_overflow_type_TI = create_typedef(intTI_type_node, "size_overflow_type_TI");
120851 +
120852 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
120853 + fntype = build_function_type_list(void_type_node,
120854 + const_char_ptr_type_node,
120855 + unsigned_type_node,
120856 + const_char_ptr_type_node,
120857 + const_char_ptr_type_node,
120858 + NULL_TREE);
120859 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
120860 +
120861 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
120862 + TREE_PUBLIC(report_size_overflow_decl) = 1;
120863 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
120864 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
120865 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
120866 +}
120867 +
120868 +
120869 +extern struct gimple_opt_pass pass_dce;
120870 +
120871 +static struct opt_pass *make_dce_pass(void)
120872 +{
120873 +#if BUILDING_GCC_VERSION >= 4009
120874 + return make_pass_dce(g);
120875 +#else
120876 + return &pass_dce.pass;
120877 +#endif
120878 +}
120879 +
120880 +
120881 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
120882 +{
120883 + int i;
120884 + const char * const plugin_name = plugin_info->base_name;
120885 + const int argc = plugin_info->argc;
120886 + const struct plugin_argument * const argv = plugin_info->argv;
120887 + bool enable = true;
120888 + struct register_pass_info insert_size_overflow_asm_pass_info;
120889 + struct register_pass_info __unused dump_before_pass_info;
120890 + struct register_pass_info __unused dump_after_pass_info;
120891 + struct register_pass_info insert_size_overflow_check_info;
120892 + struct register_pass_info dce_pass_info;
120893 + static const struct ggc_root_tab gt_ggc_r_gt_size_overflow[] = {
120894 + {
120895 + .base = &report_size_overflow_decl,
120896 + .nelt = 1,
120897 + .stride = sizeof(report_size_overflow_decl),
120898 + .cb = &gt_ggc_mx_tree_node,
120899 + .pchw = &gt_pch_nx_tree_node
120900 + },
120901 + LAST_GGC_ROOT_TAB
120902 + };
120903 +
120904 + insert_size_overflow_asm_pass_info.pass = make_insert_size_overflow_asm_pass();
120905 + insert_size_overflow_asm_pass_info.reference_pass_name = "ssa";
120906 + insert_size_overflow_asm_pass_info.ref_pass_instance_number = 1;
120907 + insert_size_overflow_asm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
120908 +
120909 + dump_before_pass_info.pass = make_dump_pass();
120910 + dump_before_pass_info.reference_pass_name = "increase_alignment";
120911 + dump_before_pass_info.ref_pass_instance_number = 1;
120912 + dump_before_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
120913 +
120914 + insert_size_overflow_check_info.pass = make_insert_size_overflow_check();
120915 + insert_size_overflow_check_info.reference_pass_name = "increase_alignment";
120916 + insert_size_overflow_check_info.ref_pass_instance_number = 1;
120917 + insert_size_overflow_check_info.pos_op = PASS_POS_INSERT_BEFORE;
120918 +
120919 + dump_after_pass_info.pass = make_dump_pass();
120920 + dump_after_pass_info.reference_pass_name = "increase_alignment";
120921 + dump_after_pass_info.ref_pass_instance_number = 1;
120922 + dump_after_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
120923 +
120924 + dce_pass_info.pass = make_dce_pass();
120925 + dce_pass_info.reference_pass_name = "vrp";
120926 + dce_pass_info.ref_pass_instance_number = 1;
120927 + dce_pass_info.pos_op = PASS_POS_INSERT_AFTER;
120928 +
120929 + if (!plugin_default_version_check(version, &gcc_version)) {
120930 + error(G_("incompatible gcc/plugin versions"));
120931 + return 1;
120932 + }
120933 +
120934 + for (i = 0; i < argc; ++i) {
120935 + if (!strcmp(argv[i].key, "no-size-overflow")) {
120936 + enable = false;
120937 + continue;
120938 + }
120939 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
120940 + }
120941 +
120942 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
120943 + if (enable) {
120944 + register_callback(plugin_name, PLUGIN_START_UNIT, &size_overflow_start_unit, NULL);
120945 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_size_overflow);
120946 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_asm_pass_info);
120947 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_before_pass_info);
120948 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_check_info);
120949 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_after_pass_info);
120950 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dce_pass_info);
120951 + }
120952 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
120953 +
120954 + return 0;
120955 +}
120956 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
120957 new file mode 100644
120958 index 0000000..0888f6c
120959 --- /dev/null
120960 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
120961 @@ -0,0 +1,364 @@
120962 +/*
120963 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
120964 + * Licensed under the GPL v2, or (at your option) v3
120965 + *
120966 + * Homepage:
120967 + * http://www.grsecurity.net/~ephox/overflow_plugin/
120968 + *
120969 + * Documentation:
120970 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
120971 + *
120972 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
120973 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
120974 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
120975 + *
120976 + * Usage:
120977 + * $ make
120978 + * $ make run
120979 + */
120980 +
120981 +#include "gcc-common.h"
120982 +#include "size_overflow.h"
120983 +
120984 +#include "size_overflow_hash.h"
120985 +#include "size_overflow_hash_aux.h"
120986 +
120987 +#define CODES_LIMIT 32
120988 +
120989 +static unsigned char get_tree_code(const_tree type)
120990 +{
120991 + switch (TREE_CODE(type)) {
120992 + case ARRAY_TYPE:
120993 + return 0;
120994 + case BOOLEAN_TYPE:
120995 + return 1;
120996 + case ENUMERAL_TYPE:
120997 + return 2;
120998 + case FUNCTION_TYPE:
120999 + return 3;
121000 + case INTEGER_TYPE:
121001 + return 4;
121002 + case POINTER_TYPE:
121003 + return 5;
121004 + case RECORD_TYPE:
121005 + return 6;
121006 + case UNION_TYPE:
121007 + return 7;
121008 + case VOID_TYPE:
121009 + return 8;
121010 + case REAL_TYPE:
121011 + return 9;
121012 + case VECTOR_TYPE:
121013 + return 10;
121014 + case REFERENCE_TYPE:
121015 + return 11;
121016 + case OFFSET_TYPE:
121017 + return 12;
121018 + case COMPLEX_TYPE:
121019 + return 13;
121020 + default:
121021 + debug_tree((tree)type);
121022 + gcc_unreachable();
121023 + }
121024 +}
121025 +
121026 +struct function_hash {
121027 + size_t tree_codes_len;
121028 + unsigned char tree_codes[CODES_LIMIT];
121029 + const_tree fndecl;
121030 + unsigned int hash;
121031 +};
121032 +
121033 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
121034 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
121035 +{
121036 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
121037 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
121038 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
121039 +
121040 + unsigned int m = 0x57559429;
121041 + unsigned int n = 0x5052acdb;
121042 + const unsigned int *key4 = (const unsigned int *)key;
121043 + unsigned int h = len;
121044 + unsigned int k = len + seed + n;
121045 + unsigned long long p;
121046 +
121047 + while (len >= 8) {
121048 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
121049 + len -= 8;
121050 + }
121051 + if (len >= 4) {
121052 + cwmixb(key4[0]) key4 += 1;
121053 + len -= 4;
121054 + }
121055 + if (len)
121056 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
121057 + cwmixb(h ^ (k + n));
121058 + return k ^ h;
121059 +
121060 +#undef cwfold
121061 +#undef cwmixa
121062 +#undef cwmixb
121063 +}
121064 +
121065 +static void set_hash(const char *fn_name, struct function_hash *fn_hash_data)
121066 +{
121067 + unsigned int fn, codes, seed = 0;
121068 +
121069 + fn = CrapWow(fn_name, strlen(fn_name), seed) & 0xffff;
121070 + codes = CrapWow((const char*)fn_hash_data->tree_codes, fn_hash_data->tree_codes_len, seed) & 0xffff;
121071 +
121072 + fn_hash_data->hash = fn ^ codes;
121073 +}
121074 +
121075 +static void set_node_codes(const_tree type, struct function_hash *fn_hash_data)
121076 +{
121077 + gcc_assert(type != NULL_TREE);
121078 + gcc_assert(TREE_CODE_CLASS(TREE_CODE(type)) == tcc_type);
121079 +
121080 + while (type && fn_hash_data->tree_codes_len < CODES_LIMIT) {
121081 + fn_hash_data->tree_codes[fn_hash_data->tree_codes_len] = get_tree_code(type);
121082 + fn_hash_data->tree_codes_len++;
121083 + type = TREE_TYPE(type);
121084 + }
121085 +}
121086 +
121087 +static void set_result_codes(const_tree node, struct function_hash *fn_hash_data)
121088 +{
121089 + const_tree result;
121090 +
121091 + gcc_assert(node != NULL_TREE);
121092 +
121093 + if (DECL_P(node)) {
121094 + result = DECL_RESULT(node);
121095 + if (result != NULL_TREE)
121096 + return set_node_codes(TREE_TYPE(result), fn_hash_data);
121097 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
121098 + }
121099 +
121100 + gcc_assert(TYPE_P(node));
121101 +
121102 + if (TREE_CODE(node) == FUNCTION_TYPE)
121103 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
121104 +
121105 + return set_node_codes(node, fn_hash_data);
121106 +}
121107 +
121108 +static void set_function_codes(struct function_hash *fn_hash_data)
121109 +{
121110 + const_tree arg, type = TREE_TYPE(fn_hash_data->fndecl);
121111 + enum tree_code code = TREE_CODE(type);
121112 +
121113 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
121114 +
121115 + set_result_codes(fn_hash_data->fndecl, fn_hash_data);
121116 +
121117 + for (arg = TYPE_ARG_TYPES(type); arg != NULL_TREE && fn_hash_data->tree_codes_len < CODES_LIMIT; arg = TREE_CHAIN(arg))
121118 + set_node_codes(TREE_VALUE(arg), fn_hash_data);
121119 +}
121120 +
121121 +static const struct size_overflow_hash *get_proper_hash_chain(const struct size_overflow_hash *entry, const char *func_name)
121122 +{
121123 + while (entry) {
121124 + if (!strcmp(entry->name, func_name))
121125 + return entry;
121126 + entry = entry->next;
121127 + }
121128 + return NULL;
121129 +}
121130 +
121131 +const struct size_overflow_hash *get_function_hash(const_tree fndecl)
121132 +{
121133 + const struct size_overflow_hash *entry;
121134 + struct function_hash fn_hash_data;
121135 + const char *func_name;
121136 +
121137 + // skip builtins __builtin_constant_p
121138 + if (DECL_BUILT_IN(fndecl))
121139 + return NULL;
121140 +
121141 + fn_hash_data.fndecl = fndecl;
121142 + fn_hash_data.tree_codes_len = 0;
121143 +
121144 + set_function_codes(&fn_hash_data);
121145 + gcc_assert(fn_hash_data.tree_codes_len != 0);
121146 +
121147 + func_name = DECL_NAME_POINTER(fn_hash_data.fndecl);
121148 + set_hash(func_name, &fn_hash_data);
121149 +
121150 + entry = size_overflow_hash[fn_hash_data.hash];
121151 + entry = get_proper_hash_chain(entry, func_name);
121152 + if (entry)
121153 + return entry;
121154 + entry = size_overflow_hash_aux[fn_hash_data.hash];
121155 + return get_proper_hash_chain(entry, func_name);
121156 +}
121157 +
121158 +static void print_missing_msg(const_tree func, unsigned int argnum)
121159 +{
121160 + location_t loc;
121161 + const char *curfunc;
121162 + struct function_hash fn_hash_data;
121163 +
121164 + fn_hash_data.fndecl = DECL_ORIGIN(func);
121165 + fn_hash_data.tree_codes_len = 0;
121166 +
121167 + loc = DECL_SOURCE_LOCATION(fn_hash_data.fndecl);
121168 + curfunc = DECL_NAME_POINTER(fn_hash_data.fndecl);
121169 +
121170 + set_function_codes(&fn_hash_data);
121171 + set_hash(curfunc, &fn_hash_data);
121172 +
121173 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, fn_hash_data.hash);
121174 +}
121175 +
121176 +unsigned int find_arg_number_tree(const_tree arg, const_tree func)
121177 +{
121178 + tree var;
121179 + unsigned int argnum = 1;
121180 +
121181 + if (TREE_CODE(arg) == SSA_NAME)
121182 + arg = SSA_NAME_VAR(arg);
121183 +
121184 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var), argnum++) {
121185 + if (!operand_equal_p(arg, var, 0) && strcmp(DECL_NAME_POINTER(var), DECL_NAME_POINTER(arg)))
121186 + continue;
121187 + if (!skip_types(var))
121188 + return argnum;
121189 + }
121190 +
121191 + return CANNOT_FIND_ARG;
121192 +}
121193 +
121194 +static const char *get_asm_string(const_gimple stmt)
121195 +{
121196 + if (!stmt)
121197 + return NULL;
121198 + if (gimple_code(stmt) != GIMPLE_ASM)
121199 + return NULL;
121200 +
121201 + return gimple_asm_string(stmt);
121202 +}
121203 +
121204 +bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt)
121205 +{
121206 + const char *str;
121207 +
121208 + str = get_asm_string(stmt);
121209 + if (!str)
121210 + return false;
121211 + return !strncmp(str, TURN_OFF_ASM_STR, sizeof(TURN_OFF_ASM_STR) - 1);
121212 +}
121213 +
121214 +bool is_size_overflow_intentional_asm_yes(const_gimple stmt)
121215 +{
121216 + const char *str;
121217 +
121218 + str = get_asm_string(stmt);
121219 + if (!str)
121220 + return false;
121221 + return !strncmp(str, YES_ASM_STR, sizeof(YES_ASM_STR) - 1);
121222 +}
121223 +
121224 +bool is_size_overflow_asm(const_gimple stmt)
121225 +{
121226 + const char *str;
121227 +
121228 + str = get_asm_string(stmt);
121229 + if (!str)
121230 + return false;
121231 + return !strncmp(str, OK_ASM_STR, sizeof(OK_ASM_STR) - 1);
121232 +}
121233 +
121234 +bool is_a_return_check(const_tree node)
121235 +{
121236 + if (TREE_CODE(node) == FUNCTION_DECL)
121237 + return true;
121238 +
121239 + gcc_assert(TREE_CODE(node) == PARM_DECL);
121240 + return false;
121241 +}
121242 +
121243 +// Get the argnum of a function decl, if node is a return then the argnum is 0
121244 +unsigned int get_function_num(const_tree node, const_tree orig_fndecl)
121245 +{
121246 + if (is_a_return_check(node))
121247 + return 0;
121248 + else
121249 + return find_arg_number_tree(node, orig_fndecl);
121250 +}
121251 +
121252 +unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl)
121253 +{
121254 + const struct size_overflow_hash *hash;
121255 + unsigned int new_argnum;
121256 + tree arg;
121257 + const_tree origarg;
121258 +
121259 + if (argnum == 0)
121260 + return argnum;
121261 +
121262 + hash = get_function_hash(fndecl);
121263 + if (hash && hash->param & (1U << argnum))
121264 + return argnum;
121265 +
121266 + if (DECL_EXTERNAL(fndecl))
121267 + return argnum;
121268 +
121269 + origarg = DECL_ARGUMENTS(DECL_ORIGIN(fndecl));
121270 + argnum--;
121271 + while (origarg && argnum) {
121272 + origarg = TREE_CHAIN(origarg);
121273 + argnum--;
121274 + }
121275 + gcc_assert(argnum == 0);
121276 + gcc_assert(origarg != NULL_TREE);
121277 +
121278 + for (arg = DECL_ARGUMENTS(fndecl), new_argnum = 1; arg; arg = TREE_CHAIN(arg), new_argnum++)
121279 + if (operand_equal_p(origarg, arg, 0) || !strcmp(DECL_NAME_POINTER(origarg), DECL_NAME_POINTER(arg)))
121280 + return new_argnum;
121281 +
121282 + return CANNOT_FIND_ARG;
121283 +}
121284 +
121285 +static bool is_in_hash_table(const_tree fndecl, unsigned int num)
121286 +{
121287 + const struct size_overflow_hash *hash;
121288 +
121289 + hash = get_function_hash(fndecl);
121290 + if (hash && (hash->param & (1U << num)))
121291 + return true;
121292 + return false;
121293 +}
121294 +
121295 +/* Check if the function has a size_overflow attribute or it is in the size_overflow hash table.
121296 + * If the function is missing everywhere then print the missing message into stderr.
121297 + */
121298 +bool is_missing_function(const_tree orig_fndecl, unsigned int num)
121299 +{
121300 + switch (DECL_FUNCTION_CODE(orig_fndecl)) {
121301 +#if BUILDING_GCC_VERSION >= 4008
121302 + case BUILT_IN_BSWAP16:
121303 +#endif
121304 + case BUILT_IN_BSWAP32:
121305 + case BUILT_IN_BSWAP64:
121306 + case BUILT_IN_EXPECT:
121307 + case BUILT_IN_MEMCMP:
121308 + return false;
121309 + default:
121310 + break;
121311 + }
121312 +
121313 + // skip test.c
121314 + if (strcmp(DECL_NAME_POINTER(current_function_decl), "coolmalloc")) {
121315 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(orig_fndecl)))
121316 + warning(0, "unnecessary size_overflow attribute on: %s\n", DECL_NAME_POINTER(orig_fndecl));
121317 + }
121318 +
121319 + if (is_in_hash_table(orig_fndecl, num))
121320 + return false;
121321 +
121322 + print_missing_msg(orig_fndecl, num);
121323 + return true;
121324 +}
121325 +
121326 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
121327 new file mode 100644
121328 index 0000000..924652b
121329 --- /dev/null
121330 +++ b/tools/gcc/stackleak_plugin.c
121331 @@ -0,0 +1,395 @@
121332 +/*
121333 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
121334 + * Licensed under the GPL v2
121335 + *
121336 + * Note: the choice of the license means that the compilation process is
121337 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
121338 + * but for the kernel it doesn't matter since it doesn't link against
121339 + * any of the gcc libraries
121340 + *
121341 + * gcc plugin to help implement various PaX features
121342 + *
121343 + * - track lowest stack pointer
121344 + *
121345 + * TODO:
121346 + * - initialize all local variables
121347 + *
121348 + * BUGS:
121349 + * - none known
121350 + */
121351 +
121352 +#include "gcc-common.h"
121353 +
121354 +int plugin_is_GPL_compatible;
121355 +
121356 +static int track_frame_size = -1;
121357 +static const char track_function[] = "pax_track_stack";
121358 +static const char check_function[] = "pax_check_alloca";
121359 +static tree track_function_decl, check_function_decl;
121360 +static bool init_locals;
121361 +
121362 +static struct plugin_info stackleak_plugin_info = {
121363 + .version = "201408011900",
121364 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
121365 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
121366 +};
121367 +
121368 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
121369 +{
121370 + gimple check_alloca;
121371 + tree alloca_size;
121372 +
121373 + // insert call to void pax_check_alloca(unsigned long size)
121374 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
121375 + check_alloca = gimple_build_call(check_function_decl, 1, alloca_size);
121376 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
121377 +}
121378 +
121379 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
121380 +{
121381 + gimple track_stack;
121382 +
121383 + // insert call to void pax_track_stack(void)
121384 + track_stack = gimple_build_call(track_function_decl, 0);
121385 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
121386 +}
121387 +
121388 +static bool is_alloca(gimple stmt)
121389 +{
121390 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
121391 + return true;
121392 +
121393 +#if BUILDING_GCC_VERSION >= 4007
121394 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
121395 + return true;
121396 +#endif
121397 +
121398 + return false;
121399 +}
121400 +
121401 +static unsigned int execute_stackleak_tree_instrument(void)
121402 +{
121403 + basic_block bb, entry_bb;
121404 + bool prologue_instrumented = false, is_leaf = true;
121405 +
121406 + entry_bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb;
121407 +
121408 + // 1. loop through BBs and GIMPLE statements
121409 + FOR_EACH_BB_FN(bb, cfun) {
121410 + gimple_stmt_iterator gsi;
121411 +
121412 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
121413 + gimple stmt;
121414 +
121415 + stmt = gsi_stmt(gsi);
121416 +
121417 + if (is_gimple_call(stmt))
121418 + is_leaf = false;
121419 +
121420 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
121421 + if (!is_alloca(stmt))
121422 + continue;
121423 +
121424 + // 2. insert stack overflow check before each __builtin_alloca call
121425 + stackleak_check_alloca(&gsi);
121426 +
121427 + // 3. insert track call after each __builtin_alloca call
121428 + stackleak_add_instrumentation(&gsi);
121429 + if (bb == entry_bb)
121430 + prologue_instrumented = true;
121431 + }
121432 + }
121433 +
121434 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
121435 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
121436 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
121437 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
121438 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
121439 + return 0;
121440 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
121441 + return 0;
121442 +
121443 + // 4. insert track call at the beginning
121444 + if (!prologue_instrumented) {
121445 + gimple_stmt_iterator gsi;
121446 +
121447 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
121448 + if (dom_info_available_p(CDI_DOMINATORS))
121449 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
121450 + gsi = gsi_start_bb(bb);
121451 + stackleak_add_instrumentation(&gsi);
121452 + }
121453 +
121454 + return 0;
121455 +}
121456 +
121457 +static unsigned int execute_stackleak_final(void)
121458 +{
121459 + rtx insn, next;
121460 +
121461 + if (cfun->calls_alloca)
121462 + return 0;
121463 +
121464 + // keep calls only if function frame is big enough
121465 + if (get_frame_size() >= track_frame_size)
121466 + return 0;
121467 +
121468 + // 1. find pax_track_stack calls
121469 + for (insn = get_insns(); insn; insn = next) {
121470 + // 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))
121471 + rtx body;
121472 +
121473 + next = NEXT_INSN(insn);
121474 + if (!CALL_P(insn))
121475 + continue;
121476 + body = PATTERN(insn);
121477 + if (GET_CODE(body) != CALL)
121478 + continue;
121479 + body = XEXP(body, 0);
121480 + if (GET_CODE(body) != MEM)
121481 + continue;
121482 + body = XEXP(body, 0);
121483 + if (GET_CODE(body) != SYMBOL_REF)
121484 + continue;
121485 +// if (strcmp(XSTR(body, 0), track_function))
121486 + if (SYMBOL_REF_DECL(body) != track_function_decl)
121487 + continue;
121488 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
121489 + // 2. delete call
121490 + delete_insn_and_edges(insn);
121491 +#if BUILDING_GCC_VERSION >= 4007
121492 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
121493 + insn = next;
121494 + next = NEXT_INSN(insn);
121495 + delete_insn_and_edges(insn);
121496 + }
121497 +#endif
121498 + }
121499 +
121500 +// print_simple_rtl(stderr, get_insns());
121501 +// print_rtl(stderr, get_insns());
121502 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
121503 +
121504 + return 0;
121505 +}
121506 +
121507 +static bool gate_stackleak_track_stack(void)
121508 +{
121509 + tree section;
121510 +
121511 + if (ix86_cmodel != CM_KERNEL)
121512 + return false;
121513 +
121514 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
121515 + if (section && TREE_VALUE(section)) {
121516 + section = TREE_VALUE(TREE_VALUE(section));
121517 +
121518 + if (!strncmp(TREE_STRING_POINTER(section), ".init.text", 10))
121519 + return false;
121520 + if (!strncmp(TREE_STRING_POINTER(section), ".devinit.text", 13))
121521 + return false;
121522 + if (!strncmp(TREE_STRING_POINTER(section), ".cpuinit.text", 13))
121523 + return false;
121524 + if (!strncmp(TREE_STRING_POINTER(section), ".meminit.text", 13))
121525 + return false;
121526 + }
121527 +
121528 + return track_frame_size >= 0;
121529 +}
121530 +
121531 +static void stackleak_start_unit(void *gcc_data, void *user_data)
121532 +{
121533 + tree fntype;
121534 +
121535 + // void pax_track_stack(void)
121536 + fntype = build_function_type_list(void_type_node, NULL_TREE);
121537 + track_function_decl = build_fn_decl(track_function, fntype);
121538 + DECL_ASSEMBLER_NAME(track_function_decl); // for LTO
121539 + TREE_PUBLIC(track_function_decl) = 1;
121540 + DECL_EXTERNAL(track_function_decl) = 1;
121541 + DECL_ARTIFICIAL(track_function_decl) = 1;
121542 +
121543 + // void pax_check_alloca(unsigned long)
121544 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
121545 + check_function_decl = build_fn_decl(check_function, fntype);
121546 + DECL_ASSEMBLER_NAME(check_function_decl); // for LTO
121547 + TREE_PUBLIC(check_function_decl) = 1;
121548 + DECL_EXTERNAL(check_function_decl) = 1;
121549 + DECL_ARTIFICIAL(check_function_decl) = 1;
121550 +}
121551 +
121552 +#if BUILDING_GCC_VERSION >= 4009
121553 +static const struct pass_data stackleak_tree_instrument_pass_data = {
121554 +#else
121555 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
121556 + .pass = {
121557 +#endif
121558 + .type = GIMPLE_PASS,
121559 + .name = "stackleak_tree_instrument",
121560 +#if BUILDING_GCC_VERSION >= 4008
121561 + .optinfo_flags = OPTGROUP_NONE,
121562 +#endif
121563 +#if BUILDING_GCC_VERSION >= 4009
121564 + .has_gate = true,
121565 + .has_execute = true,
121566 +#else
121567 + .gate = gate_stackleak_track_stack,
121568 + .execute = execute_stackleak_tree_instrument,
121569 + .sub = NULL,
121570 + .next = NULL,
121571 + .static_pass_number = 0,
121572 +#endif
121573 + .tv_id = TV_NONE,
121574 + .properties_required = PROP_gimple_leh | PROP_cfg,
121575 + .properties_provided = 0,
121576 + .properties_destroyed = 0,
121577 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
121578 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa | TODO_rebuild_cgraph_edges
121579 +#if BUILDING_GCC_VERSION < 4009
121580 + }
121581 +#endif
121582 +};
121583 +
121584 +#if BUILDING_GCC_VERSION >= 4009
121585 +static const struct pass_data stackleak_final_rtl_opt_pass_data = {
121586 +#else
121587 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
121588 + .pass = {
121589 +#endif
121590 + .type = RTL_PASS,
121591 + .name = "stackleak_final",
121592 +#if BUILDING_GCC_VERSION >= 4008
121593 + .optinfo_flags = OPTGROUP_NONE,
121594 +#endif
121595 +#if BUILDING_GCC_VERSION >= 4009
121596 + .has_gate = true,
121597 + .has_execute = true,
121598 +#else
121599 + .gate = gate_stackleak_track_stack,
121600 + .execute = execute_stackleak_final,
121601 + .sub = NULL,
121602 + .next = NULL,
121603 + .static_pass_number = 0,
121604 +#endif
121605 + .tv_id = TV_NONE,
121606 + .properties_required = 0,
121607 + .properties_provided = 0,
121608 + .properties_destroyed = 0,
121609 + .todo_flags_start = 0,
121610 + .todo_flags_finish = TODO_dump_func
121611 +#if BUILDING_GCC_VERSION < 4009
121612 + }
121613 +#endif
121614 +};
121615 +
121616 +#if BUILDING_GCC_VERSION >= 4009
121617 +namespace {
121618 +class stackleak_tree_instrument_pass : public gimple_opt_pass {
121619 +public:
121620 + stackleak_tree_instrument_pass() : gimple_opt_pass(stackleak_tree_instrument_pass_data, g) {}
121621 + bool gate() { return gate_stackleak_track_stack(); }
121622 + unsigned int execute() { return execute_stackleak_tree_instrument(); }
121623 +};
121624 +
121625 +class stackleak_final_rtl_opt_pass : public rtl_opt_pass {
121626 +public:
121627 + stackleak_final_rtl_opt_pass() : rtl_opt_pass(stackleak_final_rtl_opt_pass_data, g) {}
121628 + bool gate() { return gate_stackleak_track_stack(); }
121629 + unsigned int execute() { return execute_stackleak_final(); }
121630 +};
121631 +}
121632 +
121633 +static opt_pass *make_stackleak_tree_instrument_pass(void)
121634 +{
121635 + return new stackleak_tree_instrument_pass();
121636 +}
121637 +
121638 +static opt_pass *make_stackleak_final_rtl_opt_pass(void)
121639 +{
121640 + return new stackleak_final_rtl_opt_pass();
121641 +}
121642 +#else
121643 +static struct opt_pass *make_stackleak_tree_instrument_pass(void)
121644 +{
121645 + return &stackleak_tree_instrument_pass.pass;
121646 +}
121647 +
121648 +static struct opt_pass *make_stackleak_final_rtl_opt_pass(void)
121649 +{
121650 + return &stackleak_final_rtl_opt_pass.pass;
121651 +}
121652 +#endif
121653 +
121654 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
121655 +{
121656 + const char * const plugin_name = plugin_info->base_name;
121657 + const int argc = plugin_info->argc;
121658 + const struct plugin_argument * const argv = plugin_info->argv;
121659 + int i;
121660 + struct register_pass_info stackleak_tree_instrument_pass_info;
121661 + struct register_pass_info stackleak_final_pass_info;
121662 + static const struct ggc_root_tab gt_ggc_r_gt_stackleak[] = {
121663 + {
121664 + .base = &track_function_decl,
121665 + .nelt = 1,
121666 + .stride = sizeof(track_function_decl),
121667 + .cb = &gt_ggc_mx_tree_node,
121668 + .pchw = &gt_pch_nx_tree_node
121669 + },
121670 + {
121671 + .base = &check_function_decl,
121672 + .nelt = 1,
121673 + .stride = sizeof(check_function_decl),
121674 + .cb = &gt_ggc_mx_tree_node,
121675 + .pchw = &gt_pch_nx_tree_node
121676 + },
121677 + LAST_GGC_ROOT_TAB
121678 + };
121679 +
121680 + stackleak_tree_instrument_pass_info.pass = make_stackleak_tree_instrument_pass();
121681 +// stackleak_tree_instrument_pass_info.reference_pass_name = "tree_profile";
121682 + stackleak_tree_instrument_pass_info.reference_pass_name = "optimized";
121683 + stackleak_tree_instrument_pass_info.ref_pass_instance_number = 1;
121684 + stackleak_tree_instrument_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
121685 +
121686 + stackleak_final_pass_info.pass = make_stackleak_final_rtl_opt_pass();
121687 + stackleak_final_pass_info.reference_pass_name = "final";
121688 + stackleak_final_pass_info.ref_pass_instance_number = 1;
121689 + stackleak_final_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
121690 +
121691 + if (!plugin_default_version_check(version, &gcc_version)) {
121692 + error(G_("incompatible gcc/plugin versions"));
121693 + return 1;
121694 + }
121695 +
121696 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
121697 +
121698 + for (i = 0; i < argc; ++i) {
121699 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
121700 + if (!argv[i].value) {
121701 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
121702 + continue;
121703 + }
121704 + track_frame_size = atoi(argv[i].value);
121705 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
121706 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
121707 + continue;
121708 + }
121709 + if (!strcmp(argv[i].key, "initialize-locals")) {
121710 + if (argv[i].value) {
121711 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
121712 + continue;
121713 + }
121714 + init_locals = true;
121715 + continue;
121716 + }
121717 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
121718 + }
121719 +
121720 + register_callback(plugin_name, PLUGIN_START_UNIT, &stackleak_start_unit, NULL);
121721 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_stackleak);
121722 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
121723 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
121724 +
121725 + return 0;
121726 +}
121727 diff --git a/tools/gcc/structleak_plugin.c b/tools/gcc/structleak_plugin.c
121728 new file mode 100644
121729 index 0000000..4ee2231
121730 --- /dev/null
121731 +++ b/tools/gcc/structleak_plugin.c
121732 @@ -0,0 +1,274 @@
121733 +/*
121734 + * Copyright 2013-2014 by PaX Team <pageexec@freemail.hu>
121735 + * Licensed under the GPL v2
121736 + *
121737 + * Note: the choice of the license means that the compilation process is
121738 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
121739 + * but for the kernel it doesn't matter since it doesn't link against
121740 + * any of the gcc libraries
121741 + *
121742 + * gcc plugin to forcibly initialize certain local variables that could
121743 + * otherwise leak kernel stack to userland if they aren't properly initialized
121744 + * by later code
121745 + *
121746 + * Homepage: http://pax.grsecurity.net/
121747 + *
121748 + * Usage:
121749 + * $ # for 4.5/4.6/C based 4.7
121750 + * $ 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
121751 + * $ # for C++ based 4.7/4.8+
121752 + * $ 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
121753 + * $ gcc -fplugin=./structleak_plugin.so test.c -O2
121754 + *
121755 + * TODO: eliminate redundant initializers
121756 + * increase type coverage
121757 + */
121758 +
121759 +#include "gcc-common.h"
121760 +
121761 +// unused C type flag in all versions 4.5-4.9
121762 +#define TYPE_USERSPACE(TYPE) TYPE_LANG_FLAG_3(TYPE)
121763 +
121764 +int plugin_is_GPL_compatible;
121765 +
121766 +static struct plugin_info structleak_plugin_info = {
121767 + .version = "201401260140",
121768 + .help = "disable\tdo not activate plugin\n",
121769 +};
121770 +
121771 +static tree handle_user_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
121772 +{
121773 + *no_add_attrs = true;
121774 +
121775 + // check for types? for now accept everything linux has to offer
121776 + if (TREE_CODE(*node) != FIELD_DECL)
121777 + return NULL_TREE;
121778 +
121779 + *no_add_attrs = false;
121780 + return NULL_TREE;
121781 +}
121782 +
121783 +static struct attribute_spec user_attr = {
121784 + .name = "user",
121785 + .min_length = 0,
121786 + .max_length = 0,
121787 + .decl_required = false,
121788 + .type_required = false,
121789 + .function_type_required = false,
121790 + .handler = handle_user_attribute,
121791 +#if BUILDING_GCC_VERSION >= 4007
121792 + .affects_type_identity = true
121793 +#endif
121794 +};
121795 +
121796 +static void register_attributes(void *event_data, void *data)
121797 +{
121798 + register_attribute(&user_attr);
121799 +// register_attribute(&force_attr);
121800 +}
121801 +
121802 +static tree get_field_type(tree field)
121803 +{
121804 + return strip_array_types(TREE_TYPE(field));
121805 +}
121806 +
121807 +static bool is_userspace_type(tree type)
121808 +{
121809 + tree field;
121810 +
121811 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
121812 + tree fieldtype = get_field_type(field);
121813 + enum tree_code code = TREE_CODE(fieldtype);
121814 +
121815 + if (code == RECORD_TYPE || code == UNION_TYPE)
121816 + if (is_userspace_type(fieldtype))
121817 + return true;
121818 +
121819 + if (lookup_attribute("user", DECL_ATTRIBUTES(field)))
121820 + return true;
121821 + }
121822 + return false;
121823 +}
121824 +
121825 +static void finish_type(void *event_data, void *data)
121826 +{
121827 + tree type = (tree)event_data;
121828 +
121829 + if (TYPE_USERSPACE(type))
121830 + return;
121831 +
121832 + if (is_userspace_type(type))
121833 + TYPE_USERSPACE(type) = 1;
121834 +}
121835 +
121836 +static void initialize(tree var)
121837 +{
121838 + basic_block bb;
121839 + gimple_stmt_iterator gsi;
121840 + tree initializer;
121841 + gimple init_stmt;
121842 +
121843 + // this is the original entry bb before the forced split
121844 + // TODO: check further BBs in case more splits occured before us
121845 + bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb->next_bb;
121846 +
121847 + // first check if the variable is already initialized, warn otherwise
121848 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
121849 + gimple stmt = gsi_stmt(gsi);
121850 + tree rhs1;
121851 +
121852 + // we're looking for an assignment of a single rhs...
121853 + if (!gimple_assign_single_p(stmt))
121854 + continue;
121855 + rhs1 = gimple_assign_rhs1(stmt);
121856 +#if BUILDING_GCC_VERSION >= 4007
121857 + // ... of a non-clobbering expression...
121858 + if (TREE_CLOBBER_P(rhs1))
121859 + continue;
121860 +#endif
121861 + // ... to our variable...
121862 + if (gimple_get_lhs(stmt) != var)
121863 + continue;
121864 + // if it's an initializer then we're good
121865 + if (TREE_CODE(rhs1) == CONSTRUCTOR)
121866 + return;
121867 + }
121868 +
121869 + // these aren't the 0days you're looking for
121870 +// inform(DECL_SOURCE_LOCATION(var), "userspace variable will be forcibly initialized");
121871 +
121872 + // build the initializer expression
121873 + initializer = build_constructor(TREE_TYPE(var), NULL);
121874 +
121875 + // build the initializer stmt
121876 + init_stmt = gimple_build_assign(var, initializer);
121877 + gsi = gsi_start_bb(ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb);
121878 + gsi_insert_before(&gsi, init_stmt, GSI_NEW_STMT);
121879 + update_stmt(init_stmt);
121880 +}
121881 +
121882 +static unsigned int handle_function(void)
121883 +{
121884 + basic_block bb;
121885 + unsigned int ret = 0;
121886 + tree var;
121887 + unsigned int i;
121888 +
121889 + // split the first bb where we can put the forced initializers
121890 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
121891 + if (dom_info_available_p(CDI_DOMINATORS))
121892 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
121893 +
121894 + // enumarate all local variables and forcibly initialize our targets
121895 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
121896 + tree type = TREE_TYPE(var);
121897 +
121898 + gcc_assert(DECL_P(var));
121899 + if (!auto_var_in_fn_p(var, current_function_decl))
121900 + continue;
121901 +
121902 + // only care about structure types
121903 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
121904 + continue;
121905 +
121906 + // if the type is of interest, examine the variable
121907 + if (TYPE_USERSPACE(type))
121908 + initialize(var);
121909 + }
121910 +
121911 + return ret;
121912 +}
121913 +
121914 +#if BUILDING_GCC_VERSION >= 4009
121915 +static const struct pass_data structleak_pass_data = {
121916 +#else
121917 +static struct gimple_opt_pass structleak_pass = {
121918 + .pass = {
121919 +#endif
121920 + .type = GIMPLE_PASS,
121921 + .name = "structleak",
121922 +#if BUILDING_GCC_VERSION >= 4008
121923 + .optinfo_flags = OPTGROUP_NONE,
121924 +#endif
121925 +#if BUILDING_GCC_VERSION >= 4009
121926 + .has_gate = false,
121927 + .has_execute = true,
121928 +#else
121929 + .gate = NULL,
121930 + .execute = handle_function,
121931 + .sub = NULL,
121932 + .next = NULL,
121933 + .static_pass_number = 0,
121934 +#endif
121935 + .tv_id = TV_NONE,
121936 + .properties_required = PROP_cfg,
121937 + .properties_provided = 0,
121938 + .properties_destroyed = 0,
121939 + .todo_flags_start = 0,
121940 + .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
121941 +#if BUILDING_GCC_VERSION < 4009
121942 + }
121943 +#endif
121944 +};
121945 +
121946 +#if BUILDING_GCC_VERSION >= 4009
121947 +namespace {
121948 +class structleak_pass : public gimple_opt_pass {
121949 +public:
121950 + structleak_pass() : gimple_opt_pass(structleak_pass_data, g) {}
121951 + unsigned int execute() { return handle_function(); }
121952 +};
121953 +}
121954 +
121955 +static opt_pass *make_structleak_pass(void)
121956 +{
121957 + return new structleak_pass();
121958 +}
121959 +#else
121960 +static struct opt_pass *make_structleak_pass(void)
121961 +{
121962 + return &structleak_pass.pass;
121963 +}
121964 +#endif
121965 +
121966 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
121967 +{
121968 + int i;
121969 + const char * const plugin_name = plugin_info->base_name;
121970 + const int argc = plugin_info->argc;
121971 + const struct plugin_argument * const argv = plugin_info->argv;
121972 + bool enable = true;
121973 + struct register_pass_info structleak_pass_info;
121974 +
121975 + structleak_pass_info.pass = make_structleak_pass();
121976 + structleak_pass_info.reference_pass_name = "ssa";
121977 + structleak_pass_info.ref_pass_instance_number = 1;
121978 + structleak_pass_info.pos_op = PASS_POS_INSERT_AFTER;
121979 +
121980 + if (!plugin_default_version_check(version, &gcc_version)) {
121981 + error(G_("incompatible gcc/plugin versions"));
121982 + return 1;
121983 + }
121984 +
121985 + if (strcmp(lang_hooks.name, "GNU C")) {
121986 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
121987 + enable = false;
121988 + }
121989 +
121990 + for (i = 0; i < argc; ++i) {
121991 + if (!strcmp(argv[i].key, "disable")) {
121992 + enable = false;
121993 + continue;
121994 + }
121995 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
121996 + }
121997 +
121998 + register_callback(plugin_name, PLUGIN_INFO, NULL, &structleak_plugin_info);
121999 + if (enable) {
122000 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &structleak_pass_info);
122001 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
122002 + }
122003 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
122004 +
122005 + return 0;
122006 +}
122007 diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h
122008 index fbc6665..5e9ce79 100644
122009 --- a/tools/include/linux/compiler.h
122010 +++ b/tools/include/linux/compiler.h
122011 @@ -35,4 +35,12 @@
122012 # define unlikely(x) __builtin_expect(!!(x), 0)
122013 #endif
122014
122015 +#ifndef __size_overflow
122016 +# define __size_overflow(...)
122017 +#endif
122018 +
122019 +#ifndef __intentional_overflow
122020 +# define __intentional_overflow(...)
122021 +#endif
122022 +
122023 #endif /* _TOOLS_LINUX_COMPILER_H */
122024 diff --git a/tools/lib/api/Makefile b/tools/lib/api/Makefile
122025 index ce00f7e..0aca5e4 100644
122026 --- a/tools/lib/api/Makefile
122027 +++ b/tools/lib/api/Makefile
122028 @@ -16,7 +16,7 @@ LIB_OBJS += $(OUTPUT)fs/fs.o
122029
122030 LIBFILE = libapikfs.a
122031
122032 -CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
122033 +CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
122034 EXTLIBS = -lelf -lpthread -lrt -lm
122035 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
122036 ALL_LDFLAGS = $(LDFLAGS)
122037 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
122038 index 6789d788..4afd019e 100644
122039 --- a/tools/perf/util/include/asm/alternative-asm.h
122040 +++ b/tools/perf/util/include/asm/alternative-asm.h
122041 @@ -5,4 +5,7 @@
122042
122043 #define altinstruction_entry #
122044
122045 + .macro pax_force_retaddr rip=0, reload=0
122046 + .endm
122047 +
122048 #endif
122049 diff --git a/tools/virtio/linux/uaccess.h b/tools/virtio/linux/uaccess.h
122050 index 0a578fe..b81f62d 100644
122051 --- a/tools/virtio/linux/uaccess.h
122052 +++ b/tools/virtio/linux/uaccess.h
122053 @@ -13,7 +13,7 @@ static inline void __chk_user_ptr(const volatile void *p, size_t size)
122054 ({ \
122055 typeof(ptr) __pu_ptr = (ptr); \
122056 __chk_user_ptr(__pu_ptr, sizeof(*__pu_ptr)); \
122057 - ACCESS_ONCE(*(__pu_ptr)) = x; \
122058 + ACCESS_ONCE_RW(*(__pu_ptr)) = x; \
122059 0; \
122060 })
122061
122062 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
122063 index 56baae8..2c889c2 100644
122064 --- a/virt/kvm/kvm_main.c
122065 +++ b/virt/kvm/kvm_main.c
122066 @@ -76,12 +76,17 @@ LIST_HEAD(vm_list);
122067
122068 static cpumask_var_t cpus_hardware_enabled;
122069 static int kvm_usage_count = 0;
122070 -static atomic_t hardware_enable_failed;
122071 +static atomic_unchecked_t hardware_enable_failed;
122072
122073 struct kmem_cache *kvm_vcpu_cache;
122074 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
122075
122076 -static __read_mostly struct preempt_ops kvm_preempt_ops;
122077 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
122078 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
122079 +static struct preempt_ops kvm_preempt_ops = {
122080 + .sched_in = kvm_sched_in,
122081 + .sched_out = kvm_sched_out,
122082 +};
122083
122084 struct dentry *kvm_debugfs_dir;
122085
122086 @@ -755,7 +760,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
122087 /* We can read the guest memory with __xxx_user() later on. */
122088 if ((mem->slot < KVM_USER_MEM_SLOTS) &&
122089 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
122090 - !access_ok(VERIFY_WRITE,
122091 + !access_ok_noprefault(VERIFY_WRITE,
122092 (void __user *)(unsigned long)mem->userspace_addr,
122093 mem->memory_size)))
122094 goto out;
122095 @@ -1612,9 +1617,17 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_cached);
122096
122097 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len)
122098 {
122099 - const void *zero_page = (const void *) __va(page_to_phys(ZERO_PAGE(0)));
122100 + int r;
122101 + unsigned long addr;
122102
122103 - return kvm_write_guest_page(kvm, gfn, zero_page, offset, len);
122104 + addr = gfn_to_hva(kvm, gfn);
122105 + if (kvm_is_error_hva(addr))
122106 + return -EFAULT;
122107 + r = __clear_user((void __user *)addr + offset, len);
122108 + if (r)
122109 + return -EFAULT;
122110 + mark_page_dirty(kvm, gfn);
122111 + return 0;
122112 }
122113 EXPORT_SYMBOL_GPL(kvm_clear_guest_page);
122114
122115 @@ -1864,7 +1877,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
122116 return 0;
122117 }
122118
122119 -static struct file_operations kvm_vcpu_fops = {
122120 +static file_operations_no_const kvm_vcpu_fops __read_only = {
122121 .release = kvm_vcpu_release,
122122 .unlocked_ioctl = kvm_vcpu_ioctl,
122123 #ifdef CONFIG_COMPAT
122124 @@ -2534,7 +2547,7 @@ out:
122125 }
122126 #endif
122127
122128 -static struct file_operations kvm_vm_fops = {
122129 +static file_operations_no_const kvm_vm_fops __read_only = {
122130 .release = kvm_vm_release,
122131 .unlocked_ioctl = kvm_vm_ioctl,
122132 #ifdef CONFIG_COMPAT
122133 @@ -2634,7 +2647,7 @@ out:
122134 return r;
122135 }
122136
122137 -static struct file_operations kvm_chardev_ops = {
122138 +static file_operations_no_const kvm_chardev_ops __read_only = {
122139 .unlocked_ioctl = kvm_dev_ioctl,
122140 .compat_ioctl = kvm_dev_ioctl,
122141 .llseek = noop_llseek,
122142 @@ -2660,7 +2673,7 @@ static void hardware_enable_nolock(void *junk)
122143
122144 if (r) {
122145 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
122146 - atomic_inc(&hardware_enable_failed);
122147 + atomic_inc_unchecked(&hardware_enable_failed);
122148 printk(KERN_INFO "kvm: enabling virtualization on "
122149 "CPU%d failed\n", cpu);
122150 }
122151 @@ -2716,10 +2729,10 @@ static int hardware_enable_all(void)
122152
122153 kvm_usage_count++;
122154 if (kvm_usage_count == 1) {
122155 - atomic_set(&hardware_enable_failed, 0);
122156 + atomic_set_unchecked(&hardware_enable_failed, 0);
122157 on_each_cpu(hardware_enable_nolock, NULL, 1);
122158
122159 - if (atomic_read(&hardware_enable_failed)) {
122160 + if (atomic_read_unchecked(&hardware_enable_failed)) {
122161 hardware_disable_all_nolock();
122162 r = -EBUSY;
122163 }
122164 @@ -3123,7 +3136,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
122165 kvm_arch_vcpu_put(vcpu);
122166 }
122167
122168 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
122169 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
122170 struct module *module)
122171 {
122172 int r;
122173 @@ -3170,7 +3183,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
122174 if (!vcpu_align)
122175 vcpu_align = __alignof__(struct kvm_vcpu);
122176 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
122177 - 0, NULL);
122178 + SLAB_USERCOPY, NULL);
122179 if (!kvm_vcpu_cache) {
122180 r = -ENOMEM;
122181 goto out_free_3;
122182 @@ -3180,9 +3193,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
122183 if (r)
122184 goto out_free;
122185
122186 + pax_open_kernel();
122187 kvm_chardev_ops.owner = module;
122188 kvm_vm_fops.owner = module;
122189 kvm_vcpu_fops.owner = module;
122190 + pax_close_kernel();
122191
122192 r = misc_register(&kvm_dev);
122193 if (r) {
122194 @@ -3192,9 +3207,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
122195
122196 register_syscore_ops(&kvm_syscore_ops);
122197
122198 - kvm_preempt_ops.sched_in = kvm_sched_in;
122199 - kvm_preempt_ops.sched_out = kvm_sched_out;
122200 -
122201 r = kvm_init_debug();
122202 if (r) {
122203 printk(KERN_ERR "kvm: create debugfs files failed\n");